CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_pymodule.h52 linesDownload Raw Back to numba
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/*
11 * Macro to handle GIL/free-threading at module level. Call on a newly created
12 * module returned by a call to PyModule_Create().
13 */
14#ifdef Py_GIL_DISABLED
15#define MOD_NOGIL(m) \
16        do { \
17                PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); \
18        } while(0)
19#else
20#define MOD_NOGIL(m) do {} while(0)
21#endif
22
23#define MOD_ERROR_VAL NULL
24#define MOD_SUCCESS_VAL(val) val
25#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
26#define MOD_DEF(ob, name, doc, methods) { \
27        static struct PyModuleDef moduledef = { \
28          PyModuleDef_HEAD_INIT, name, doc, -1, methods, NULL, NULL, NULL, NULL }; \
29        ob = PyModule_Create(&moduledef); \
30        if (ob == NULL) { return MOD_ERROR_VAL; } \
31        MOD_NOGIL(ob); \
32}
33#define MOD_INIT_EXEC(name) PyInit_##name();
34
35#define PyString_AsString PyUnicode_AsUTF8
36#define PyString_Check PyUnicode_Check
37#define PyString_FromFormat PyUnicode_FromFormat
38#define PyString_FromString PyUnicode_FromString
39#define PyString_InternFromString PyUnicode_InternFromString
40#define PyInt_Type PyLong_Type
41#define PyInt_Check PyLong_Check
42#define PyInt_CheckExact PyLong_CheckExact
43#define SetAttrStringFromVoidPointer(m, name) do { \
44        PyObject *tmp = PyLong_FromVoidPtr((void *) &name); \
45        PyObject_SetAttrString(m, #name, tmp); \
46        Py_DECREF(tmp); } while (0)
47
48
49#define NB_SUPPORTED_PYTHON_MINOR ((PY_MINOR_VERSION == 10) || (PY_MINOR_VERSION == 11) || (PY_MINOR_VERSION == 12) || (PY_MINOR_VERSION == 13) || (PY_MINOR_VERSION == 14))
50
51#endif /* NUMBA_PY_MODULE_H_ */
52 
Aluode/PerceptionLabPortable · CoolFace