Update Pybind11 to prevent conflict with wxTranslate

We change the pybind templates '_' to be '_x' to avoid conflicting with
the wxTranslate macro `_`
This commit is contained in:
Seth Hillbrand 2021-08-30 16:55:49 -07:00
parent 84c7cc6c21
commit 317fae2098
16 changed files with 75 additions and 75 deletions

View File

@ -225,7 +225,7 @@ public:
return PyLong_FromUnsignedLongLong((unsigned long long) src);
}
PYBIND11_TYPE_CASTER(T, _<std::is_integral<T>::value>("int", "float"));
PYBIND11_TYPE_CASTER(T, _x<std::is_integral<T>::value>("int", "float"));
};
template<typename T> struct void_caster {
@ -238,7 +238,7 @@ public:
static handle cast(T, return_value_policy /* policy */, handle /* parent */) {
return none().inc_ref();
}
PYBIND11_TYPE_CASTER(T, _("None"));
PYBIND11_TYPE_CASTER(T, _x("None"));
};
template <> class type_caster<void_type> : public void_caster<void_type> {};
@ -281,7 +281,7 @@ public:
template <typename T> using cast_op_type = void*&;
operator void *&() { return value; }
static constexpr auto name = _("capsule");
static constexpr auto name = _x("capsule");
private:
void *value = nullptr;
};
@ -332,7 +332,7 @@ public:
static handle cast(bool src, return_value_policy /* policy */, handle /* parent */) {
return handle(src ? Py_True : Py_False).inc_ref();
}
PYBIND11_TYPE_CASTER(bool, _("bool"));
PYBIND11_TYPE_CASTER(bool, _x("bool"));
};
// Helper class for UTF-{8,16,32} C++ stl strings:
@ -402,7 +402,7 @@ template <typename StringType, bool IsView = false> struct string_caster {
return s;
}
PYBIND11_TYPE_CASTER(StringType, _(PYBIND11_STRING_NAME));
PYBIND11_TYPE_CASTER(StringType, _x(PYBIND11_STRING_NAME));
private:
static handle decode_utfN(const char *buffer, ssize_t nbytes) {
@ -537,7 +537,7 @@ public:
return one_char;
}
static constexpr auto name = _(PYBIND11_STRING_NAME);
static constexpr auto name = _x(PYBIND11_STRING_NAME);
template <typename _T> using cast_op_type = pybind11::detail::cast_op_type<_T>;
};
@ -574,7 +574,7 @@ public:
return cast(*src, policy, parent);
}
static constexpr auto name = _("Tuple[") + concat(make_caster<Ts>::name...) + _("]");
static constexpr auto name = _x("Tuple[") + concat(make_caster<Ts>::name...) + _x("]");
template <typename T> using cast_op_type = type;
@ -757,14 +757,14 @@ template <typename base, typename holder> struct is_holder_type :
template <typename base, typename deleter> struct is_holder_type<base, std::unique_ptr<base, deleter>> :
std::true_type {};
template <typename T> struct handle_type_name { static constexpr auto name = _<T>(); };
template <> struct handle_type_name<bytes> { static constexpr auto name = _(PYBIND11_BYTES_NAME); };
template <> struct handle_type_name<int_> { static constexpr auto name = _("int"); };
template <> struct handle_type_name<iterable> { static constexpr auto name = _("Iterable"); };
template <> struct handle_type_name<iterator> { static constexpr auto name = _("Iterator"); };
template <> struct handle_type_name<none> { static constexpr auto name = _("None"); };
template <> struct handle_type_name<args> { static constexpr auto name = _("*args"); };
template <> struct handle_type_name<kwargs> { static constexpr auto name = _("**kwargs"); };
template <typename T> struct handle_type_name { static constexpr auto name = _x<T>(); };
template <> struct handle_type_name<bytes> { static constexpr auto name = _x(PYBIND11_BYTES_NAME); };
template <> struct handle_type_name<int_> { static constexpr auto name = _x("int"); };
template <> struct handle_type_name<iterable> { static constexpr auto name = _x("Iterable"); };
template <> struct handle_type_name<iterator> { static constexpr auto name = _x("Iterator"); };
template <> struct handle_type_name<none> { static constexpr auto name = _x("None"); };
template <> struct handle_type_name<args> { static constexpr auto name = _x("*args"); };
template <> struct handle_type_name<kwargs> { static constexpr auto name = _x("**kwargs"); };
template <typename type>
struct pyobject_caster {

View File

@ -97,7 +97,7 @@ public:
return PyDelta_FromDSU(dd.count(), ss.count(), us.count());
}
PYBIND11_TYPE_CASTER(type, _("datetime.timedelta"));
PYBIND11_TYPE_CASTER(type, _x("datetime.timedelta"));
};
inline std::tm *localtime_thread_safe(const std::time_t *time, std::tm *buf) {
@ -195,7 +195,7 @@ public:
localtime.tm_sec,
us.count());
}
PYBIND11_TYPE_CASTER(type, _("datetime.datetime"));
PYBIND11_TYPE_CASTER(type, _x("datetime.datetime"));
};
// Other clocks that are not the system clock are not measured as datetime.datetime objects

View File

@ -59,7 +59,7 @@ public:
return PyComplex_FromDoubles((double) src.real(), (double) src.imag());
}
PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
PYBIND11_TYPE_CASTER(std::complex<T>, _x("complex"));
};
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -51,8 +51,8 @@ constexpr descr<N1 + N2, Ts1..., Ts2...> operator+(const descr<N1, Ts1...> &a, c
}
template <size_t N>
constexpr descr<N - 1> _(char const(&text)[N]) { return descr<N - 1>(text); }
constexpr descr<0> _(char const(&)[1]) { return {}; }
constexpr descr<N - 1> _x(char const(&text)[N]) { return descr<N - 1>(text); }
constexpr descr<0> _x(char const(&)[1]) { return {}; }
template <size_t Rem, size_t... Digits> struct int_to_str : int_to_str<Rem/10, Rem%10, Digits...> { };
template <size_t...Digits> struct int_to_str<0, Digits...> {
@ -61,24 +61,24 @@ template <size_t...Digits> struct int_to_str<0, Digits...> {
// Ternary description (like std::conditional)
template <bool B, size_t N1, size_t N2>
constexpr enable_if_t<B, descr<N1 - 1>> _(char const(&text1)[N1], char const(&)[N2]) {
return _(text1);
constexpr enable_if_t<B, descr<N1 - 1>> _x(char const(&text1)[N1], char const(&)[N2]) {
return _x(text1);
}
template <bool B, size_t N1, size_t N2>
constexpr enable_if_t<!B, descr<N2 - 1>> _(char const(&)[N1], char const(&text2)[N2]) {
return _(text2);
constexpr enable_if_t<!B, descr<N2 - 1>> _x(char const(&)[N1], char const(&text2)[N2]) {
return _x(text2);
}
template <bool B, typename T1, typename T2>
constexpr enable_if_t<B, T1> _(const T1 &d, const T2 &) { return d; }
constexpr enable_if_t<B, T1> _x(const T1 &d, const T2 &) { return d; }
template <bool B, typename T1, typename T2>
constexpr enable_if_t<!B, T2> _(const T1 &, const T2 &d) { return d; }
constexpr enable_if_t<!B, T2> _x(const T1 &, const T2 &d) { return d; }
template <size_t Size> auto constexpr _() -> decltype(int_to_str<Size / 10, Size % 10>::digits) {
template <size_t Size> auto constexpr _x() -> decltype(int_to_str<Size / 10, Size % 10>::digits) {
return int_to_str<Size / 10, Size % 10>::digits;
}
template <typename Type> constexpr descr<1, Type> _() { return {'%'}; }
template <typename Type> constexpr descr<1, Type> _x() { return {'%'}; }
constexpr descr<0> concat() { return {}; }
@ -88,12 +88,12 @@ constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) { return descr; }
template <size_t N, typename... Ts, typename... Args>
constexpr auto concat(const descr<N, Ts...> &d, const Args &...args)
-> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) {
return d + _(", ") + concat(args...);
return d + _x(", ") + concat(args...);
}
template <size_t N, typename... Ts>
constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
return _("{") + descr + _("}");
return _x("{") + descr + _x("}");
}
PYBIND11_NAMESPACE_END(detail)

View File

@ -24,7 +24,7 @@ public:
template <typename> using cast_op_type = value_and_holder &;
operator value_and_holder &() { return *value; }
static constexpr auto name = _<value_and_holder>();
static constexpr auto name = _x<value_and_holder>();
private:
value_and_holder *value = nullptr;

View File

@ -865,7 +865,7 @@ template <typename type> class type_caster_base : public type_caster_generic {
using itype = intrinsic_t<type>;
public:
static constexpr auto name = _<type>();
static constexpr auto name = _x<type>();
type_caster_base() : type_caster_base(typeid(type)) { }
explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) { }

View File

@ -189,20 +189,20 @@ template <typename Type_> struct EigenProps {
static constexpr bool show_f_contiguous = !show_c_contiguous && show_order && requires_col_major;
static constexpr auto descriptor =
_("numpy.ndarray[") + npy_format_descriptor<Scalar>::name +
_("[") + _<fixed_rows>(_<(size_t) rows>(), _("m")) +
_(", ") + _<fixed_cols>(_<(size_t) cols>(), _("n")) +
_("]") +
_x("numpy.ndarray[") + npy_format_descriptor<Scalar>::name +
_x("[") + _x<fixed_rows>(_x<(size_t) rows>(), _x("m")) +
_x(", ") + _x<fixed_cols>(_x<(size_t) cols>(), _x("n")) +
_x("]") +
// For a reference type (e.g. Ref<MatrixXd>) we have other constraints that might need to be
// satisfied: writeable=True (for a mutable reference), and, depending on the map's stride
// options, possibly f_contiguous or c_contiguous. We include them in the descriptor output
// to provide some hint as to why a TypeError is occurring (otherwise it can be confusing to
// see that a function accepts a 'numpy.ndarray[float64[3,2]]' and an error message that you
// *gave* a numpy.ndarray of the right type and dimensions.
_<show_writeable>(", flags.writeable", "") +
_<show_c_contiguous>(", flags.c_contiguous", "") +
_<show_f_contiguous>(", flags.f_contiguous", "") +
_("]");
_x<show_writeable>(", flags.writeable", "") +
_x<show_c_contiguous>(", flags.c_contiguous", "") +
_x<show_f_contiguous>(", flags.f_contiguous", "") +
_x("]");
};
// Casts an Eigen type to numpy array. If given a base, the numpy array references the src data,
@ -590,8 +590,8 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
).release();
}
PYBIND11_TYPE_CASTER(Type, _<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", "scipy.sparse.csc_matrix[")
+ npy_format_descriptor<Scalar>::name + _("]"));
PYBIND11_TYPE_CASTER(Type, _x<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", "scipy.sparse.csc_matrix[")
+ npy_format_descriptor<Scalar>::name + _x("]"));
};
PYBIND11_NAMESPACE_END(detail)

View File

@ -109,8 +109,8 @@ public:
return cpp_function(std::forward<Func>(f_), policy).release();
}
PYBIND11_TYPE_CASTER(type, _("Callable[[") + concat(make_caster<Args>::name...) + _("], ")
+ make_caster<retval_type>::name + _("]"));
PYBIND11_TYPE_CASTER(type, _x("Callable[[") + concat(make_caster<Args>::name...) + _x("], ")
+ make_caster<retval_type>::name + _x("]"));
};
PYBIND11_NAMESPACE_END(detail)

View File

@ -44,7 +44,7 @@ class array; // Forward declaration
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 = _x("numpy.ndarray"); };
template <typename type, typename SFINAE = void> struct npy_format_descriptor;
@ -287,7 +287,7 @@ template <typename T> struct array_info_scalar {
using type = T;
static constexpr bool is_array = false;
static constexpr bool is_empty = false;
static constexpr auto extents = _("");
static constexpr auto extents = _x("");
static void append_extents(list& /* shape */) { }
};
// Computes underlying type and a comma-separated list of extents for array
@ -306,8 +306,8 @@ template <typename T, size_t N> struct array_info<std::array<T, N>> {
array_info<T>::append_extents(shape);
}
static constexpr auto extents = _<array_info<T>::is_array>(
concat(_<N>(), array_info<T>::extents), _<N>()
static constexpr auto extents = _x<array_info<T>::is_array>(
concat(_x<N>(), array_info<T>::extents), _x<N>()
);
};
// For numpy we have special handling for arrays of characters, so we don't include
@ -990,7 +990,7 @@ template <typename T>
struct format_descriptor<T, detail::enable_if_t<detail::array_info<T>::is_array>> {
static std::string format() {
using namespace detail;
static constexpr auto extents = _("(") + array_info<T>::extents + _(")");
static constexpr auto extents = _x("(") + array_info<T>::extents + _x(")");
return extents.text + format_descriptor<remove_all_extents_t<T>>::format();
}
};
@ -1025,28 +1025,28 @@ struct npy_format_descriptor_name;
template <typename T>
struct npy_format_descriptor_name<T, enable_if_t<std::is_integral<T>::value>> {
static constexpr auto name = _<std::is_same<T, bool>::value>(
_("bool"), _<std::is_signed<T>::value>("numpy.int", "numpy.uint") + _<sizeof(T)*8>()
static constexpr auto name = _x<std::is_same<T, bool>::value>(
_x("bool"), _x<std::is_signed<T>::value>("numpy.int", "numpy.uint") + _x<sizeof(T)*8>()
);
};
template <typename T>
struct npy_format_descriptor_name<T, enable_if_t<std::is_floating_point<T>::value>> {
static constexpr auto name = _<std::is_same<T, float>::value
static constexpr auto name = _x<std::is_same<T, float>::value
|| std::is_same<T, const float>::value
|| std::is_same<T, double>::value
|| std::is_same<T, const double>::value>(
_("numpy.float") + _<sizeof(T)*8>(), _("numpy.longdouble")
_x("numpy.float") + _x<sizeof(T)*8>(), _x("numpy.longdouble")
);
};
template <typename T>
struct npy_format_descriptor_name<T, enable_if_t<is_complex<T>::value>> {
static constexpr auto name = _<std::is_same<typename T::value_type, float>::value
static constexpr auto name = _x<std::is_same<typename T::value_type, float>::value
|| std::is_same<typename T::value_type, const float>::value
|| std::is_same<typename T::value_type, double>::value
|| std::is_same<typename T::value_type, const double>::value>(
_("numpy.complex") + _<sizeof(typename T::value_type)*16>(), _("numpy.longcomplex")
_x("numpy.complex") + _x<sizeof(typename T::value_type)*16>(), _x("numpy.longcomplex")
);
};
@ -1074,7 +1074,7 @@ public:
};
#define PYBIND11_DECL_CHAR_FMT \
static constexpr auto name = _("S") + _<N>(); \
static constexpr auto name = _x("S") + _x<N>(); \
static pybind11::dtype dtype() { return pybind11::dtype(std::string("S") + std::to_string(N)); }
template <size_t N> struct npy_format_descriptor<char[N]> { PYBIND11_DECL_CHAR_FMT };
template <size_t N> struct npy_format_descriptor<std::array<char, N>> { PYBIND11_DECL_CHAR_FMT };
@ -1086,7 +1086,7 @@ private:
public:
static_assert(!array_info<T>::is_empty, "Zero-sized arrays are not supported");
static constexpr auto name = _("(") + array_info<T>::extents + _(")") + base_descr::name;
static constexpr auto name = _x("(") + array_info<T>::extents + _x(")") + base_descr::name;
static pybind11::dtype dtype() {
list shape;
array_info<T>::append_extents(shape);
@ -1668,7 +1668,7 @@ vectorize_extractor(const Func &f, Return (*) (Args ...)) {
}
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 = _x("numpy.ndarray[") + npy_format_descriptor<T>::name + _x("]");
};
PYBIND11_NAMESPACE_END(detail)

