From e979d0a7d3412b44c15f9886af2192f05b987e83 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Wed, 8 Jul 2020 14:14:52 +0200 Subject: [PATCH 1/4] Change NAMESPACE_BEGIN and NAMESPACE_END macros into PYBIND11_NAMESPACE_BEGIN and PYBIND11_NAMESPACE_END --- include/pybind11/attr.h | 8 ++++---- include/pybind11/buffer_info.h | 8 ++++---- include/pybind11/cast.h | 20 +++++++++--------- include/pybind11/chrono.h | 8 ++++---- include/pybind11/complex.h | 8 ++++---- include/pybind11/detail/class.h | 8 ++++---- include/pybind11/detail/common.h | 32 +++++++++++++---------------- include/pybind11/detail/descr.h | 8 ++++---- include/pybind11/detail/init.h | 12 +++++------ include/pybind11/detail/internals.h | 8 ++++---- include/pybind11/detail/typeid.h | 8 ++++---- include/pybind11/eigen.h | 8 ++++---- include/pybind11/embed.h | 8 ++++---- include/pybind11/eval.h | 4 ++-- include/pybind11/functional.h | 8 ++++---- include/pybind11/iostream.h | 12 +++++------ include/pybind11/numpy.h | 12 +++++------ include/pybind11/operators.h | 8 ++++---- include/pybind11/options.h | 4 ++-- include/pybind11/pybind11.h | 24 +++++++++++----------- include/pybind11/pytypes.h | 32 ++++++++++++++--------------- include/pybind11/stl.h | 8 ++++---- include/pybind11/stl_bind.h | 12 +++++------ tests/pybind11_tests.h | 8 ++++---- tests/test_copy_move.cpp | 8 ++++---- 25 files changed, 140 insertions(+), 144 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 58390239af..54065fc9e1 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -12,7 +12,7 @@ #include "cast.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /// \addtogroup annotations /// @{ @@ -113,7 +113,7 @@ struct call_guard { /// @} annotations -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) /* Forward declarations */ enum op_id : 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; } -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/buffer_info.h b/include/pybind11/buffer_info.h index 1f4115a1fa..0bf42880b7 100644 --- a/include/pybind11/buffer_info.h +++ b/include/pybind11/buffer_info.h @@ -11,7 +11,7 @@ #include "detail/common.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /// Information record describing a Python buffer object struct buffer_info { @@ -94,7 +94,7 @@ struct buffer_info { bool ownview = false; }; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) template struct compare_buffer_info { static bool compare(const buffer_info& b) { @@ -110,5 +110,5 @@ template struct compare_buffer_info struct is_copy_assignable struct is_copy_assignable> : all_of, is_copy_assignable> {}; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) // polymorphic_type_hook::get(src, tinfo) determines whether the object pointed // to by `src` actually is an instance of some class derived from `itype`. @@ -855,7 +855,7 @@ struct polymorphic_type_hook_base struct polymorphic_type_hook : public polymorphic_type_hook_base {}; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) /// Generic type caster for objects stored on the heap template class type_caster_base : public type_caster_generic { @@ -1708,7 +1708,7 @@ template make_caster load_type(const handle &handle) { return conv; } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) // pytype -> C++ type template ::value, int> = 0> @@ -1779,7 +1779,7 @@ template T object::cast() && { return pybind11::cast(std::move(* template <> inline void object::cast() const & { return; } template <> inline void object::cast() && { return; } -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) // Declared in pytypes.h: template ::value, int>> @@ -1806,7 +1806,7 @@ template enable_if_t::value, T pybind11_fail("Internal error: cast_safe fallback invoked"); } template <> inline void cast_safe(object &&) {} -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) template 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); } } -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) // forward declaration (definition in attr.h) struct function_record; @@ -2185,7 +2185,7 @@ object object_api::call(Args &&...args) const { return operator()(std::forward(args)...); } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) #define PYBIND11_MAKE_OPAQUE(...) \ namespace pybind11 { namespace detail { \ @@ -2196,4 +2196,4 @@ NAMESPACE_END(detail) /// typedef, e.g.: `PYBIND11_OVERLOAD(PYBIND11_TYPE(ReturnType), PYBIND11_TYPE(Parent), f, arg)` #define PYBIND11_TYPE(...) __VA_ARGS__ -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index ea777e6965..6b9ab9b82a 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -27,8 +27,8 @@ #define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) #endif -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) template class duration_caster { public: @@ -180,5 +180,5 @@ template class type_caster> { }; -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/complex.h b/include/pybind11/complex.h index 3f89638571..f8327eb373 100644 --- a/include/pybind11/complex.h +++ b/include/pybind11/complex.h @@ -17,7 +17,7 @@ # undef I #endif -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) template struct format_descriptor, detail::enable_if_t::value>> { static constexpr const char c = format_descriptor::c; @@ -32,7 +32,7 @@ template constexpr const char format_descriptor< #endif -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) template struct is_fmt_numeric, detail::enable_if_t::value>> { static constexpr bool value = true; @@ -61,5 +61,5 @@ template class type_caster> { PYBIND11_TYPE_CASTER(std::complex, _("complex")); }; -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index f6b89c20e1..d58f04e612 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -12,8 +12,8 @@ #include "../attr.h" #include "../options.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) #if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION) # define PYBIND11_BUILTIN_QUALNAME @@ -664,5 +664,5 @@ inline PyObject* make_new_python_type(const type_record &rec) { return (PyObject *) type; } -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index f4840daef6..8b609e7260 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -9,12 +9,8 @@ #pragma once -#if !defined(NAMESPACE_BEGIN) -# define NAMESPACE_BEGIN(name) namespace name { -#endif -#if !defined(NAMESPACE_END) -# define NAMESPACE_END(name) } -#endif +#define PYBIND11_NAMESPACE_BEGIN(name) namespace name { +#define PYBIND11_NAMESPACE_END(name) } // 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 @@ -325,7 +321,7 @@ extern "C" { 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 size_t = std::size_t; @@ -382,7 +378,7 @@ enum class return_value_policy : uint8_t { 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); } @@ -560,7 +556,7 @@ template constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); } #endif -NAMESPACE_BEGIN(constexpr_impl) +PYBIND11_NAMESPACE_BEGIN(constexpr_impl) /// Implementation details for constexpr functions constexpr int first(int i) { return i; } template @@ -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; } template 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. Returns sizeof...(Ts) if /// 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 } #endif -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /// C++ bindings of builtin Python exceptions class builtin_exception : public std::runtime_error { @@ -715,7 +711,7 @@ PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used in template 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 // 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 @@ -728,7 +724,7 @@ template struct is_fmt_numeric std::is_integral::value ? detail::log2(sizeof(T))*2 + std::is_unsigned::value : 8 + ( std::is_same::value ? 1 : std::is_same::value ? 2 : 0)); }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) template struct format_descriptor::value>> { static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric::index]; @@ -753,7 +749,7 @@ struct error_scope { /// Dummy destructor wrapper that can be used to expose classes with a private destructor struct nodelete { template void operator()(T*) { } }; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) template struct overload_cast_impl { 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 -> decltype(pmf) { return pmf; } }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) // overload_cast requires variable templates: C++14 #if defined(PYBIND11_CPP14) @@ -795,7 +791,7 @@ template struct overload_cast { }; #endif // overload_cast -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) // 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 @@ -834,8 +830,8 @@ class any_container { const std::vector *operator->() const { return &v; } }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/descr.h b/include/pybind11/detail/descr.h index 8d404e5346..92720cd562 100644 --- a/include/pybind11/detail/descr.h +++ b/include/pybind11/detail/descr.h @@ -11,8 +11,8 @@ #include "common.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) #if !defined(_MSC_VER) # define PYBIND11_DESCR_CONSTEXPR static constexpr @@ -96,5 +96,5 @@ constexpr descr type_descr(const descr &descr) { return _("{") + descr + _("}"); } -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index acfe00bdb7..35b95bcfae 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -11,8 +11,8 @@ #include "class.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) template <> class type_caster { @@ -30,7 +30,7 @@ class type_caster { value_and_holder *value = nullptr; }; -NAMESPACE_BEGIN(initimpl) +PYBIND11_NAMESPACE_BEGIN(initimpl) inline void no_nullptr(void *ptr) { if (!ptr) throw type_error("pybind11::init(): factory function returned nullptr"); @@ -330,6 +330,6 @@ struct pickle_factory { } }; -NAMESPACE_END(initimpl) -NAMESPACE_END(detail) -NAMESPACE_END(pybind11) +PYBIND11_NAMESPACE_END(initimpl) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(pybind11) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 166a18a32f..cf40e9fe99 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -11,8 +11,8 @@ #include "../pytypes.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) // Forward declarations inline PyTypeObject *make_static_property_type(); inline PyTypeObject *make_default_metaclass(); @@ -317,7 +317,7 @@ const char *c_str(Args &&...args) { 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 /// 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; } -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/typeid.h b/include/pybind11/detail/typeid.h index 9c8a4fc69a..148889ffef 100644 --- a/include/pybind11/detail/typeid.h +++ b/include/pybind11/detail/typeid.h @@ -18,8 +18,8 @@ #include "common.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) /// Erase all occurrences of a substring inline void erase_all(std::string &string, const std::string &search) { for (size_t pos = 0;;) { @@ -43,7 +43,7 @@ PYBIND11_NOINLINE inline void clean_type_id(std::string &name) { #endif detail::erase_all(name, "pybind11::"); } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /// Return a string representation of a C++ type template static std::string type_id() { @@ -52,4 +52,4 @@ template static std::string type_id() { return name; } -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/eigen.h b/include/pybind11/eigen.h index d963d9650b..22139def60 100644 --- a/include/pybind11/eigen.h +++ b/include/pybind11/eigen.h @@ -41,14 +41,14 @@ // 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) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) // Provide a convenience alias for easier pass-by-ref usage with fully dynamic strides: using EigenDStride = Eigen::Stride; template using EigenDRef = Eigen::Ref; template using EigenDMap = Eigen::Map; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) #if EIGEN_VERSION_AT_LEAST(3,3,0) using EigenIndex = Eigen::Index; @@ -597,8 +597,8 @@ struct type_caster::value>> { + npy_format_descriptor::name + _("]")); }; -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) #if defined(__GNUG__) || defined(__clang__) # pragma GCC diagnostic pop diff --git a/include/pybind11/embed.h b/include/pybind11/embed.h index f814c783e7..3258e15763 100644 --- a/include/pybind11/embed.h +++ b/include/pybind11/embed.h @@ -66,8 +66,8 @@ void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable) -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) /// Python 2.7/3.x compatible version of `PyImport_AppendInittab` and error checks. struct embedded_module { @@ -86,7 +86,7 @@ struct embedded_module { } }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /** \rst Initialize the Python interpreter. No other pybind11 or CPython API functions can be @@ -199,4 +199,4 @@ class scoped_interpreter { bool is_valid = true; }; -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/eval.h b/include/pybind11/eval.h index 422e629f5b..ba82cf42ae 100644 --- a/include/pybind11/eval.h +++ b/include/pybind11/eval.h @@ -13,7 +13,7 @@ #include "pybind11.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) enum eval_mode { /// Evaluate a string containing an isolated expression @@ -129,4 +129,4 @@ object eval_file(str fname, object global = globals(), object local = object()) } #endif -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index f8bda64831..57b6cd210f 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -12,8 +12,8 @@ #include "pybind11.h" #include -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) template struct type_caster> { @@ -97,5 +97,5 @@ struct type_caster> { + make_caster::name + _("]")); }; -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/iostream.h b/include/pybind11/iostream.h index c43b7c93a6..eaf92dfa49 100644 --- a/include/pybind11/iostream.h +++ b/include/pybind11/iostream.h @@ -17,8 +17,8 @@ #include #include -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) // Buffer that writes to Python instead of C++ class pythonbuf : public std::streambuf { @@ -72,7 +72,7 @@ class pythonbuf : public std::streambuf { } }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /** \rst @@ -144,7 +144,7 @@ class scoped_estream_redirect : public scoped_ostream_redirect { }; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) // Class to redirect output as a context manager. C++ backend. class OstreamRedirect { @@ -170,7 +170,7 @@ class OstreamRedirect { } }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /** \rst This is a helper function to add a C++ redirect context manager to Python @@ -206,4 +206,4 @@ inline class_ add_ostream_redirect(module m, std::strin .def("__exit__", [](detail::OstreamRedirect &self_, args) { self_.exit(); }); } -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 49a1e4f5e9..d322c01351 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -35,11 +35,11 @@ upon the library user. */ 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 -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) template <> struct handle_type_name { static constexpr auto name = _("numpy.ndarray"); }; @@ -442,7 +442,7 @@ struct type_caster> { template struct type_caster> : type_caster> {}; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) class dtype : public object { public: @@ -979,7 +979,7 @@ struct format_descriptor::is_array> } }; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) template struct pyobject_caster> { using type = array_t; @@ -1608,7 +1608,7 @@ template struct handle_type_name> { static constexpr auto name = _("numpy.ndarray[") + npy_format_descriptor::name + _("]"); }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) // Vanilla pointer vectorizer: template @@ -1638,7 +1638,7 @@ Helper vectorize(Return (Class::*f)(Args...) const) { return Helper(std::mem_fn(f)); } -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) #if defined(_MSC_VER) #pragma warning(pop) diff --git a/include/pybind11/operators.h b/include/pybind11/operators.h index 293d5abd29..086cb4cfd8 100644 --- a/include/pybind11/operators.h +++ b/include/pybind11/operators.h @@ -18,8 +18,8 @@ # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant #endif -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) /// Enumeration with all supported operator types enum op_id : int { @@ -160,13 +160,13 @@ PYBIND11_UNARY_OPERATOR(float, float_, (double) l) #undef PYBIND11_BINARY_OPERATOR #undef PYBIND11_INPLACE_OPERATOR #undef PYBIND11_UNARY_OPERATOR -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) using detail::self; // Add named operators so that they are accessible via `py::`. using detail::hash; -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) #if defined(_MSC_VER) # pragma warning(pop) diff --git a/include/pybind11/options.h b/include/pybind11/options.h index cc1e1f6f0f..d74db1c68d 100644 --- a/include/pybind11/options.h +++ b/include/pybind11/options.h @@ -11,7 +11,7 @@ #include "detail/common.h" -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) class options { public: @@ -62,4 +62,4 @@ class options { state previous_state; }; -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 45828dba89..ee28705245 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -50,7 +50,7 @@ # include #endif -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object class cpp_function : public function { @@ -909,7 +909,7 @@ inline dict globals() { return reinterpret_borrow(p ? p : module::import("__main__").attr("__dict__").ptr()); } -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) /// Generic support for creating new Python heap types class generic_type : public object { template friend class class_; @@ -1047,7 +1047,7 @@ inline void call_operator_delete(void *p, size_t s, size_t a) { #endif } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /// Given a pointer to a member function, cast it to its `Derived` version. /// Forward everything else unchanged. @@ -1425,7 +1425,7 @@ detail::initimpl::pickle_factory pickle(GetState &&g, SetSta return {std::forward(g), std::forward(s)}; } -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) struct enum_base { enum_base(handle base, handle parent) : m_base(base), m_parent(parent) { } @@ -1576,7 +1576,7 @@ struct enum_base { handle m_parent; }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /// Binds C++ enumerations and enumeration classes to Python template class enum_ : public class_ { @@ -1628,7 +1628,7 @@ template class enum_ : public class_ { detail::enum_base m_base; }; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) inline void keep_alive_impl(handle nurse, handle patient) { @@ -1698,7 +1698,7 @@ struct iterator_state { bool first_or_done; }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /// Makes a python iterator from a first and past-the-end C++ InputIterator. template exception &get_exception_object() { static exception 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 @@ -1863,7 +1863,7 @@ exception ®ister_exception(handle scope, return ex; } -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) { auto strings = tuple(args.size()); 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()) file.attr("flush")(); } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) template void print(Args &&...args) { @@ -2203,7 +2203,7 @@ template function get_overload(const T *this_ptr, const char *name) { #define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \ 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) # pragma warning(pop) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 6cf7fe173f..b2180fd3e5 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -14,14 +14,14 @@ #include #include -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /* A few forward declarations */ class handle; class object; class str; class iterator; struct arg; struct arg_v; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) class args_proxy; inline bool isinstance_generic(handle obj, const std::type_info &tp); @@ -158,7 +158,7 @@ class object_api : public pyobject_tag { bool rich_compare(object_api const &other, int value) const; }; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) /** \rst Holds a reference to a Python object (no reference counting) @@ -311,9 +311,9 @@ template T reinterpret_borrow(handle h) { return {h, object::borrow \endrst */ template T reinterpret_steal(handle h) { return {h, object::stolen_t{}}; } -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) 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 /// 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 -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) inline handle get_function(handle value) { if (value) { #if PY_MAJOR_VERSION >= 3 @@ -520,7 +520,7 @@ class accessor : public object_api> { mutable object cache; }; -NAMESPACE_BEGIN(accessor_policies) +PYBIND11_NAMESPACE_BEGIN(accessor_policies) struct obj_attr { using key_type = object; 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 template @@ -638,7 +638,7 @@ class generic_iterator : public Policy { 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 template struct arrow_proxy { @@ -711,7 +711,7 @@ class dict_readonly { PyObject *key = nullptr, *value = nullptr; ssize_t pos = -1; }; -NAMESPACE_END(iterator_policies) +PYBIND11_NAMESPACE_END(iterator_policies) #if !defined(PYPY_VERSION) using tuple_iterator = generic_iterator; @@ -770,7 +770,7 @@ class simple_collector; template class unpacking_collector; -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) // 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 @@ -1045,7 +1045,7 @@ class bool_ : public object { } }; -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) // 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). // (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; } } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) class int_ : public object { public: @@ -1409,7 +1409,7 @@ inline iterator iter(handle obj) { } /// @} python_builtins -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) template iterator object_api::begin() const { return iter(derived()); } template iterator object_api::end() const { return iterator::sentinel(); } template item_accessor object_api::operator[](handle key) const { @@ -1490,5 +1490,5 @@ PYBIND11_MATH_OPERATOR_BINARY(operator>>=, PyNumber_InPlaceRshift) #undef PYBIND11_MATH_OPERATOR_UNARY #undef PYBIND11_MATH_OPERATOR_BINARY -NAMESPACE_END(detail) -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index b5f7e723f4..6c2bebda87 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -48,8 +48,8 @@ # define PYBIND11_HAS_VARIANT 1 #endif -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) /// 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. @@ -374,14 +374,14 @@ template struct type_caster> : variant_caster> { }; #endif -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) inline std::ostream &operator<<(std::ostream &os, const handle &obj) { os << (std::string) str(obj); return os; } -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) #if defined(_MSC_VER) #pragma warning(pop) diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index da233eca99..61b94b6220 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -15,8 +15,8 @@ #include #include -NAMESPACE_BEGIN(PYBIND11_NAMESPACE) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_BEGIN(detail) /* SFINAE helper class used by 'is_comparable */ template struct container_traits { @@ -413,7 +413,7 @@ vector_buffer(Class_& cl) { template enable_if_t...>::value> vector_buffer(Class_&) {} -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) // // std::vector @@ -511,7 +511,7 @@ class_ bind_vector(handle scope, std::string const &name, A // std::map, std::unordered_map // -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(detail) /* Fallback functions */ template void map_if_insertion_operator(const Args &...) { } @@ -577,7 +577,7 @@ template auto map_if_insertion_operator(Class_ & } -NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(detail) template , typename... Args> class_ bind_map(handle scope, const std::string &name, Args&&... args) { @@ -653,4 +653,4 @@ class_ bind_map(handle scope, const std::string &name, Args&&. return cl; } -NAMESPACE_END(PYBIND11_NAMESPACE) +PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/tests/pybind11_tests.h b/tests/pybind11_tests.h index 90963a5dea..1e47416270 100644 --- a/tests/pybind11_tests.h +++ b/tests/pybind11_tests.h @@ -53,13 +53,13 @@ class IncType : public UserType { /// 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). struct RValueCaster {}; -NAMESPACE_BEGIN(pybind11) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(pybind11) +PYBIND11_NAMESPACE_BEGIN(detail) template<> class type_caster { public: PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster")); 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(); } }; -NAMESPACE_END(detail) -NAMESPACE_END(pybind11) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(pybind11) diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp index 98d5e0a0bd..0f698bdf05 100644 --- a/tests/test_copy_move.cpp +++ b/tests/test_copy_move.cpp @@ -68,8 +68,8 @@ class CopyOnlyInt { int value; }; -NAMESPACE_BEGIN(pybind11) -NAMESPACE_BEGIN(detail) +PYBIND11_NAMESPACE_BEGIN(pybind11) +PYBIND11_NAMESPACE_BEGIN(detail) template <> struct type_caster { PYBIND11_TYPE_CASTER(MoveOnlyInt, _("MoveOnlyInt")); bool load(handle src, bool) { value = MoveOnlyInt(src.cast()); return true; } @@ -97,8 +97,8 @@ template <> struct type_caster { operator CopyOnlyInt&() { return value; } template using cast_op_type = pybind11::detail::cast_op_type; }; -NAMESPACE_END(detail) -NAMESPACE_END(pybind11) +PYBIND11_NAMESPACE_END(detail) +PYBIND11_NAMESPACE_END(pybind11) TEST_SUBMODULE(copy_move_policies, m) { // test_lacking_copy_ctor From 3096e9655bada2b6977b22362288a57b24e85880 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Wed, 8 Jul 2020 15:06:47 +0200 Subject: [PATCH 2/4] Fix sudden HomeBrew 'python not installed' error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0e504582f3..5e7e93481d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -243,7 +243,7 @@ before_install: PY_CMD=python$PYTHON if [ "$TRAVIS_OS_NAME" = "osx" ]; 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 curl -fsSL https://bootstrap.pypa.io/get-pip.py | $PY_CMD - --user fi From 7a8cc07c0fde9944dc51635701985d04bb8fcce6 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Wed, 8 Jul 2020 15:12:33 +0200 Subject: [PATCH 3/4] Sweep difference in 'Class.__init__() must be called when overriding __init__' error message between CPython and PyPy under the rug --- tests/test_class.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_class.py b/tests/test_class.py index 9807535e8e..6fa5b157a7 100644 --- a/tests/test_class.py +++ b/tests/test_class.py @@ -109,7 +109,10 @@ def __init__(self): pass with pytest.raises(TypeError) as exc_info: 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 class RabbitHamster(m.Rabbit, m.Hamster): @@ -118,8 +121,9 @@ def __init__(self): with pytest.raises(TypeError) as exc_info: RabbitHamster() - expected = "m.class_.Hamster.__init__() must be called when overriding __init__" - assert msg(exc_info.value) == expected + expected = ["m.class_.Hamster.__init__() must be called when overriding __init__", + "Hamster.__init__() must be called when overriding __init__"] # PyPy + assert msg(exc_info.value) in expected def test_automatic_upcasting(): From 681ebc4e049277a05ff2d3bba2750a8f63a7059c Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 8 Jul 2020 15:49:15 -0400 Subject: [PATCH 4/4] Homebrew updated to 3.8 yesterday. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5e7e93481d..12067bca8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -147,9 +147,9 @@ matrix: osx_image: xcode7.3 env: PYTHON=2.7 CPP=14 CLANG CMAKE=1 - 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 - env: PYTHON=3.7 CPP=14 CLANG DEBUG=1 + env: PYTHON=3.8 CPP=14 CLANG DEBUG=1 # Test a PyPy 2.7 build - os: linux dist: trusty