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 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include <Python.h>
#include "pylcm_subscription.h"
//#define dbg(...) fprintf (stderr, __VA_ARGS__)
#define dbg(...)
// to support python 2.5 and earlier
#ifndef Py_TYPE
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
#endif
extern PyTypeObject pylcmeventlog_type;
extern PyTypeObject pylcm_type;
extern PyTypeObject pylcm_subscription_type;
/* module initialization */
static PyMethodDef lcmmod_methods[] = {
{ NULL, NULL } /* sentinel */
};
PyDoc_STRVAR (lcmmod_doc, "LCM python extension modules");
// macro to make module init portable between python 2 and 3
#if PY_MAJOR_VERSION >= 3
#define MOD_DEF(ob, name, doc, methods) \
static struct PyModuleDef moduledef = { \
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
ob = PyModule_Create(&moduledef);
#else
#define MOD_DEF(ob, name, doc, methods) \
ob = Py_InitModule3(name, methods, doc);
#endif
PyMODINIT_FUNC
#if PY_MAJOR_VERSION >=3
PyInit__lcm (void)
#else
init_lcm (void)
#endif
{
PyObject *m;
Py_TYPE(&pylcmeventlog_type) = &PyType_Type;
Py_TYPE(&pylcm_type) = &PyType_Type;
Py_TYPE(&pylcm_subscription_type) = &PyType_Type;
MOD_DEF(m, "_lcm", lcmmod_doc, lcmmod_methods);
Py_INCREF (&pylcmeventlog_type);
if (PyModule_AddObject (m, "EventLog",
(PyObject *)&pylcmeventlog_type) != 0) {
#if PY_MAJOR_VERSION >= 3
return NULL; // in python 3 return NULL on error
#else
return;
#endif
}
Py_INCREF (&pylcm_type);
if (PyModule_AddObject (m, "LCM", (PyObject *)&pylcm_type) != 0) {
#if PY_MAJOR_VERSION >= 3
return NULL; // in python 3 return NULL on error
#else
return;
#endif
}
Py_INCREF (&pylcm_subscription_type);
if (PyModule_AddObject (m, "LCMSubscription",
(PyObject *)&pylcm_subscription_type) != 0) {
#if PY_MAJOR_VERSION >= 3
return NULL; // in python 3 return NULL on error
#else
return;
#endif
}
#if PY_MAJOR_VERSION >= 3
return m; // in python 3, we must return the PyObject
#endif
}
|