summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-07 20:25:46 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-07 20:25:46 (GMT)
commite45b7c09ece01c9b35a14b89eb64e1324ed321a8 (patch)
treed64a23ff36d35c76ad881b61ed08e644c0c82dbe
parent242c170f878cc38eb32b26b55f69a9d7cef947a7 (diff)
parentde0574bdabc1183706406b421dea2e3e3c165eb3 (diff)
downloadcpython-e45b7c09ece01c9b35a14b89eb64e1324ed321a8.zip
cpython-e45b7c09ece01c9b35a14b89eb64e1324ed321a8.tar.gz
cpython-e45b7c09ece01c9b35a14b89eb64e1324ed321a8.tar.bz2
Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
Original patch by Niklas Koep.
-rw-r--r--Doc/c-api/typeobj.rst3
-rw-r--r--Doc/extending/newtypes.rst4
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c6
5 files changed, 15 insertions, 2 deletions
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index 2c448a0..25e6c83 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -116,7 +116,8 @@ type objects) *must* have the :attr:`ob_size` field.
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
:attr:`~definition.__name__` attribute, and the :attr:`__module__` attribute is undefined
(unless explicitly set in the dictionary, as explained above). This means your
- type will be impossible to pickle.
+ type will be impossible to pickle. Additionally, it will not be listed in
+ module documentations created with pydoc.
This field is not inherited by subtypes.
diff --git a/Doc/extending/newtypes.rst b/Doc/extending/newtypes.rst
index a69f114..4a6e26c 100644
--- a/Doc/extending/newtypes.rst
+++ b/Doc/extending/newtypes.rst
@@ -129,7 +129,9 @@ our objects and in some error messages, for example::
Note that the name is a dotted name that includes both the module name and the
name of the type within the module. The module in this case is :mod:`noddy` and
-the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`. ::
+the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`.
+One side effect of using an undotted name is that the pydoc documentation tool
+will not list the new type in the module documentation. ::
sizeof(noddy_NoddyObject), /* tp_basicsize */
diff --git a/Misc/ACKS b/Misc/ACKS
index d5eed57..2527836 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -783,6 +783,7 @@ Jeff Knupp
Kubilay Kocak
Greg Kochanski
Manvisha Kodali
+Niklas Koep
Damon Kohler
Marko Kohtala
Vajrasky Kok
diff --git a/Misc/NEWS b/Misc/NEWS
index 051c5f6..c258a67 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
Core and Builtins
-----------------
+- Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
+ Original patch by Niklas Koep.
+
- Issue #24098: Fixed possible crash when AST is changed in process of
compiling it.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index cb251dd..52d5982 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4893,6 +4893,12 @@ PyType_Ready(PyTypeObject *type)
_Py_AddToAllObjects((PyObject *)type, 0);
#endif
+ if (type->tp_name == NULL) {
+ PyErr_Format(PyExc_SystemError,
+ "Type does not define the tp_name field.");
+ goto error;
+ }
+
/* Initialize tp_base (defaults to BaseObject unless that's us) */
base = type->tp_base;
if (base == NULL && type != &PyBaseObject_Type) {