mirror of
https://github.com/python/cpython.git
synced 2025-09-24 17:33:29 +00:00
gh-100926: fix thread safety of ctypes
__pointer_type__
(#133843)
This commit is contained in:
parent
53383e90e4
commit
70f9b3de36
2 changed files with 73 additions and 6 deletions
|
@ -576,8 +576,16 @@ _ctypes_CType_Type___sizeof___impl(PyObject *self, PyTypeObject *cls)
|
||||||
return PyLong_FromSsize_t(size);
|
return PyLong_FromSsize_t(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*[clinic input]
|
||||||
|
@getter
|
||||||
|
@critical_section
|
||||||
|
_ctypes.CType_Type.__pointer_type__
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ctype_get_pointer_type(PyObject *self, void *Py_UNUSED(ignored))
|
_ctypes_CType_Type___pointer_type___get_impl(PyObject *self)
|
||||||
|
/*[clinic end generated code: output=718c9ff10b2b0012 input=ff7498aa6edf487c]*/
|
||||||
{
|
{
|
||||||
ctypes_state *st = get_module_state_by_def(Py_TYPE(self));
|
ctypes_state *st = get_module_state_by_def(Py_TYPE(self));
|
||||||
StgInfo *info;
|
StgInfo *info;
|
||||||
|
@ -599,8 +607,16 @@ ctype_get_pointer_type(PyObject *self, void *Py_UNUSED(ignored))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*[clinic input]
|
||||||
|
@setter
|
||||||
|
@critical_section
|
||||||
|
_ctypes.CType_Type.__pointer_type__
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ctype_set_pointer_type(PyObject *self, PyObject *tp, void *Py_UNUSED(ignored))
|
_ctypes_CType_Type___pointer_type___set_impl(PyObject *self, PyObject *value)
|
||||||
|
/*[clinic end generated code: output=6259be8ea21693fa input=9b2dc2400c388982]*/
|
||||||
{
|
{
|
||||||
ctypes_state *st = get_module_state_by_def(Py_TYPE(self));
|
ctypes_state *st = get_module_state_by_def(Py_TYPE(self));
|
||||||
StgInfo *info;
|
StgInfo *info;
|
||||||
|
@ -612,7 +628,7 @@ ctype_set_pointer_type(PyObject *self, PyObject *tp, void *Py_UNUSED(ignored))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_XSETREF(info->pointer_type, Py_XNewRef(tp));
|
Py_XSETREF(info->pointer_type, Py_XNewRef(value));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,8 +642,7 @@ static PyMethodDef ctype_methods[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyGetSetDef ctype_getsets[] = {
|
static PyGetSetDef ctype_getsets[] = {
|
||||||
{ "__pointer_type__", ctype_get_pointer_type, ctype_set_pointer_type,
|
_CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF
|
||||||
"pointer type", NULL },
|
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1254,9 +1269,11 @@ PyCPointerType_SetProto(ctypes_state *st, PyObject *self, StgInfo *stginfo, PyOb
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_XSETREF(stginfo->proto, Py_NewRef(proto));
|
Py_XSETREF(stginfo->proto, Py_NewRef(proto));
|
||||||
|
STGINFO_LOCK(info);
|
||||||
if (info->pointer_type == NULL) {
|
if (info->pointer_type == NULL) {
|
||||||
Py_XSETREF(info->pointer_type, Py_NewRef(self));
|
Py_XSETREF(info->pointer_type, Py_NewRef(self));
|
||||||
}
|
}
|
||||||
|
STGINFO_UNLOCK();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
52
Modules/_ctypes/clinic/_ctypes.c.h
generated
52
Modules/_ctypes/clinic/_ctypes.c.h
generated
|
@ -31,6 +31,56 @@ _ctypes_CType_Type___sizeof__(PyObject *self, PyTypeObject *cls, PyObject *const
|
||||||
return _ctypes_CType_Type___sizeof___impl(self, cls);
|
return _ctypes_CType_Type___sizeof___impl(self, cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_ctypes_CType_Type___pointer_type___DOCSTR)
|
||||||
|
# define _ctypes_CType_Type___pointer_type___DOCSTR NULL
|
||||||
|
#endif
|
||||||
|
#if defined(_CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF)
|
||||||
|
# undef _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF
|
||||||
|
# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, _ctypes_CType_Type___pointer_type___DOCSTR},
|
||||||
|
#else
|
||||||
|
# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, NULL, _ctypes_CType_Type___pointer_type___DOCSTR},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_ctypes_CType_Type___pointer_type___get_impl(PyObject *self);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_ctypes_CType_Type___pointer_type___get(PyObject *self, void *Py_UNUSED(context))
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
|
||||||
|
Py_BEGIN_CRITICAL_SECTION(self);
|
||||||
|
return_value = _ctypes_CType_Type___pointer_type___get_impl(self);
|
||||||
|
Py_END_CRITICAL_SECTION();
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(_ctypes_CType_Type___pointer_type___DOCSTR)
|
||||||
|
# define _ctypes_CType_Type___pointer_type___DOCSTR NULL
|
||||||
|
#endif
|
||||||
|
#if defined(_CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF)
|
||||||
|
# undef _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF
|
||||||
|
# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, _ctypes_CType_Type___pointer_type___DOCSTR},
|
||||||
|
#else
|
||||||
|
# define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", NULL, (setter)_ctypes_CType_Type___pointer_type___set, NULL},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int
|
||||||
|
_ctypes_CType_Type___pointer_type___set_impl(PyObject *self, PyObject *value);
|
||||||
|
|
||||||
|
static int
|
||||||
|
_ctypes_CType_Type___pointer_type___set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
|
||||||
|
{
|
||||||
|
int return_value;
|
||||||
|
|
||||||
|
Py_BEGIN_CRITICAL_SECTION(self);
|
||||||
|
return_value = _ctypes_CType_Type___pointer_type___set_impl(self, value);
|
||||||
|
Py_END_CRITICAL_SECTION();
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(CDataType_from_address__doc__,
|
PyDoc_STRVAR(CDataType_from_address__doc__,
|
||||||
"from_address($self, value, /)\n"
|
"from_address($self, value, /)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
|
@ -1000,4 +1050,4 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py
|
||||||
}
|
}
|
||||||
return Simple_from_outparm_impl(self, cls);
|
return Simple_from_outparm_impl(self, cls);
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=9fb75bf7e9a17df2 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=f4bc2a77ec073b8a input=a9049054013a1b77]*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue