From 77586fd6a2518a8d430335de36d7ad4b5bed43f8 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sun, 6 Mar 2016 13:38:18 +0100 Subject: [PATCH] add version suffix to internal pybind11 data structures to avoid conflicts with future versions --- include/pybind11/cast.h | 5 +++-- include/pybind11/common.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 12cc5b28..5dda8f7d 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 e4cb9be5..8f0e61e6 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(); \