diff options
author | Georg Brandl <georg@python.org> | 2008-12-05 15:12:15 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-12-05 15:12:15 (GMT) |
commit | 913b2a382f237c89a43198001398c61b3196b0be (patch) | |
tree | cad950671e6b0bdef9722719a2449e0d4ec432e7 /Doc/includes | |
parent | a872de55dc9d4e292c4b8fe7e09741081890305e (diff) | |
download | cpython-913b2a382f237c89a43198001398c61b3196b0be.zip cpython-913b2a382f237c89a43198001398c61b3196b0be.tar.gz cpython-913b2a382f237c89a43198001398c61b3196b0be.tar.bz2 |
#4504, #4505: Update noddy examples in "Extending & Embedding".
Diffstat (limited to 'Doc/includes')
-rw-r--r-- | Doc/includes/noddy.c | 59 | ||||
-rw-r--r-- | Doc/includes/noddy2.c | 63 | ||||
-rw-r--r-- | Doc/includes/noddy3.c | 63 | ||||
-rw-r--r-- | Doc/includes/noddy4.c | 64 | ||||
-rw-r--r-- | Doc/includes/shoddy.c | 19 | ||||
-rw-r--r-- | Doc/includes/typestruct.h | 3 |
6 files changed, 137 insertions, 134 deletions
diff --git a/Doc/includes/noddy.c b/Doc/includes/noddy.c index ec2d669..26a49a9 100644 --- a/Doc/includes/noddy.c +++ b/Doc/includes/noddy.c @@ -7,47 +7,48 @@ typedef struct { static PyTypeObject noddy_NoddyType = { PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "noddy.Noddy", /*tp_name*/ - sizeof(noddy_NoddyObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ + "noddy.Noddy", /* tp_name */ + sizeof(noddy_NoddyObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ "Noddy objects", /* tp_doc */ }; -static PyMethodDef noddy_methods[] = { - {NULL} /* Sentinel */ +static PyModuleDef noddymodule = { + PyModuleDef_HEAD_INIT, + "noddy", + "Example module that creates an extension type.", + -1, + NULL, NULL, NULL, NULL, NULL }; -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void -#endif PyMODINIT_FUNC -initnoddy(void) +PyInit_noddy(void) { PyObject* m; noddy_NoddyType.tp_new = PyType_GenericNew; if (PyType_Ready(&noddy_NoddyType) < 0) - return; + return NULL; - m = Py_InitModule3("noddy", noddy_methods, - "Example module that creates an extension type."); + m = PyModule_Create(&noddymodule); + if (m == NULL) + return NULL; Py_INCREF(&noddy_NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); diff --git a/Doc/includes/noddy2.c b/Doc/includes/noddy2.c index eaa355f..5daecf9 100644 --- a/Doc/includes/noddy2.c +++ b/Doc/includes/noddy2.c @@ -13,7 +13,7 @@ Noddy_dealloc(Noddy* self) { Py_XDECREF(self->first); Py_XDECREF(self->last); - self->ob_type->tp_free((PyObject*)self); + Py_TYPE(self)->tp_free((PyObject*)self); } static PyObject * @@ -124,26 +124,26 @@ static PyMethodDef Noddy_methods[] = { static PyTypeObject NoddyType = { PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "noddy.Noddy", /*tp_name*/ - sizeof(Noddy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Noddy_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "noddy.Noddy", /* tp_name */ + sizeof(Noddy), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Noddy_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ "Noddy objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ @@ -164,26 +164,25 @@ static PyTypeObject NoddyType = { Noddy_new, /* tp_new */ }; -static PyMethodDef module_methods[] = { - {NULL} /* Sentinel */ +static PyModuleDef noddy2module = { + PyModuleDef_HEAD_INIT, + "noddy2", + "Example module that creates an extension type.", + -1, + NULL, NULL, NULL, NULL, NULL }; -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void -#endif PyMODINIT_FUNC -initnoddy2(void) +PyInit_noddy2(void) { PyObject* m; if (PyType_Ready(&NoddyType) < 0) - return; - - m = Py_InitModule3("noddy2", module_methods, - "Example module that creates an extension type."); + return NULL; + m = PyModule_Create(&noddy2module); if (m == NULL) - return; + return NULL; Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); diff --git a/Doc/includes/noddy3.c b/Doc/includes/noddy3.c index 3a1c0c2..39cdfdb 100644 --- a/Doc/includes/noddy3.c +++ b/Doc/includes/noddy3.c @@ -13,7 +13,7 @@ Noddy_dealloc(Noddy* self) { Py_XDECREF(self->first); Py_XDECREF(self->last); - self->ob_type->tp_free((PyObject*)self); + Py_TYPE(self)->tp_free((PyObject*)self); } static PyObject * @@ -177,26 +177,26 @@ static PyMethodDef Noddy_methods[] = { static PyTypeObject NoddyType = { PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "noddy.Noddy", /*tp_name*/ - sizeof(Noddy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Noddy_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "noddy.Noddy", /* tp_name */ + sizeof(Noddy), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Noddy_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE, /* tp_flags */ "Noddy objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ @@ -217,26 +217,25 @@ static PyTypeObject NoddyType = { Noddy_new, /* tp_new */ }; -static PyMethodDef module_methods[] = { - {NULL} /* Sentinel */ +static PyModuleDef noddy3module = { + PyModuleDef_HEAD_INIT, + "noddy3", + "Example module that creates an extension type.", + -1, + NULL, NULL, NULL, NULL, NULL }; -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void -#endif PyMODINIT_FUNC -initnoddy3(void) +PyInit_noddy3(void) { PyObject* m; if (PyType_Ready(&NoddyType) < 0) - return; - - m = Py_InitModule3("noddy3", module_methods, - "Example module that creates an extension type."); + return NULL; + m = PyModule_Create(&noddy3module); if (m == NULL) - return; + return NULL; Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); diff --git a/Doc/includes/noddy4.c b/Doc/includes/noddy4.c index ac0b1f4..94507ec 100644 --- a/Doc/includes/noddy4.c +++ b/Doc/includes/noddy4.c @@ -47,7 +47,7 @@ static void Noddy_dealloc(Noddy* self) { Noddy_clear(self); - self->ob_type->tp_free((PyObject*)self); + Py_TYPE(self)->tp_free((PyObject*)self); } static PyObject * @@ -158,26 +158,27 @@ static PyMethodDef Noddy_methods[] = { static PyTypeObject NoddyType = { PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "noddy.Noddy", /*tp_name*/ - sizeof(Noddy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)Noddy_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + "noddy.Noddy", /* tp_name */ + sizeof(Noddy), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Noddy_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC, /* tp_flags */ "Noddy objects", /* tp_doc */ (traverseproc)Noddy_traverse, /* tp_traverse */ (inquiry)Noddy_clear, /* tp_clear */ @@ -198,26 +199,25 @@ static PyTypeObject NoddyType = { Noddy_new, /* tp_new */ }; -static PyMethodDef module_methods[] = { - {NULL} /* Sentinel */ +static PyModuleDef noddy4module = { + PyModuleDef_HEAD_INIT, + "noddy4", + "Example module that creates an extension type.", + -1, + NULL, NULL, NULL, NULL, NULL }; -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void -#endif PyMODINIT_FUNC -initnoddy4(void) +PyInit_noddy4(void) { PyObject* m; if (PyType_Ready(&NoddyType) < 0) - return; - - m = Py_InitModule3("noddy4", module_methods, - "Example module that creates an extension type."); + return NULL; + m = PyModule_Create(&noddy4module); if (m == NULL) - return; + return NULL; Py_INCREF(&NoddyType); PyModule_AddObject(m, "Noddy", (PyObject *)&NoddyType); diff --git a/Doc/includes/shoddy.c b/Doc/includes/shoddy.c index 4c46bea..3757bca 100644 --- a/Doc/includes/shoddy.c +++ b/Doc/includes/shoddy.c @@ -32,7 +32,6 @@ Shoddy_init(Shoddy *self, PyObject *args, PyObject *kwds) static PyTypeObject ShoddyType = { PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ "shoddy.Shoddy", /* tp_name */ sizeof(Shoddy), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -52,7 +51,7 @@ static PyTypeObject ShoddyType = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE, /* tp_flags */ + Py_TPFLAGS_BASETYPE, /* tp_flags */ 0, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ @@ -73,18 +72,26 @@ static PyTypeObject ShoddyType = { 0, /* tp_new */ }; +static PyModuleDef shoddymodule = { + PyModuleDef_HEAD_INIT, + "shoddy", + "Shoddy module", + -1, + NULL, NULL, NULL, NULL, NULL +}; + PyMODINIT_FUNC -initshoddy(void) +PyInit_shoddy(void) { PyObject *m; ShoddyType.tp_base = &PyList_Type; if (PyType_Ready(&ShoddyType) < 0) - return; + return NULL; - m = Py_InitModule3("shoddy", NULL, "Shoddy module"); + m = PyModule_Create(&shoddymodule); if (m == NULL) - return; + return NULL; Py_INCREF(&ShoddyType); PyModule_AddObject(m, "Shoddy", (PyObject *) &ShoddyType); diff --git a/Doc/includes/typestruct.h b/Doc/includes/typestruct.h index 0afe375..f6451b9 100644 --- a/Doc/includes/typestruct.h +++ b/Doc/includes/typestruct.h @@ -34,21 +34,18 @@ typedef struct _typeobject { char *tp_doc; /* Documentation string */ - /* Assigned meaning in release 2.0 */ /* call function for all accessible objects */ traverseproc tp_traverse; /* delete references to contained objects */ inquiry tp_clear; - /* Assigned meaning in release 2.1 */ /* rich comparisons */ richcmpfunc tp_richcompare; /* weak reference enabler */ long tp_weaklistoffset; - /* Added in release 2.2 */ /* Iterators */ getiterfunc tp_iter; iternextfunc tp_iternext; |