diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 12cc5b28e..5dda8f7d3 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -34,12 +34,13 @@ PYBIND11_NOINLINE inline internals &get_internals() { if (internals_ptr) return *internals_ptr; handle builtins(PyEval_GetBuiltins()); - capsule caps(builtins["__pybind11__"]); + const char *id = PYBIND11_INTERNALS_ID; + capsule caps(builtins[id]); if (caps.check()) { internals_ptr = caps; } else { internals_ptr = new internals(); - builtins["__pybind11__"] = capsule(internals_ptr); + builtins[id] = capsule(internals_ptr); } return *internals_ptr; } diff --git a/include/pybind11/common.h b/include/pybind11/common.h index e4cb9be50..8f0e61e6e 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -110,6 +110,10 @@ #endif #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_INTERNALS_ID "__pybind11_" \ + PYBIND11_TOSTRING(PYBIND11_VERSION_MAJOR) "_" PYBIND11_TOSTRING(PYBIND11_VERSION_MINOR) "__" #define PYBIND11_PLUGIN(name) \ static PyObject *pybind11_init(); \