View File

@ -232,7 +232,7 @@ protected:
}
/* Generate a readable signature describing the function's arguments and return value types */
static constexpr auto signature = _("(") + cast_in::arg_names + _(") -> ") + cast_out::name;
static constexpr auto signature = _x("(") + cast_in::arg_names + _x(") -> ") + cast_out::name;
PYBIND11_DESCR_CONSTEXPR auto types = decltype(signature)::types();
/* Register the function with Python from generic (non-templated) code */

View File

@ -95,7 +95,7 @@ template <typename Type, typename Key> struct set_caster {
return s.release();
}
PYBIND11_TYPE_CASTER(type, _("Set[") + key_conv::name + _("]"));
PYBIND11_TYPE_CASTER(type, _x("Set[") + key_conv::name + _x("]"));
};
template <typename Type, typename Key, typename Value> struct map_caster {
@ -137,7 +137,7 @@ template <typename Type, typename Key, typename Value> struct map_caster {
return d.release();
}
PYBIND11_TYPE_CASTER(Type, _("Dict[") + key_conv::name + _(", ") + value_conv::name + _("]"));
PYBIND11_TYPE_CASTER(Type, _x("Dict[") + key_conv::name + _x(", ") + value_conv::name + _x("]"));
};
template <typename Type, typename Value> struct list_caster {
@ -183,7 +183,7 @@ public:
return l.release();
}
PYBIND11_TYPE_CASTER(Type, _("List[") + value_conv::name + _("]"));
PYBIND11_TYPE_CASTER(Type, _x("List[") + value_conv::name + _x("]"));
};
template <typename Type, typename Alloc> struct type_caster<std::vector<Type, Alloc>>
@ -240,7 +240,7 @@ public:
return l.release();
}
PYBIND11_TYPE_CASTER(ArrayType, _("List[") + value_conv::name + _<Resizable>(_(""), _("[") + _<Size>() + _("]")) + _("]"));
PYBIND11_TYPE_CASTER(ArrayType, _x("List[") + value_conv::name + _x<Resizable>(_x(""), _x("[") + _x<Size>() + _x("]")) + _x("]"));
};
template <typename Type, size_t Size> struct type_caster<std::array<Type, Size>>
@ -290,7 +290,7 @@ template<typename T> struct optional_caster {
return true;
}
PYBIND11_TYPE_CASTER(T, _("Optional[") + value_conv::name + _("]"));
PYBIND11_TYPE_CASTER(T, _x("Optional[") + value_conv::name + _x("]"));
};
#if defined(PYBIND11_HAS_OPTIONAL)
@ -370,7 +370,7 @@ struct variant_caster<V<Ts...>> {
}
using Type = V<Ts...>;
PYBIND11_TYPE_CASTER(Type, _("Union[") + detail::concat(make_caster<Ts>::name...) + _("]"));
PYBIND11_TYPE_CASTER(Type, _x("Union[") + detail::concat(make_caster<Ts>::name...) + _x("]"));
};
#if defined(PYBIND11_HAS_VARIANT)

