From a4d0d95e2ec717f15b42cd3e4b3bbccf12f57d57 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Wed, 17 May 2017 18:29:53 -0400 Subject: [PATCH] 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. --- include/pybind11/cast.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 91b3e375..ace344ef 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -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 +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());