diff --git a/lib/python/common_extension.c b/lib/python/common_extension.c index 556fea443..46ae9e560 100644 --- a/lib/python/common_extension.c +++ b/lib/python/common_extension.c @@ -197,7 +197,7 @@ static PyMethodDef PyTask_methods[] = { {NULL} /* Sentinel */ }; -static PyTypeObject PyTaskType = { +PyTypeObject PyTaskType = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ "task.Task", /* tp_name */ sizeof(PyTask), /* tp_basicsize */ @@ -325,37 +325,3 @@ PyObject *check_simple_value(PyObject *self, PyObject *args) { } Py_RETURN_FALSE; } - -static PyMethodDef common_methods[] = { - {"check_simple_value", check_simple_value, METH_VARARGS, - "Should the object be passed by value?"}, - {NULL} /* Sentinel */ -}; - -#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ -#define PyMODINIT_FUNC void -#endif - -PyMODINIT_FUNC initcommon(void) { - PyObject *m; - - if (PyType_Ready(&PyTaskType) < 0) - return; - - if (PyType_Ready(&PyObjectIDType) < 0) - return; - - m = Py_InitModule3("common", common_methods, - "Example module that creates an extension type."); - - Py_INCREF(&PyTaskType); - PyModule_AddObject(m, "Task", (PyObject *) &PyTaskType); - - Py_INCREF(&PyObjectIDType); - PyModule_AddObject(m, "ObjectID", (PyObject *) &PyObjectIDType); - - char common_error[] = "common.error"; - CommonError = PyErr_NewException(common_error, NULL, NULL); - Py_INCREF(CommonError); - PyModule_AddObject(m, "common_error", CommonError); -} diff --git a/lib/python/common_extension.h b/lib/python/common_extension.h index 578c548d0..1fce38e42 100644 --- a/lib/python/common_extension.h +++ b/lib/python/common_extension.h @@ -24,6 +24,8 @@ typedef struct { extern PyTypeObject PyObjectIDType; +extern PyTypeObject PyTaskType; + int PyObjectToUniqueID(PyObject *object, object_id *objectid); PyObject *PyObjectID_make(object_id object_id); diff --git a/lib/python/common_module.c b/lib/python/common_module.c new file mode 100644 index 000000000..d5222cd87 --- /dev/null +++ b/lib/python/common_module.c @@ -0,0 +1,38 @@ +#include +#include "node.h" + +#include "common_extension.h" + +static PyMethodDef common_methods[] = { + {"check_simple_value", check_simple_value, METH_VARARGS, + "Should the object be passed by value?"}, + {NULL} /* Sentinel */ +}; + +#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ +#define PyMODINIT_FUNC void +#endif + +PyMODINIT_FUNC initcommon(void) { + PyObject *m; + + if (PyType_Ready(&PyTaskType) < 0) + return; + + if (PyType_Ready(&PyObjectIDType) < 0) + return; + + m = Py_InitModule3("common", common_methods, + "A module for common types. This is used for testing."); + + Py_INCREF(&PyTaskType); + PyModule_AddObject(m, "Task", (PyObject *) &PyTaskType); + + Py_INCREF(&PyObjectIDType); + PyModule_AddObject(m, "ObjectID", (PyObject *) &PyObjectIDType); + + char common_error[] = "common.error"; + CommonError = PyErr_NewException(common_error, NULL, NULL); + Py_INCREF(CommonError); + PyModule_AddObject(m, "common_error", CommonError); +} diff --git a/lib/python/setup.py b/lib/python/setup.py index db915b06b..8ef8a1abd 100644 --- a/lib/python/setup.py +++ b/lib/python/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages, Extension common_module = Extension("common", - sources=["common_extension.c"], + sources=["common_module.c", "common_extension.c"], include_dirs=["../../", "../../thirdparty"], extra_objects=["../../build/libcommon.a"], extra_compile_args=["--std=c99", "-Werror"])