Skip to content

Commit 6547543

Browse files
committed
eliminate 'global const' from c_void_p_Type; nowadays we require Python 2.7+, so we can assume ctypes is available
1 parent ccea840 commit 6547543

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/conversions.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ end
110110
#########################################################################
111111
# Pointer conversions, using ctypes or PyCapsule
112112

113-
PyObject(p::Ptr) = py_void_p(p)
113+
PyObject(p::Ptr) = pycall(c_void_p_Type, PyObject, UInt(p))
114114

115115
function convert(::Type{Ptr{Void}}, po::PyObject)
116116
if pyisinstance(po, c_void_p_Type)

src/pyinit.jl

+3-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ufuncType = PyNULL()
1515
const format_traceback = PyNULL()
1616
const pyproperty = PyNULL()
1717
const jlfun2pyfun = PyNULL()
18+
const c_void_p_Type = PyNULL()
1819

1920
# other global constants initialized at runtime are defined via Ref
2021
# or are simply left as non-const values
@@ -72,16 +73,8 @@ function __init__()
7273
# xrange type (or range in Python 3)
7374
pyxrange[] = @pyglobalobj(:PyRange_Type)
7475

75-
# cache ctypes.c_void_p type and function if available
76-
vpt, pvp = try
77-
(pyimport("ctypes")["c_void_p"],
78-
p::Ptr -> pycall(c_void_p_Type, PyObject, UInt(p)))
79-
catch # fallback to CObject
80-
(@pyglobalobj(:PyCObject_FromVoidPtr),
81-
p::Ptr -> PyObject(ccall(pycobject_new, PyPtr, (Ptr{Void}, Ptr{Void}), p, C_NULL)))
82-
end
83-
global const c_void_p_Type = vpt
84-
global const py_void_p = pvp
76+
# ctypes.c_void_p for Ptr types
77+
copy!(c_void_p_Type, pyimport("ctypes")["c_void_p"])
8578

8679
# traceback.format_tb function, for show(PyError)
8780
copy!(format_traceback, pyimport("traceback")["format_tb"])

0 commit comments

Comments
 (0)