summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorHouzéfa Abbasbhay <houzefa.abba@xcg-consulting.fr>2014-12-01 11:54:01 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2015-02-12 18:21:12 (GMT)
commita4b1749c3ca7baafbf188539d8b96f1cd131a968 (patch)
tree5bdd99d54f74d9a3dd4fcad97bfedf7a8643f650 /bindings
parente4ebeefab3791ebf665710fd5fbf3aa1313bc118 (diff)
downloadlasso-a4b1749c3ca7baafbf188539d8b96f1cd131a968.zip
lasso-a4b1749c3ca7baafbf188539d8b96f1cd131a968.tar.gz
lasso-a4b1749c3ca7baafbf188539d8b96f1cd131a968.tar.bz2
Python 3: Fix module init
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/wrapper_bottom.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/bindings/python/wrapper_bottom.c b/bindings/python/wrapper_bottom.c
index 730c21b..30971b1 100644
--- a/bindings/python/wrapper_bottom.c
+++ b/bindings/python/wrapper_bottom.c
@@ -1,12 +1,30 @@
-PyMODINIT_FUNC
-init_lasso(void)
+// Module init has changed quite a bit between Python 2 & 3.
+// Defines taken from <http://python3porting.com/cextensions.html>.
+
+#if PY_MAJOR_VERSION >= 3
+ #define MOD_ERROR_VAL NULL
+ #define MOD_SUCCESS_VAL(val) val
+ #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
+ #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_ERROR_VAL
+ #define MOD_SUCCESS_VAL(val)
+ #define MOD_INIT(name) void init##name(void)
+ #define MOD_DEF(ob, name, doc, methods) \
+ ob = Py_InitModule3(name, methods, doc);
+#endif
+
+MOD_INIT(_lasso)
{
PyObject *m, *d;
if (PyType_Ready(&PyGObjectPtrType) < 0)
- return;
+ return MOD_ERROR_VAL;
- m = Py_InitModule3("_lasso", lasso_methods, "_lasso wrapper module");
+ MOD_DEF(m, "_lasso", "_lasso wrapper module", lasso_methods);
d = PyModule_GetDict(m);
register_constants(d);
@@ -17,5 +35,7 @@ init_lasso(void)
lasso_init();
lasso_log_set_handler(G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION | G_LOG_LEVEL_MASK,
lasso_python_log, NULL);
+
+ return MOD_SUCCESS_VAL(m);
}