Skip to content

Commit e604f31

Browse files
committed
PyType_FromModuleAndSpec() can accept tp_doc=NULL
1 parent 9568622 commit e604f31

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ New Features
366366
* Added :c:func:`PyUnicode_AsUTF8AndSize` to the limited C API.
367367
(Contributed by Alex Gaynor in :issue:`41784`.)
368368

369+
* The :c:func:`PyType_FromModuleAndSpec` function can accept tp_doc=NULL.
370+
(Contributed by Hai Shi in :issue:`41832`.)
371+
369372

370373
Porting to Python 3.10
371374
----------------------
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:c:func:`PyType_FromModuleAndSpec` can accept tp_doc=NULL.

Modules/_testcapimodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,6 +3987,11 @@ test_structseq_newtype_doesnt_leak(PyObject *Py_UNUSED(self),
39873987
assert(PyType_FastSubclass(structseq_type, Py_TPFLAGS_TUPLE_SUBCLASS));
39883988
Py_DECREF(structseq_type);
39893989

3990+
descr.doc = NULL;
3991+
structseq_type = PyStructSequence_NewType(&descr);
3992+
assert(structseq_type != NULL);
3993+
Py_DECREF(structseq_type);
3994+
39903995
Py_RETURN_NONE;
39913996
}
39923997

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,12 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
30123012
else if (slot->slot == Py_tp_doc) {
30133013
/* For the docstring slot, which usually points to a static string
30143014
literal, we need to make a copy */
3015+
3016+
/* bpo-41832: PyType_FromModuleAndSpec() can accept tp_doc=NULL. */
3017+
if (slot->pfunc == NULL) {
3018+
type->tp_doc = NULL;
3019+
continue;
3020+
}
30153021
size_t len = strlen(slot->pfunc)+1;
30163022
char *tp_doc = PyObject_MALLOC(len);
30173023
if (tp_doc == NULL) {

0 commit comments

Comments
 (0)