Mailing List Archive

python/dist/src/Doc/ext noddy.c,1.1,1.2
Update of /cvsroot/python/python/dist/src/Doc/ext
In directory usw-pr-cvs1:/tmp/cvs-serv3956/ext

Modified Files:
noddy.c
Log Message:
Modernize the minimal example of an extension type.

Index: noddy.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/ext/noddy.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** noddy.c 28 Mar 2002 23:32:53 -0000 1.1
--- noddy.c 12 Apr 2002 16:17:06 -0000 1.2
***************
*** 5,8 ****
--- 5,9 ----
typedef struct {
PyObject_HEAD
+ /* Type-specific fields go here. */
} noddy_NoddyObject;

***************
*** 12,20 ****
noddy_NoddyObject* noddy;

- if (!PyArg_ParseTuple(args,":new_noddy"))
- return NULL;
-
noddy = PyObject_New(noddy_NoddyObject, &noddy_NoddyType);

return (PyObject*)noddy;
}
--- 13,20 ----
noddy_NoddyObject* noddy;

noddy = PyObject_New(noddy_NoddyObject, &noddy_NoddyType);

+ /* Initialize type-specific fields here. */
+
return (PyObject*)noddy;
}
***************
*** 23,30 ****
noddy_noddy_dealloc(PyObject* self)
{
PyObject_Del(self);
}

! static PyTypeObject noddy_NoddyType = {
PyObject_HEAD_INIT(NULL)
0,
--- 23,34 ----
noddy_noddy_dealloc(PyObject* self)
{
+ /* Free any external resources here;
+ * if the instance owns references to any Python
+ * objects, call Py_DECREF() on them here.
+ */
PyObject_Del(self);
}

! statichere PyTypeObject noddy_NoddyType = {
PyObject_HEAD_INIT(NULL)
0,
***************
*** 45,51 ****

static PyMethodDef noddy_methods[] = {
! {"new_noddy", noddy_new_noddy, METH_VARARGS,
"Create a new Noddy object."},
! {NULL, NULL, 0, NULL}
};

--- 49,56 ----

static PyMethodDef noddy_methods[] = {
! {"new_noddy", noddy_new_noddy, METH_NOARGS,
"Create a new Noddy object."},
!
! {NULL} /* Sentinel */
};

***************
*** 54,58 ****
{
noddy_NoddyType.ob_type = &PyType_Type;

! Py_InitModule("noddy", noddy_methods);
}
--- 59,66 ----
{
noddy_NoddyType.ob_type = &PyType_Type;
+ if (PyType_Ready(&noddy_NoddyType))
+ return;

! Py_InitModule3("noddy", noddy_methods
! "Example module that creates an extension type.");
}