forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl.c
48 lines (40 loc) · 1.06 KB
/
dl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <Python.h>
#include <dlfcn.h>
PyObject* module;
static PyMethodDef TorchDlMethods[] = {
{NULL, NULL, 0, NULL}
};
#if PY_MAJOR_VERSION != 2
static struct PyModuleDef torchdlmodule = {
PyModuleDef_HEAD_INIT,
"torch._dl",
NULL,
-1,
TorchDlMethods
};
#endif
#if PY_MAJOR_VERSION == 2
PyMODINIT_FUNC init_dl(void)
#else
PyMODINIT_FUNC PyInit__dl(void)
#endif
{
#if PY_MAJOR_VERSION == 2
#define ASSERT_TRUE(cmd) if (!(cmd)) {PyErr_SetString(PyExc_ImportError, "initialization error"); return;}
#else
#define ASSERT_TRUE(cmd) if (!(cmd)) return NULL
#endif
#if PY_MAJOR_VERSION == 2
ASSERT_TRUE(module = Py_InitModule("torch._dl", TorchDlMethods));
#else
ASSERT_TRUE(module = PyModule_Create(&torchdlmodule));
#endif
ASSERT_TRUE(PyModule_AddIntConstant(module, "RTLD_GLOBAL", (int64_t) RTLD_GLOBAL) == 0);
ASSERT_TRUE(PyModule_AddIntConstant(module, "RTLD_NOW", (int64_t) RTLD_NOW) == 0);
ASSERT_TRUE(PyModule_AddIntConstant(module, "RTLD_LAZY", (int64_t) RTLD_LAZY) == 0);
#if PY_MAJOR_VERSION == 2
#else
return module;
#endif
#undef ASSERT_TRUE
}