|
| 1 | + |
| 2 | +// C.f. https://numpy.org/doc/1.21/reference/c-api/array.html#importing-the-api |
| 3 | +#define PY_ARRAY_UNIQUE_SYMBOL _cpp2py_ARRAY_API |
| 4 | +#ifndef CLAIR_C2PY_WRAP_GEN |
| 5 | +#ifdef __clang__ |
| 6 | +// #pragma clang diagnostic ignored "-W#warnings" |
| 7 | +#endif |
| 8 | +#ifdef __GNUC__ |
| 9 | +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" |
| 10 | +#pragma GCC diagnostic ignored "-Wcast-function-type" |
| 11 | +#pragma GCC diagnostic ignored "-Wcpp" |
| 12 | +#endif |
| 13 | + |
| 14 | +#define C2PY_VERSION_MAJOR 0 |
| 15 | +#define C2PY_VERSION_MINOR 1 |
| 16 | + |
| 17 | +#include <c2py/c2py.hpp> |
| 18 | + |
| 19 | +using c2py::operator""_a; |
| 20 | + |
| 21 | +// ==================== Wrapped classes ===================== |
| 22 | + |
| 23 | +// ==================== enums ===================== |
| 24 | + |
| 25 | +// ==================== module classes ===================== |
| 26 | + |
| 27 | +// ==================== module functions ==================== |
| 28 | + |
| 29 | +// funcA |
| 30 | +static auto const fun_0 = c2py::dispatcher_f_kw_t{c2py::cfun([]() { return A::funcA(); })}; |
| 31 | + |
| 32 | +// funcB |
| 33 | +static auto const fun_1 = c2py::dispatcher_f_kw_t{c2py::cfun([]() { return A::B::funcB(); })}; |
| 34 | + |
| 35 | +static const auto doc_d_0 = fun_0.doc({R"DOC( )DOC"}); |
| 36 | +static const auto doc_d_1 = fun_1.doc({R"DOC( )DOC"}); |
| 37 | +//--------------------- module function table ----------------------------- |
| 38 | + |
| 39 | +static PyMethodDef module_methods[] = { |
| 40 | + {"funcA", (PyCFunction)c2py::pyfkw<fun_0>, METH_VARARGS | METH_KEYWORDS, doc_d_0.c_str()}, |
| 41 | + {"funcB", (PyCFunction)c2py::pyfkw<fun_1>, METH_VARARGS | METH_KEYWORDS, doc_d_1.c_str()}, |
| 42 | + {nullptr, nullptr, 0, nullptr} // Sentinel |
| 43 | +}; |
| 44 | + |
| 45 | +//--------------------- module struct & init error definition ------------ |
| 46 | + |
| 47 | +//// module doc directly in the code or "" if not present... |
| 48 | +/// Or mandatory ? |
| 49 | +static struct PyModuleDef module_def = {PyModuleDef_HEAD_INIT, |
| 50 | + "namespace", /* name of module */ |
| 51 | + R"RAWDOC(Test for namespace filtering)RAWDOC", /* module documentation, may be NULL */ |
| 52 | + -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ |
| 53 | + module_methods, |
| 54 | + NULL, |
| 55 | + NULL, |
| 56 | + NULL, |
| 57 | + NULL}; |
| 58 | + |
| 59 | +//--------------------- module init function ----------------------------- |
| 60 | + |
| 61 | +extern "C" __attribute__((visibility("default"))) PyObject *PyInit_namespace() { |
| 62 | + |
| 63 | + if (not c2py::check_python_version("namespace")) return NULL; |
| 64 | + |
| 65 | + // import numpy iff 'numpy/arrayobject.h' included |
| 66 | +#ifdef Py_ARRAYOBJECT_H |
| 67 | + import_array(); |
| 68 | +#endif |
| 69 | + |
| 70 | + PyObject *m; |
| 71 | + |
| 72 | + if (PyType_Ready(&c2py::wrap_pytype<c2py::py_range>) < 0) return NULL; |
| 73 | + |
| 74 | + m = PyModule_Create(&module_def); |
| 75 | + if (m == NULL) return NULL; |
| 76 | + |
| 77 | + auto &conv_table = *c2py::conv_table_sptr.get(); |
| 78 | + |
| 79 | + conv_table[std::type_index(typeid(c2py::py_range)).name()] = &c2py::wrap_pytype<c2py::py_range>; |
| 80 | + |
| 81 | + return m; |
| 82 | +} |
| 83 | +#endif |
| 84 | +// CLAIR_WRAP_GEN |
0 commit comments