mirror of https://github.com/python/cpython
Changed the assignment of PyType_GenericNew to tp_new slot. Now do
this in module initialization before calling PyType_Ready. (Sorry Tim.) This is necessary to compile on cygwin. AFAIK, we support cygwin. If so, then we need to write extentions this way. Fixed bug in implementation of tp_init function. It should be an int function, not a PyObject *.
This commit is contained in:
parent
ded8e740df
commit
db6a569de7
|
@ -99,23 +99,6 @@ static PyTypeObject noddy_NoddyType = {
|
||||||
0, /*tp_as_buffer*/
|
0, /*tp_as_buffer*/
|
||||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||||
"Noddy objects", /* tp_doc */
|
"Noddy objects", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
|
||||||
0, /* tp_clear */
|
|
||||||
0, /* tp_richcompare */
|
|
||||||
0, /* tp_weaklistoffset */
|
|
||||||
0, /* tp_iter */
|
|
||||||
0, /* tp_iternext */
|
|
||||||
0, /* tp_methods */
|
|
||||||
0, /* tp_members */
|
|
||||||
0, /* tp_getset */
|
|
||||||
0, /* tp_base */
|
|
||||||
0, /* tp_dict */
|
|
||||||
0, /* tp_descr_get */
|
|
||||||
0, /* tp_descr_set */
|
|
||||||
0, /* tp_dictoffset */
|
|
||||||
0, /* tp_init */
|
|
||||||
0, /* tp_alloc */
|
|
||||||
PyType_GenericNew, /* tp_new */
|
|
||||||
};
|
};
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
@ -209,10 +192,17 @@ 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
|
objects. To enable object creation, we have to provide a
|
||||||
\member{tp_new} implementation. In this case, we can just use the
|
\member{tp_new} implementation. In this case, we can just use the
|
||||||
default implementation provided by the API function
|
default implementation provided by the API function
|
||||||
\cfunction{PyType_GenericNew}.
|
\cfunction{PyType_GenericNew}. We'd like to just assign this to the
|
||||||
|
\member{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 \member{tp_new} slot in the module initialization function
|
||||||
|
just before calling \cfunction{PyType_Ready()}:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
PyType_GenericNew, /* tp_new */
|
noddy_NoddyType.tp_new = PyType_GenericNew;
|
||||||
|
if (PyType_Ready(&noddy_NoddyType) < 0)
|
||||||
|
return;
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
All the other type methods are \NULL, so we'll go over them later
|
All the other type methods are \NULL, so we'll go over them later
|
||||||
|
@ -397,7 +387,7 @@ default allocation.
|
||||||
We provide an initialization function:
|
We provide an initialization function:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
static PyObject *
|
static int
|
||||||
Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
|
Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *first=NULL, *last=NULL;
|
PyObject *first=NULL, *last=NULL;
|
||||||
|
@ -407,7 +397,7 @@ Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
|
||||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
|
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
|
||||||
&first, &last,
|
&first, &last,
|
||||||
&self->number))
|
&self->number))
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
Py_XDECREF(self->first);
|
Py_XDECREF(self->first);
|
||||||
|
@ -421,8 +411,7 @@ Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
|
||||||
self->last = last;
|
self->last = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
return 0;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue