Skip to content

Commit

Permalink
Issue python#18287: PyType_Ready() now checks that tp_name is not NULL.
Browse files Browse the repository at this point in the history
Original patch by Niklas Koep.
  • Loading branch information
serhiy-storchaka committed Oct 7, 2016
1 parent 8793b21 commit de0574b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion Doc/extending/newtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ Jeff Knupp
Kubilay Kocak
Greg Kochanski
Manvisha Kodali
Niklas Koep
Damon Kohler
Marko Kohtala
Vajrasky Kok
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Release date: TBA
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.

Expand Down
6 changes: 6 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4820,6 +4820,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) {
Expand Down

0 comments on commit de0574b

Please sign in to comment.