Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ false
isbitsunion(u::Union) = (@_pure_meta; ccall(:jl_array_store_unboxed, Cint, (Any,), u) != Cint(0))
isbitsunion(x) = false

isptrelement(t::Type) = (@_pure_meta; ccall(:jl_array_store_unboxed, Cint, (Any,), t) == Cint(0))
Copy link
Member

Choose a reason for hiding this comment

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

we already define this here, so maybe we should consolidate.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not quite the same, since the other query is related to this query by the formula isbitsunion(u) = u isa Union && isptrelement(u)

Copy link
Member

Choose a reason for hiding this comment

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

Right; I was mainly pointing out that maybe we should define a single ccall definition for this (and have isbitsunion call that), just to minimize the need to update things in two places if jl_array_store_unboxed ever changes.


function _unsetindex!(A::Array{T}, i::Int) where {T}
@boundscheck checkbounds(A, i)
if isptrelement(T)
t = @_gc_preserve_begin A
p = Ptr{Ptr{Cvoid}}(pointer(A))
unsafe_store!(p, C_NULL, i)
@_gc_preserve_end t
end
return A
end


"""
Base.bitsunionsize(U::Union)

Expand Down
4 changes: 2 additions & 2 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ end

function _delete!(h::Dict{K,V}, index) where {K,V}
@inbounds h.slots[index] = 0x2
isbitstype(K) || isbitsunion(K) || ccall(:jl_arrayunset, Cvoid, (Any, UInt), h.keys, index-1)
isbitstype(V) || isbitsunion(V) || ccall(:jl_arrayunset, Cvoid, (Any, UInt), h.vals, index-1)
@inbounds _unsetindex!(h.keys, index)
@inbounds _unsetindex!(h.vals, index)
h.ndel += 1
h.count -= 1
h.age += 1
Expand Down
5 changes: 2 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,9 @@ JL_DLLEXPORT void jl_arrayset(jl_array_t *a JL_ROOTING_ARGUMENT, jl_value_t *rhs
JL_DLLEXPORT void jl_arrayunset(jl_array_t *a, size_t i)
{
if (i >= jl_array_len(a))
jl_bounds_error_int((jl_value_t*)a, i+1);
char *ptail = (char*)a->data + i*a->elsize;
jl_bounds_error_int((jl_value_t*)a, i + 1);
if (a->flags.ptrarray)
memset(ptail, 0, a->elsize);
((jl_value_t**)a->data)[i] = NULL;
}

// at this size and bigger, allocate resized array data with malloc
Expand Down