Skip to content

Commit 2f5baa1

Browse files
Add C-API tests (#25886)
1 parent b115579 commit 2f5baa1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add test to check that ``PyStructSequence_NewType`` accepts a
2+
``PyStructSequence_Desc`` with ``doc`` field set to ``NULL``.

Modules/_testcapimodule.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,6 +3860,25 @@ test_structseq_newtype_doesnt_leak(PyObject *Py_UNUSED(self),
38603860
Py_RETURN_NONE;
38613861
}
38623862

3863+
static PyObject *
3864+
test_structseq_newtype_null_descr_doc(PyObject *Py_UNUSED(self),
3865+
PyObject *Py_UNUSED(args))
3866+
{
3867+
PyStructSequence_Field descr_fields[1] = {
3868+
(PyStructSequence_Field){NULL, NULL}
3869+
};
3870+
// Test specifically for NULL .doc field.
3871+
PyStructSequence_Desc descr = {"_testcapi.test_descr", NULL, &descr_fields[0], 0};
3872+
3873+
PyTypeObject* structseq_type = PyStructSequence_NewType(&descr);
3874+
assert(structseq_type != NULL);
3875+
assert(PyType_Check(structseq_type));
3876+
assert(PyType_FastSubclass(structseq_type, Py_TPFLAGS_TUPLE_SUBCLASS));
3877+
Py_DECREF(structseq_type);
3878+
3879+
Py_RETURN_NONE;
3880+
}
3881+
38633882
static PyObject *
38643883
test_incref_decref_API(PyObject *ob, PyObject *Py_UNUSED(ignored))
38653884
{
@@ -5618,6 +5637,8 @@ static PyMethodDef TestMethods[] = {
56185637
{"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS},
56195638
{"test_structseq_newtype_doesnt_leak",
56205639
test_structseq_newtype_doesnt_leak, METH_NOARGS},
5640+
{"test_structseq_newtype_null_descr_doc",
5641+
test_structseq_newtype_null_descr_doc, METH_NOARGS},
56215642
{"test_incref_decref_API", test_incref_decref_API, METH_NOARGS},
56225643
{"test_long_and_overflow", test_long_and_overflow, METH_NOARGS},
56235644
{"test_long_as_double", test_long_as_double, METH_NOARGS},

0 commit comments

Comments
 (0)