Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
d81d11a6
Commit
d81d11a6
authored
Sep 13, 2017
by
tzh1043
Committed by
Dean Moldovan
Sep 13, 2017
Browse files
Make PYBIND11_MODULE name usable with define (#1082)
parent
9f82370e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
include/pybind11/detail/common.h
include/pybind11/detail/common.h
+5
-4
include/pybind11/embed.h
include/pybind11/embed.h
+7
-6
No files found.
include/pybind11/detail/common.h
View file @
d81d11a6
...
...
@@ -205,6 +205,7 @@ extern "C" {
#define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
#define PYBIND11_STRINGIFY(x) #x
#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
#define PYBIND11_CONCAT(first, second) first##second
/** \rst
***Deprecated in favor of PYBIND11_MODULE***
...
...
@@ -267,7 +268,7 @@ extern "C" {
}
\endrst */
#define PYBIND11_MODULE(name, variable) \
static void pybind11_init_
##
name(pybind11::module &);
\
static void
PYBIND11_CONCAT(
pybind11_init_
,
name
)
(pybind11::module &); \
PYBIND11_PLUGIN_IMPL(name) { \
int major, minor; \
if (sscanf(Py_GetVersion(), "%i.%i", &major, &minor) != 2) { \
...
...
@@ -281,9 +282,9 @@ extern "C" {
major, minor); \
return nullptr; \
} \
auto m = pybind11::module(
#name);
\
auto m = pybind11::module(
PYBIND11_TOSTRING(name));
\
try { \
pybind11_init_
##
name(m);
\
PYBIND11_CONCAT(
pybind11_init_
,
name
)
(m); \
return m.ptr(); \
} catch (pybind11::error_already_set &e) { \
PyErr_SetString(PyExc_ImportError, e.what()); \
...
...
@@ -293,7 +294,7 @@ extern "C" {
return nullptr; \
} \
} \
void pybind11_init_
##
name(pybind11::module &variable)
void
PYBIND11_CONCAT(
pybind11_init_
,
name
)
(pybind11::module &variable)
NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
...
...
include/pybind11/embed.h
View file @
d81d11a6
...
...
@@ -44,11 +44,11 @@
}
\endrst */
#define PYBIND11_EMBEDDED_MODULE(name, variable) \
static void pybind11_init_
##
name(pybind11::module &);
\
static PyObject *pybind11_init_wrapper_
##
name() {
\
auto m = pybind11::module(
#name);
\
static void
PYBIND11_CONCAT(
pybind11_init_
,
name
)
(pybind11::module &); \
static PyObject
PYBIND11_CONCAT(
*pybind11_init_wrapper_
,
name
)
() { \
auto m = pybind11::module(
PYBIND11_TOSTRING(name));
\
try { \
pybind11_init_
##
name(m);
\
PYBIND11_CONCAT(
pybind11_init_
,
name
)
(m); \
return m.ptr(); \
} catch (pybind11::error_already_set &e) { \
PyErr_SetString(PyExc_ImportError, e.what()); \
...
...
@@ -59,8 +59,9 @@
} \
} \
PYBIND11_EMBEDDED_MODULE_IMPL(name) \
pybind11::detail::embedded_module name(#name, pybind11_init_impl_##name); \
void pybind11_init_##name(pybind11::module &variable)
pybind11::detail::embedded_module name(PYBIND11_TOSTRING(name), \
PYBIND11_CONCAT(pybind11_init_impl_, name)); \
void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment