1 | n/a | #include <Python.h> |
---|
2 | n/a | |
---|
3 | n/a | typedef struct { |
---|
4 | n/a | PyObject_HEAD |
---|
5 | n/a | /* Type-specific fields go here. */ |
---|
6 | n/a | } noddy_NoddyObject; |
---|
7 | n/a | |
---|
8 | n/a | static PyTypeObject noddy_NoddyType = { |
---|
9 | n/a | PyVarObject_HEAD_INIT(NULL, 0) |
---|
10 | n/a | "noddy.Noddy", /* tp_name */ |
---|
11 | n/a | sizeof(noddy_NoddyObject), /* tp_basicsize */ |
---|
12 | n/a | 0, /* tp_itemsize */ |
---|
13 | n/a | 0, /* tp_dealloc */ |
---|
14 | n/a | 0, /* tp_print */ |
---|
15 | n/a | 0, /* tp_getattr */ |
---|
16 | n/a | 0, /* tp_setattr */ |
---|
17 | n/a | 0, /* tp_reserved */ |
---|
18 | n/a | 0, /* tp_repr */ |
---|
19 | n/a | 0, /* tp_as_number */ |
---|
20 | n/a | 0, /* tp_as_sequence */ |
---|
21 | n/a | 0, /* tp_as_mapping */ |
---|
22 | n/a | 0, /* tp_hash */ |
---|
23 | n/a | 0, /* tp_call */ |
---|
24 | n/a | 0, /* tp_str */ |
---|
25 | n/a | 0, /* tp_getattro */ |
---|
26 | n/a | 0, /* tp_setattro */ |
---|
27 | n/a | 0, /* tp_as_buffer */ |
---|
28 | n/a | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
---|
29 | n/a | "Noddy objects", /* tp_doc */ |
---|
30 | n/a | }; |
---|
31 | n/a | |
---|
32 | n/a | static PyModuleDef noddymodule = { |
---|
33 | n/a | PyModuleDef_HEAD_INIT, |
---|
34 | n/a | "noddy", |
---|
35 | n/a | "Example module that creates an extension type.", |
---|
36 | n/a | -1, |
---|
37 | n/a | NULL, NULL, NULL, NULL, NULL |
---|
38 | n/a | }; |
---|
39 | n/a | |
---|
40 | n/a | PyMODINIT_FUNC |
---|
41 | n/a | PyInit_noddy(void) |
---|
42 | n/a | { |
---|
43 | n/a | PyObject* m; |
---|
44 | n/a | |
---|
45 | n/a | noddy_NoddyType.tp_new = PyType_GenericNew; |
---|
46 | n/a | if (PyType_Ready(&noddy_NoddyType) < 0) |
---|
47 | n/a | return NULL; |
---|
48 | n/a | |
---|
49 | n/a | m = PyModule_Create(&noddymodule); |
---|
50 | n/a | if (m == NULL) |
---|
51 | n/a | return NULL; |
---|
52 | n/a | |
---|
53 | n/a | Py_INCREF(&noddy_NoddyType); |
---|
54 | n/a | PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); |
---|
55 | n/a | return m; |
---|
56 | n/a | } |
---|