[Python-checkins] Add C-API tests (#25886)

ambv webhook-mailer at python.org
Tue May 4 07:07:36 EDT 2021


https://github.com/python/cpython/commit/2f5baa17504feb9a7613bac32fdceed4894434de
commit: 2f5baa17504feb9a7613bac32fdceed4894434de
branch: main
author: Ken Jin <28750310+Fidget-Spinner at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-05-04T13:07:31+02:00
summary:

Add C-API tests (#25886)

files:
A Misc/NEWS.d/next/Tests/2021-05-04-18-10-57.bpo-42083.EMS2TK.rst
M Modules/_testcapimodule.c

diff --git a/Misc/NEWS.d/next/Tests/2021-05-04-18-10-57.bpo-42083.EMS2TK.rst b/Misc/NEWS.d/next/Tests/2021-05-04-18-10-57.bpo-42083.EMS2TK.rst
new file mode 100644
index 00000000000000..8457508237a888
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2021-05-04-18-10-57.bpo-42083.EMS2TK.rst
@@ -0,0 +1,2 @@
+Add test to check that ``PyStructSequence_NewType`` accepts a
+``PyStructSequence_Desc`` with ``doc`` field set to ``NULL``.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 26ebacba642a4f..0a3040f703da97 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -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))
 {
@@ -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},



More information about the Python-checkins mailing list