1 #ifndef NUMBA_PY_MODULE_H_ 2 #define NUMBA_PY_MODULE_H_ 3 4 #define PY_SSIZE_T_CLEAN 5 6 #include <Python.h> 7 #include <structmember.h> 8 #include <frameobject.h> 9 10 #if PY_MAJOR_VERSION >= 3 11 #define MOD_ERROR_VAL NULL 12 #define MOD_SUCCESS_VAL(val) val 13 #define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) 14 #define MOD_DEF(ob, name, doc, methods) { \ 15 static struct PyModuleDef moduledef = { \ 16 PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \ 17 ob = PyModule_Create(&moduledef); } 18 #define MOD_INIT_EXEC(name) PyInit_##name(); 19 #else 20 #define MOD_ERROR_VAL 21 #define MOD_SUCCESS_VAL(val) 22 #define MOD_INIT(name) PyMODINIT_FUNC init##name(void) 23 #define MOD_DEF(ob, name, doc, methods) \ 24 ob = Py_InitModule3(name, methods, doc); 25 #define MOD_INIT_EXEC(name) init##name(); 26 #endif 27 28 29 #if PY_MAJOR_VERSION >= 3 30 #define PyString_AsString PyUnicode_AsUTF8 31 #define PyString_Check PyUnicode_Check 32 #define PyString_FromFormat PyUnicode_FromFormat 33 #define PyString_FromString PyUnicode_FromString 34 #define PyString_InternFromString PyUnicode_InternFromString 35 #define PyInt_Type PyLong_Type 36 #define PyInt_Check PyLong_Check 37 #define PyInt_CheckExact PyLong_CheckExact 38 #else 39 #define Py_hash_t long 40 #define Py_uhash_t unsigned long 41 #endif 42 43 #if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4) 44 #define PyMem_RawMalloc malloc 45 #define PyMem_RawRealloc realloc 46 #define PyMem_RawFree free 47 #endif 48 49 #ifndef Py_MIN 50 #define Py_MIN(x, y) (((x) > (y)) ? (y) : (x)) 51 #endif 52 53 #ifndef Py_MAX 54 #define Py_MAX(x, y) (((x) < (y)) ? (y) : (x)) 55 #endif 56 57 #endif /* NUMBA_PY_MODULE_H_ */ 58