Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap PyInit_##name in macro to allow macros as module names #168

Merged
merged 1 commit into from Apr 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/nanobind/nb_defs.h
Expand Up @@ -131,12 +131,15 @@
# error "nanobind requires a newer PyPy version (>= 7.3.10)"
#endif

#define NB_MODULE(name, variable) \
#define NB_MODULE_IMPL(name) \
extern "C" [[maybe_unused]] NB_EXPORT PyObject *PyInit_##name(); \
extern "C" NB_EXPORT PyObject *PyInit_##name()

#define NB_MODULE(name, variable) \
static PyModuleDef NB_CONCAT(nanobind_module_def_, name); \
[[maybe_unused]] static void NB_CONCAT(nanobind_init_, \
name)(::nanobind::module_ &); \
extern "C" NB_EXPORT PyObject *PyInit_##name() { \
NB_MODULE_IMPL(name) { \
nanobind::module_ m = \
nanobind::steal<nanobind::module_>(nanobind::detail::module_new( \
NB_TOSTRING(name), &NB_CONCAT(nanobind_module_def_, name))); \
Expand Down