mirror of
https://github.com/python/cpython.git
synced 2025-10-02 05:12:23 +00:00
gh-78878: Fix crash when creating an instance of _ctypes.CField
(#14837)
This commit is contained in:
parent
e0b4d966a8
commit
d713c54ac8
4 changed files with 10 additions and 10 deletions
|
@ -54,6 +54,12 @@ class StructFieldsTestCase(unittest.TestCase):
|
||||||
x.char = b'a\0b\0'
|
x.char = b'a\0b\0'
|
||||||
self.assertEqual(bytes(x), b'a\x00###')
|
self.assertEqual(bytes(x), b'a\x00###')
|
||||||
|
|
||||||
|
def test_6(self):
|
||||||
|
class X(Structure):
|
||||||
|
_fields_ = [("x", c_int)]
|
||||||
|
CField = type(X.x)
|
||||||
|
self.assertRaises(TypeError, CField)
|
||||||
|
|
||||||
def test_gh99275(self):
|
def test_gh99275(self):
|
||||||
class BrokenStructure(Structure):
|
class BrokenStructure(Structure):
|
||||||
def __init_subclass__(cls, **kwargs):
|
def __init_subclass__(cls, **kwargs):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix crash when creating an instance of :class:`!_ctypes.CField`.
|
|
@ -30,13 +30,6 @@ static void pymem_destructor(PyObject *ptr)
|
||||||
/*
|
/*
|
||||||
PyCField_Type
|
PyCField_Type
|
||||||
*/
|
*/
|
||||||
static PyObject *
|
|
||||||
PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
CFieldObject *obj;
|
|
||||||
obj = (CFieldObject *)type->tp_alloc(type, 0);
|
|
||||||
return (PyObject *)obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expects the size, index and offset for the current field in *psize and
|
* Expects the size, index and offset for the current field in *psize and
|
||||||
|
@ -68,7 +61,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index,
|
||||||
#define CONT_BITFIELD 2
|
#define CONT_BITFIELD 2
|
||||||
#define EXPAND_BITFIELD 3
|
#define EXPAND_BITFIELD 3
|
||||||
|
|
||||||
self = (CFieldObject *)_PyObject_CallNoArgs((PyObject *)&PyCField_Type);
|
self = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
dict = PyType_stgdict(desc);
|
dict = PyType_stgdict(desc);
|
||||||
|
@ -341,7 +334,7 @@ PyTypeObject PyCField_Type = {
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
0, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
PyCField_new, /* tp_new */
|
0, /* tp_new */
|
||||||
0, /* tp_free */
|
0, /* tp_free */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
new_descr = (CFieldObject *)_PyObject_CallNoArgs((PyObject *)&PyCField_Type);
|
new_descr = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0);
|
||||||
if (new_descr == NULL) {
|
if (new_descr == NULL) {
|
||||||
Py_DECREF(fdescr);
|
Py_DECREF(fdescr);
|
||||||
Py_DECREF(fieldlist);
|
Py_DECREF(fieldlist);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue