@@ -99,23 +99,6 @@ \section{The Basics
99
99
0, /*tp_as_buffer*/
100
100
Py_TPFLAGS_DEFAULT, /*tp_flags*/
101
101
"Noddy objects", /* tp_doc */
102
-
0, /* tp_traverse */
103
-
0, /* tp_clear */
104
-
0, /* tp_richcompare */
105
-
0, /* tp_weaklistoffset */
106
-
0, /* tp_iter */
107
-
0, /* tp_iternext */
108
-
0, /* tp_methods */
109
-
0, /* tp_members */
110
-
0, /* tp_getset */
111
-
0, /* tp_base */
112
-
0, /* tp_dict */
113
-
0, /* tp_descr_get */
114
-
0, /* tp_descr_set */
115
-
0, /* tp_dictoffset */
116
-
0, /* tp_init */
117
-
0, /* tp_alloc */
118
-
PyType_GenericNew, /* tp_new */
119
102
};
120
103
\end{verbatim}
121
104
@@ -209,10 +192,17 @@ \section{The Basics
209
192
objects. To enable object creation, we have to provide a
210
193
\member{tp_new} implementation. In this case, we can just use the
211
194
default implementation provided by the API function
212
-
\cfunction{PyType_GenericNew}.
195
+
\cfunction{PyType_GenericNew}. We'd like to just assign this to the
196
+
\member{tp_new} slot, but we can't, for portability sake, On some
197
+
platforms or compilers, we can't statically initialize a structure
198
+
member with a function defined in another C module, so, instead, we'll
199
+
assign the \member{tp_new} slot in the module initialization function
200
+
just before calling \cfunction{PyType_Ready()}:
213
201
214
202
\begin{verbatim}
215
-
PyType_GenericNew, /* tp_new */
203
+
noddy_NoddyType.tp_new = PyType_GenericNew;
204
+
if (PyType_Ready(&noddy_NoddyType) < 0)
205
+
return;
216
206
\end{verbatim}
217
207
218
208
All the other type methods are \NULL, so we'll go over them later
@@ -397,7 +387,7 @@ \subsection{Adding data and methods to the Basic example}
397
387
We provide an initialization function:
398
388
399
389
\begin{verbatim}
400
-
static PyObject *
390
+
static int
401
391
Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
402
392
{
403
393
PyObject *first=NULL, *last=NULL;
@@ -407,7 +397,7 @@ \subsection{Adding data and methods to the Basic example}
407
397
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
408
398
&first, &last,
409
399
&self->number))
410
-
return NULL;
400
+
return -1;
411
401
412
402
if (first) {
413
403
Py_XDECREF(self->first);
@@ -421,8 +411,7 @@ \subsection{Adding data and methods to the Basic example}
421
411
self->last = last;
422
412
}
423
413
424
-
Py_INCREF(Py_None);
425
-
return Py_None;
414
+
return 0;
426
415
}
427
416
\end{verbatim}
428
417
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4