summaryrefslogtreecommitdiffstats
path: root/Doc/ext/noddy.c
blob: 23f26efc3d007d764daa4721f8ae3b121b366a63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <Python.h>

static PyTypeObject noddy_NoddyType;

typedef struct {
    PyObject_HEAD
    /* Type-specific fields go here. */
} noddy_NoddyObject;

static PyObject*
noddy_new_noddy(PyObject* self, PyObject* args)
{
    noddy_NoddyObject* noddy;

    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 = {
    PyObject_HEAD_INIT(NULL)
    0,
    "Noddy",
    sizeof(noddy_NoddyObject),
    0,
    noddy_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 */
};

static PyMethodDef noddy_methods[] = {
    {"new_noddy", noddy_new_noddy, METH_NOARGS,
     "Create a new Noddy object."},

    {NULL}  /* Sentinel */
};

PyMODINIT_FUNC
initnoddy(void) 
{
    noddy_NoddyType.ob_type = &PyType_Type;
    if (PyType_Ready(&noddy_NoddyType))
        return;

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