Debian Codegraph @

protolib/src/python/protokit.cpp

raw
1 /**
2 * Python ProtoKit Wrapper
3 * By: Tom Wambold and Brian Adamson
4 */
5
6 // IMPORTANT NOTE: This code is not _yet_ compatible with Python3
7
8 #include "protopy.h"
9
10 // We include the other .cpp files directly
11 #include "protopipe.cpp"
12
13
14 extern "C" {
15
16 static PyMethodDef protokit_methods[] = {{NULL}};
17
18 #if PY_MAJOR_VERSION >= 3
19 static struct PyModuleDef moduledef = {
20 PyModuleDef_HEAD_INIT,
21 "protokit", /* m_name */
22 "Python wrapper for Protokit", /* m_doc */
23 -1, /* m_size */
24 protokit_methods, /* m_methods */
25 NULL, /* m_reload */
26 NULL, /* m_traverse */
27 NULL, /* m_clear */
28 NULL, /* m_free */
29 };
30 #endif // end PY_MAJOR_VERSION >= 3
31
32
33 static PyObject *
34 moduleinit(void)
35 {
36 PyObject *m;
37
38 if (PyType_Ready(&PipeType) < 0)
39 return m;
40
41 #if PY_MAJOR_VERSION >= 3
42 m = PyModule_Create(&moduledef);
43 #else
44 m = Py_InitModule3("protokit", protokit_methods, "Python wrapper for Protokit");
45 #endif
46
47 if (m == NULL)
48 return NULL;
49
50 ProtoError = PyErr_NewException((char*)"protokit.ProtoError", NULL, NULL);
51 Py_INCREF(ProtoError);
52 PyModule_AddObject(m, "ProtoError", ProtoError);
53
54 Py_INCREF(&PipeType);
55 PyModule_AddObject(m, "Pipe", (PyObject *)&PipeType);
56
57 return m;
58 }
59
60 #if PY_MAJOR_VERSION < 3
61 PyMODINIT_FUNC
62 initprotokit(void)
63 {
64 moduleinit();
65 }
66 #else
67 PyMODINIT_FUNC
68 PyInit_protokit(void)
69 {
70 return moduleinit();
71 }
72 #endif
73
74
75 } // extern "C"