mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-127945: add lock held assertions in ctypes arrays (#132720)
This commit is contained in:
parent
69cda31261
commit
5b06d2ceca
2 changed files with 19 additions and 13 deletions
|
|
@ -3356,14 +3356,13 @@ _PyCData_set(ctypes_state *st,
|
|||
CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
|
||||
Py_ssize_t size, char *ptr)
|
||||
{
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(dst);
|
||||
CDataObject *src;
|
||||
int err;
|
||||
|
||||
if (setfunc) {
|
||||
PyObject *res;
|
||||
Py_BEGIN_CRITICAL_SECTION(dst);
|
||||
res = setfunc(ptr, value, size);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return res;
|
||||
}
|
||||
if (!CDataObject_Check(st, value)) {
|
||||
|
|
@ -3373,9 +3372,7 @@ _PyCData_set(ctypes_state *st,
|
|||
}
|
||||
if (info && info->setfunc) {
|
||||
PyObject *res;
|
||||
Py_BEGIN_CRITICAL_SECTION(dst);
|
||||
res = info->setfunc(ptr, value, size);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return res;
|
||||
}
|
||||
/*
|
||||
|
|
@ -3397,9 +3394,7 @@ _PyCData_set(ctypes_state *st,
|
|||
Py_DECREF(ob);
|
||||
return result;
|
||||
} else if (value == Py_None && PyCPointerTypeObject_Check(st, type)) {
|
||||
Py_BEGIN_CRITICAL_SECTION(dst);
|
||||
*(void **)ptr = NULL;
|
||||
Py_END_CRITICAL_SECTION();
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
|
@ -3417,11 +3412,6 @@ _PyCData_set(ctypes_state *st,
|
|||
if (err) {
|
||||
Py_BEGIN_CRITICAL_SECTION(src);
|
||||
memcpy(ptr, src->b_ptr, size);
|
||||
|
||||
if (PyCPointerTypeObject_Check(st, type)) {
|
||||
/* XXX */
|
||||
}
|
||||
|
||||
value = GetKeepedObjects(src);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
if (value == NULL)
|
||||
|
|
@ -3485,6 +3475,8 @@ PyCData_set(ctypes_state *st,
|
|||
PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
|
||||
Py_ssize_t index, Py_ssize_t size, char *ptr)
|
||||
{
|
||||
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(dst);
|
||||
|
||||
CDataObject *mem = (CDataObject *)dst;
|
||||
PyObject *result;
|
||||
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ _pack_legacy_size(CFieldObject *field)
|
|||
}
|
||||
|
||||
static int
|
||||
PyCField_set(PyObject *op, PyObject *inst, PyObject *value)
|
||||
PyCField_set_lock_held(PyObject *op, PyObject *inst, PyObject *value)
|
||||
{
|
||||
CDataObject *dst;
|
||||
char *ptr;
|
||||
|
|
@ -265,6 +265,16 @@ PyCField_set(PyObject *op, PyObject *inst, PyObject *value)
|
|||
self->index, _pack_legacy_size(self), ptr);
|
||||
}
|
||||
|
||||
static int
|
||||
PyCField_set(PyObject *op, PyObject *inst, PyObject *value)
|
||||
{
|
||||
int res;
|
||||
Py_BEGIN_CRITICAL_SECTION(inst);
|
||||
res = PyCField_set_lock_held(op, inst, value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyCField_get(PyObject *op, PyObject *inst, PyObject *type)
|
||||
{
|
||||
|
|
@ -280,9 +290,13 @@ PyCField_get(PyObject *op, PyObject *inst, PyObject *type)
|
|||
return NULL;
|
||||
}
|
||||
src = _CDataObject_CAST(inst);
|
||||
return PyCData_get(st, self->proto, self->getfunc, inst,
|
||||
PyObject *res;
|
||||
Py_BEGIN_CRITICAL_SECTION(inst);
|
||||
res = PyCData_get(st, self->proto, self->getfunc, inst,
|
||||
self->index, _pack_legacy_size(self),
|
||||
src->b_ptr + self->byte_offset);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue