You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ctypes.wstring_at and string_at call Python API without the GIL #47804
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/theller'closed_at=<Date2008-08-19.17:23:37.153>created_at=<Date2008-08-14.16:39:51.528>labels= ['ctypes', 'type-crash']
title='ctypes.wstring_at and string_at call Python API without the GIL'updated_at=<Date2008-09-23.08:23:51.991>user='https://bugs.python.org/kevinwatters'
in Lib/ctypes/init.py the wstring_at and string_at functions are
declared with CFUNCTYPE.
This means that in Modules/_ctypes/callproc.c when the functions are
invoked, Py_UNBLOCK_THREADS and Py_BLOCK_THREADS surround the call. But
string_at and wstring_at call PyString_FromString and
PyUnicode_FromWideChar, respectively.
The solution (I think) is to declare the functions with PYFUNCTYPE
instead, so that callproc.c doesn't release the GIL when calling them.
Good catch! Indeed, when PyString_FromString or PyUnicode_FromWideChar
fail, Python crashes with
Fatal Python error: PyThreadState_Get: no current thread
in a debug build, and an access violation in a release build (tested on
Windows).
Also, your patch suggestion is absolutely correct and fixes the problem.
Activity
kevinwatters commentedon Aug 14, 2008
in Lib/ctypes/init.py the wstring_at and string_at functions are
declared with CFUNCTYPE.
This means that in Modules/_ctypes/callproc.c when the functions are
invoked, Py_UNBLOCK_THREADS and Py_BLOCK_THREADS surround the call. But
string_at and wstring_at call PyString_FromString and
PyUnicode_FromWideChar, respectively.
The solution (I think) is to declare the functions with PYFUNCTYPE
instead, so that callproc.c doesn't release the GIL when calling them.
theller commentedon Aug 14, 2008
Good catch! Indeed, when PyString_FromString or PyUnicode_FromWideChar
fail, Python crashes with
Fatal Python error: PyThreadState_Get: no current thread
in a debug build, and an access violation in a release build (tested on
Windows).
Also, your patch suggestion is absolutely correct and fixes the problem.
theller commentedon Aug 19, 2008
This is fixed now in SVN, in trunk, branches/py3k, and
branches/release25-maint. Thanks again.
vstinner commentedon Sep 23, 2008
Reference to the SVN: