mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Force hidden visibility on pybind code
This adds a PYBIND11_NAMESPACE macro that expands to the `pybind11` namespace with hidden visibility under gcc-type compilers, and otherwise to the plain `pybind11`. This then forces hidden visibility on everything in pybind, solving the visibility issues discussed at end end of #949.
This commit is contained in:
parent
8d3cedbe2b
commit
a859dd67a2
@ -12,7 +12,7 @@
|
||||
|
||||
#include "cast.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
/// \addtogroup annotations
|
||||
/// @{
|
||||
@ -478,4 +478,4 @@ constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
|
||||
}
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
/// Information record describing a Python buffer object
|
||||
struct buffer_info {
|
||||
@ -105,4 +105,4 @@ template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_
|
||||
};
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
// Forward declarations:
|
||||
inline PyTypeObject *make_static_property_type();
|
||||
@ -2084,4 +2084,4 @@ NAMESPACE_END(detail)
|
||||
template<> class type_caster<Type> : public type_caster_base<Type> { }; \
|
||||
}}
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds)
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <typename type> class duration_caster {
|
||||
@ -159,4 +159,4 @@ template <typename Rep, typename Period> class type_caster<std::chrono::duration
|
||||
};
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
inline PyTypeObject *type_incref(PyTypeObject *type) {
|
||||
@ -599,4 +599,4 @@ inline PyObject* make_new_python_type(const type_record &rec) {
|
||||
}
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -16,6 +16,17 @@
|
||||
# define NAMESPACE_END(name) }
|
||||
#endif
|
||||
|
||||
// Robust support for some features and loading modules compiled against different pybind versions
|
||||
// requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute on
|
||||
// the main `pybind11` namespace.
|
||||
#if !defined(PYBIND11_NAMESPACE)
|
||||
# ifdef __GNUG__
|
||||
# define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
|
||||
# else
|
||||
# define PYBIND11_NAMESPACE pybind11
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
|
||||
# if __cplusplus >= 201402L
|
||||
# define PYBIND11_CPP14
|
||||
@ -297,7 +308,7 @@ extern "C" {
|
||||
void pybind11_init_##name(pybind11::module &variable)
|
||||
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
using ssize_t = Py_ssize_t;
|
||||
using size_t = std::size_t;
|
||||
@ -877,4 +888,4 @@ NAMESPACE_END(detail)
|
||||
|
||||
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -17,7 +17,7 @@
|
||||
# undef I
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
static constexpr const char c = format_descriptor<T>::c;
|
||||
@ -58,4 +58,4 @@ public:
|
||||
PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
|
||||
};
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
/* Concatenate type signatures at compile time using C++14 */
|
||||
@ -182,4 +182,4 @@ PYBIND11_NOINLINE inline descr type_descr(descr&& d) { return _("{") + std::move
|
||||
#endif
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -35,7 +35,7 @@
|
||||
// of matrices seems highly undesirable.
|
||||
static_assert(EIGEN_VERSION_AT_LEAST(3,2,7), "Eigen support in pybind11 requires Eigen >= 3.2.7");
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
// Provide a convenience alias for easier pass-by-ref usage with fully dynamic strides:
|
||||
using EigenDStride = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>;
|
||||
@ -601,7 +601,7 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
|
||||
};
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
||||
#if defined(__GNUG__) || defined(__clang__)
|
||||
# pragma GCC diagnostic pop
|
||||
|
@ -63,7 +63,7 @@
|
||||
void pybind11_init_##name(pybind11::module &variable)
|
||||
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
/// Python 2.7/3.x compatible version of `PyImport_AppendInittab` and error checks.
|
||||
@ -190,4 +190,4 @@ private:
|
||||
bool is_valid = true;
|
||||
};
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include "pybind11.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
enum eval_mode {
|
||||
/// Evaluate a string containing an isolated expression
|
||||
@ -114,4 +114,4 @@ object eval_file(str fname, object global = globals(), object local = object())
|
||||
return reinterpret_steal<object>(result);
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "pybind11.h"
|
||||
#include <functional>
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
template <typename Return, typename... Args>
|
||||
@ -82,4 +82,4 @@ public:
|
||||
};
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -34,7 +34,7 @@
|
||||
upon the library user. */
|
||||
static_assert(sizeof(ssize_t) == sizeof(Py_intptr_t), "ssize_t != Py_intptr_t");
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
class array; // Forward declaration
|
||||
|
||||
@ -1591,7 +1591,7 @@ Helper vectorize(Return (Class::*f)(Args...) const) {
|
||||
return Helper(std::mem_fn(f));
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
|
@ -18,7 +18,7 @@
|
||||
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
/// Enumeration with all supported operator types
|
||||
@ -160,7 +160,7 @@ NAMESPACE_END(detail)
|
||||
|
||||
using detail::self;
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
class options {
|
||||
public:
|
||||
@ -62,4 +62,4 @@ private:
|
||||
state previous_state;
|
||||
};
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include "options.h"
|
||||
#include "class_support.h"
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
/// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object
|
||||
class cpp_function : public function {
|
||||
@ -1862,7 +1862,7 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
|
||||
#define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \
|
||||
PYBIND11_OVERLOAD_PURE_NAME(ret_type, cname, #fn, fn, __VA_ARGS__)
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
|
||||
/* A few forward declarations */
|
||||
class handle; class object;
|
||||
@ -1320,4 +1320,4 @@ template <typename D>
|
||||
handle object_api<D>::get_type() const { return (PyObject *) Py_TYPE(derived().ptr()); }
|
||||
|
||||
NAMESPACE_END(detail)
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -46,7 +46,7 @@
|
||||
# define PYBIND11_HAS_VARIANT 1
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
/// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for
|
||||
@ -362,7 +362,7 @@ inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
|
||||
return os;
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
|
||||
/* SFINAE helper class used by 'is_comparable */
|
||||
@ -598,4 +598,4 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&.
|
||||
return cl;
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
NAMESPACE_BEGIN(pybind11)
|
||||
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
||||
NAMESPACE_BEGIN(detail)
|
||||
/// Erase all occurrences of a substring
|
||||
inline void erase_all(std::string &string, const std::string &search) {
|
||||
@ -50,4 +50,4 @@ template <typename T> static std::string type_id() {
|
||||
return name;
|
||||
}
|
||||
|
||||
NAMESPACE_END(pybind11)
|
||||
NAMESPACE_END(PYBIND11_NAMESPACE)
|
||||
|
Loading…
Reference in New Issue
Block a user