Skip to content

Commit ca568a3

Browse files
author
Christopher Doris
committed
fix gc issues
1 parent bdc884b commit ca568a3

File tree

12 files changed

+14
-14
lines changed

12 files changed

+14
-14
lines changed

src/Py.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ the top level then `pycopy!(x, pything())` inside `__init__()`.
8888
8989
Assumes `dst` is NULL, otherwise a memory leak will occur.
9090
"""
91-
pycopy!(dst::Py, src) = GC.@preserve src setptr!(dst, incref(getptr(src)))
91+
pycopy!(dst::Py, src) = Base.GC.@preserve src setptr!(dst, incref(getptr(src)))
9292

9393
"""
9494
pydel!(x::Py)

src/PythonCall.jl

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include("utils.jl")
1010

1111
include("cpython/CPython.jl")
1212

13+
include("gc.jl")
1314
include("Py.jl")
1415
include("err.jl")
1516
include("config.jl")

src/abstract/iter.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ export pynext
1919
2020
Return the next item in the iterator `x`. When there are no more items, return NULL.
2121
"""
22-
unsafe_pynext(x::Py) = GC.@preserve x pynew(errcheck_ambig(C.PyIter_Next(getptr(x))))
22+
unsafe_pynext(x::Py) = Base.GC.@preserve x pynew(errcheck_ambig(C.PyIter_Next(getptr(x))))

src/concrete/bytes.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pyisbytes(x) = pytypecheckfast(x, C.Py_TPFLAGS_BYTES_SUBCLASS)
1919
function pybytes_asdata(x::Py)
2020
ptr = Ref(Ptr{Cchar}(0))
2121
len = Ref(C.Py_ssize_t(0))
22-
GC.@preserve x errcheck(C.PyBytes_AsStringAndSize(getptr(x), ptr, len))
22+
Base.GC.@preserve x errcheck(C.PyBytes_AsStringAndSize(getptr(x), ptr, len))
2323
ptr[], len[]
2424
end
2525

src/concrete/ctypes.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct pyconvert_rule_ctypessimplevalue{R,S} <: Function end
22

33
function (::pyconvert_rule_ctypessimplevalue{R,SAFE})(::Type{T}, x::Py) where {R,SAFE,T}
4-
ptr = GC.@preserve x C.PySimpleObject_GetValue(Ptr{R}, getptr(x))
4+
ptr = Base.GC.@preserve x C.PySimpleObject_GetValue(Ptr{R}, getptr(x))
55
ans = unsafe_load(ptr)
66
if SAFE
77
pyconvert_return(convert(T, ans))

src/concrete/numpy.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct pyconvert_rule_numpysimplevalue{R,S} <: Function end
22

33
function (::pyconvert_rule_numpysimplevalue{R,SAFE})(::Type{T}, x::Py) where {R,SAFE,T}
4-
ans = GC.@preserve x C.PySimpleObject_GetValue(R, getptr(x))
4+
ans = Base.GC.@preserve x C.PySimpleObject_GetValue(R, getptr(x))
55
if SAFE
66
pyconvert_return(convert(T, ans))
77
else

src/concrete/str.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pystr(x::Char) = pystr(string(x))
1313
pystr(::Type{String}, x) = (s=pystr(x); ans=pystr_asstring(s); pydel!(s); ans)
1414
export pystr
1515

16-
pystr_asUTF8bytes(x::Py) = GC.@preserve x pynew(errcheck(C.PyUnicode_AsUTF8String(getptr(x))))
16+
pystr_asUTF8bytes(x::Py) = Base.GC.@preserve x pynew(errcheck(C.PyUnicode_AsUTF8String(getptr(x))))
1717
pystr_asUTF8vector(x::Py) = (b=pystr_asUTF8bytes(x); ans=pybytes_asvector(b); pydel!(b); ans)
1818
pystr_asstring(x::Py) = (b=pystr_asUTF8bytes(x); ans=pybytes_asUTF8string(b); pydel!(b); ans)
1919

src/concrete/tuple.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function pytuple_setitem(xs::Py, i, x)
66
end
77

88
function pytuple_getitem(xs::Py, i)
9-
GC.@preserve xs pynew(incref(errcheck(C.PyTuple_GetItem(getptr(xs), i))))
9+
Base.GC.@preserve xs pynew(incref(errcheck(C.PyTuple_GetItem(getptr(xs), i))))
1010
end
1111

1212
function pytuple_fromiter(xs)

src/cpython/CPython.jl

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ include("extras.jl")
1616
include("context.jl")
1717
include("gil.jl")
1818
include("jlwrap.jl")
19-
include("gc.jl")
2019

2120
function __init__()
2221
init_context()

src/err.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function errget()
2525
(pynew(t[]), pynew(v[]), pynew(b[]))
2626
end
2727

28-
errset(t::Py) = GC.@preserve t C.PyErr_SetNone(getptr(t))
29-
errset(t::Py, v::Py) = GC.@preserve t v C.PyErr_SetObject(getptr(t), getptr(v))
30-
errset(t::Py, v::String) = GC.@preserve t C.PyErr_SetString(getptr(t), v)
28+
errset(t::Py) = Base.GC.@preserve t C.PyErr_SetNone(getptr(t))
29+
errset(t::Py, v::Py) = Base.GC.@preserve t v C.PyErr_SetObject(getptr(t), getptr(v))
30+
errset(t::Py, v::String) = Base.GC.@preserve t C.PyErr_SetString(getptr(t), v)
3131

3232
function errnormalize!(t::Py, v::Py, b::Py)
3333
tptr = getptr(t)

src/gc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module GC
88
import ..PythonCall.C
99

1010
const ENABLED = Ref(true)
11-
const QUEUE = PyPtr[]
11+
const QUEUE = C.PyPtr[]
1212

1313
"""
1414
PythonCall.GC.disable()

src/jlwrap/base.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function C._pyjl_callmethod(f, self_::C.PyPtr, args_::C.PyPtr, nargs::C.Py_ssize
8686
return incref(getptr(ans))
8787
catch exc
8888
if exc isa PyException
89-
GC.@preserve exc C.PyErr_Restore(incref(getptr(exc._t)), incref(getptr(exc._v)), incref(getptr(exc._b)))
89+
Base.GC.@preserve exc C.PyErr_Restore(incref(getptr(exc._t)), incref(getptr(exc._v)), incref(getptr(exc._b)))
9090
return C.PyNULL
9191
else
9292
try
@@ -117,7 +117,7 @@ function pyjl_handle_error(f, self, exc)
117117
return C.PyNULL
118118
else
119119
# Otherwise, return the given object (e.g. NotImplemented)
120-
return GC.@preserve t incref(getptr(t))
120+
return Base.GC.@preserve t incref(getptr(t))
121121
end
122122
end
123123

0 commit comments

Comments
 (0)