diff options
author | Fred Drake <fdrake@acm.org> | 2002-04-12 16:17:06 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2002-04-12 16:17:06 (GMT) |
commit | ee48519bc63c2d423bcc267437d26722fbc37c4e (patch) | |
tree | 777b5d540b2970422bfd50fed1df9f13eb481d64 /Doc | |
parent | 28de8d4b372ac6bf6adb305484b6e8a9bf21ca8f (diff) | |
download | cpython-ee48519bc63c2d423bcc267437d26722fbc37c4e.zip cpython-ee48519bc63c2d423bcc267437d26722fbc37c4e.tar.gz cpython-ee48519bc63c2d423bcc267437d26722fbc37c4e.tar.bz2 |
Modernize the minimal example of an extension type.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/ext/noddy.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/Doc/ext/noddy.c b/Doc/ext/noddy.c index d0842e0..51d801f 100644 --- a/Doc/ext/noddy.c +++ b/Doc/ext/noddy.c @@ -4,6 +4,7 @@ staticforward PyTypeObject noddy_NoddyType; typedef struct { PyObject_HEAD + /* Type-specific fields go here. */ } noddy_NoddyObject; static PyObject* @@ -11,21 +12,24 @@ noddy_new_noddy(PyObject* self, PyObject* args) { noddy_NoddyObject* noddy; - if (!PyArg_ParseTuple(args,":new_noddy")) - return NULL; - noddy = PyObject_New(noddy_NoddyObject, &noddy_NoddyType); + /* Initialize type-specific fields here. */ + return (PyObject*)noddy; } static void 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); } -static PyTypeObject noddy_NoddyType = { +statichere PyTypeObject noddy_NoddyType = { PyObject_HEAD_INIT(NULL) 0, "Noddy", @@ -44,15 +48,19 @@ static PyTypeObject noddy_NoddyType = { }; static PyMethodDef noddy_methods[] = { - {"new_noddy", noddy_new_noddy, METH_VARARGS, + {"new_noddy", noddy_new_noddy, METH_NOARGS, "Create a new Noddy object."}, - {NULL, NULL, 0, NULL} + + {NULL} /* Sentinel */ }; DL_EXPORT(void) initnoddy(void) { noddy_NoddyType.ob_type = &PyType_Type; + if (PyType_Ready(&noddy_NoddyType)) + return; - Py_InitModule("noddy", noddy_methods); + Py_InitModule3("noddy", noddy_methods + "Example module that creates an extension type."); } |