Skip to content

Commit f8e8403

Browse files
authored
Open pybind11 namespace with consistent visility. (#4098)
1 parent aa95371 commit f8e8403

8 files changed

+25
-25
lines changed

docs/advanced/cast/custom.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type is explicitly allowed.
3838

3939
.. code-block:: cpp
4040
41-
namespace pybind11 { namespace detail {
41+
namespace PYBIND11_NAMESPACE { namespace detail {
4242
template <> struct type_caster<inty> {
4343
public:
4444
/**
@@ -78,7 +78,7 @@ type is explicitly allowed.
7878
return PyLong_FromLong(src.long_value);
7979
}
8080
};
81-
}} // namespace pybind11::detail
81+
}} // namespace PYBIND11_NAMESPACE::detail
8282
8383
.. note::
8484

docs/advanced/cast/stl.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ types:
4242
.. code-block:: cpp
4343
4444
// `boost::optional` as an example -- can be any `std::optional`-like container
45-
namespace pybind11 { namespace detail {
45+
namespace PYBIND11_NAMESPACE { namespace detail {
4646
template <typename T>
4747
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
4848
}}
@@ -54,7 +54,7 @@ for custom variant types:
5454
.. code-block:: cpp
5555
5656
// `boost::variant` as an example -- can be any `std::variant`-like container
57-
namespace pybind11 { namespace detail {
57+
namespace PYBIND11_NAMESPACE { namespace detail {
5858
template <typename... Ts>
5959
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
6060
@@ -66,7 +66,7 @@ for custom variant types:
6666
return boost::apply_visitor(args...);
6767
}
6868
};
69-
}} // namespace pybind11::detail
69+
}} // namespace PYBIND11_NAMESPACE::detail
7070
7171
The ``visit_helper`` specialization is not required if your ``name::variant`` provides
7272
a ``name::visit()`` function. For any other function name, the specialization must be

docs/advanced/classes.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ whether a downcast is safe, you can proceed by specializing the
12281228
std::string bark() const { return sound; }
12291229
};
12301230
1231-
namespace pybind11 {
1231+
namespace PYBIND11_NAMESPACE {
12321232
template<> struct polymorphic_type_hook<Pet> {
12331233
static const void *get(const Pet *src, const std::type_info*& type) {
12341234
// note that src may be nullptr
@@ -1239,7 +1239,7 @@ whether a downcast is safe, you can proceed by specializing the
12391239
return src;
12401240
}
12411241
};
1242-
} // namespace pybind11
1242+
} // namespace PYBIND11_NAMESPACE
12431243
12441244
When pybind11 wants to convert a C++ pointer of type ``Base*`` to a
12451245
Python object, it calls ``polymorphic_type_hook<Base>::get()`` to

docs/advanced/smart_ptrs.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ specialized:
157157
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
158158
159159
// Only needed if the type's `.get()` goes by another name
160-
namespace pybind11 { namespace detail {
160+
namespace PYBIND11_NAMESPACE { namespace detail {
161161
template <typename T>
162162
struct holder_helper<SmartPtr<T>> { // <-- specialization
163163
static const T *get(const SmartPtr<T> &p) { return p.getPointer(); }

tests/test_custom_type_casters.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ArgInspector2 {
2121
};
2222
class ArgAlwaysConverts {};
2323

24-
namespace pybind11 {
24+
namespace PYBIND11_NAMESPACE {
2525
namespace detail {
2626
template <>
2727
struct type_caster<ArgInspector1> {
@@ -74,7 +74,7 @@ struct type_caster<ArgAlwaysConverts> {
7474
}
7575
};
7676
} // namespace detail
77-
} // namespace pybind11
77+
} // namespace PYBIND11_NAMESPACE
7878

7979
// test_custom_caster_destruction
8080
class DestructionTester {
@@ -92,7 +92,7 @@ class DestructionTester {
9292
return *this;
9393
}
9494
};
95-
namespace pybind11 {
95+
namespace PYBIND11_NAMESPACE {
9696
namespace detail {
9797
template <>
9898
struct type_caster<DestructionTester> {
@@ -104,15 +104,15 @@ struct type_caster<DestructionTester> {
104104
}
105105
};
106106
} // namespace detail
107-
} // namespace pybind11
107+
} // namespace PYBIND11_NAMESPACE
108108

109109
// Define type caster outside of `pybind11::detail` and then alias it.
110110
namespace other_lib {
111111
struct MyType {};
112112
// Corrupt `py` shorthand alias for surrounding context.
113113
namespace py {}
114114
// Corrupt unqualified relative `pybind11` namespace.
115-
namespace pybind11 {}
115+
namespace PYBIND11_NAMESPACE {}
116116
// Correct alias.
117117
namespace py_ = ::pybind11;
118118
// Define caster. This is effectively no-op, we only ensure it compiles and we
@@ -127,12 +127,12 @@ struct my_caster {
127127
};
128128
} // namespace other_lib
129129
// Effectively "alias" it into correct namespace (via inheritance).
130-
namespace pybind11 {
130+
namespace PYBIND11_NAMESPACE {
131131
namespace detail {
132132
template <>
133133
struct type_caster<other_lib::MyType> : public other_lib::my_caster {};
134134
} // namespace detail
135-
} // namespace pybind11
135+
} // namespace PYBIND11_NAMESPACE
136136

137137
TEST_SUBMODULE(custom_type_casters, m) {
138138
// test_custom_type_casters

tests/test_smart_ptr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ struct ElementList {
266266
// It is always possible to construct a ref<T> from an Object* pointer without
267267
// possible inconsistencies, hence the 'true' argument at the end.
268268
// Make pybind11 aware of the non-standard getter member function
269-
namespace pybind11 {
269+
namespace PYBIND11_NAMESPACE {
270270
namespace detail {
271271
template <typename T>
272272
struct holder_helper<ref<T>> {
273273
static const T *get(const ref<T> &p) { return p.get_ptr(); }
274274
};
275275
} // namespace detail
276-
} // namespace pybind11
276+
} // namespace PYBIND11_NAMESPACE
277277

278278
// Make pybind aware of the ref-counted wrapper type (s):
279279
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true);

tests/test_stl.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
#if defined(PYBIND11_TEST_BOOST)
2424
# include <boost/optional.hpp>
2525

26-
namespace pybind11 {
26+
namespace PYBIND11_NAMESPACE {
2727
namespace detail {
2828
template <typename T>
2929
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
3030

3131
template <>
3232
struct type_caster<boost::none_t> : void_caster<boost::none_t> {};
3333
} // namespace detail
34-
} // namespace pybind11
34+
} // namespace PYBIND11_NAMESPACE
3535
#endif
3636

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

46-
namespace pybind11 {
46+
namespace PYBIND11_NAMESPACE {
4747
namespace detail {
4848
template <typename... Ts>
4949
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
@@ -56,7 +56,7 @@ struct visit_helper<boost::variant> {
5656
}
5757
};
5858
} // namespace detail
59-
} // namespace pybind11
59+
} // namespace PYBIND11_NAMESPACE
6060
#endif
6161

6262
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
@@ -159,13 +159,13 @@ class ReferenceSensitiveOptional {
159159
std::vector<T> storage;
160160
};
161161

162-
namespace pybind11 {
162+
namespace PYBIND11_NAMESPACE {
163163
namespace detail {
164164
template <typename T>
165165
struct type_caster<ReferenceSensitiveOptional<T>>
166166
: optional_caster<ReferenceSensitiveOptional<T>> {};
167167
} // namespace detail
168-
} // namespace pybind11
168+
} // namespace PYBIND11_NAMESPACE
169169

170170
TEST_SUBMODULE(stl, m) {
171171
// test_vector

tests/test_tagbased_polymorphic.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ std::string Animal::name_of_kind(Kind kind) {
117117
return raw_name;
118118
}
119119

120-
namespace pybind11 {
120+
namespace PYBIND11_NAMESPACE {
121121
template <typename itype>
122122
struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal, itype>::value>> {
123123
static const void *get(const itype *src, const std::type_info *&type) {
124124
type = src ? Animal::type_of_kind(src->kind) : nullptr;
125125
return src;
126126
}
127127
};
128-
} // namespace pybind11
128+
} // namespace PYBIND11_NAMESPACE
129129

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

0 commit comments

Comments
 (0)