Skip to content

Commit

Permalink
Change NAMESPACE_* macros into PYBIND11_NAMESPACE_* (pybind#2283)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
YannickJadoul and henryiii authored Jul 8, 2020
1 parent 0d70f0e commit f980d76
Show file tree
Hide file tree
Showing 27 changed files with 150 additions and 150 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions include/pybind11/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "cast.h"

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

/// \addtogroup annotations
/// @{
Expand Down Expand Up @@ -113,7 +113,7 @@ struct call_guard<T, Ts...> {

/// @} annotations

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
/* Forward declarations */
enum op_id : int;
enum op_type : int;
Expand Down Expand Up @@ -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)
8 changes: 4 additions & 4 deletions include/pybind11/buffer_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -94,7 +94,7 @@ struct buffer_info {
bool ownview = false;
};

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)

template <typename T, typename SFINAE = void> struct compare_buffer_info {
static bool compare(const buffer_info& b) {
Expand All @@ -110,5 +110,5 @@ template <typename T> struct compare_buffer_info<T, detail::enable_if_t<std::is_
}
};

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
20 changes: 10 additions & 10 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
# define PYBIND11_HAS_U8STRING
#endif

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)

/// 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.
Expand Down Expand Up @@ -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>>
: 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
// to by `src` actually is an instance of some class derived from `itype`.
Expand Down Expand Up @@ -855,7 +855,7 @@ struct polymorphic_type_hook_base<itype, detail::enable_if_t<std::is_polymorphic
template <typename itype, typename SFINAE = void>
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
template <typename type> class type_caster_base : public type_caster_generic {
Expand Down Expand Up @@ -1708,7 +1708,7 @@ template <typename T> make_caster<T> load_type(const handle &handle) {
return conv;
}

NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)

// pytype -> C++ type
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
Expand Down Expand Up @@ -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() && { return; }

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)

// Declared in pytypes.h:
template <typename T, enable_if_t<!is_pyobject<T>::value, int>>
Expand All @@ -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"); }
template <> inline void cast_safe<void>(object &&) {}

NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)

template <return_value_policy policy = return_value_policy::automatic_reference>
tuple make_tuple() { return tuple(0); }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2185,7 +2185,7 @@ object object_api<Derived>::call(Args &&...args) const {
return operator()<policy>(std::forward<Args>(args)...);
}

NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)

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

NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
8 changes: 4 additions & 4 deletions include/pybind11/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename type> class duration_caster {
public:
Expand Down Expand Up @@ -180,5 +180,5 @@ template <typename Rep, typename Period> class type_caster<std::chrono::duration
: public duration_caster<std::chrono::duration<Rep, Period>> {
};

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
8 changes: 4 additions & 4 deletions include/pybind11/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# undef I
#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>> {
static constexpr const char c = format_descriptor<T>::c;
Expand All @@ -32,7 +32,7 @@ template <typename T> constexpr const char format_descriptor<

#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>> {
static constexpr bool value = true;
Expand Down Expand Up @@ -61,5 +61,5 @@ template <typename T> class type_caster<std::complex<T>> {

PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
};
NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
8 changes: 4 additions & 4 deletions include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
32 changes: 14 additions & 18 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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); }

Expand Down Expand Up @@ -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...); }
#endif

NAMESPACE_BEGIN(constexpr_impl)
PYBIND11_NAMESPACE_BEGIN(constexpr_impl)
/// Implementation details for constexpr functions
constexpr int first(int i) { return i; }
template <typename T, typename... Ts>
Expand All @@ -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 <typename T, typename... Ts>
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
/// none match.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -715,7 +711,7 @@ PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used in

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
// 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
Expand All @@ -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_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>> {
static constexpr const char c = "?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
Expand All @@ -753,7 +749,7 @@ struct error_scope {
/// Dummy destructor wrapper that can be used to expose classes with a private destructor
struct nodelete { template <typename T> void operator()(T*) { } };

NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
template <typename... Args>
struct overload_cast_impl {
constexpr overload_cast_impl() {} // MSVC 2015 needs this
Expand All @@ -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)
Expand All @@ -795,7 +791,7 @@ template <typename... Args> 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
Expand Down Expand Up @@ -834,8 +830,8 @@ class any_container {
const std::vector<T> *operator->() const { return &v; }
};

NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)



NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
8 changes: 4 additions & 4 deletions include/pybind11/detail/descr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,5 +96,5 @@ constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
return _("{") + descr + _("}");
}

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
12 changes: 6 additions & 6 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<value_and_holder> {
Expand All @@ -30,7 +30,7 @@ class type_caster<value_and_holder> {
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");
Expand Down Expand Up @@ -330,6 +330,6 @@ struct pickle_factory<Get, Set, RetState(Self), NewInstance(ArgState)> {
}
};

NAMESPACE_END(initimpl)
NAMESPACE_END(detail)
NAMESPACE_END(pybind11)
PYBIND11_NAMESPACE_END(initimpl)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(pybind11)
Loading

0 comments on commit f980d76

Please sign in to comment.