classification
Title: ctypes.wstring_at and string_at call Python API without the GIL
Type: crash Stage:
Components: ctypes Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: kevinwatters, theller, vstinner
Priority: normal Keywords:

Created on 2008-08-14 16:39 by kevinwatters, last changed 2008-09-23 08:23 by vstinner. This issue is now closed.

Messages (4)
msg71135 - (view) Author: Kevin Watters (kevinwatters) Date: 2008-08-14 16:39
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.
msg71143 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-08-14 19:06
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.
msg71452 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-08-19 17:23
This is fixed now in SVN, in trunk, branches/py3k, and
branches/release25-maint.  Thanks again.
msg73621 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-09-23 08:23
Reference to the SVN:
- trunk: rev65681
- release25-maint branch: rev65858
History
Date User Action Args
2008-09-23 08:23:52vstinnersetnosy: + vstinner
messages: + msg73621
2008-08-19 17:23:37thellersetstatus: open -> closed
resolution: fixed
messages: + msg71452
2008-08-14 19:06:45thellersetmessages: + msg71143
2008-08-14 16:39:51kevinwatterscreate