Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
PyType_FromModuleAndSpec() can accept tp_doc=NULL
  • Loading branch information
shihai1991 committed Nov 3, 2020
commit e604f311822e7d97f75563267ceb37014b8c114f
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ 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.
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
(Contributed by Hai Shi in :issue:`41832`.)


Porting to Python 3.10
----------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:c:func:`PyType_FromModuleAndSpec` can accept tp_doc=NULL.
5 changes: 5 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3987,6 +3987,11 @@ 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);
Comment thread
shihai1991 marked this conversation as resolved.
Outdated

Py_RETURN_NONE;
}

Expand Down
6 changes: 6 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3012,6 +3012,12 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
else if (slot->slot == Py_tp_doc) {
/* For the docstring slot, which usually points to a static string
literal, we need to make a copy */

/* bpo-41832: PyType_FromModuleAndSpec() can accept tp_doc=NULL. */
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
if (slot->pfunc == NULL) {
type->tp_doc = NULL;
continue;
}
size_t len = strlen(slot->pfunc)+1;
char *tp_doc = PyObject_MALLOC(len);
if (tp_doc == NULL) {
Expand Down