1 |
#ifndef PYSHAPELIB_H |
2 |
#define PYSHAPELIB_H |
3 |
|
4 |
#include <Python.h> |
5 |
#include <structmember.h> |
6 |
|
7 |
#define PYSHAPELIB_ADD_CONSTANT(constant) PyModule_AddIntConstant(module, #constant, constant) |
8 |
|
9 |
#define PYSHAPELIB_DEFINE_TYPE(type, name, doc) \ |
10 |
{ \ |
11 |
PyObject_HEAD_INIT(NULL) \ |
12 |
0, /*ob_size*/ \ |
13 |
name, /*tp_name*/ \ |
14 |
sizeof(type), /*tp_basicsize*/ \ |
15 |
0, /*tp_itemsize*/ \ |
16 |
(destructor) type ## _dealloc, /*tp_dealloc*/ \ |
17 |
0, /*tp_print*/ \ |
18 |
0, /*tp_getattr*/ \ |
19 |
0, /*tp_setattr*/ \ |
20 |
0, /*tp_compare*/ \ |
21 |
0, /*tp_repr*/ \ |
22 |
0, /*tp_as_number*/ \ |
23 |
0, /*tp_as_sequence*/ \ |
24 |
0, /*tp_as_mapping*/ \ |
25 |
0, /*tp_hash */ \ |
26 |
0, /*tp_call*/ \ |
27 |
0, /*tp_str*/ \ |
28 |
0, /*tp_getattro*/ \ |
29 |
0, /*tp_setattro*/ \ |
30 |
0, /*tp_as_buffer*/ \ |
31 |
Py_TPFLAGS_DEFAULT, /*tp_flags*/ \ |
32 |
doc, /* tp_doc */ \ |
33 |
0, /* tp_traverse */ \ |
34 |
0, /* tp_clear */ \ |
35 |
0, /* tp_richcompare */ \ |
36 |
0, /* tp_weaklistoffset */ \ |
37 |
0, /* tp_iter */ \ |
38 |
0, /* tp_iternext */ \ |
39 |
type ## _methods, /* tp_methods */ \ |
40 |
0, /* tp_members */ \ |
41 |
type ## _getsetters, /* tp_getset */ \ |
42 |
0, /* tp_base */ \ |
43 |
0, /* tp_dict */ \ |
44 |
0, /* tp_descr_get */ \ |
45 |
0, /* tp_descr_set */ \ |
46 |
0, /* tp_dictoffset */ \ |
47 |
(initproc) type ## _init, /* tp_init */ \ |
48 |
0, /* tp_alloc */ \ |
49 |
type ## _new, /* tp_new */ \ |
50 |
} \ |
51 |
/**/ |
52 |
|
53 |
#define PYSHAPELIB_ADD_TYPE(type, name) \ |
54 |
type.ob_type = &PyType_Type; \ |
55 |
if (PyType_Ready(&type) >= 0) \ |
56 |
{ \ |
57 |
Py_INCREF(&type); \ |
58 |
PyModule_AddObject(module, name, (PyObject*)&type); \ |
59 |
} |
60 |
|
61 |
|
62 |
|
63 |
#endif |