Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add test to check that ``PyStructSequence_NewType`` accepts a
``PyStructSequence_Desc`` with ``doc`` field set to ``NULL``.
21 changes: 21 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3860,6 +3860,25 @@ test_structseq_newtype_doesnt_leak(PyObject *Py_UNUSED(self),
Py_RETURN_NONE;
}

static PyObject *
test_structseq_newtype_null_descr_doc(PyObject *Py_UNUSED(self),
PyObject *Py_UNUSED(args))
{
PyStructSequence_Field descr_fields[1] = {
(PyStructSequence_Field){NULL, NULL}
};
// Test specifically for NULL .doc field.
PyStructSequence_Desc descr = {"_testcapi.test_descr", NULL, &descr_fields[0], 0};

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))
{
Expand Down Expand Up @@ -5618,6 +5637,8 @@ static PyMethodDef TestMethods[] = {
{"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS},
{"test_structseq_newtype_doesnt_leak",
test_structseq_newtype_doesnt_leak, METH_NOARGS},
{"test_structseq_newtype_null_descr_doc",
test_structseq_newtype_null_descr_doc, 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},
Expand Down