View File

@ -92,7 +92,7 @@ public:
return true;
}
PYBIND11_TYPE_CASTER(T, _("os.PathLike"));
PYBIND11_TYPE_CASTER(T, _x("os.PathLike"));
};
template<> struct type_caster<std::filesystem::path>

View File

@ -69,7 +69,7 @@ PYBIND11_NAMESPACE_BEGIN(pybind11)
PYBIND11_NAMESPACE_BEGIN(detail)
template<> class type_caster<RValueCaster> {
public:
PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster"));
PYBIND11_TYPE_CASTER(RValueCaster, _x("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(); }
};

View File

@ -24,7 +24,7 @@ PYBIND11_NAMESPACE_BEGIN(detail)
template <>
class type_caster<ConstRefCasted> {
public:
static constexpr auto name = _<ConstRefCasted>();
static constexpr auto name = _x<ConstRefCasted>();
// Input is unimportant, a new value will always be constructed based on the
// cast operator.

View File

@ -85,13 +85,13 @@ public:
PYBIND11_NAMESPACE_BEGIN(pybind11)
PYBIND11_NAMESPACE_BEGIN(detail)
template <> struct type_caster<MoveOnlyInt> {
PYBIND11_TYPE_CASTER(MoveOnlyInt, _("MoveOnlyInt"));
PYBIND11_TYPE_CASTER(MoveOnlyInt, _x("MoveOnlyInt"));
bool load(handle src, bool) { value = MoveOnlyInt(src.cast<int>()); return true; }
static handle cast(const MoveOnlyInt &m, return_value_policy r, handle p) { return pybind11::cast(m.value, r, p); }
};
template <> struct type_caster<MoveOrCopyInt> {
PYBIND11_TYPE_CASTER(MoveOrCopyInt, _("MoveOrCopyInt"));
PYBIND11_TYPE_CASTER(MoveOrCopyInt, _x("MoveOrCopyInt"));
bool load(handle src, bool) { value = MoveOrCopyInt(src.cast<int>()); return true; }
static handle cast(const MoveOrCopyInt &m, return_value_policy r, handle p) { return pybind11::cast(m.value, r, p); }
};
@ -100,7 +100,7 @@ template <> struct type_caster<CopyOnlyInt> {
protected:
CopyOnlyInt value;
public:
static constexpr auto name = _("CopyOnlyInt");
static constexpr auto name = _x("CopyOnlyInt");
bool load(handle src, bool) { value = CopyOnlyInt(src.cast<int>()); return true; }
static handle cast(const CopyOnlyInt &m, return_value_policy r, handle p) { return pybind11::cast(m.value, r, p); }
static handle cast(const CopyOnlyInt *src, return_value_policy policy, handle parent) {

View File

@ -18,7 +18,7 @@ class ArgAlwaysConverts { };
namespace pybind11 { namespace detail {
template <> struct type_caster<ArgInspector1> {
public:
PYBIND11_TYPE_CASTER(ArgInspector1, _("ArgInspector1"));
PYBIND11_TYPE_CASTER(ArgInspector1, _x("ArgInspector1"));
bool load(handle src, bool convert) {
value.arg = "loading ArgInspector1 argument " +
@ -33,7 +33,7 @@ public:
};
template <> struct type_caster<ArgInspector2> {
public:
PYBIND11_TYPE_CASTER(ArgInspector2, _("ArgInspector2"));
PYBIND11_TYPE_CASTER(ArgInspector2, _x("ArgInspector2"));
bool load(handle src, bool convert) {
value.arg = "loading ArgInspector2 argument " +
@ -48,7 +48,7 @@ public:
};
template <> struct type_caster<ArgAlwaysConverts> {
public:
PYBIND11_TYPE_CASTER(ArgAlwaysConverts, _("ArgAlwaysConverts"));
PYBIND11_TYPE_CASTER(ArgAlwaysConverts, _x("ArgAlwaysConverts"));
bool load(handle, bool convert) {
return convert;
@ -76,7 +76,7 @@ public:
};
namespace pybind11 { namespace detail {
template <> struct type_caster<DestructionTester> {
PYBIND11_TYPE_CASTER(DestructionTester, _("DestructionTester"));
PYBIND11_TYPE_CASTER(DestructionTester, _x("DestructionTester"));
bool load(handle, bool) { return true; }
static handle cast(const DestructionTester &, return_value_policy, handle) {