Skip to content

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

Description

@aslze

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions