From dabfb676234fc23c98dbca8dbf50c7c9282990c3 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Wed, 4 Nov 2020 00:22:28 +0800 Subject: [PATCH] apply victor's comment --- Doc/whatsnew/3.10.rst | 3 ++- Modules/_lsprof.c | 2 -- Modules/_testcapimodule.c | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 8a16c6a7e86fb3..21058c733c7b4f 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -366,7 +366,8 @@ New Features * Added :c:func:`PyUnicode_AsUTF8AndSize` to the limited C API. (Contributed by Alex Gaynor in :issue:`41784`.) -* The :c:func:`PyType_FromModuleAndSpec` function can accept tp_doc=NULL. +* The :c:func:`PyType_FromModuleAndSpec` function now accepts NULL ``tp_doc`` + slot. (Contributed by Hai Shi in :issue:`41832`.) diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 78d464d1481d75..a438c0457b85a3 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -489,14 +489,12 @@ static PyStructSequence_Field profiler_subentry_fields[] = { static PyStructSequence_Desc profiler_entry_desc = { .name = "_lsprof.profiler_entry", - .doc = "", .fields = profiler_entry_fields, .n_in_sequence = 6 }; static PyStructSequence_Desc profiler_subentry_desc = { .name = "_lsprof.profiler_subentry", - .doc = "", .fields = profiler_subentry_fields, .n_in_sequence = 5 }; diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 3f5dc22395131e..c371c824ea39a7 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3987,10 +3987,20 @@ test_structseq_newtype_doesnt_leak(PyObject *Py_UNUSED(self), assert(PyType_FastSubclass(structseq_type, Py_TPFLAGS_TUPLE_SUBCLASS)); Py_DECREF(structseq_type); - descr.doc = NULL; - structseq_type = PyStructSequence_NewType(&descr); - assert(structseq_type != NULL); - Py_DECREF(structseq_type); + Py_RETURN_NONE; +} + +static PyType_Spec HeapDocCType_spec; + +static PyObject * +test_PyType_FromSpec(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) +{ + void *tp_doc = HeapDocCType_spec.slots[0].pfunc; + HeapDocCType_spec.slots[0].pfunc = NULL; + PyObject *HeapDocCType = PyType_FromSpec(&HeapDocCType_spec); + assert(HeapDocCType != NULL); + HeapDocCType_spec.slots[0].pfunc = tp_doc; + Py_DECREF(HeapDocCType); Py_RETURN_NONE; } @@ -5606,6 +5616,7 @@ 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_PyType_FromSpec", test_PyType_FromSpec, 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},