WIP: modifications for Python 3

This commit is contained in:
Matthias Koefferlein 2018-06-09 09:42:13 +02:00
parent e1858973e2
commit d938bb999b
2 changed files with 38 additions and 3 deletions

View File

@ -2195,14 +2195,16 @@ PythonModule::init (const char *mod_name, const char *description)
m_mod_name = pymod_name + "." + mod_name;
m_mod_description = description;
PyObject *module = 0;
#if PY_MAJOR_VERSION < 3
static PyMethodDef module_methods[] = {
{NULL} // Sentinel
};
PyObject *module = 0;
#if PY_MAJOR_VERSION < 3
module = Py_InitModule3 (m_mod_name.c_str (), module_methods, m_mod_description.c_str ());
#else
struct PyModuleDef mod_def = {

View File

@ -146,6 +146,8 @@ static PyMethodDef BridgeMethods[] = {
{ NULL, NULL, 0, NULL } // terminal
};
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC
initbridge_sample ()
{
@ -160,3 +162,34 @@ initbridge_sample ()
Py_INCREF (BridgeError);
PyModule_AddObject (m, "error", BridgeError);
}
#else
static
struct PyModuleDef bridge_module =
{
PyModuleDef_HEAD_INIT,
"bridge_sample",
NULL,
-1,
BridgeMethods
};
PyMODINIT_FUNC
PyInit_bridge_sample ()
{
PyObject *m;
m = PyModule_Create (&bridge_module);
if (m == NULL) {
return NULL;
}
BridgeError = PyErr_NewException ((char *) "bridge_sample.error", NULL, NULL);
Py_INCREF (BridgeError);
PyModule_AddObject (m, "error", BridgeError);
return m;
}
#endif