Skip to content

Commit f980d76

Browse files
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 <[email protected]>
1 parent 0d70f0e commit f980d76

27 files changed

+150
-150
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ matrix:
147147
osx_image: xcode7.3
148148
env: PYTHON=2.7 CPP=14 CLANG CMAKE=1
149149
- os: osx
150-
name: Python 3.7, c++14, AppleClang 9, Debug build
150+
name: Python 3.8, c++14, AppleClang 9, Debug build
151151
osx_image: xcode9.4
152-
env: PYTHON=3.7 CPP=14 CLANG DEBUG=1
152+
env: PYTHON=3.8 CPP=14 CLANG DEBUG=1
153153
# Test a PyPy 2.7 build
154154
- os: linux
155155
dist: trusty
@@ -243,7 +243,7 @@ before_install:
243243
PY_CMD=python$PYTHON
244244
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
245245
if [ "$PY" = "3" ]; then
246-
brew update && brew unlink python@2 && brew upgrade python
246+
brew update && brew unlink python@2 && (brew upgrade python || brew install python)
247247
else
248248
curl -fsSL https://bootstrap.pypa.io/get-pip.py | $PY_CMD - --user
249249
fi

include/pybind11/attr.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "cast.h"
1414

15-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
15+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1616

1717
/// \addtogroup annotations
1818
/// @{
@@ -113,7 +113,7 @@ struct call_guard<T, Ts...> {
113113

114114
/// @} annotations
115115

116-
NAMESPACE_BEGIN(detail)
116+
PYBIND11_NAMESPACE_BEGIN(detail)
117117
/* Forward declarations */
118118
enum op_id : int;
119119
enum op_type : int;
@@ -524,5 +524,5 @@ constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
524524
return named == 0 || (self + named + has_args + has_kwargs) == nargs;
525525
}
526526

527-
NAMESPACE_END(detail)
528-
NAMESPACE_END(PYBIND11_NAMESPACE)
527+
PYBIND11_NAMESPACE_END(detail)
528+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/buffer_info.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "detail/common.h"
1313

14-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
14+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1515

1616
/// Information record describing a Python buffer object
1717
struct buffer_info {
@@ -94,7 +94,7 @@ struct buffer_info {
9494
bool ownview = false;
9595
};
9696

97-
NAMESPACE_BEGIN(detail)
97+
PYBIND11_NAMESPACE_BEGIN(detail)
9898

9999
template <typename T, typename SFINAE = void> struct compare_buffer_info {
100100
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_
110110
}
111111
};
112112

113-
NAMESPACE_END(detail)
114-
NAMESPACE_END(PYBIND11_NAMESPACE)
113+
PYBIND11_NAMESPACE_END(detail)
114+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/cast.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
# define PYBIND11_HAS_U8STRING
3737
#endif
3838

39-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
40-
NAMESPACE_BEGIN(detail)
39+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
40+
PYBIND11_NAMESPACE_BEGIN(detail)
4141

4242
/// A life support system for temporary objects created by `type_caster::load()`.
4343
/// 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
816816
template <typename T1, typename T2> struct is_copy_assignable<std::pair<T1, T2>>
817817
: all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {};
818818

819-
NAMESPACE_END(detail)
819+
PYBIND11_NAMESPACE_END(detail)
820820

821821
// polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed
822822
// 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
855855
template <typename itype, typename SFINAE = void>
856856
struct polymorphic_type_hook : public polymorphic_type_hook_base<itype> {};
857857

858-
NAMESPACE_BEGIN(detail)
858+
PYBIND11_NAMESPACE_BEGIN(detail)
859859

860860
/// Generic type caster for objects stored on the heap
861861
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) {
17081708
return conv;
17091709
}
17101710

1711-
NAMESPACE_END(detail)
1711+
PYBIND11_NAMESPACE_END(detail)
17121712

17131713
// pytype -> C++ type
17141714
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(*
17791779
template <> inline void object::cast() const & { return; }
17801780
template <> inline void object::cast() && { return; }
17811781

1782-
NAMESPACE_BEGIN(detail)
1782+
PYBIND11_NAMESPACE_BEGIN(detail)
17831783

17841784
// Declared in pytypes.h:
17851785
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
18061806
pybind11_fail("Internal error: cast_safe fallback invoked"); }
18071807
template <> inline void cast_safe<void>(object &&) {}
18081808

1809-
NAMESPACE_END(detail)
1809+
PYBIND11_NAMESPACE_END(detail)
18101810

18111811
template <return_value_policy policy = return_value_policy::automatic_reference>
18121812
tuple make_tuple() { return tuple(0); }
@@ -1914,7 +1914,7 @@ inline namespace literals {
19141914
constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
19151915
}
19161916

1917-
NAMESPACE_BEGIN(detail)
1917+
PYBIND11_NAMESPACE_BEGIN(detail)
19181918

19191919
// forward declaration (definition in attr.h)
19201920
struct function_record;
@@ -2185,7 +2185,7 @@ object object_api<Derived>::call(Args &&...args) const {
21852185
return operator()<policy>(std::forward<Args>(args)...);
21862186
}
21872187

2188-
NAMESPACE_END(detail)
2188+
PYBIND11_NAMESPACE_END(detail)
21892189

21902190
#define PYBIND11_MAKE_OPAQUE(...) \
21912191
namespace pybind11 { namespace detail { \
@@ -2196,4 +2196,4 @@ NAMESPACE_END(detail)
21962196
/// typedef, e.g.: `PYBIND11_OVERLOAD(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)`
21972197
#define PYBIND11_TYPE(...) __VA_ARGS__
21982198

2199-
NAMESPACE_END(PYBIND11_NAMESPACE)
2199+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/chrono.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds)
2828
#endif
2929

30-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
31-
NAMESPACE_BEGIN(detail)
30+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
31+
PYBIND11_NAMESPACE_BEGIN(detail)
3232

3333
template <typename type> class duration_caster {
3434
public:
@@ -180,5 +180,5 @@ template <typename Rep, typename Period> class type_caster<std::chrono::duration
180180
: public duration_caster<std::chrono::duration<Rep, Period>> {
181181
};
182182

183-
NAMESPACE_END(detail)
184-
NAMESPACE_END(PYBIND11_NAMESPACE)
183+
PYBIND11_NAMESPACE_END(detail)
184+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/complex.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# undef I
1818
#endif
1919

20-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
20+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
2121

2222
template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
2323
static constexpr const char c = format_descriptor<T>::c;
@@ -32,7 +32,7 @@ template <typename T> constexpr const char format_descriptor<
3232

3333
#endif
3434

35-
NAMESPACE_BEGIN(detail)
35+
PYBIND11_NAMESPACE_BEGIN(detail)
3636

3737
template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
3838
static constexpr bool value = true;
@@ -61,5 +61,5 @@ template <typename T> class type_caster<std::complex<T>> {
6161

6262
PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
6363
};
64-
NAMESPACE_END(detail)
65-
NAMESPACE_END(PYBIND11_NAMESPACE)
64+
PYBIND11_NAMESPACE_END(detail)
65+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/detail/class.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "../attr.h"
1313
#include "../options.h"
1414

15-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
16-
NAMESPACE_BEGIN(detail)
15+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
16+
PYBIND11_NAMESPACE_BEGIN(detail)
1717

1818
#if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION)
1919
# define PYBIND11_BUILTIN_QUALNAME
@@ -664,5 +664,5 @@ inline PyObject* make_new_python_type(const type_record &rec) {
664664
return (PyObject *) type;
665665
}
666666

667-
NAMESPACE_END(detail)
668-
NAMESPACE_END(PYBIND11_NAMESPACE)
667+
PYBIND11_NAMESPACE_END(detail)
668+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/detail/common.h

+14-18
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99

1010
#pragma once
1111

12-
#if !defined(NAMESPACE_BEGIN)
13-
# define NAMESPACE_BEGIN(name) namespace name {
14-
#endif
15-
#if !defined(NAMESPACE_END)
16-
# define NAMESPACE_END(name) }
17-
#endif
12+
#define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
13+
#define PYBIND11_NAMESPACE_END(name) }
1814

1915
// Robust support for some features and loading modules compiled against different pybind versions
2016
// requires forcing hidden visibility on pybind code, so we enforce this by setting the attribute on
@@ -325,7 +321,7 @@ extern "C" {
325321
void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
326322

327323

328-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
324+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
329325

330326
using ssize_t = Py_ssize_t;
331327
using size_t = std::size_t;
@@ -382,7 +378,7 @@ enum class return_value_policy : uint8_t {
382378
reference_internal
383379
};
384380

385-
NAMESPACE_BEGIN(detail)
381+
PYBIND11_NAMESPACE_BEGIN(detail)
386382

387383
inline static constexpr int log2(size_t n, int k = 0) { return (n <= 1) ? k : log2(n >> 1, k + 1); }
388384

@@ -560,7 +556,7 @@ template <typename T, typename... Ts>
560556
constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); }
561557
#endif
562558

563-
NAMESPACE_BEGIN(constexpr_impl)
559+
PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
564560
/// Implementation details for constexpr functions
565561
constexpr int first(int i) { return i; }
566562
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...);
569565
constexpr int last(int /*i*/, int result) { return result; }
570566
template <typename T, typename... Ts>
571567
constexpr int last(int i, int result, T v, Ts... vs) { return last(i + 1, v ? i : result, vs...); }
572-
NAMESPACE_END(constexpr_impl)
568+
PYBIND11_NAMESPACE_END(constexpr_impl)
573569

