Skip to content

gh-100926: use explicit stginfo lock for pointer cache #133867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
@@ -578,14 +578,13 @@ _ctypes_CType_Type___sizeof___impl(PyObject *self, PyTypeObject *cls)

/*[clinic input]
@getter
@critical_section
_ctypes.CType_Type.__pointer_type__

[clinic start generated code]*/

static PyObject *
_ctypes_CType_Type___pointer_type___get_impl(PyObject *self)
/*[clinic end generated code: output=718c9ff10b2b0012 input=ff7498aa6edf487c]*/
/*[clinic end generated code: output=718c9ff10b2b0012 input=ad12dc835943ceb8]*/
{
ctypes_state *st = get_module_state_by_def(Py_TYPE(self));
StgInfo *info;
@@ -596,9 +595,12 @@ _ctypes_CType_Type___pointer_type___get_impl(PyObject *self)
PyErr_Format(PyExc_TypeError, "%R must have storage info", self);
return NULL;
}

if (info->pointer_type) {
return Py_NewRef(info->pointer_type);
PyObject *pointer_type;
STGINFO_LOCK(info);
pointer_type = Py_XNewRef(info->pointer_type);
STGINFO_UNLOCK();
if (pointer_type) {
return pointer_type;
}

PyErr_Format(PyExc_AttributeError,
@@ -609,14 +611,13 @@ _ctypes_CType_Type___pointer_type___get_impl(PyObject *self)

/*[clinic input]
@setter
@critical_section
_ctypes.CType_Type.__pointer_type__

[clinic start generated code]*/

static int
_ctypes_CType_Type___pointer_type___set_impl(PyObject *self, PyObject *value)
/*[clinic end generated code: output=6259be8ea21693fa input=9b2dc2400c388982]*/
/*[clinic end generated code: output=6259be8ea21693fa input=a05055fc7f4714b6]*/
{
ctypes_state *st = get_module_state_by_def(Py_TYPE(self));
StgInfo *info;
@@ -627,8 +628,9 @@ _ctypes_CType_Type___pointer_type___set_impl(PyObject *self, PyObject *value)
PyErr_Format(PyExc_TypeError, "%R must have storage info", self);
return -1;
}

STGINFO_LOCK(info);
Py_XSETREF(info->pointer_type, Py_XNewRef(value));
STGINFO_UNLOCK();
return 0;
}

12 changes: 2 additions & 10 deletions Modules/_ctypes/clinic/_ctypes.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Oops, something went wrong.