Skip to content

Embedded module name cannot be an existing C++ symbol #2172

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

Closed
aslze opened this issue Apr 18, 2020 · 0 comments · Fixed by #2282
Closed

Embedded module name cannot be an existing C++ symbol #2172

aslze opened this issue Apr 18, 2020 · 0 comments · Fixed by #2282

Comments

@aslze
Copy link

aslze commented Apr 18, 2020

Issue description

You cannot create an embedded module whose name is an existing C++ namespace or other symbol. I think this should not be a strange situation: creating a Python module that wraps a C++ library and takes its namespace as name.

This fails if physics is already a C++ namespace:

PYBIND11_EMBEDDED_MODULE(physics, m)

The PYBIND11_EMBEDDED_MODULE(name, variable) macro prefixes name many times when defining its needed symbols to avoid clashes, except once, when defining the actual pybind11::detail::embedded_module object. I doubt this object's name is relevant in the C++ side, what is relevant is the real module name, seen by Python.

Proposed solution

I would prefix that object just like the others. Line 64 in "embed.h":

pybind11::detail::embedded_module name(PYBIND11_TOSTRING(name)

Could be changed to:

pybind11::detail::embedded_module PYBIND11_CONCAT(pybind11_module_, name)(PYBIND11_TOSTRING(name)

In the above example the global object created would be pybind11_module_physics which does not collide.

bstaletic added a commit to bstaletic/pybind11 that referenced this issue Jul 7, 2020
This avoids a potential conflict with names in the same scope of the
same name as the embedded module, like namespaces or other global
variables.

Fixes pybind#2172
YannickJadoul pushed a commit that referenced this issue Jul 10, 2020
This avoids a potential conflict with names in the same scope of the
same name as the embedded module, like namespaces or other global
variables.

Fixes #2172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant