bpo-31443: Formulate the type slot initialization rules in terms of C99. (#3688)

This commit is contained in:
Stefan Krah 2017-09-22 17:44:58 +02:00 committed by GitHub
parent 5e02c7826f
commit ca72589bfa
2 changed files with 15 additions and 14 deletions

View file

@ -177,16 +177,9 @@ the module. We'll expand this example later to have more interesting behavior.
For now, all we want to be able to do is to create new :class:`Noddy` objects.
To enable object creation, we have to provide a :c:member:`~PyTypeObject.tp_new` implementation.
In this case, we can just use the default implementation provided by the API
function :c:func:`PyType_GenericNew`. We'd like to just assign this to the
:c:member:`~PyTypeObject.tp_new` slot, but we can't, for portability sake, On some platforms or
compilers, we can't statically initialize a structure member with a function
defined in another C module, so, instead, we'll assign the :c:member:`~PyTypeObject.tp_new` slot
in the module initialization function just before calling
:c:func:`PyType_Ready`::
function :c:func:`PyType_GenericNew`. ::
noddy_NoddyType.tp_new = PyType_GenericNew;
if (PyType_Ready(&noddy_NoddyType) < 0)
return;
PyType_GenericNew, /* tp_new */
All the other type methods are *NULL*, so we'll go over them later --- that's
for a later section!