Skip to content

Commit 36a01cf

Browse files
committed
Allow compile in Python 2/3
1 parent d566f47 commit 36a01cf

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
from __future__ import unicode_literals
2+
33
from distutils.core import setup, Extension
44
import sys
55
import os

src/RadProfModule.c

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,23 +1103,45 @@ static PyMethodDef radProfMethods[] = {
11031103
{NULL, NULL, 0, NULL} /* Sentinel */
11041104
};
11051105

1106-
static struct PyModuleDef pyguidemodule = {
1107-
PyModuleDef_HEAD_INIT,
1108-
"radProf", /* name of module */
1109-
radProfModule_doc, /* module documentation, may be NULL */
1110-
-1, /* size of per-interpreter state of the module,
1111-
or -1 if the module keeps state in global variables. */
1112-
radProfMethods
1113-
};
11141106

1115-
// Module initialization function
1116-
PyMODINIT_FUNC PyInit_radProf(void) {
1117-
import_array();
1118-
return PyModule_Create(&pyguidemodule);
1119-
// PyObject *m;
1120-
// m = PyModule_Create(&pyguidemodule);
1121-
// if (m == NULL)
1122-
// return NULL;
1107+
#if PY_MAJOR_VERSION >= 3
11231108

1124-
// import_array();
1125-
}
1109+
static struct PyModuleDef pyguidemodule = {
1110+
PyModuleDef_HEAD_INIT,
1111+
"radProf", /* name of module */
1112+
radProfModule_doc, /* module documentation, may be NULL */
1113+
-1, /* size of per-interpreter state of the module,
1114+
or -1 if the module keeps state in global variables. */
1115+
radProfMethods
1116+
};
1117+
1118+
#endif
1119+
1120+
1121+
#if PY_MAJOR_VERSION >= 3
1122+
1123+
// Module initialization function
1124+
PyMODINIT_FUNC PyInit_radProf(void) {
1125+
import_array();
1126+
return PyModule_Create(&pyguidemodule);
1127+
// PyObject *m;
1128+
// m = PyModule_Create(&pyguidemodule);
1129+
// if (m == NULL)
1130+
// return NULL;
1131+
1132+
// import_array();
1133+
}
1134+
1135+
#else
1136+
1137+
// Module initialization function
1138+
PyMODINIT_FUNC initradProf(void) {
1139+
PyObject *m;
1140+
m = Py_InitModule3("radProf", radProfMethods, radProfModule_doc);
1141+
if (m == NULL)
1142+
return;
1143+
1144+
import_array();
1145+
}
1146+
1147+
#endif

0 commit comments

Comments
 (0)