add version suffix to internal pybind11 data structures to avoid conflicts with future versions

This commit is contained in:
Wenzel Jakob 2016-03-06 13:38:18 +01:00
parent 8d862b37b4
commit 77586fd6a2
2 changed files with 7 additions and 2 deletions

View File

@ -34,12 +34,13 @@ PYBIND11_NOINLINE inline internals &get_internals() {
if (internals_ptr) if (internals_ptr)
return *internals_ptr; return *internals_ptr;
handle builtins(PyEval_GetBuiltins()); handle builtins(PyEval_GetBuiltins());
capsule caps(builtins["__pybind11__"]); const char *id = PYBIND11_INTERNALS_ID;
capsule caps(builtins[id]);
if (caps.check()) { if (caps.check()) {
internals_ptr = caps; internals_ptr = caps;
} else { } else {
internals_ptr = new internals(); internals_ptr = new internals();
builtins["__pybind11__"] = capsule(internals_ptr); builtins[id] = capsule(internals_ptr);
} }
return *internals_ptr; return *internals_ptr;
} }

View File

@ -110,6 +110,10 @@
#endif #endif
#define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code #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) \ #define PYBIND11_PLUGIN(name) \
static PyObject *pybind11_init(); \ static PyObject *pybind11_init(); \