Skip to content

Conversation

@synthfi
Copy link
Contributor

@synthfi synthfi commented Sep 1, 2023

See #739 for example of the segfault that I'm seeing

  • Updates Base.append!(l1::MutableLinkedList{T}, l2::MutableLinkedList{T}) where T so that the resulting object doesn't print endlessly to the screen, and that collect doesn't segfault the julia session
    • adds more lines to update node next and prev pointers
  • Adds a test in the append section so that the second argument is checked for being empty

with these changes, I'm seeing this work without segfaulting

(@v1.9) pkg> activate .
  Activating project at `~/repos/DataStructures.jl`

julia> using DataStructures

julia> l1, l2 = MutableLinkedList{Int}(1,2), MutableLinkedList{Int}(3,4)
(MutableLinkedList{Int64}(1, 2), MutableLinkedList{Int64}(3, 4))

julia> append!(l1, l2)
MutableLinkedList{Int64}(1, 2, 3, 4)

julia> collect(l1)
4-element Vector{Int64}:
 1
 2
 3
 4

julia> l2
MutableLinkedList{Int64}()

Copy link
Collaborator

@laborg laborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the problematic behaviour. For 1.0 it should be decided if append! should mutate the second list...

@oxinabox
Copy link
Member

oxinabox commented Oct 10, 2023

It should not, since we want to match the behavour of append!ing two Vectors

@synthfi
Copy link
Contributor Author

synthfi commented Oct 11, 2023

I'll change it to do a copy of the second list

@oxinabox
Copy link
Member

It's unfortunate since that's very expensive with a linked list.
Its too bad these are double-y linked lists...

Linked lists are such a can of worms

@oxinabox oxinabox merged commit 83cdb1b into JuliaCollections:master Oct 23, 2023
@synthfi synthfi deleted the ll-fix-append branch October 26, 2023 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants