Skip to content

Commit 1cd057e

Browse files
simonbyrnerandy3k
authored andcommitted
Don't use jl_value_ptr (#267)
Wrap objects in a Ref to avoid immutable relocation problems.
1 parent e75f66c commit 1cd057e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/callback.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function julia_extptr_callback(p::Ptr{ListSxp})
3737
# julia function pointer
3838
f_sxp = car(l)::Ptr{ExtPtrSxp}
3939
ptr = ccall((:R_ExternalPtrAddr, libR), Ptr{Cvoid}, (Ptr{ExtPtrSxp},), f_sxp)
40-
f = unsafe_pointer_to_objref(ptr)
40+
f = unsafe_pointer_to_objref(ptr)[]
4141
l = cdr(l)
4242

4343
# # extract arguments
@@ -111,9 +111,11 @@ We store the pointer and the object in a const Dict to prevent it being
111111
removed by the Julia GC.
112112
"""
113113
function sexp(::Type{RClass{:externalptr}}, j)
114-
jptr = ccall(:jl_value_ptr, Ptr{Cvoid}, (Any,), j)
114+
# wrap in a `Ref`
115+
refj = Ref(j)
116+
jptr = pointer_from_objref(refj)
115117
s = makeExternalPtr(jptr)
116-
jtypExtPtrs[s] = j
118+
jtypExtPtrs[s] = refj
117119
registerCFinalizerEx(s)
118120
s
119121
end

0 commit comments

Comments
 (0)