Skip to content

Commit

Permalink
move null check in unsafe_convert of RefValue (#55766)
Browse files Browse the repository at this point in the history
LLVM can optimize out this check but our optimizer can't, so this leads
to smaller IR in most cases.
  • Loading branch information
JeffBezanson authored Sep 16, 2024
1 parent a993cd8 commit 55c40ce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/refvalue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function unsafe_convert(P::Union{Type{Ptr{T}},Type{Ptr{Cvoid}}}, b::RefValue{T})
# Instead, explicitly load the pointer from the `RefValue`,
# which also ensures this returns same pointer as the one rooted in the `RefValue` object.
p = atomic_pointerref(Ptr{Ptr{Cvoid}}(pointer_from_objref(b)), :monotonic)
end
if p == C_NULL
throw(UndefRefError())
if p == C_NULL
throw(UndefRefError())
end
end
return p
end
Expand Down

0 comments on commit 55c40ce

Please sign in to comment.