blob: 51d801fcd19bb0c1d96a5c8f5b95f10cc799af3f [file] [log] [blame]
Fred Drake2ab0a102002-03-28 23:32:53 +00001#include <Python.h>
2
3staticforward PyTypeObject noddy_NoddyType;
4
5typedef struct {
6 PyObject_HEAD
Fred Drakeee485192002-04-12 16:17:06 +00007 /* Type-specific fields go here. */
Fred Drake2ab0a102002-03-28 23:32:53 +00008} noddy_NoddyObject;
9
10static PyObject*
11noddy_new_noddy(PyObject* self, PyObject* args)
12{
13 noddy_NoddyObject* noddy;
14
Fred Drake2ab0a102002-03-28 23:32:53 +000015 noddy = PyObject_New(noddy_NoddyObject, &noddy_NoddyType);
16
Fred Drakeee485192002-04-12 16:17:06 +000017 /* Initialize type-specific fields here. */
18
Fred Drake2ab0a102002-03-28 23:32:53 +000019 return (PyObject*)noddy;
20}
21
22static void
23noddy_noddy_dealloc(PyObject* self)
24{
Fred Drakeee485192002-04-12 16:17:06 +000025 /* Free any external resources here;
26 * if the instance owns references to any Python
27 * objects, call Py_DECREF() on them here.
28 */
Fred Drake2ab0a102002-03-28 23:32:53 +000029 PyObject_Del(self);
30}
31
Fred Drakeee485192002-04-12 16:17:06 +000032statichere PyTypeObject noddy_NoddyType = {
Fred Drake2ab0a102002-03-28 23:32:53 +000033 PyObject_HEAD_INIT(NULL)
34 0,
35 "Noddy",
36 sizeof(noddy_NoddyObject),
37 0,
38 noddy_noddy_dealloc, /*tp_dealloc*/
39 0, /*tp_print*/
40 0, /*tp_getattr*/
41 0, /*tp_setattr*/
42 0, /*tp_compare*/
43 0, /*tp_repr*/
44 0, /*tp_as_number*/
45 0, /*tp_as_sequence*/
46 0, /*tp_as_mapping*/
47 0, /*tp_hash */
48};
49
50static PyMethodDef noddy_methods[] = {
Fred Drakeee485192002-04-12 16:17:06 +000051 {"new_noddy", noddy_new_noddy, METH_NOARGS,
Fred Drake2ab0a102002-03-28 23:32:53 +000052 "Create a new Noddy object."},
Fred Drakeee485192002-04-12 16:17:06 +000053
54 {NULL} /* Sentinel */
Fred Drake2ab0a102002-03-28 23:32:53 +000055};
56
57DL_EXPORT(void)
58initnoddy(void)
59{
60 noddy_NoddyType.ob_type = &PyType_Type;
Fred Drakeee485192002-04-12 16:17:06 +000061 if (PyType_Ready(&noddy_NoddyType))
62 return;
Fred Drake2ab0a102002-03-28 23:32:53 +000063
Fred Drakeee485192002-04-12 16:17:06 +000064 Py_InitModule3("noddy", noddy_methods
65 "Example module that creates an extension type.");
Fred Drake2ab0a102002-03-28 23:32:53 +000066}