Skip to content

ctypes.wstring_at and string_at call Python API without the GIL #47804

Closed

Description

@kevinwatters
BPO 3554
Nosy @theller, @vstinner

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 = <Date 2008-08-19.17:23:37.153>
created_at = <Date 2008-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 = <Date 2008-09-23.08:23:51.991>
user = 'https://bugs.python.org/kevinwatters'

bugs.python.org fields:

activity = <Date 2008-09-23.08:23:51.991>
actor = 'vstinner'
assignee = 'theller'
closed = True
closed_date = <Date 2008-08-19.17:23:37.153>
closer = 'theller'
components = ['ctypes']
creation = <Date 2008-08-14.16:39:51.528>
creator = 'kevinwatters'
dependencies = []
files = []
hgrepos = []
issue_num = 3554
keywords = []
message_count = 4.0
messages = ['71135', '71143', '71452', '73621']
nosy_count = 3.0
nosy_names = ['theller', 'vstinner', 'kevinwatters']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue3554'
versions = ['Python 2.6', 'Python 2.5', 'Python 3.0', 'Python 3.1', 'Python 2.7']

Activity

  1. kevinwatters commented on Aug 14, 2008

    kevinwattersmannequin
    MannequinAuthor

    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.

  2. theller commented on Aug 14, 2008

    @theller

    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.

  3. theller commented on Aug 19, 2008

    @theller

    This is fixed now in SVN, in trunk, branches/py3k, and
    branches/release25-maint. Thanks again.

  4. vstinner commented on Sep 23, 2008

    @vstinner
    Member

    Reference to the SVN:

    • trunk: rev65681
    • release25-maint branch: rev65858
  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

topic-ctypestype-crashA hard crash of the interpreter, possibly with a core dump

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions