mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
bpo-34784: Fix PyStructSequence_NewType with heap-allocated StructSequence (GH-9665)
This commit is contained in:
parent
1a6be91e6f
commit
474eedfb3d
5 changed files with 242 additions and 140 deletions
|
|
@ -3313,6 +3313,31 @@ test_decref_doesnt_leak(PyObject *ob, PyObject *Py_UNUSED(ignored))
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
test_structseq_newtype_doesnt_leak(PyObject *Py_UNUSED(self),
|
||||
PyObject *Py_UNUSED(args))
|
||||
{
|
||||
PyStructSequence_Desc descr;
|
||||
PyStructSequence_Field descr_fields[3];
|
||||
|
||||
descr_fields[0] = (PyStructSequence_Field){"foo", "foo value"};
|
||||
descr_fields[1] = (PyStructSequence_Field){NULL, "some hidden value"};
|
||||
descr_fields[2] = (PyStructSequence_Field){0, NULL};
|
||||
|
||||
descr.name = "_testcapi.test_descr";
|
||||
descr.doc = "This is used to test for memory leaks in NewType";
|
||||
descr.fields = descr_fields;
|
||||
descr.n_in_sequence = 1;
|
||||
|
||||
PyTypeObject* structseq_type = PyStructSequence_NewType(&descr);
|
||||
assert(structseq_type != NULL);
|
||||
assert(PyType_Check(structseq_type));
|
||||
assert(PyType_FastSubclass(structseq_type, Py_TPFLAGS_TUPLE_SUBCLASS));
|
||||
Py_DECREF(structseq_type);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
test_incref_decref_API(PyObject *ob, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
|
|
@ -4721,6 +4746,8 @@ static PyMethodDef TestMethods[] = {
|
|||
{"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS},
|
||||
{"test_xdecref_doesnt_leak",test_xdecref_doesnt_leak, METH_NOARGS},
|
||||
{"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS},
|
||||
{"test_structseq_newtype_doesnt_leak",
|
||||
test_structseq_newtype_doesnt_leak, METH_NOARGS},
|
||||
{"test_incref_decref_API", test_incref_decref_API, METH_NOARGS},
|
||||
{"test_long_and_overflow", test_long_and_overflow, METH_NOARGS},
|
||||
{"test_long_as_double", test_long_as_double, METH_NOARGS},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue