forked from bazel-contrib/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfoo.cc
52 lines (41 loc) · 1.28 KB
/
foo.cc
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
49
50
51
52
#include <Python.h>
#include <stddef.h>
#ifndef MODULE_NAME
#define MODULE_NAME ext_typical
#endif
// Stringification requires two levels of indirection (_STR and _XSTR) because
// #s will not expand argment s. Instead, macro expansion occurs when _XSTR
// is expanded, then the result of this expansion is stringified in _STR.
#define _STR(s) #s
#define _XSTR(s) _STR(s)
#define _MODULE_STRING _XSTR(MODULE_NAME)
// Token concatenation requires two levels of indirection (similar to
// stringification).
#define _CONCAT(x, y) x##y
#define _XCONCAT(x, y) _CONCAT(x, y)
#define _INIT_FUNC_NAME _XCONCAT(PyInit_, MODULE_NAME)
struct module_state {
//PyObject *error;
};
extern "C" {
static PyMethodDef ext_simple_symbols[] = {
{nullptr, nullptr} // sentinel
};
static int ext_simple_traverse(PyObject *m, visitproc visit, void *arg) {
return 0;
}
static int ext_simple_clear(PyObject *m) {
return 0;
}
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT, _MODULE_STRING, nullptr,
sizeof(struct module_state), ext_simple_symbols, nullptr,
ext_simple_traverse, ext_simple_clear, nullptr};
PyMODINIT_FUNC _INIT_FUNC_NAME(void) {
PyObject *module = PyModule_Create(&moduledef);
if (module == nullptr) {
return nullptr;
}
return module;
}
}