Skip to content

Commit 267f90a

Browse files
authored
GC safety (#758)
Updates some old GC-unsafe code that pre-dates the modern `Ref`.
1 parent bf2c913 commit 267f90a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/exception.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ struct PyError <: Exception
1313
# PyErr_Occurred returns non-NULL, and clears the Python error
1414
# indicator.
1515
function PyError(msg::AbstractString)
16-
exc = Array{PyPtr}(undef, 3)
17-
pexc = convert(UInt, pointer(exc))
16+
ptype, pvalue, ptraceback = Ref{PyPtr}(), Ref{PyPtr}(), Ref{PyPtr}()
1817
# equivalent of passing C pointers &exc[1], &exc[2], &exc[3]:
19-
ccall((@pysym :PyErr_Fetch), Cvoid, (UInt,UInt,UInt),
20-
pexc, pexc + sizeof(PyPtr), pexc + 2*sizeof(PyPtr))
21-
ccall((@pysym :PyErr_NormalizeException), Cvoid, (UInt,UInt,UInt),
22-
pexc, pexc + sizeof(PyPtr), pexc + 2*sizeof(PyPtr))
23-
new(msg, PyObject(exc[1]), PyObject(exc[2]), PyObject(exc[3]))
18+
ccall((@pysym :PyErr_Fetch), Cvoid, (Ref{PyPtr},Ref{PyPtr},Ref{PyPtr}), ptype, pvalue, ptraceback)
19+
ccall((@pysym :PyErr_NormalizeException), Cvoid, (Ref{PyPtr},Ref{PyPtr},Ref{PyPtr}), ptype, pvalue, ptraceback)
20+
new(msg, PyObject(ptype[]), PyObject(pvalue[]), PyObject(ptraceback[]))
2421
end
2522

2623
PyError(msg::AbstractString, e::PyError) = new(msg, e.T, e.val, e.traceback)
@@ -203,4 +200,4 @@ used in a `catch` block so that `catch_backtrace()` is valid.
203200
"""
204201
macro pyraise(e)
205202
:(pyraise($(esc(e)), catch_backtrace()))
206-
end
203+
end

0 commit comments

Comments
 (0)