Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
f8e8403b
"git@developer.sourcefind.cn:gaoqiong/pybind11.git" did not exist on "868d94fcb4769ad3a5d826c9f5483376433da8a5"
Unverified
Commit
f8e8403b
authored
Aug 01, 2022
by
Thomas Eding
Committed by
GitHub
Aug 01, 2022
Browse files
Open pybind11 namespace with consistent visility. (#4098)
parent
aa953710
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
25 deletions
+25
-25
docs/advanced/cast/custom.rst
docs/advanced/cast/custom.rst
+2
-2
docs/advanced/cast/stl.rst
docs/advanced/cast/stl.rst
+3
-3
docs/advanced/classes.rst
docs/advanced/classes.rst
+2
-2
docs/advanced/smart_ptrs.rst
docs/advanced/smart_ptrs.rst
+1
-1
tests/test_custom_type_casters.cpp
tests/test_custom_type_casters.cpp
+7
-7
tests/test_smart_ptr.cpp
tests/test_smart_ptr.cpp
+2
-2
tests/test_stl.cpp
tests/test_stl.cpp
+6
-6
tests/test_tagbased_polymorphic.cpp
tests/test_tagbased_polymorphic.cpp
+2
-2
No files found.
docs/advanced/cast/custom.rst
View file @
f8e8403b
...
@@ -38,7 +38,7 @@ type is explicitly allowed.
...
@@ -38,7 +38,7 @@ type is explicitly allowed.
.. code-block:: cpp
.. code-block:: cpp
namespace
pybind11
{ namespace detail {
namespace
PYBIND11_NAMESPACE
{ namespace detail {
template <> struct type_caster<inty> {
template <> struct type_caster<inty> {
public:
public:
/**
/**
...
@@ -78,7 +78,7 @@ type is explicitly allowed.
...
@@ -78,7 +78,7 @@ type is explicitly allowed.
return PyLong_FromLong(src.long_value);
return PyLong_FromLong(src.long_value);
}
}
};
};
}} // namespace
pybind11
::detail
}} // namespace
PYBIND11_NAMESPACE
::detail
.. note::
.. note::
...
...
docs/advanced/cast/stl.rst
View file @
f8e8403b
...
@@ -42,7 +42,7 @@ types:
...
@@ -42,7 +42,7 @@ types:
.. code-block:: cpp
.. code-block:: cpp
// `boost::optional` as an example -- can be any `std::optional`-like container
// `boost::optional` as an example -- can be any `std::optional`-like container
namespace
pybind11
{ namespace detail {
namespace
PYBIND11_NAMESPACE
{ namespace detail {
template <typename T>
template <typename T>
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
}}
}}
...
@@ -54,7 +54,7 @@ for custom variant types:
...
@@ -54,7 +54,7 @@ for custom variant types:
.. code-block:: cpp
.. code-block:: cpp
// `boost::variant` as an example -- can be any `std::variant`-like container
// `boost::variant` as an example -- can be any `std::variant`-like container
namespace
pybind11
{ namespace detail {
namespace
PYBIND11_NAMESPACE
{ namespace detail {
template <typename... Ts>
template <typename... Ts>
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
...
@@ -66,7 +66,7 @@ for custom variant types:
...
@@ -66,7 +66,7 @@ for custom variant types:
return boost::apply_visitor(args...);
return boost::apply_visitor(args...);
}
}
};
};
}} // namespace
pybind11
::detail
}} // namespace
PYBIND11_NAMESPACE
::detail
The ``visit_helper`` specialization is not required if your ``name::variant`` provides
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
a ``name::visit()`` function. For any other function name, the specialization must be
...
...
docs/advanced/classes.rst
View file @
f8e8403b
...
@@ -1228,7 +1228,7 @@ whether a downcast is safe, you can proceed by specializing the
...
@@ -1228,7 +1228,7 @@ whether a downcast is safe, you can proceed by specializing the
std::string bark() const { return sound; }
std::string bark() const { return sound; }
};
};
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
template<> struct polymorphic_type_hook<Pet> {
template<> struct polymorphic_type_hook<Pet> {
static const void *get(const Pet *src, const std::type_info*& type) {
static const void *get(const Pet *src, const std::type_info*& type) {
// note that src may be nullptr
// note that src may be nullptr
...
@@ -1239,7 +1239,7 @@ whether a downcast is safe, you can proceed by specializing the
...
@@ -1239,7 +1239,7 @@ whether a downcast is safe, you can proceed by specializing the
return src;
return src;
}
}
};
};
} // namespace
pybind11
} // namespace
PYBIND11_NAMESPACE
When pybind11 wants to convert a C++ pointer of type ``Base*`` to a
When pybind11 wants to convert a C++ pointer of type ``Base*`` to a
Python object, it calls ``polymorphic_type_hook<Base>::get()`` to
Python object, it calls ``polymorphic_type_hook<Base>::get()`` to
...
...
docs/advanced/smart_ptrs.rst
View file @
f8e8403b
...
@@ -157,7 +157,7 @@ specialized:
...
@@ -157,7 +157,7 @@ specialized:
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
// Only needed if the type's `.get()` goes by another name
// Only needed if the type's `.get()` goes by another name
namespace
pybind11
{ namespace detail {
namespace
PYBIND11_NAMESPACE
{ namespace detail {
template <typename T>
template <typename T>
struct holder_helper<SmartPtr<T>> { // <-- specialization
struct holder_helper<SmartPtr<T>> { // <-- specialization
static const T *get(const SmartPtr<T> &p) { return p.getPointer(); }
static const T *get(const SmartPtr<T> &p) { return p.getPointer(); }
...
...
tests/test_custom_type_casters.cpp
View file @
f8e8403b
...
@@ -21,7 +21,7 @@ public:
...
@@ -21,7 +21,7 @@ public:
};
};
class
ArgAlwaysConverts
{};
class
ArgAlwaysConverts
{};
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
>
template
<
>
struct
type_caster
<
ArgInspector1
>
{
struct
type_caster
<
ArgInspector1
>
{
...
@@ -74,7 +74,7 @@ public:
...
@@ -74,7 +74,7 @@ public:
}
}
};
};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
// test_custom_caster_destruction
// test_custom_caster_destruction
class
DestructionTester
{
class
DestructionTester
{
...
@@ -92,7 +92,7 @@ public:
...
@@ -92,7 +92,7 @@ public:
return
*
this
;
return
*
this
;
}
}
};
};
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
>
template
<
>
struct
type_caster
<
DestructionTester
>
{
struct
type_caster
<
DestructionTester
>
{
...
@@ -104,7 +104,7 @@ struct type_caster<DestructionTester> {
...
@@ -104,7 +104,7 @@ struct type_caster<DestructionTester> {
}
}
};
};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
// Define type caster outside of `pybind11::detail` and then alias it.
// Define type caster outside of `pybind11::detail` and then alias it.
namespace
other_lib
{
namespace
other_lib
{
...
@@ -112,7 +112,7 @@ struct MyType {};
...
@@ -112,7 +112,7 @@ struct MyType {};
// Corrupt `py` shorthand alias for surrounding context.
// Corrupt `py` shorthand alias for surrounding context.
namespace
py
{}
namespace
py
{}
// Corrupt unqualified relative `pybind11` namespace.
// Corrupt unqualified relative `pybind11` namespace.
namespace
pybind11
{}
namespace
PYBIND11_NAMESPACE
{}
// Correct alias.
// Correct alias.
namespace
py_
=
::
pybind11
;
namespace
py_
=
::
pybind11
;
// Define caster. This is effectively no-op, we only ensure it compiles and we
// Define caster. This is effectively no-op, we only ensure it compiles and we
...
@@ -127,12 +127,12 @@ struct my_caster {
...
@@ -127,12 +127,12 @@ struct my_caster {
};
};
}
// namespace other_lib
}
// namespace other_lib
// Effectively "alias" it into correct namespace (via inheritance).
// Effectively "alias" it into correct namespace (via inheritance).
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
>
template
<
>
struct
type_caster
<
other_lib
::
MyType
>
:
public
other_lib
::
my_caster
{};
struct
type_caster
<
other_lib
::
MyType
>
:
public
other_lib
::
my_caster
{};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
TEST_SUBMODULE
(
custom_type_casters
,
m
)
{
TEST_SUBMODULE
(
custom_type_casters
,
m
)
{
// test_custom_type_casters
// test_custom_type_casters
...
...
tests/test_smart_ptr.cpp
View file @
f8e8403b
...
@@ -266,14 +266,14 @@ struct ElementList {
...
@@ -266,14 +266,14 @@ struct ElementList {
// It is always possible to construct a ref<T> from an Object* pointer without
// It is always possible to construct a ref<T> from an Object* pointer without
// possible inconsistencies, hence the 'true' argument at the end.
// possible inconsistencies, hence the 'true' argument at the end.
// Make pybind11 aware of the non-standard getter member function
// Make pybind11 aware of the non-standard getter member function
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
typename
T
>
template
<
typename
T
>
struct
holder_helper
<
ref
<
T
>>
{
struct
holder_helper
<
ref
<
T
>>
{
static
const
T
*
get
(
const
ref
<
T
>
&
p
)
{
return
p
.
get_ptr
();
}
static
const
T
*
get
(
const
ref
<
T
>
&
p
)
{
return
p
.
get_ptr
();
}
};
};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
// Make pybind aware of the ref-counted wrapper type (s):
// Make pybind aware of the ref-counted wrapper type (s):
PYBIND11_DECLARE_HOLDER_TYPE
(
T
,
ref
<
T
>
,
true
);
PYBIND11_DECLARE_HOLDER_TYPE
(
T
,
ref
<
T
>
,
true
);
...
...
tests/test_stl.cpp
View file @
f8e8403b
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
#if defined(PYBIND11_TEST_BOOST)
#if defined(PYBIND11_TEST_BOOST)
# include <boost/optional.hpp>
# include <boost/optional.hpp>
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
typename
T
>
template
<
typename
T
>
struct
type_caster
<
boost
::
optional
<
T
>>
:
optional_caster
<
boost
::
optional
<
T
>>
{};
struct
type_caster
<
boost
::
optional
<
T
>>
:
optional_caster
<
boost
::
optional
<
T
>>
{};
...
@@ -31,7 +31,7 @@ struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
...
@@ -31,7 +31,7 @@ struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
template
<
>
template
<
>
struct
type_caster
<
boost
::
none_t
>
:
void_caster
<
boost
::
none_t
>
{};
struct
type_caster
<
boost
::
none_t
>
:
void_caster
<
boost
::
none_t
>
{};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
#endif
#endif
// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
...
@@ -43,7 +43,7 @@ using std::variant;
...
@@ -43,7 +43,7 @@ using std::variant;
# define PYBIND11_TEST_VARIANT 1
# define PYBIND11_TEST_VARIANT 1
using
boost
::
variant
;
using
boost
::
variant
;
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
typename
...
Ts
>
template
<
typename
...
Ts
>
struct
type_caster
<
boost
::
variant
<
Ts
...
>>
:
variant_caster
<
boost
::
variant
<
Ts
...
>>
{};
struct
type_caster
<
boost
::
variant
<
Ts
...
>>
:
variant_caster
<
boost
::
variant
<
Ts
...
>>
{};
...
@@ -56,7 +56,7 @@ struct visit_helper<boost::variant> {
...
@@ -56,7 +56,7 @@ struct visit_helper<boost::variant> {
}
}
};
};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
#endif
#endif
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
std
::
string
,
std
::
allocator
<
std
::
string
>>
);
PYBIND11_MAKE_OPAQUE
(
std
::
vector
<
std
::
string
,
std
::
allocator
<
std
::
string
>>
);
...
@@ -159,13 +159,13 @@ private:
...
@@ -159,13 +159,13 @@ private:
std
::
vector
<
T
>
storage
;
std
::
vector
<
T
>
storage
;
};
};
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
namespace
detail
{
namespace
detail
{
template
<
typename
T
>
template
<
typename
T
>
struct
type_caster
<
ReferenceSensitiveOptional
<
T
>>
struct
type_caster
<
ReferenceSensitiveOptional
<
T
>>
:
optional_caster
<
ReferenceSensitiveOptional
<
T
>>
{};
:
optional_caster
<
ReferenceSensitiveOptional
<
T
>>
{};
}
// namespace detail
}
// namespace detail
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
TEST_SUBMODULE
(
stl
,
m
)
{
TEST_SUBMODULE
(
stl
,
m
)
{
// test_vector
// test_vector
...
...
tests/test_tagbased_polymorphic.cpp
View file @
f8e8403b
...
@@ -117,7 +117,7 @@ std::string Animal::name_of_kind(Kind kind) {
...
@@ -117,7 +117,7 @@ std::string Animal::name_of_kind(Kind kind) {
return
raw_name
;
return
raw_name
;
}
}
namespace
pybind11
{
namespace
PYBIND11_NAMESPACE
{
template
<
typename
itype
>
template
<
typename
itype
>
struct
polymorphic_type_hook
<
itype
,
detail
::
enable_if_t
<
std
::
is_base_of
<
Animal
,
itype
>::
value
>>
{
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
)
{
static
const
void
*
get
(
const
itype
*
src
,
const
std
::
type_info
*&
type
)
{
...
@@ -125,7 +125,7 @@ struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal,
...
@@ -125,7 +125,7 @@ struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal,
return
src
;
return
src
;
}
}
};
};
}
// namespace
pybind11
}
// namespace
PYBIND11_NAMESPACE
TEST_SUBMODULE
(
tagbased_polymorphic
,
m
)
{
TEST_SUBMODULE
(
tagbased_polymorphic
,
m
)
{
py
::
class_
<
Animal
>
(
m
,
"Animal"
).
def_readonly
(
"name"
,
&
Animal
::
name
);
py
::
class_
<
Animal
>
(
m
,
"Animal"
).
def_readonly
(
"name"
,
&
Animal
::
name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment