Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-41832: PyType_FromModuleAndSpec() can accept the NULL tp_doc slot. #23123

Merged
merged 8 commits into from
Nov 6, 2020
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
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.
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved
(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);
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved

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. */
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved
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