Change NAMESPACE_* macros into PYBIND11_NAMESPACE_* (#2283)

* Change NAMESPACE_BEGIN and NAMESPACE_END macros into PYBIND11_NAMESPACE_BEGIN and PYBIND11_NAMESPACE_END

* Fix sudden HomeBrew 'python not installed' error

* Sweep difference in 'Class.__init__() must be called when overriding __init__' error message between CPython and PyPy under the rug

* Homebrew updated to 3.8 yesterday.

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
Yannick Jadoul 2020-07-09 00:14:41 +02:00 committed by GitHub
parent 0d70f0e18e
commit f980d76d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 150 additions and 150 deletions

View File

@ -147,9 +147,9 @@ matrix:
osx_image: xcode7.3 osx_image: xcode7.3
env: PYTHON=2.7 CPP=14 CLANG CMAKE=1 env: PYTHON=2.7 CPP=14 CLANG CMAKE=1
- os: osx - os: osx
name: Python 3.7, c++14, AppleClang 9, Debug build name: Python 3.8, c++14, AppleClang 9, Debug build
osx_image: xcode9.4 osx_image: xcode9.4
env: PYTHON=3.7 CPP=14 CLANG DEBUG=1 env: PYTHON=3.8 CPP=14 CLANG DEBUG=1
# Test a PyPy 2.7 build # Test a PyPy 2.7 build
- os: linux - os: linux
dist: trusty dist: trusty
@ -243,7 +243,7 @@ before_install:
PY_CMD=python$PYTHON PY_CMD=python$PYTHON
if [ "$TRAVIS_OS_NAME" = "osx" ]; then if [ "$TRAVIS_OS_NAME" = "osx" ]; then
if [ "$PY" = "3" ]; then if [ "$PY" = "3" ]; then
brew update && brew unlink python@2 && brew upgrade python brew update && brew unlink python@2 && (brew upgrade python || brew install python)
else else
curl -fsSL https://bootstrap.pypa.io/get-pip.py | $PY_CMD - --user curl -fsSL https://bootstrap.pypa.io/get-pip.py | $PY_CMD - --user
fi fi

View File

@ -12,7 +12,7 @@
#include "cast.h" #include "cast.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
/// \addtogroup annotations /// \addtogroup annotations
/// @{ /// @{
@ -113,7 +113,7 @@ struct call_guard<T, Ts...> {
/// @} annotations /// @} annotations
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/* Forward declarations */ /* Forward declarations */
enum op_id : int; enum op_id : int;
enum op_type : int; enum op_type : int;
@ -524,5 +524,5 @@ constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
return named == 0 || (self + named + has_args + has_kwargs) == nargs; return named == 0 || (self + named + has_args + has_kwargs) == nargs;
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -11,7 +11,7 @@
#include "detail/common.h" #include "detail/common.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
/// Information record describing a Python buffer object /// Information record describing a Python buffer object
struct buffer_info { struct buffer_info {
@ -94,7 +94,7 @@ private:
bool ownview = false; bool ownview = false;
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename T, typename SFINAE = void> struct compare_buffer_info { template <typename T, typename SFINAE = void> struct compare_buffer_info {
static bool compare(const buffer_info& b) { static bool compare(const buffer_info& b) {
@ -110,5 +110,5 @@ template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_
} }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -36,8 +36,8 @@
# define PYBIND11_HAS_U8STRING # define PYBIND11_HAS_U8STRING
#endif #endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// A life support system for temporary objects created by `type_caster::load()`. /// A life support system for temporary objects created by `type_caster::load()`.
/// Adding a patient will keep it alive up until the enclosing function returns. /// Adding a patient will keep it alive up until the enclosing function returns.
@ -816,7 +816,7 @@ template <typename Container> struct is_copy_assignable<Container, enable_if_t<a
template <typename T1, typename T2> struct is_copy_assignable<std::pair<T1, T2>> template <typename T1, typename T2> struct is_copy_assignable<std::pair<T1, T2>>
: all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {}; : all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {};
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
// polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed // polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed
// to by `src` actually is an instance of some class derived from `itype`. // to by `src` actually is an instance of some class derived from `itype`.
@ -855,7 +855,7 @@ struct polymorphic_type_hook_base<itype, detail::enable_if_t<std::is_polymorphic
template <typename itype, typename SFINAE = void> template <typename itype, typename SFINAE = void>
struct polymorphic_type_hook : public polymorphic_type_hook_base<itype> {}; struct polymorphic_type_hook : public polymorphic_type_hook_base<itype> {};
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// Generic type caster for objects stored on the heap /// Generic type caster for objects stored on the heap
template <typename type> class type_caster_base : public type_caster_generic { template <typename type> class type_caster_base : public type_caster_generic {
@ -1708,7 +1708,7 @@ template <typename T> make_caster<T> load_type(const handle &handle) {
return conv; return conv;
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
// pytype -> C++ type // pytype -> C++ type
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0> template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
@ -1779,7 +1779,7 @@ template <typename T> T object::cast() && { return pybind11::cast<T>(std::move(*
template <> inline void object::cast() const & { return; } template <> inline void object::cast() const & { return; }
template <> inline void object::cast() && { return; } template <> inline void object::cast() && { return; }
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Declared in pytypes.h: // Declared in pytypes.h:
template <typename T, enable_if_t<!is_pyobject<T>::value, int>> template <typename T, enable_if_t<!is_pyobject<T>::value, int>>
@ -1806,7 +1806,7 @@ template <typename T> enable_if_t<cast_is_temporary_value_reference<T>::value, T
pybind11_fail("Internal error: cast_safe fallback invoked"); } pybind11_fail("Internal error: cast_safe fallback invoked"); }
template <> inline void cast_safe<void>(object &&) {} template <> inline void cast_safe<void>(object &&) {}
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
template <return_value_policy policy = return_value_policy::automatic_reference> template <return_value_policy policy = return_value_policy::automatic_reference>
tuple make_tuple() { return tuple(0); } tuple make_tuple() { return tuple(0); }
@ -1914,7 +1914,7 @@ inline namespace literals {
constexpr arg operator"" _a(const char *name, size_t) { return arg(name); } constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
} }
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// forward declaration (definition in attr.h) // forward declaration (definition in attr.h)
struct function_record; struct function_record;
@ -2185,7 +2185,7 @@ object object_api<Derived>::call(Args &&...args) const {
return operator()<policy>(std::forward<Args>(args)...); return operator()<policy>(std::forward<Args>(args)...);
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
#define PYBIND11_MAKE_OPAQUE(...) \ #define PYBIND11_MAKE_OPAQUE(...) \
namespace pybind11 { namespace detail { \ namespace pybind11 { namespace detail { \
@ -2196,4 +2196,4 @@ NAMESPACE_END(detail)
/// typedef, e.g.: `PYBIND11_OVERLOAD(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)` /// typedef, e.g.: `PYBIND11_OVERLOAD(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
#define PYBIND11_TYPE(...) __VA_ARGS__ #define PYBIND11_TYPE(...) __VA_ARGS__
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -27,8 +27,8 @@
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) #define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds)
#endif #endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename type> class duration_caster { template <typename type> class duration_caster {
public: public:
@ -180,5 +180,5 @@ template <typename Rep, typename Period> class type_caster<std::chrono::duration
: public duration_caster<std::chrono::duration<Rep, Period>> { : public duration_caster<std::chrono::duration<Rep, Period>> {
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -17,7 +17,7 @@
# undef I # undef I
#endif #endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> { 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; static constexpr const char c = format_descriptor<T>::c;
@ -32,7 +32,7 @@ template <typename T> constexpr const char format_descriptor<
#endif #endif
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> { template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
static constexpr bool value = true; static constexpr bool value = true;
@ -61,5 +61,5 @@ public:
PYBIND11_TYPE_CASTER(std::complex<T>, _("complex")); PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -12,8 +12,8 @@
#include "../attr.h" #include "../attr.h"
#include "../options.h" #include "../options.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
#if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION) #if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION)
# define PYBIND11_BUILTIN_QUALNAME # define PYBIND11_BUILTIN_QUALNAME
@ -664,5 +664,5 @@ inline PyObject* make_new_python_type(const type_record &rec) {
return (PyObject *) type; return (PyObject *) type;
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -9,12 +9,8 @@
#pragma once #pragma once
#if !defined(NAMESPACE_BEGIN) #define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
# define NAMESPACE_BEGIN(name) namespace name { #define PYBIND11_NAMESPACE_END(name) }
#endif
#if !defined(NAMESPACE_END)
# define NAMESPACE_END(name) }
#endif
// Robust support for some features and loading modules compiled against different pybind versions // 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 // requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute on
@ -325,7 +321,7 @@ extern "C" {
void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable) void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
using ssize_t = Py_ssize_t; using ssize_t = Py_ssize_t;
using size_t = std::size_t; using size_t = std::size_t;
@ -382,7 +378,7 @@ enum class return_value_policy : uint8_t {
reference_internal reference_internal
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
inline static constexpr int log2(size_t n, int k = 0) { return (n <= 1) ? k : log2(n >> 1, k + 1); } inline static constexpr int log2(size_t n, int k = 0) { return (n <= 1) ? k : log2(n >> 1, k + 1); }
@ -560,7 +556,7 @@ template <typename T, typename... Ts>
constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); } constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); }
#endif #endif
NAMESPACE_BEGIN(constexpr_impl) PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
/// Implementation details for constexpr functions /// Implementation details for constexpr functions
constexpr int first(int i) { return i; } constexpr int first(int i) { return i; }
template <typename T, typename... Ts> template <typename T, typename... Ts>
@ -569,7 +565,7 @@ constexpr int first(int i, T v, Ts... vs) { return v ? i : first(i + 1, vs...);
constexpr int last(int /*i*/, int result) { return result; } constexpr int last(int /*i*/, int result) { return result; }
template <typename T, typename... Ts> template <typename T, typename... Ts>
constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); } constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); }
NAMESPACE_END(constexpr_impl) PYBIND11_NAMESPACE_END(constexpr_impl)
/// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if /// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if
/// none match. /// none match.
@ -683,7 +679,7 @@ using expand_side_effects = bool[];
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false } #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
#endif #endif
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// C++ bindings of builtin Python exceptions /// C++ bindings of builtin Python exceptions
class builtin_exception : public std::runtime_error { class builtin_exception : public std::runtime_error {
@ -715,7 +711,7 @@ PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used in
template <typename T, typename SFINAE = void> struct format_descriptor { }; template <typename T, typename SFINAE = void> struct format_descriptor { };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Returns the index of the given type in the type char array below, and in the list in numpy.h // Returns the index of the given type in the type char array below, and in the list in numpy.h
// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double; // The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
// complex float,double,long double. Note that the long double types only participate when long // complex float,double,long double. Note that the long double types only participate when long
@ -728,7 +724,7 @@ template <typename T> struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>
std::is_integral<T>::value ? detail::log2(sizeof(T))*2 + std::is_unsigned<T>::value : 8 + ( std::is_integral<T>::value ? detail::log2(sizeof(T))*2 + std::is_unsigned<T>::value : 8 + (
std::is_same<T, double>::value ? 1 : std::is_same<T, long double>::value ? 2 : 0)); std::is_same<T, double>::value ? 1 : std::is_same<T, long double>::value ? 2 : 0));
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> { template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index]; static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
@ -753,7 +749,7 @@ struct error_scope {
/// Dummy destructor wrapper that can be used to expose classes with a private destructor /// Dummy destructor wrapper that can be used to expose classes with a private destructor
struct nodelete { template <typename T> void operator()(T*) { } }; struct nodelete { template <typename T> void operator()(T*) { } };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename... Args> template <typename... Args>
struct overload_cast_impl { struct overload_cast_impl {
constexpr overload_cast_impl() {} // MSVC 2015 needs this constexpr overload_cast_impl() {} // MSVC 2015 needs this
@ -770,7 +766,7 @@ struct overload_cast_impl {
constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
-> decltype(pmf) { return pmf; } -> decltype(pmf) { return pmf; }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
// overload_cast requires variable templates: C++14 // overload_cast requires variable templates: C++14
#if defined(PYBIND11_CPP14) #if defined(PYBIND11_CPP14)
@ -795,7 +791,7 @@ template <typename... Args> struct overload_cast {
}; };
#endif // overload_cast #endif // overload_cast
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from // Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
// any standard container (or C-style array) supporting std::begin/std::end, any singleton // any standard container (or C-style array) supporting std::begin/std::end, any singleton
@ -834,8 +830,8 @@ public:
const std::vector<T> *operator->() const { return &v; } const std::vector<T> *operator->() const { return &v; }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -11,8 +11,8 @@
#include "common.h" #include "common.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
# define PYBIND11_DESCR_CONSTEXPR static constexpr # define PYBIND11_DESCR_CONSTEXPR static constexpr
@ -96,5 +96,5 @@ constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
return _("{") + descr + _("}"); return _("{") + descr + _("}");
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -11,8 +11,8 @@
#include "class.h" #include "class.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <> template <>
class type_caster<value_and_holder> { class type_caster<value_and_holder> {
@ -30,7 +30,7 @@ private:
value_and_holder *value = nullptr; value_and_holder *value = nullptr;
}; };
NAMESPACE_BEGIN(initimpl) PYBIND11_NAMESPACE_BEGIN(initimpl)
inline void no_nullptr(void *ptr) { inline void no_nullptr(void *ptr) {
if (!ptr) throw type_error("pybind11::init(): factory function returned nullptr"); if (!ptr) throw type_error("pybind11::init(): factory function returned nullptr");
@ -330,6 +330,6 @@ struct pickle_factory<Get, Set, RetState(Self), NewInstance(ArgState)> {
} }
}; };
NAMESPACE_END(initimpl) PYBIND11_NAMESPACE_END(initimpl)
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(pybind11) PYBIND11_NAMESPACE_END(pybind11)

View File

@ -11,8 +11,8 @@
#include "../pytypes.h" #include "../pytypes.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Forward declarations // Forward declarations
inline PyTypeObject *make_static_property_type(); inline PyTypeObject *make_static_property_type();
inline PyTypeObject *make_default_metaclass(); inline PyTypeObject *make_default_metaclass();
@ -317,7 +317,7 @@ const char *c_str(Args &&...args) {
return strings.front().c_str(); return strings.front().c_str();
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// Returns a named pointer that is shared among all extension modules (using the same /// Returns a named pointer that is shared among all extension modules (using the same
/// pybind11 version) running in the current interpreter. Names starting with underscores /// pybind11 version) running in the current interpreter. Names starting with underscores
@ -349,4 +349,4 @@ T &get_or_create_shared_data(const std::string &name) {
return *ptr; return *ptr;
} }
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -18,8 +18,8 @@
#include "common.h" #include "common.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// Erase all occurrences of a substring /// Erase all occurrences of a substring
inline void erase_all(std::string &string, const std::string &search) { inline void erase_all(std::string &string, const std::string &search) {
for (size_t pos = 0;;) { for (size_t pos = 0;;) {
@ -43,7 +43,7 @@ PYBIND11_NOINLINE inline void clean_type_id(std::string &name) {
#endif #endif
detail::erase_all(name, "pybind11::"); detail::erase_all(name, "pybind11::");
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// Return a string representation of a C++ type /// Return a string representation of a C++ type
template <typename T> static std::string type_id() { template <typename T> static std::string type_id() {
@ -52,4 +52,4 @@ template <typename T> static std::string type_id() {
return name; return name;
} }
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -41,14 +41,14 @@
// of matrices seems highly undesirable. // of matrices seems highly undesirable.
static_assert(EIGEN_VERSION_AT_LEAST(3,2,7), "Eigen support in pybind11 requires Eigen >= 3.2.7"); static_assert(EIGEN_VERSION_AT_LEAST(3,2,7), "Eigen support in pybind11 requires Eigen >= 3.2.7");
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
// Provide a convenience alias for easier pass-by-ref usage with fully dynamic strides: // Provide a convenience alias for easier pass-by-ref usage with fully dynamic strides:
using EigenDStride = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>; using EigenDStride = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>;
template <typename MatrixType> using EigenDRef = Eigen::Ref<MatrixType, 0, EigenDStride>; template <typename MatrixType> using EigenDRef = Eigen::Ref<MatrixType, 0, EigenDStride>;
template <typename MatrixType> using EigenDMap = Eigen::Map<MatrixType, 0, EigenDStride>; template <typename MatrixType> using EigenDMap = Eigen::Map<MatrixType, 0, EigenDStride>;
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
#if EIGEN_VERSION_AT_LEAST(3,3,0) #if EIGEN_VERSION_AT_LEAST(3,3,0)
using EigenIndex = Eigen::Index; using EigenIndex = Eigen::Index;
@ -597,8 +597,8 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
+ npy_format_descriptor<Scalar>::name + _("]")); + npy_format_descriptor<Scalar>::name + _("]"));
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(__GNUG__) || defined(__clang__) #if defined(__GNUG__) || defined(__clang__)
# pragma GCC diagnostic pop # pragma GCC diagnostic pop

View File

@ -66,8 +66,8 @@
void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable) void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// Python 2.7/3.x compatible version of `PyImport_AppendInittab` and error checks. /// Python 2.7/3.x compatible version of `PyImport_AppendInittab` and error checks.
struct embedded_module { struct embedded_module {
@ -86,7 +86,7 @@ struct embedded_module {
} }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/** \rst /** \rst
Initialize the Python interpreter. No other pybind11 or CPython API functions can be Initialize the Python interpreter. No other pybind11 or CPython API functions can be
@ -199,4 +199,4 @@ private:
bool is_valid = true; bool is_valid = true;
}; };
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -13,7 +13,7 @@
#include "pybind11.h" #include "pybind11.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
enum eval_mode { enum eval_mode {
/// Evaluate a string containing an isolated expression /// Evaluate a string containing an isolated expression
@ -129,4 +129,4 @@ object eval_file(str fname, object global = globals(), object local = object())
} }
#endif #endif
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -12,8 +12,8 @@
#include "pybind11.h" #include "pybind11.h"
#include <functional> #include <functional>
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename Return, typename... Args> template <typename Return, typename... Args>
struct type_caster<std::function<Return(Args...)>> { struct type_caster<std::function<Return(Args...)>> {
@ -97,5 +97,5 @@ public:
+ make_caster<retval_type>::name + _("]")); + make_caster<retval_type>::name + _("]"));
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -17,8 +17,8 @@
#include <memory> #include <memory>
#include <iostream> #include <iostream>
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Buffer that writes to Python instead of C++ // Buffer that writes to Python instead of C++
class pythonbuf : public std::streambuf { class pythonbuf : public std::streambuf {
@ -72,7 +72,7 @@ public:
} }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/** \rst /** \rst
@ -144,7 +144,7 @@ public:
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Class to redirect output as a context manager. C++ backend. // Class to redirect output as a context manager. C++ backend.
class OstreamRedirect { class OstreamRedirect {
@ -170,7 +170,7 @@ public:
} }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/** \rst /** \rst
This is a helper function to add a C++ redirect context manager to Python This is a helper function to add a C++ redirect context manager to Python
@ -206,4 +206,4 @@ inline class_<detail::OstreamRedirect> add_ostream_redirect(module m, std::strin
.def("__exit__", [](detail::OstreamRedirect &self_, args) { self_.exit(); }); .def("__exit__", [](detail::OstreamRedirect &self_, args) { self_.exit(); });
} }
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -35,11 +35,11 @@
upon the library user. */ upon the library user. */
static_assert(sizeof(ssize_t) == sizeof(Py_intptr_t), "ssize_t != Py_intptr_t"); static_assert(sizeof(ssize_t) == sizeof(Py_intptr_t), "ssize_t != Py_intptr_t");
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
class array; // Forward declaration class array; // Forward declaration
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <> struct handle_type_name<array> { static constexpr auto name = _("numpy.ndarray"); }; template <> struct handle_type_name<array> { static constexpr auto name = _("numpy.ndarray"); };
@ -442,7 +442,7 @@ struct type_caster<unchecked_reference<T, Dim>> {
template <typename T, ssize_t Dim> template <typename T, ssize_t Dim>
struct type_caster<unchecked_mutable_reference<T, Dim>> : type_caster<unchecked_reference<T, Dim>> {}; struct type_caster<unchecked_mutable_reference<T, Dim>> : type_caster<unchecked_reference<T, Dim>> {};
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
class dtype : public object { class dtype : public object {
public: public:
@ -979,7 +979,7 @@ struct format_descriptor<T, detail::enable_if_t<detail::array_info<T>::is_array>
} }
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename T, int ExtraFlags> template <typename T, int ExtraFlags>
struct pyobject_caster<array_t<T, ExtraFlags>> { struct pyobject_caster<array_t<T, ExtraFlags>> {
using type = array_t<T, ExtraFlags>; using type = array_t<T, ExtraFlags>;
@ -1608,7 +1608,7 @@ template <typename T, int Flags> struct handle_type_name<array_t<T, Flags>> {
static constexpr auto name = _("numpy.ndarray[") + npy_format_descriptor<T>::name + _("]"); static constexpr auto name = _("numpy.ndarray[") + npy_format_descriptor<T>::name + _("]");
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
// Vanilla pointer vectorizer: // Vanilla pointer vectorizer:
template <typename Return, typename... Args> template <typename Return, typename... Args>
@ -1638,7 +1638,7 @@ Helper vectorize(Return (Class::*f)(Args...) const) {
return Helper(std::mem_fn(f)); return Helper(std::mem_fn(f));
} }
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)

View File

@ -18,8 +18,8 @@
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#endif #endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// Enumeration with all supported operator types /// Enumeration with all supported operator types
enum op_id : int { enum op_id : int {
@ -160,13 +160,13 @@ PYBIND11_UNARY_OPERATOR(float, float_, (double) l)
#undef PYBIND11_BINARY_OPERATOR #undef PYBIND11_BINARY_OPERATOR
#undef PYBIND11_INPLACE_OPERATOR #undef PYBIND11_INPLACE_OPERATOR
#undef PYBIND11_UNARY_OPERATOR #undef PYBIND11_UNARY_OPERATOR
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
using detail::self; using detail::self;
// Add named operators so that they are accessible via `py::`. // Add named operators so that they are accessible via `py::`.
using detail::hash; using detail::hash;
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(_MSC_VER) #if defined(_MSC_VER)
# pragma warning(pop) # pragma warning(pop)

View File

@ -11,7 +11,7 @@
#include "detail/common.h" #include "detail/common.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
class options { class options {
public: public:
@ -62,4 +62,4 @@ private:
state previous_state; state previous_state;
}; };
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -50,7 +50,7 @@
# include <cxxabi.h> # include <cxxabi.h>
#endif #endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
/// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object
class cpp_function : public function { class cpp_function : public function {
@ -909,7 +909,7 @@ inline dict globals() {
return reinterpret_borrow<dict>(p ? p : module::import("__main__").attr("__dict__").ptr()); return reinterpret_borrow<dict>(p ? p : module::import("__main__").attr("__dict__").ptr());
} }
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// Generic support for creating new Python heap types /// Generic support for creating new Python heap types
class generic_type : public object { class generic_type : public object {
template <typename...> friend class class_; template <typename...> friend class class_;
@ -1047,7 +1047,7 @@ inline void call_operator_delete(void *p, size_t s, size_t a) {
#endif #endif
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// Given a pointer to a member function, cast it to its `Derived` version. /// Given a pointer to a member function, cast it to its `Derived` version.
/// Forward everything else unchanged. /// Forward everything else unchanged.
@ -1425,7 +1425,7 @@ detail::initimpl::pickle_factory<GetState, SetState> pickle(GetState &&g, SetSta
return {std::forward<GetState>(g), std::forward<SetState>(s)}; return {std::forward<GetState>(g), std::forward<SetState>(s)};
} }
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
struct enum_base { struct enum_base {
enum_base(handle base, handle parent) : m_base(base), m_parent(parent) { } enum_base(handle base, handle parent) : m_base(base), m_parent(parent) { }
@ -1576,7 +1576,7 @@ struct enum_base {
handle m_parent; handle m_parent;
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// Binds C++ enumerations and enumeration classes to Python /// Binds C++ enumerations and enumeration classes to Python
template <typename Type> class enum_ : public class_<Type> { template <typename Type> class enum_ : public class_<Type> {
@ -1628,7 +1628,7 @@ private:
detail::enum_base m_base; detail::enum_base m_base;
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
inline void keep_alive_impl(handle nurse, handle patient) { inline void keep_alive_impl(handle nurse, handle patient) {
@ -1698,7 +1698,7 @@ struct iterator_state {
bool first_or_done; bool first_or_done;
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// Makes a python iterator from a first and past-the-end C++ InputIterator. /// Makes a python iterator from a first and past-the-end C++ InputIterator.
template <return_value_policy Policy = return_value_policy::reference_internal, template <return_value_policy Policy = return_value_policy::reference_internal,
@ -1831,13 +1831,13 @@ public:
} }
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Returns a reference to a function-local static exception object used in the simple // Returns a reference to a function-local static exception object used in the simple
// register_exception approach below. (It would be simpler to have the static local variable // register_exception approach below. (It would be simpler to have the static local variable
// directly in register_exception, but that makes clang <3.5 segfault - issue #1349). // directly in register_exception, but that makes clang <3.5 segfault - issue #1349).
template <typename CppException> template <typename CppException>
exception<CppException> &get_exception_object() { static exception<CppException> ex; return ex; } exception<CppException> &get_exception_object() { static exception<CppException> ex; return ex; }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/** /**
* Registers a Python exception in `m` of the given `name` and installs an exception translator to * Registers a Python exception in `m` of the given `name` and installs an exception translator to
@ -1863,7 +1863,7 @@ exception<CppException> &register_exception(handle scope,
return ex; return ex;
} }
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) { PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) {
auto strings = tuple(args.size()); auto strings = tuple(args.size());
for (size_t i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
@ -1894,7 +1894,7 @@ PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) {
if (kwargs.contains("flush") && kwargs["flush"].cast<bool>()) if (kwargs.contains("flush") && kwargs["flush"].cast<bool>())
file.attr("flush")(); file.attr("flush")();
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args> template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
void print(Args &&...args) { void print(Args &&...args) {
@ -2203,7 +2203,7 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
#define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \ #define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \
PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__) PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
# pragma warning(pop) # pragma warning(pop)

View File

@ -14,14 +14,14 @@
#include <utility> #include <utility>
#include <type_traits> #include <type_traits>
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
/* A few forward declarations */ /* A few forward declarations */
class handle; class object; class handle; class object;
class str; class iterator; class str; class iterator;
struct arg; struct arg_v; struct arg; struct arg_v;
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
class args_proxy; class args_proxy;
inline bool isinstance_generic(handle obj, const std::type_info &tp); inline bool isinstance_generic(handle obj, const std::type_info &tp);
@ -158,7 +158,7 @@ private:
bool rich_compare(object_api const &other, int value) const; bool rich_compare(object_api const &other, int value) const;
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/** \rst /** \rst
Holds a reference to a Python object (no reference counting) Holds a reference to a Python object (no reference counting)
@ -311,9 +311,9 @@ template <typename T> T reinterpret_borrow(handle h) { return {h, object::borrow
\endrst */ \endrst */
template <typename T> T reinterpret_steal(handle h) { return {h, object::stolen_t{}}; } template <typename T> T reinterpret_steal(handle h) { return {h, object::stolen_t{}}; }
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
inline std::string error_string(); inline std::string error_string();
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
/// Fetch and hold an error which was already set in Python. An instance of this is typically /// Fetch and hold an error which was already set in Python. An instance of this is typically
/// thrown to propagate python-side errors back through C++ which can either be caught manually or /// thrown to propagate python-side errors back through C++ which can either be caught manually or
@ -446,7 +446,7 @@ inline ssize_t hash(handle obj) {
/// @} python_builtins /// @} python_builtins
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
inline handle get_function(handle value) { inline handle get_function(handle value) {
if (value) { if (value) {
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
@ -520,7 +520,7 @@ private:
mutable object cache; mutable object cache;
}; };
NAMESPACE_BEGIN(accessor_policies) PYBIND11_NAMESPACE_BEGIN(accessor_policies)
struct obj_attr { struct obj_attr {
using key_type = object; using key_type = object;
static object get(handle obj, handle key) { return getattr(obj, key); } static object get(handle obj, handle key) { return getattr(obj, key); }
@ -597,7 +597,7 @@ struct tuple_item {
} }
} }
}; };
NAMESPACE_END(accessor_policies) PYBIND11_NAMESPACE_END(accessor_policies)
/// STL iterator template used for tuple, list, sequence and dict /// STL iterator template used for tuple, list, sequence and dict
template <typename Policy> template <typename Policy>
@ -638,7 +638,7 @@ public:
friend bool operator<=(const It &a, const It &b) { return !(a > b); } friend bool operator<=(const It &a, const It &b) { return !(a > b); }
}; };
NAMESPACE_BEGIN(iterator_policies) PYBIND11_NAMESPACE_BEGIN(iterator_policies)
/// Quick proxy class needed to implement ``operator->`` for iterators which can't return pointers /// Quick proxy class needed to implement ``operator->`` for iterators which can't return pointers
template <typename T> template <typename T>
struct arrow_proxy { struct arrow_proxy {
@ -711,7 +711,7 @@ private:
PyObject *key = nullptr, *value = nullptr; PyObject *key = nullptr, *value = nullptr;
ssize_t pos = -1; ssize_t pos = -1;
}; };
NAMESPACE_END(iterator_policies) PYBIND11_NAMESPACE_END(iterator_policies)
#if !defined(PYPY_VERSION) #if !defined(PYPY_VERSION)
using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>; using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>;
@ -770,7 +770,7 @@ class simple_collector;
template <return_value_policy policy = return_value_policy::automatic_reference> template <return_value_policy policy = return_value_policy::automatic_reference>
class unpacking_collector; class unpacking_collector;
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
// TODO: After the deprecated constructors are removed, this macro can be simplified by // TODO: After the deprecated constructors are removed, this macro can be simplified by
// inheriting ctors: `using Parent::Parent`. It's not an option right now because // inheriting ctors: `using Parent::Parent`. It's not an option right now because
@ -1045,7 +1045,7 @@ private:
} }
}; };
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
// Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1; // Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1;
// otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned). // otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned).
// (The distinction is critically important when casting a returned -1 error value to some other // (The distinction is critically important when casting a returned -1 error value to some other
@ -1065,7 +1065,7 @@ Unsigned as_unsigned(PyObject *o) {
return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v; return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
} }
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
class int_ : public object { class int_ : public object {
public: public:
@ -1409,7 +1409,7 @@ inline iterator iter(handle obj) {
} }
/// @} python_builtins /// @} python_builtins
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <typename D> iterator object_api<D>::begin() const { return iter(derived()); } template <typename D> iterator object_api<D>::begin() const { return iter(derived()); }
template <typename D> iterator object_api<D>::end() const { return iterator::sentinel(); } template <typename D> iterator object_api<D>::end() const { return iterator::sentinel(); }
template <typename D> item_accessor object_api<D>::operator[](handle key) const { template <typename D> item_accessor object_api<D>::operator[](handle key) const {
@ -1490,5 +1490,5 @@ PYBIND11_MATH_OPERATOR_BINARY(operator>>=, PyNumber_InPlaceRshift)
#undef PYBIND11_MATH_OPERATOR_UNARY #undef PYBIND11_MATH_OPERATOR_UNARY
#undef PYBIND11_MATH_OPERATOR_BINARY #undef PYBIND11_MATH_OPERATOR_BINARY
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -48,8 +48,8 @@
# define PYBIND11_HAS_VARIANT 1 # define PYBIND11_HAS_VARIANT 1
#endif #endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for /// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for
/// forwarding a container element). Typically used indirect via forwarded_type(), below. /// forwarding a container element). Typically used indirect via forwarded_type(), below.
@ -374,14 +374,14 @@ template <typename... Ts>
struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> { }; struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> { };
#endif #endif
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
inline std::ostream &operator<<(std::ostream &os, const handle &obj) { inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
os << (std::string) str(obj); os << (std::string) str(obj);
return os; return os;
} }
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)

View File

@ -15,8 +15,8 @@
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/* SFINAE helper class used by 'is_comparable */ /* SFINAE helper class used by 'is_comparable */
template <typename T> struct container_traits { template <typename T> struct container_traits {
@ -413,7 +413,7 @@ vector_buffer(Class_& cl) {
template <typename Vector, typename Class_, typename... Args> template <typename Vector, typename Class_, typename... Args>
enable_if_t<!detail::any_of<std::is_same<Args, buffer_protocol>...>::value> vector_buffer(Class_&) {} enable_if_t<!detail::any_of<std::is_same<Args, buffer_protocol>...>::value> vector_buffer(Class_&) {}
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
// //
// std::vector // std::vector
@ -511,7 +511,7 @@ class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, A
// std::map, std::unordered_map // std::map, std::unordered_map
// //
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
/* Fallback functions */ /* Fallback functions */
template <typename, typename, typename... Args> void map_if_insertion_operator(const Args &...) { } template <typename, typename, typename... Args> void map_if_insertion_operator(const Args &...) { }
@ -577,7 +577,7 @@ template <typename Map, typename Class_> auto map_if_insertion_operator(Class_ &
} }
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args> template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args>
class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&... args) { class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&... args) {
@ -653,4 +653,4 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&.
return cl; return cl;
} }
NAMESPACE_END(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -53,13 +53,13 @@ public:
/// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast context. /// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast context.
/// Used to test recursive casters (e.g. std::tuple, stl containers). /// Used to test recursive casters (e.g. std::tuple, stl containers).
struct RValueCaster {}; struct RValueCaster {};
NAMESPACE_BEGIN(pybind11) PYBIND11_NAMESPACE_BEGIN(pybind11)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template<> class type_caster<RValueCaster> { template<> class type_caster<RValueCaster> {
public: public:
PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster")); PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster"));
static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); } static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); }
static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); } static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); }
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(pybind11) PYBIND11_NAMESPACE_END(pybind11)

View File

@ -109,7 +109,10 @@ def test_inheritance_init(msg):
pass pass
with pytest.raises(TypeError) as exc_info: with pytest.raises(TypeError) as exc_info:
Python() Python()
assert msg(exc_info.value) == "m.class_.Pet.__init__() must be called when overriding __init__" expected = ["m.class_.Pet.__init__() must be called when overriding __init__",
"Pet.__init__() must be called when overriding __init__"] # PyPy?
# TODO: fix PyPy error message wrt. tp_name/__qualname__?
assert msg(exc_info.value) in expected
# Multiple bases # Multiple bases
class RabbitHamster(m.Rabbit, m.Hamster): class RabbitHamster(m.Rabbit, m.Hamster):
@ -118,8 +121,9 @@ def test_inheritance_init(msg):
with pytest.raises(TypeError) as exc_info: with pytest.raises(TypeError) as exc_info:
RabbitHamster() RabbitHamster()
expected = "m.class_.Hamster.__init__() must be called when overriding __init__" expected = ["m.class_.Hamster.__init__() must be called when overriding __init__",
assert msg(exc_info.value) == expected "Hamster.__init__() must be called when overriding __init__"] # PyPy
assert msg(exc_info.value) in expected
def test_automatic_upcasting(): def test_automatic_upcasting():

View File

@ -68,8 +68,8 @@ public:
int value; int value;
}; };
NAMESPACE_BEGIN(pybind11) PYBIND11_NAMESPACE_BEGIN(pybind11)
NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
template <> struct type_caster<MoveOnlyInt> { template <> struct type_caster<MoveOnlyInt> {
PYBIND11_TYPE_CASTER(MoveOnlyInt, _("MoveOnlyInt")); PYBIND11_TYPE_CASTER(MoveOnlyInt, _("MoveOnlyInt"));
bool load(handle src, bool) { value = MoveOnlyInt(src.cast<int>()); return true; } bool load(handle src, bool) { value = MoveOnlyInt(src.cast<int>()); return true; }
@ -97,8 +97,8 @@ public:
operator CopyOnlyInt&() { return value; } operator CopyOnlyInt&() { return value; }
template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>; template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>;
}; };
NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)
NAMESPACE_END(pybind11) PYBIND11_NAMESPACE_END(pybind11)
TEST_SUBMODULE(copy_move_policies, m) { TEST_SUBMODULE(copy_move_policies, m) {
// test_lacking_copy_ctor // test_lacking_copy_ctor