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