Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open pybind11 namespace with consistent visility. #4098

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/advanced/cast/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type is explicitly allowed.

.. code-block:: cpp

namespace pybind11 { namespace detail {
namespace PYBIND11_NAMESPACE { namespace detail {
template <> struct type_caster<inty> {
public:
/**
Expand Down Expand Up @@ -78,7 +78,7 @@ type is explicitly allowed.
return PyLong_FromLong(src.long_value);
}
};
}} // namespace pybind11::detail
}} // namespace PYBIND11_NAMESPACE::detail

.. note::

Expand Down
6 changes: 3 additions & 3 deletions docs/advanced/cast/stl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ types:
.. code-block:: cpp

// `boost::optional` as an example -- can be any `std::optional`-like container
namespace pybind11 { namespace detail {
namespace PYBIND11_NAMESPACE { namespace detail {
template <typename T>
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
}}
Expand All @@ -54,7 +54,7 @@ for custom variant types:
.. code-block:: cpp

// `boost::variant` as an example -- can be any `std::variant`-like container
namespace pybind11 { namespace detail {
namespace PYBIND11_NAMESPACE { namespace detail {
template <typename... Ts>
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};

Expand All @@ -66,7 +66,7 @@ for custom variant types:
return boost::apply_visitor(args...);
}
};
}} // namespace pybind11::detail
}} // namespace PYBIND11_NAMESPACE::detail

The ``visit_helper`` specialization is not required if your ``name::variant`` provides
a ``name::visit()`` function. For any other function name, the specialization must be
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ whether a downcast is safe, you can proceed by specializing the
std::string bark() const { return sound; }
};

namespace pybind11 {
namespace PYBIND11_NAMESPACE {
template<> struct polymorphic_type_hook<Pet> {
static const void *get(const Pet *src, const std::type_info*& type) {
// note that src may be nullptr
Expand All @@ -1239,7 +1239,7 @@ whether a downcast is safe, you can proceed by specializing the
return src;
}
};
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

When pybind11 wants to convert a C++ pointer of type ``Base*`` to a
Python object, it calls ``polymorphic_type_hook<Base>::get()`` to
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/smart_ptrs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ specialized:
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);

// Only needed if the type's `.get()` goes by another name
namespace pybind11 { namespace detail {
namespace PYBIND11_NAMESPACE { namespace detail {
template <typename T>
struct holder_helper<SmartPtr<T>> { // <-- specialization
static const T *get(const SmartPtr<T> &p) { return p.getPointer(); }
Expand Down
14 changes: 7 additions & 7 deletions tests/test_custom_type_casters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ArgInspector2 {
};
class ArgAlwaysConverts {};

namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <>
struct type_caster<ArgInspector1> {
Expand Down Expand Up @@ -74,7 +74,7 @@ struct type_caster<ArgAlwaysConverts> {
}
};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

// test_custom_caster_destruction
class DestructionTester {
Expand All @@ -92,7 +92,7 @@ class DestructionTester {
return *this;
}
};
namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <>
struct type_caster<DestructionTester> {
Expand All @@ -104,15 +104,15 @@ struct type_caster<DestructionTester> {
}
};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

// Define type caster outside of `pybind11::detail` and then alias it.
namespace other_lib {
struct MyType {};
// Corrupt `py` shorthand alias for surrounding context.
namespace py {}
// Corrupt unqualified relative `pybind11` namespace.
namespace pybind11 {}
namespace PYBIND11_NAMESPACE {}
// Correct alias.
namespace py_ = ::pybind11;
// Define caster. This is effectively no-op, we only ensure it compiles and we
Expand All @@ -127,12 +127,12 @@ struct my_caster {
};
} // namespace other_lib
// Effectively "alias" it into correct namespace (via inheritance).
namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <>
struct type_caster<other_lib::MyType> : public other_lib::my_caster {};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

TEST_SUBMODULE(custom_type_casters, m) {
// test_custom_type_casters
Expand Down
4 changes: 2 additions & 2 deletions tests/test_smart_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ struct ElementList {
// It is always possible to construct a ref<T> from an Object* pointer without
// possible inconsistencies, hence the 'true' argument at the end.
// Make pybind11 aware of the non-standard getter member function
namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <typename T>
struct holder_helper<ref<T>> {
static const T *get(const ref<T> &p) { return p.get_ptr(); }
};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

// Make pybind aware of the ref-counted wrapper type (s):
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true);
Expand Down
12 changes: 6 additions & 6 deletions tests/test_stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#if defined(PYBIND11_TEST_BOOST)
# include <boost/optional.hpp>

namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <typename T>
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};

template <>
struct type_caster<boost::none_t> : void_caster<boost::none_t> {};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE
#endif

// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
Expand All @@ -43,7 +43,7 @@ using std::variant;
# define PYBIND11_TEST_VARIANT 1
using boost::variant;

namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <typename... Ts>
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
Expand All @@ -56,7 +56,7 @@ struct visit_helper<boost::variant> {
}
};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE
#endif

PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
Expand Down Expand Up @@ -159,13 +159,13 @@ class ReferenceSensitiveOptional {
std::vector<T> storage;
};

namespace pybind11 {
namespace PYBIND11_NAMESPACE {
namespace detail {
template <typename T>
struct type_caster<ReferenceSensitiveOptional<T>>
: optional_caster<ReferenceSensitiveOptional<T>> {};
} // namespace detail
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

TEST_SUBMODULE(stl, m) {
// test_vector
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tagbased_polymorphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ std::string Animal::name_of_kind(Kind kind) {
return raw_name;
}

namespace pybind11 {
namespace PYBIND11_NAMESPACE {
template <typename itype>
struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal, itype>::value>> {
static const void *get(const itype *src, const std::type_info *&type) {
type = src ? Animal::type_of_kind(src->kind) : nullptr;
return src;
}
};
} // namespace pybind11
} // namespace PYBIND11_NAMESPACE

TEST_SUBMODULE(tagbased_polymorphic, m) {
py::class_<Animal>(m, "Animal").def_readonly("name", &Animal::name);
Expand Down