Make static internals ptr pybind version specific

Under gcc, the `static internals *internals_ptr` is shared across .so's,
which breaks for obvious reasons.

This commit fixes it by moving the static pointer declaration into a
pybind-version-templated function.
This commit is contained in:
Jason Rhinelander 2017-05-17 18:29:53 -04:00
parent 731a9f6cea
commit a4d0d95e2e

View File

@ -43,8 +43,15 @@ struct type_info {
bool default_holder : 1;
};
// Store the static internals pointer in a version-specific function so that we're guaranteed it
// will be distinct for modules compiled for different pybind11 versions. Without this, some
// compilers (i.e. gcc) can use the same static pointer storage location across different .so's,
// even though the `get_internals()` function itself is local to each shared object.
template <int = PYBIND11_VERSION_MAJOR, int = PYBIND11_VERSION_MINOR>
internals *&get_internals_ptr() { static internals *internals_ptr = nullptr; return internals_ptr; }
PYBIND11_NOINLINE inline internals &get_internals() {
static internals *internals_ptr = nullptr;
internals *&internals_ptr = get_internals_ptr();
if (internals_ptr)
return *internals_ptr;
handle builtins(PyEval_GetBuiltins());