Caffe2 - C++ API
A deep learning, cross platform ML framework
dl.c
1 #include <Python.h>
2 #include <dlfcn.h>
3 
4 PyObject* module;
5 
6 static PyMethodDef TorchDlMethods[] = {
7  {NULL, NULL, 0, NULL}
8 };
9 
10 #if PY_MAJOR_VERSION != 2
11 static struct PyModuleDef torchdlmodule = {
12  PyModuleDef_HEAD_INIT,
13  "torch._dl",
14  NULL,
15  -1,
16  TorchDlMethods
17 };
18 #endif
19 
20 #if PY_MAJOR_VERSION == 2
21 PyMODINIT_FUNC init_dl(void)
22 #else
23 PyMODINIT_FUNC PyInit__dl(void)
24 #endif
25 {
26 
27 #if PY_MAJOR_VERSION == 2
28 #define ASSERT_TRUE(cmd) if (!(cmd)) {PyErr_SetString(PyExc_ImportError, "initialization error"); return;}
29 #else
30 #define ASSERT_TRUE(cmd) if (!(cmd)) return NULL
31 #endif
32 
33 #if PY_MAJOR_VERSION == 2
34  ASSERT_TRUE(module = Py_InitModule("torch._dl", TorchDlMethods));
35 #else
36  ASSERT_TRUE(module = PyModule_Create(&torchdlmodule));
37 #endif
38  ASSERT_TRUE(PyModule_AddIntConstant(module, "RTLD_GLOBAL", (int64_t) RTLD_GLOBAL) == 0);
39  ASSERT_TRUE(PyModule_AddIntConstant(module, "RTLD_NOW", (int64_t) RTLD_NOW) == 0);
40  ASSERT_TRUE(PyModule_AddIntConstant(module, "RTLD_LAZY", (int64_t) RTLD_LAZY) == 0);
41 
42 #if PY_MAJOR_VERSION == 2
43 #else
44  return module;
45 #endif
46 
47 #undef ASSERT_TRUE
48 }