Skip to content

Instantly share code, notes, and snippets.

@gdementen
Last active December 17, 2015 15:59
Show Gist options
  • Save gdementen/5635324 to your computer and use it in GitHub Desktop.
Save gdementen/5635324 to your computer and use it in GitHub Desktop.
recursive ctypes structures make numba fail to compile
line 91, in from_ctypes_type
return from_ctypes_type(ctypes_type._type_).pointer()
File "c:\soft\Python27-32b\Lib\site-packages\numba\support\ctypes_support.py",
line 97, in from_ctypes_type
for name, field_type in ctypes_type._fields_]
File "c:\soft\Python27-32b\Lib\site-packages\numba\support\ctypes_support.py",
line 91, in from_ctypes_type
return from_ctypes_type(ctypes_type._type_).pointer()
File "c:\soft\Python27-32b\Lib\site-packages\numba\support\ctypes_support.py",
line 88, in from_ctypes_type
if numba.utils.hashable(ctypes_type) and ctypes_type in ctypes_map:
RuntimeError: maximum recursion depth exceeded
from ctypes import pythonapi, Structure, POINTER
from numba import autojit
class PyInterpreterState(Structure):
pass
class PyThreadState(Structure):
pass
PyThreadState._fields_ = [
("next", POINTER(PyThreadState)),
("interp", POINTER(PyInterpreterState))
# ...
]
savethread = pythonapi.PyEval_SaveThread
savethread.argtypes = []
savethread.restype = POINTER(PyThreadState)
restorethread = pythonapi.PyEval_RestoreThread
restorethread.argtypes = [POINTER(PyThreadState)]
restorethread.restype = None
@autojit
def test_gil():
threadstate = savethread()
restorethread(threadstate)
test_gil()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment