blob: 8f79fcf6bf4c3c7b720cf88cb7d3205d1b8b977d [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001#include <Python.h>
2
3typedef struct {
4 PyObject_HEAD
5 /* Type-specific fields go here. */
6} noddy_NoddyObject;
7
8static PyTypeObject noddy_NoddyType = {
Georg Brandl51335292009-05-05 07:55:26 +00009 PyVarObject_HEAD_INIT(NULL, 0)
Georg Brandl913b2a32008-12-05 15:12:15 +000010 "noddy.Noddy", /* tp_name */
11 sizeof(noddy_NoddyObject), /* tp_basicsize */
12 0, /* tp_itemsize */
13 0, /* tp_dealloc */
14 0, /* tp_print */
15 0, /* tp_getattr */
16 0, /* tp_setattr */
Mark Dickinson9f989262009-02-02 21:29:40 +000017 0, /* tp_reserved */
Georg Brandl913b2a32008-12-05 15:12:15 +000018 0, /* tp_repr */
19 0, /* tp_as_number */
20 0, /* tp_as_sequence */
21 0, /* tp_as_mapping */
22 0, /* tp_hash */
23 0, /* tp_call */
24 0, /* tp_str */
25 0, /* tp_getattro */
26 0, /* tp_setattro */
27 0, /* tp_as_buffer */
28 Py_TPFLAGS_DEFAULT, /* tp_flags */
Georg Brandl116aa622007-08-15 14:28:22 +000029 "Noddy objects", /* tp_doc */
30};
31
Georg Brandl913b2a32008-12-05 15:12:15 +000032static PyModuleDef noddymodule = {
33 PyModuleDef_HEAD_INIT,
34 "noddy",
35 "Example module that creates an extension type.",
36 -1,
37 NULL, NULL, NULL, NULL, NULL
Georg Brandl116aa622007-08-15 14:28:22 +000038};
39
Georg Brandl116aa622007-08-15 14:28:22 +000040PyMODINIT_FUNC
Georg Brandl913b2a32008-12-05 15:12:15 +000041PyInit_noddy(void)
Georg Brandl116aa622007-08-15 14:28:22 +000042{
43 PyObject* m;
44
45 noddy_NoddyType.tp_new = PyType_GenericNew;
46 if (PyType_Ready(&noddy_NoddyType) < 0)
Georg Brandl913b2a32008-12-05 15:12:15 +000047 return NULL;
Georg Brandl116aa622007-08-15 14:28:22 +000048
Georg Brandl913b2a32008-12-05 15:12:15 +000049 m = PyModule_Create(&noddymodule);
50 if (m == NULL)
51 return NULL;
Georg Brandl116aa622007-08-15 14:28:22 +000052
53 Py_INCREF(&noddy_NoddyType);
54 PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType);
Benjamin Peterson71e30a02008-12-24 16:27:25 +000055 return m;
Georg Brandl116aa622007-08-15 14:28:22 +000056}