574570
/// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if
575571
/// none match.
@@ -683,7 +679,7 @@ using expand_side_effects = bool[];
683679
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
684680
#endif
685681

686-
NAMESPACE_END(detail)
682+
PYBIND11_NAMESPACE_END(detail)
687683

688684
/// C++ bindings of builtin Python exceptions
689685
class builtin_exception : public std::runtime_error {
@@ -715,7 +711,7 @@ PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used in
715711

716712
template <typename T, typename SFINAE = void> struct format_descriptor { };
717713

718-
NAMESPACE_BEGIN(detail)
714+
PYBIND11_NAMESPACE_BEGIN(detail)
719715
// Returns the index of the given type in the type char array below, and in the list in numpy.h
720716
// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
721717
// 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>
728724
std::is_integral<T>::value ? detail::log2(sizeof(T))*2 + std::is_unsigned<T>::value : 8 + (
729725
std::is_same<T, double>::value ? 1 : std::is_same<T, long double>::value ? 2 : 0));
730726
};
731-
NAMESPACE_END(detail)
727+
PYBIND11_NAMESPACE_END(detail)
732728

733729
template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_arithmetic<T>::value>> {
734730
static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
@@ -753,7 +749,7 @@ struct error_scope {
753749
/// Dummy destructor wrapper that can be used to expose classes with a private destructor
754750
struct nodelete { template <typename T> void operator()(T*) { } };
755751

756-
NAMESPACE_BEGIN(detail)
752+
PYBIND11_NAMESPACE_BEGIN(detail)
757753
template <typename... Args>
758754
struct overload_cast_impl {
759755
constexpr overload_cast_impl() {} // MSVC 2015 needs this
@@ -770,7 +766,7 @@ struct overload_cast_impl {
770766
constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept
771767
-> decltype(pmf) { return pmf; }
772768
};
773-
NAMESPACE_END(detail)
769+
PYBIND11_NAMESPACE_END(detail)
774770

775771
// overload_cast requires variable templates: C++14
776772
#if defined(PYBIND11_CPP14)
@@ -795,7 +791,7 @@ template <typename... Args> struct overload_cast {
795791
};
796792
#endif // overload_cast
797793

798-
NAMESPACE_BEGIN(detail)
794+
PYBIND11_NAMESPACE_BEGIN(detail)
799795

800796
// Adaptor for converting arbitrary container arguments into a vector; implicitly convertible from
801797
// any standard container (or C-style array) supporting std::begin/std::end, any singleton
@@ -834,8 +830,8 @@ class any_container {
834830
const std::vector<T> *operator->() const { return &v; }
835831
};
836832

837-
NAMESPACE_END(detail)
833+
PYBIND11_NAMESPACE_END(detail)
838834

839835

840836

841-
NAMESPACE_END(PYBIND11_NAMESPACE)
837+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/detail/descr.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include "common.h"
1313

14-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
15-
NAMESPACE_BEGIN(detail)
14+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
15+
PYBIND11_NAMESPACE_BEGIN(detail)
1616

1717
#if !defined(_MSC_VER)
1818
# define PYBIND11_DESCR_CONSTEXPR static constexpr
@@ -96,5 +96,5 @@ constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
9696
return _("{") + descr + _("}");
9797
}
9898

99-
NAMESPACE_END(detail)
100-
NAMESPACE_END(PYBIND11_NAMESPACE)
99+
PYBIND11_NAMESPACE_END(detail)
100+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

include/pybind11/detail/init.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
#include "class.h"
1313

14-
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
15-
NAMESPACE_BEGIN(detail)
14+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
15+
PYBIND11_NAMESPACE_BEGIN(detail)
1616

1717
template <>
1818
class type_caster<value_and_holder> {
@@ -30,7 +30,7 @@ class type_caster<value_and_holder> {
3030
value_and_holder *value = nullptr;
3131
};
3232

33-
NAMESPACE_BEGIN(initimpl)
33+
PYBIND11_NAMESPACE_BEGIN(initimpl)
3434

3535
inline void no_nullptr(void *ptr) {
3636
if (!ptr) throw type_error("pybind11::init(): factory function returned nullptr");
@@ -330,6 +330,6 @@ struct pickle_factory<Get, Set, RetState(Self), NewInstance(ArgState)> {
330330
}
331331
};
332332

333-
NAMESPACE_END(initimpl)
334-
NAMESPACE_END(detail)
335-
NAMESPACE_END(pybind11)
333+
PYBIND11_NAMESPACE_END(initimpl)
334+
PYBIND11_NAMESPACE_END(detail)
335+
PYBIND11_NAMESPACE_END(pybind11)

0 commit comments

Comments
 (0)