OrderedCollections.jl
OrderedCollections.jl copied to clipboard
Deleting nothing from OrderedDict
Deleting nothing from OrderedDict seems to behave wildly, is it a known issue?
julia> using OrderedCollections
julia> x = OrderedDict(2 => 0.1, nothing => 0.2, 3 => 0.5)
OrderedDict{Union{Nothing, Int64}, Float64} with 3 entries:
2 => 0.1
nothing => 0.2
3 => 0.5
julia> delete!(x, nothing)
OrderedDict{Union{Nothing, Int64}, Float64} with 2 entries:
nothing => 0.1
nothing => 0.2
julia> x
OrderedDict{Union{Nothing, Int64}, Float64} with 2 entries:
nothing => 0.1
nothing => 0.2
julia> x = OrderedDict(2 => 0.1, 5 => 0.4, 10 => 0.4, nothing => 0.03)
OrderedDict{Union{Nothing, Int64}, Float64} with 4 entries:
2 => 0.1
5 => 0.4
10 => 0.4
nothing => 0.03
julia> delete!(x, nothing)
OrderedDict{Union{Nothing, Int64}, Float64} with 3 entries:
2 => 0.1
5 => 0.4
10 => 0.4
julia> x
signal (11): Segmentation fault
in expression starting at none:0
jl_gc_pool_alloc at /buildworker/worker/package_linux64/build/src/gc.c:1217
For the segfault, I created an upstream report: https://github.com/JuliaLang/julia/issues/45959#issue-1297699025
Could this have something to do with these lines? Maybe jl_arrayunset is called with invalid arguments or something like that. But that's just a guess, I'm not familiar with these internals.
Apparently an error with out of bounds indexing according to this comment
Not too familiar with the source code, but it looks like it happens in the rehash! function, where the code assumes that if the key is not a bitstype, it contains pointers (see the definition of the ptrs variable). This assumption is violated for union bitstypes, where the union is neither a bitstype, nor stored as a pointer.