Skip to content

Commit 849adab

Browse files
committed
be more careful about rooting pointers in pyincref/decref
1 parent 8d30002 commit 849adab

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/PyCall.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,23 @@ it is equivalent to a `PyNULL()` object.
9898
"""
9999
ispynull(o::PyObject) = o.o == PyPtr_NULL
100100

101-
function pydecref_(o::PyPtr)
101+
function pydecref_(o::Union{PyPtr,PyObject})
102102
ccall(@pysym(:Py_DecRef), Cvoid, (PyPtr,), o)
103103
return o
104104
end
105105

106106
function pydecref(o::PyObject)
107-
pydecref_(o.o)
107+
pydecref_(o)
108108
o.o = PyPtr_NULL
109-
o
109+
return o
110110
end
111111

112-
function pyincref_(o::PyPtr)
112+
function pyincref_(o::Union{PyPtr,PyObject})
113113
ccall((@pysym :Py_IncRef), Cvoid, (PyPtr,), o)
114114
return o
115115
end
116116

117-
function pyincref(o::PyObject)
118-
pyincref_(o.o)
119-
o
120-
end
117+
pyincref(o::PyObject) = pyincref_(o)
121118

122119
# doing an incref *before* creating a PyObject may safer in the
123120
# case of borrowed references, to ensure that no exception or interrupt

0 commit comments

Comments
 (0)