You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ph...@apache.org on 2018/08/01 10:56:35 UTC
[2/2] nifi-minifi-cpp git commit: MINIFICPP-584 - update pybind to
prevent hang for Python3.7 on OSX
MINIFICPP-584 - update pybind to prevent hang for Python3.7 on OSX
This closes #385.
Signed-off-by: Marc Parisi <ph...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/1a3136b7
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/1a3136b7
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/1a3136b7
Branch: refs/heads/master
Commit: 1a3136b71412e72584429580815dc8ba0e1450b3
Parents: d5e5a4f
Author: Dustin Rodrigues <du...@gmail.com>
Authored: Tue Jul 31 23:01:53 2018 -0400
Committer: Marc Parisi <ph...@apache.org>
Committed: Wed Aug 1 06:56:20 2018 -0400
----------------------------------------------------------------------
thirdparty/pybind11/include/pybind11/cast.h | 193 ++++++++++-----
thirdparty/pybind11/include/pybind11/complex.h | 4 +
.../pybind11/include/pybind11/detail/class.h | 36 ++-
.../pybind11/include/pybind11/detail/common.h | 106 ++++----
.../pybind11/include/pybind11/detail/descr.h | 197 +++++----------
.../pybind11/include/pybind11/detail/init.h | 22 +-
.../include/pybind11/detail/internals.h | 58 +++--
thirdparty/pybind11/include/pybind11/eigen.h | 71 +++---
thirdparty/pybind11/include/pybind11/embed.h | 2 +-
.../pybind11/include/pybind11/functional.h | 6 +-
thirdparty/pybind11/include/pybind11/numpy.h | 103 ++++----
thirdparty/pybind11/include/pybind11/pybind11.h | 245 ++++++++++---------
thirdparty/pybind11/include/pybind11/pytypes.h | 3 +
thirdparty/pybind11/include/pybind11/stl.h | 25 +-
thirdparty/pybind11/include/pybind11/stl_bind.h | 2 +-
15 files changed, 578 insertions(+), 495 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/cast.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/cast.h b/thirdparty/pybind11/include/pybind11/cast.h
index eab904b..4084d42 100644
--- a/thirdparty/pybind11/include/pybind11/cast.h
+++ b/thirdparty/pybind11/include/pybind11/cast.h
@@ -17,6 +17,7 @@
#include <array>
#include <limits>
#include <tuple>
+#include <type_traits>
#if defined(PYBIND11_CPP17)
# if defined(__has_include)
@@ -774,11 +775,47 @@ template <typename T1, typename T2> struct is_copy_constructible<std::pair<T1, T
: all_of<is_copy_constructible<T1>, is_copy_constructible<T2>> {};
#endif
+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`.
+// If so, it sets `tinfo` to point to the std::type_info representing that derived
+// type, and returns a pointer to the start of the most-derived object of that type
+// (in which `src` is a subobject; this will be the same address as `src` in most
+// single inheritance cases). If not, or if `src` is nullptr, it simply returns `src`
+// and leaves `tinfo` at its default value of nullptr.
+//
+// The default polymorphic_type_hook just returns src. A specialization for polymorphic
+// types determines the runtime type of the passed object and adjusts the this-pointer
+// appropriately via dynamic_cast<void*>. This is what enables a C++ Animal* to appear
+// to Python as a Dog (if Dog inherits from Animal, Animal is polymorphic, Dog is
+// registered with pybind11, and this Animal is in fact a Dog).
+//
+// You may specialize polymorphic_type_hook yourself for types that want to appear
+// polymorphic to Python but do not use C++ RTTI. (This is a not uncommon pattern
+// in performance-sensitive applications, used most notably in LLVM.)
+template <typename itype, typename SFINAE = void>
+struct polymorphic_type_hook
+{
+ static const void *get(const itype *src, const std::type_info*&) { return src; }
+};
+template <typename itype>
+struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_polymorphic<itype>::value>>
+{
+ static const void *get(const itype *src, const std::type_info*& type) {
+ type = src ? &typeid(*src) : nullptr;
+ return dynamic_cast<const void*>(src);
+ }
+};
+
+NAMESPACE_BEGIN(detail)
+
/// Generic type caster for objects stored on the heap
template <typename type> class type_caster_base : public type_caster_generic {
using itype = intrinsic_t<type>;
+
public:
- static PYBIND11_DESCR name() { return type_descr(_<type>()); }
+ static constexpr auto name = _<type>();
type_caster_base() : type_caster_base(typeid(type)) { }
explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) { }
@@ -793,32 +830,28 @@ public:
return cast(&src, return_value_policy::move, parent);
}
- // Returns a (pointer, type_info) pair taking care of necessary RTTI type lookup for a
- // polymorphic type. If the instance isn't derived, returns the non-RTTI base version.
- template <typename T = itype, enable_if_t<std::is_polymorphic<T>::value, int> = 0>
+ // Returns a (pointer, type_info) pair taking care of necessary type lookup for a
+ // polymorphic type (using RTTI by default, but can be overridden by specializing
+ // polymorphic_type_hook). If the instance isn't derived, returns the base version.
static std::pair<const void *, const type_info *> src_and_type(const itype *src) {
- const void *vsrc = src;
auto &cast_type = typeid(itype);
const std::type_info *instance_type = nullptr;
- if (vsrc) {
- instance_type = &typeid(*src);
- if (!same_type(cast_type, *instance_type)) {
- // This is a base pointer to a derived type; if it is a pybind11-registered type, we
- // can get the correct derived pointer (which may be != base pointer) by a
- // dynamic_cast to most derived type:
- if (auto *tpi = get_type_info(*instance_type))
- return {dynamic_cast<const void *>(src), const_cast<const type_info *>(tpi)};
- }
+ const void *vsrc = polymorphic_type_hook<itype>::get(src, instance_type);
+ if (instance_type && !same_type(cast_type, *instance_type)) {
+ // This is a base pointer to a derived type. If the derived type is registered
+ // with pybind11, we want to make the full derived object available.
+ // In the typical case where itype is polymorphic, we get the correct
+ // derived pointer (which may be != base pointer) by a dynamic_cast to
+ // most derived type. If itype is not polymorphic, we won't get here
+ // except via a user-provided specialization of polymorphic_type_hook,
+ // and the user has promised that no this-pointer adjustment is
+ // required in that case, so it's OK to use static_cast.
+ if (const auto *tpi = get_type_info(*instance_type))
+ return {vsrc, tpi};
}
// Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so
// don't do a cast
- return type_caster_generic::src_and_type(vsrc, cast_type, instance_type);
- }
-
- // Non-polymorphic type, so no dynamic casting; just call the generic version directly
- template <typename T = itype, enable_if_t<!std::is_polymorphic<T>::value, int> = 0>
- static std::pair<const void *, const type_info *> src_and_type(const itype *src) {
- return type_caster_generic::src_and_type(src, typeid(itype));
+ return type_caster_generic::src_and_type(src, cast_type, instance_type);
}
static handle cast(const itype *src, return_value_policy policy, handle parent) {
@@ -835,7 +868,7 @@ public:
nullptr, nullptr, holder);
}
- template <typename T> using cast_op_type = cast_op_type<T>;
+ template <typename T> using cast_op_type = detail::cast_op_type<T>;
operator itype*() { return (type *) value; }
operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); }
@@ -885,7 +918,7 @@ private:
"std::reference_wrapper<T> caster requires T to have a caster with an `T &` operator");
public:
bool load(handle src, bool convert) { return subcaster.load(src, convert); }
- static PYBIND11_DESCR name() { return caster_t::name(); }
+ static constexpr auto name = caster_t::name;
static handle cast(const std::reference_wrapper<type> &src, return_value_policy policy, handle parent) {
// It is definitely wrong to take ownership of this pointer, so mask that rvp
if (policy == return_value_policy::take_ownership || policy == return_value_policy::automatic)
@@ -900,7 +933,7 @@ public:
protected: \
type value; \
public: \
- static PYBIND11_DESCR name() { return type_descr(py_name); } \
+ static constexpr auto name = py_name; \
template <typename T_, enable_if_t<std::is_same<type, remove_cv_t<T_>>::value, int> = 0> \
static handle cast(T_ *src, return_value_policy policy, handle parent) { \
if (!src) return none().release(); \
@@ -977,20 +1010,34 @@ public:
return true;
}
- static handle cast(T src, return_value_policy /* policy */, handle /* parent */) {
- if (std::is_floating_point<T>::value) {
- return PyFloat_FromDouble((double) src);
- } else if (sizeof(T) <= sizeof(long)) {
- if (std::is_signed<T>::value)
- return PyLong_FromLong((long) src);
- else
- return PyLong_FromUnsignedLong((unsigned long) src);
- } else {
- if (std::is_signed<T>::value)
- return PyLong_FromLongLong((long long) src);
- else
- return PyLong_FromUnsignedLongLong((unsigned long long) src);
- }
+ template<typename U = T>
+ static typename std::enable_if<std::is_floating_point<U>::value, handle>::type
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
+ return PyFloat_FromDouble((double) src);
+ }
+
+ template<typename U = T>
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value && (sizeof(U) <= sizeof(long)), handle>::type
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
+ return PYBIND11_LONG_FROM_SIGNED((long) src);
+ }
+
+ template<typename U = T>
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value && (sizeof(U) <= sizeof(unsigned long)), handle>::type
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
+ return PYBIND11_LONG_FROM_UNSIGNED((unsigned long) src);
+ }
+
+ template<typename U = T>
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_signed<U>::value && (sizeof(U) > sizeof(long)), handle>::type
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
+ return PyLong_FromLongLong((long long) src);
+ }
+
+ template<typename U = T>
+ static typename std::enable_if<!std::is_floating_point<U>::value && std::is_unsigned<U>::value && (sizeof(U) > sizeof(unsigned long)), handle>::type
+ cast(U src, return_value_policy /* policy */, handle /* parent */) {
+ return PyLong_FromUnsignedLongLong((unsigned long long) src);
}
PYBIND11_TYPE_CASTER(T, _<std::is_integral<T>::value>("int", "float"));
@@ -1049,7 +1096,7 @@ public:
template <typename T> using cast_op_type = void*&;
operator void *&() { return value; }
- static PYBIND11_DESCR name() { return type_descr(_("capsule")); }
+ static constexpr auto name = _("capsule");
private:
void *value = nullptr;
};
@@ -1171,7 +1218,7 @@ private:
#else
// PyPy seems to have multiple problems related to PyUnicode_UTF*: the UTF8 version
// sometimes segfaults for unknown reasons, while the UTF16 and 32 versions require a
- // non-const char * arguments, which is also a nuissance, so bypass the whole thing by just
+ // non-const char * arguments, which is also a nuisance, so bypass the whole thing by just
// passing the encoding as a string value, which works properly:
return PyUnicode_Decode(buffer, nbytes, UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr);
#endif
@@ -1216,6 +1263,7 @@ template <typename CharT> struct type_caster<CharT, enable_if_t<is_std_char_type
using StringCaster = type_caster<StringType>;
StringCaster str_caster;
bool none = false;
+ CharT one_char = 0;
public:
bool load(handle src, bool convert) {
if (!src) return false;
@@ -1243,7 +1291,7 @@ public:
}
operator CharT*() { return none ? nullptr : const_cast<CharT *>(static_cast<StringType &>(str_caster).c_str()); }
- operator CharT() {
+ operator CharT&() {
if (none)
throw value_error("Cannot convert None to a character");
@@ -1267,7 +1315,8 @@ public:
if (char0_bytes == str_len) {
// If we have a 128-255 value, we can decode it into a single char:
if (char0_bytes == 2 && (v0 & 0xFC) == 0xC0) { // 0x110000xx 0x10xxxxxx
- return static_cast<CharT>(((v0 & 3) << 6) + (static_cast<unsigned char>(value[1]) & 0x3F));
+ one_char = static_cast<CharT>(((v0 & 3) << 6) + (static_cast<unsigned char>(value[1]) & 0x3F));
+ return one_char;
}
// Otherwise we have a single character, but it's > U+00FF
throw value_error("Character code point not in range(0x100)");
@@ -1278,19 +1327,20 @@ public:
// surrogate pair with total length 2 instantly indicates a range error (but not a "your
// string was too long" error).
else if (StringCaster::UTF_N == 16 && str_len == 2) {
- char16_t v0 = static_cast<char16_t>(value[0]);
- if (v0 >= 0xD800 && v0 < 0xE000)
+ one_char = static_cast<CharT>(value[0]);
+ if (one_char >= 0xD800 && one_char < 0xE000)
throw value_error("Character code point not in range(0x10000)");
}
if (str_len != 1)
throw value_error("Expected a character, but multi-character string found");
- return value[0];
+ one_char = value[0];
+ return one_char;
}
- static PYBIND11_DESCR name() { return type_descr(_(PYBIND11_STRING_NAME)); }
- template <typename _T> using cast_op_type = remove_reference_t<pybind11::detail::cast_op_type<_T>>;
+ static constexpr auto name = _(PYBIND11_STRING_NAME);
+ template <typename _T> using cast_op_type = pybind11::detail::cast_op_type<_T>;
};
// Base implementation for std::tuple and std::pair
@@ -1314,9 +1364,7 @@ public:
return cast_impl(std::forward<T>(src), policy, parent, indices{});
}
- static PYBIND11_DESCR name() {
- return type_descr(_("Tuple[") + detail::concat(make_caster<Ts>::name()...) + _("]"));
- }
+ static constexpr auto name = _("Tuple[") + concat(make_caster<Ts>::name...) + _("]");
template <typename T> using cast_op_type = type;
@@ -1389,7 +1437,7 @@ public:
explicit operator type*() { return this->value; }
explicit operator type&() { return *(this->value); }
- explicit operator holder_type*() { return &holder; }
+ explicit operator holder_type*() { return std::addressof(holder); }
// Workaround for Intel compiler bug
// see pybind11 issue 94
@@ -1414,7 +1462,7 @@ protected:
bool load_value(value_and_holder &&v_h) {
if (v_h.holder_constructed()) {
value = v_h.value_ptr();
- holder = v_h.holder<holder_type>();
+ holder = v_h.template holder<holder_type>();
return true;
} else {
throw cast_error("Unable to cast from non-held to held instance (T& to Holder<T>) "
@@ -1459,9 +1507,9 @@ struct move_only_holder_caster {
static handle cast(holder_type &&src, return_value_policy, handle) {
auto *ptr = holder_helper<holder_type>::get(src);
- return type_caster_base<type>::cast_holder(ptr, &src);
+ return type_caster_base<type>::cast_holder(ptr, std::addressof(src));
}
- static PYBIND11_DESCR name() { return type_caster_base<type>::name(); }
+ static constexpr auto name = type_caster_base<type>::name;
};
template <typename type, typename deleter>
@@ -1492,10 +1540,10 @@ 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 PYBIND11_DESCR name() { return _<T>(); } };
-template <> struct handle_type_name<bytes> { static PYBIND11_DESCR name() { return _(PYBIND11_BYTES_NAME); } };
-template <> struct handle_type_name<args> { static PYBIND11_DESCR name() { return _("*args"); } };
-template <> struct handle_type_name<kwargs> { static PYBIND11_DESCR name() { return _("**kwargs"); } };
+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<args> { static constexpr auto name = _("*args"); };
+template <> struct handle_type_name<kwargs> { static constexpr auto name = _("**kwargs"); };
template <typename type>
struct pyobject_caster {
@@ -1513,7 +1561,7 @@ struct pyobject_caster {
static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) {
return src.inc_ref();
}
- PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name());
+ PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name);
};
template <typename T>
@@ -1558,9 +1606,13 @@ template <typename type> using cast_is_temporary_value_reference = bool_constant
// When a value returned from a C++ function is being cast back to Python, we almost always want to
// force `policy = move`, regardless of the return value policy the function/method was declared
-// with. Some classes (most notably Eigen::Ref and related) need to avoid this, and so can do so by
-// specializing this struct.
+// with.
template <typename Return, typename SFINAE = void> struct return_value_policy_override {
+ static return_value_policy policy(return_value_policy p) { return p; }
+};
+
+template <typename Return> struct return_value_policy_override<Return,
+ detail::enable_if_t<std::is_base_of<type_caster_generic, make_caster<Return>>::value, void>> {
static return_value_policy policy(return_value_policy p) {
return !std::is_lvalue_reference<Return>::value && !std::is_pointer<Return>::value
? return_value_policy::move : p;
@@ -1574,7 +1626,7 @@ template <typename T, typename SFINAE> type_caster<T, SFINAE> &load_type(type_ca
throw cast_error("Unable to cast Python instance to C++ type (compile in debug mode for details)");
#else
throw cast_error("Unable to cast Python instance of type " +
- (std::string) str(handle.get_type()) + " to C++ type '" + type_id<T>() + "''");
+ (std::string) str(handle.get_type()) + " to C++ type '" + type_id<T>() + "'");
#endif
}
return conv;
@@ -1683,6 +1735,9 @@ template <> inline void cast_safe<void>(object &&) {}
NAMESPACE_END(detail)
+template <return_value_policy policy = return_value_policy::automatic_reference>
+tuple make_tuple() { return tuple(0); }
+
template <return_value_policy policy = return_value_policy::automatic_reference,
typename... Args> tuple make_tuple(Args&&... args_) {
constexpr size_t size = sizeof...(Args);
@@ -1799,6 +1854,10 @@ struct function_call {
/// The `convert` value the arguments should be loaded with
std::vector<bool> args_convert;
+ /// Extra references for the optional `py::args` and/or `py::kwargs` arguments (which, if
+ /// present, are also in `args` but without a reference).
+ object args_ref, kwargs_ref;
+
/// The parent, if any
handle parent;
@@ -1826,7 +1885,7 @@ public:
static constexpr bool has_kwargs = kwargs_pos < 0;
static constexpr bool has_args = args_pos < 0;
- static PYBIND11_DESCR arg_names() { return detail::concat(make_caster<Args>::name()...); }
+ static constexpr auto arg_names = concat(type_descr(make_caster<Args>::name)...);
bool load_args(function_call &call) {
return load_impl_sequence(call, indices{});
@@ -2045,9 +2104,13 @@ object object_api<Derived>::call(Args &&...args) const {
NAMESPACE_END(detail)
-#define PYBIND11_MAKE_OPAQUE(Type) \
+#define PYBIND11_MAKE_OPAQUE(...) \
namespace pybind11 { namespace detail { \
- template<> class type_caster<Type> : public type_caster_base<Type> { }; \
+ template<> class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> { }; \
}}
+/// Lets you pass a type containing a `,` through a macro parameter without needing a separate
+/// 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)
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/complex.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/complex.h b/thirdparty/pybind11/include/pybind11/complex.h
index 5dac27c..3f89638 100644
--- a/thirdparty/pybind11/include/pybind11/complex.h
+++ b/thirdparty/pybind11/include/pybind11/complex.h
@@ -25,9 +25,13 @@ template <typename T> struct format_descriptor<std::complex<T>, detail::enable_i
static std::string format() { return std::string(value); }
};
+#ifndef PYBIND11_CPP17
+
template <typename T> constexpr const char format_descriptor<
std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>>::value[3];
+#endif
+
NAMESPACE_BEGIN(detail)
template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/detail/class.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/detail/class.h b/thirdparty/pybind11/include/pybind11/detail/class.h
index f745992..7a5dd01 100644
--- a/thirdparty/pybind11/include/pybind11/detail/class.h
+++ b/thirdparty/pybind11/include/pybind11/detail/class.h
@@ -14,6 +14,15 @@
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
+#if PY_VERSION_HEX >= 0x03030000
+# define PYBIND11_BUILTIN_QUALNAME
+# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj)
+#else
+// In pre-3.3 Python, we still set __qualname__ so that we can produce reliable function type
+// signatures; in 3.3+ this macro expands to nothing:
+# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj) setattr((PyObject *) obj, "__qualname__", nameobj)
+#endif
+
inline PyTypeObject *type_incref(PyTypeObject *type) {
Py_INCREF(type);
return type;
@@ -48,7 +57,7 @@ inline PyTypeObject *make_static_property_type() {
pybind11_fail("make_static_property_type(): error allocating type!");
heap_type->ht_name = name_obj.inc_ref().ptr();
-#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
+#ifdef PYBIND11_BUILTIN_QUALNAME
heap_type->ht_qualname = name_obj.inc_ref().ptr();
#endif
@@ -63,6 +72,7 @@ inline PyTypeObject *make_static_property_type() {
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
+ PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
return type;
}
@@ -161,7 +171,7 @@ inline PyTypeObject* make_default_metaclass() {
pybind11_fail("make_default_metaclass(): error allocating metaclass!");
heap_type->ht_name = name_obj.inc_ref().ptr();
-#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
+#ifdef PYBIND11_BUILTIN_QUALNAME
heap_type->ht_qualname = name_obj.inc_ref().ptr();
#endif
@@ -179,6 +189,7 @@ inline PyTypeObject* make_default_metaclass() {
pybind11_fail("make_default_metaclass(): failure in PyType_Ready()!");
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
+ PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
return type;
}
@@ -363,7 +374,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
pybind11_fail("make_object_base_type(): error allocating type!");
heap_type->ht_name = name_obj.inc_ref().ptr();
-#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
+#ifdef PYBIND11_BUILTIN_QUALNAME
heap_type->ht_qualname = name_obj.inc_ref().ptr();
#endif
@@ -384,6 +395,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
pybind11_fail("PyType_Ready failed in make_object_base_type():" + error_string());
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
+ PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
assert(!PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC));
return (PyObject *) heap_type;
@@ -504,13 +516,15 @@ inline void enable_buffer_protocol(PyHeapTypeObject *heap_type) {
inline PyObject* make_new_python_type(const type_record &rec) {
auto name = reinterpret_steal<object>(PYBIND11_FROM_STRING(rec.name));
-#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
- auto ht_qualname = name;
- if (rec.scope && hasattr(rec.scope, "__qualname__")) {
- ht_qualname = reinterpret_steal<object>(
+ auto qualname = name;
+ if (rec.scope && !PyModule_Check(rec.scope.ptr()) && hasattr(rec.scope, "__qualname__")) {
+#if PY_MAJOR_VERSION >= 3
+ qualname = reinterpret_steal<object>(
PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name.ptr()));
- }
+#else
+ qualname = str(rec.scope.attr("__qualname__").cast<std::string>() + "." + rec.name);
#endif
+ }
object module;
if (rec.scope) {
@@ -552,8 +566,8 @@ inline PyObject* make_new_python_type(const type_record &rec) {
pybind11_fail(std::string(rec.name) + ": Unable to create type object!");
heap_type->ht_name = name.release().ptr();
-#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
- heap_type->ht_qualname = ht_qualname.release().ptr();
+#ifdef PYBIND11_BUILTIN_QUALNAME
+ heap_type->ht_qualname = qualname.inc_ref().ptr();
#endif
auto type = &heap_type->ht_type;
@@ -599,6 +613,8 @@ inline PyObject* make_new_python_type(const type_record &rec) {
if (module) // Needed by pydoc
setattr((PyObject *) type, "__module__", module);
+ PYBIND11_SET_OLDPY_QUALNAME(type, qualname);
+
return (PyObject *) type;
}
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/detail/common.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/detail/common.h b/thirdparty/pybind11/include/pybind11/detail/common.h
index 8f763f0..3c67228 100644
--- a/thirdparty/pybind11/include/pybind11/detail/common.h
+++ b/thirdparty/pybind11/include/pybind11/detail/common.h
@@ -46,8 +46,8 @@
// Compiler version assertions
#if defined(__INTEL_COMPILER)
-# if __INTEL_COMPILER < 1500
-# error pybind11 requires Intel C++ compiler v15 or newer
+# if __INTEL_COMPILER < 1700
+# error pybind11 requires Intel C++ compiler v17 or newer
# endif
#elif defined(__clang__) && !defined(__apple_build_version__)
# if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
@@ -92,8 +92,8 @@
#endif
#define PYBIND11_VERSION_MAJOR 2
-#define PYBIND11_VERSION_MINOR 2
-#define PYBIND11_VERSION_PATCH 1
+#define PYBIND11_VERSION_MINOR 3
+#define PYBIND11_VERSION_PATCH dev0
/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
#if defined(_MSC_VER)
@@ -158,6 +158,8 @@
#define PYBIND11_BYTES_SIZE PyBytes_Size
#define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
#define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
+#define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) o)
+#define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) o)
#define PYBIND11_BYTES_NAME "bytes"
#define PYBIND11_STRING_NAME "str"
#define PYBIND11_SLICE_OBJECT PyObject
@@ -180,6 +182,8 @@
#define PYBIND11_BYTES_SIZE PyString_Size
#define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o))
#define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))
+#define PYBIND11_LONG_FROM_SIGNED(o) PyInt_FromSsize_t((ssize_t) o) // Returns long if needed.
+#define PYBIND11_LONG_FROM_UNSIGNED(o) PyInt_FromSize_t((size_t) o) // Returns long if needed.
#define PYBIND11_BYTES_NAME "str"
#define PYBIND11_STRING_NAME "unicode"
#define PYBIND11_SLICE_OBJECT PySliceObject
@@ -207,6 +211,31 @@ extern "C" {
#define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
#define PYBIND11_CONCAT(first, second) first##second
+#define PYBIND11_CHECK_PYTHON_VERSION \
+ { \
+ const char *compiled_ver = PYBIND11_TOSTRING(PY_MAJOR_VERSION) \
+ "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
+ const char *runtime_ver = Py_GetVersion(); \
+ size_t len = std::strlen(compiled_ver); \
+ if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
+ || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
+ PyErr_Format(PyExc_ImportError, \
+ "Python version mismatch: module was compiled for Python %s, " \
+ "but the interpreter version is incompatible: %s.", \
+ compiled_ver, runtime_ver); \
+ return nullptr; \
+ } \
+ }
+
+#define PYBIND11_CATCH_INIT_EXCEPTIONS \
+ catch (pybind11::error_already_set &e) { \
+ PyErr_SetString(PyExc_ImportError, e.what()); \
+ return nullptr; \
+ } catch (const std::exception &e) { \
+ PyErr_SetString(PyExc_ImportError, e.what()); \
+ return nullptr; \
+ } \
+
/** \rst
***Deprecated in favor of PYBIND11_MODULE***
@@ -226,27 +255,10 @@ extern "C" {
PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
static PyObject *pybind11_init(); \
PYBIND11_PLUGIN_IMPL(name) { \
- int major, minor; \
- if (sscanf(Py_GetVersion(), "%i.%i", &major, &minor) != 2) { \
- PyErr_SetString(PyExc_ImportError, "Can't parse Python version."); \
- return nullptr; \
- } else if (major != PY_MAJOR_VERSION || minor != PY_MINOR_VERSION) { \
- PyErr_Format(PyExc_ImportError, \
- "Python version mismatch: module was compiled for " \
- "version %i.%i, while the interpreter is running " \
- "version %i.%i.", PY_MAJOR_VERSION, PY_MINOR_VERSION, \
- major, minor); \
- return nullptr; \
- } \
+ PYBIND11_CHECK_PYTHON_VERSION \
try { \
return pybind11_init(); \
- } catch (pybind11::error_already_set &e) { \
- PyErr_SetString(PyExc_ImportError, e.what()); \
- return nullptr; \
- } catch (const std::exception &e) { \
- PyErr_SetString(PyExc_ImportError, e.what()); \
- return nullptr; \
- } \
+ } PYBIND11_CATCH_INIT_EXCEPTIONS \
} \
PyObject *pybind11_init()
@@ -270,29 +282,12 @@ extern "C" {
#define PYBIND11_MODULE(name, variable) \
static void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &); \
PYBIND11_PLUGIN_IMPL(name) { \
- int major, minor; \
- if (sscanf(Py_GetVersion(), "%i.%i", &major, &minor) != 2) { \
- PyErr_SetString(PyExc_ImportError, "Can't parse Python version."); \
- return nullptr; \
- } else if (major != PY_MAJOR_VERSION || minor != PY_MINOR_VERSION) { \
- PyErr_Format(PyExc_ImportError, \
- "Python version mismatch: module was compiled for " \
- "version %i.%i, while the interpreter is running " \
- "version %i.%i.", PY_MAJOR_VERSION, PY_MINOR_VERSION, \
- major, minor); \
- return nullptr; \
- } \
+ PYBIND11_CHECK_PYTHON_VERSION \
auto m = pybind11::module(PYBIND11_TOSTRING(name)); \
try { \
PYBIND11_CONCAT(pybind11_init_, name)(m); \
return m.ptr(); \
- } catch (pybind11::error_already_set &e) { \
- PyErr_SetString(PyExc_ImportError, e.what()); \
- return nullptr; \
- } catch (const std::exception &e) { \
- PyErr_SetString(PyExc_ImportError, e.what()); \
- return nullptr; \
- } \
+ } PYBIND11_CATCH_INIT_EXCEPTIONS \
} \
void PYBIND11_CONCAT(pybind11_init_, name)(pybind11::module &variable)
@@ -377,18 +372,20 @@ constexpr size_t instance_simple_holder_in_ptrs() {
struct type_info;
struct value_and_holder;
+struct nonsimple_values_and_holders {
+ void **values_and_holders;
+ uint8_t *status;
+};
+
/// The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
struct instance {
PyObject_HEAD
/// Storage for pointers and holder; see simple_layout, below, for a description
union {
void *simple_value_holder[1 + instance_simple_holder_in_ptrs()];
- struct {
- void **values_and_holders;
- uint8_t *status;
- } nonsimple;
+ nonsimple_values_and_holders nonsimple;
};
- /// Weak references (needed for keep alive):
+ /// Weak references
PyObject *weakrefs;
/// If true, the pointer is owned which means we're free to manage it with a holder.
bool owned : 1;
@@ -405,10 +402,10 @@ struct instance {
* (which is typically the size of two pointers), or when multiple inheritance is used on the
* python side. Non-simple layout allocates the required amount of memory to have multiple
* bound C++ classes as parents. Under this layout, `nonsimple.values_and_holders` is set to a
- * pointer to allocated space of the required space to hold a a sequence of value pointers and
+ * pointer to allocated space of the required space to hold a sequence of value pointers and
* holders followed `status`, a set of bit flags (1 byte each), i.e.
* [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple of
- * `sizeof(void *)`. `nonsimple.holder_constructed` is, for convenience, a pointer to the
+ * `sizeof(void *)`. `nonsimple.status` is, for convenience, a pointer to the
* beginning of the [bb...] block (but not independently allocated).
*
* Status bits indicate whether the associated holder is constructed (&
@@ -471,7 +468,7 @@ template <size_t... IPrev, size_t I, bool B, bool... Bs> struct select_indices_i
: select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>, I + 1, Bs...> {};
template <bool... Bs> using select_indices = typename select_indices_impl<index_sequence<>, 0, Bs...>::type;
-/// Backports of std::bool_constant and std::negation to accomodate older compilers
+/// Backports of std::bool_constant and std::negation to accommodate older compilers
template <bool B> using bool_constant = std::integral_constant<bool, B>;
template <typename T> struct negation : bool_constant<!T::value> { };
@@ -581,6 +578,11 @@ template <typename T, typename... Us> using deferred_t = typename deferred_type<
template <typename Base, typename Derived> using is_strict_base_of = bool_constant<
std::is_base_of<Base, Derived>::value && !std::is_same<Base, Derived>::value>;
+/// Like is_base_of, but also requires that the base type is accessible (i.e. that a Derived pointer
+/// can be converted to a Base pointer)
+template <typename Base, typename Derived> using is_accessible_base_of = bool_constant<
+ std::is_base_of<Base, Derived>::value && std::is_convertible<Derived *, Base *>::value>;
+
template <template<typename...> class Base>
struct is_template_base_of_impl {
template <typename... Us> static std::true_type check(Base<Us...> *);
@@ -699,9 +701,13 @@ template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_ar
static std::string format() { return std::string(1, c); }
};
+#if !defined(PYBIND11_CPP17)
+
template <typename T> constexpr const char format_descriptor<
T, detail::enable_if_t<std::is_arithmetic<T>::value>>::value[2];
+#endif
+
/// RAII wrapper that temporarily clears any Python error state
struct error_scope {
PyObject *type, *value, *trace;
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/detail/descr.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/detail/descr.h b/thirdparty/pybind11/include/pybind11/detail/descr.h
index e3bf2ba..8d404e5 100644
--- a/thirdparty/pybind11/include/pybind11/detail/descr.h
+++ b/thirdparty/pybind11/include/pybind11/detail/descr.h
@@ -1,6 +1,5 @@
/*
- pybind11/detail/descr.h: Helper type for concatenating type signatures
- either at runtime (C++11) or compile time (C++14)
+ pybind11/detail/descr.h: Helper type for concatenating type signatures at compile time
Copyright (c) 2016 Wenzel Jakob <we...@epfl.ch>
@@ -15,171 +14,87 @@
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
-/* Concatenate type signatures at compile time using C++14 */
-#if defined(PYBIND11_CPP14) && !defined(_MSC_VER)
-#define PYBIND11_CONSTEXPR_DESCR
-
-template <size_t Size1, size_t Size2> class descr {
- template <size_t Size1_, size_t Size2_> friend class descr;
-public:
- constexpr descr(char const (&text) [Size1+1], const std::type_info * const (&types)[Size2+1])
- : descr(text, types,
- make_index_sequence<Size1>(),
- make_index_sequence<Size2>()) { }
-
- constexpr const char *text() const { return m_text; }
- constexpr const std::type_info * const * types() const { return m_types; }
-
- template <size_t OtherSize1, size_t OtherSize2>
- constexpr descr<Size1 + OtherSize1, Size2 + OtherSize2> operator+(const descr<OtherSize1, OtherSize2> &other) const {
- return concat(other,
- make_index_sequence<Size1>(),
- make_index_sequence<Size2>(),
- make_index_sequence<OtherSize1>(),
- make_index_sequence<OtherSize2>());
- }
+#if !defined(_MSC_VER)
+# define PYBIND11_DESCR_CONSTEXPR static constexpr
+#else
+# define PYBIND11_DESCR_CONSTEXPR const
+#endif
-protected:
- template <size_t... Indices1, size_t... Indices2>
- constexpr descr(
- char const (&text) [Size1+1],
- const std::type_info * const (&types) [Size2+1],
- index_sequence<Indices1...>, index_sequence<Indices2...>)
- : m_text{text[Indices1]..., '\0'},
- m_types{types[Indices2]..., nullptr } {}
-
- template <size_t OtherSize1, size_t OtherSize2, size_t... Indices1,
- size_t... Indices2, size_t... OtherIndices1, size_t... OtherIndices2>
- constexpr descr<Size1 + OtherSize1, Size2 + OtherSize2>
- concat(const descr<OtherSize1, OtherSize2> &other,
- index_sequence<Indices1...>, index_sequence<Indices2...>,
- index_sequence<OtherIndices1...>, index_sequence<OtherIndices2...>) const {
- return descr<Size1 + OtherSize1, Size2 + OtherSize2>(
- { m_text[Indices1]..., other.m_text[OtherIndices1]..., '\0' },
- { m_types[Indices2]..., other.m_types[OtherIndices2]..., nullptr }
- );
- }
+/* Concatenate type signatures at compile time */
+template <size_t N, typename... Ts>
+struct descr {
+ char text[N + 1];
+
+ constexpr descr() : text{'\0'} { }
+ constexpr descr(char const (&s)[N+1]) : descr(s, make_index_sequence<N>()) { }
+
+ template <size_t... Is>
+ constexpr descr(char const (&s)[N+1], index_sequence<Is...>) : text{s[Is]..., '\0'} { }
-protected:
- char m_text[Size1 + 1];
- const std::type_info * m_types[Size2 + 1];
+ template <typename... Chars>
+ constexpr descr(char c, Chars... cs) : text{c, static_cast<char>(cs)..., '\0'} { }
+
+ static constexpr std::array<const std::type_info *, sizeof...(Ts) + 1> types() {
+ return {{&typeid(Ts)..., nullptr}};
+ }
};
-template <size_t Size> constexpr descr<Size - 1, 0> _(char const(&text)[Size]) {
- return descr<Size - 1, 0>(text, { nullptr });
+template <size_t N1, size_t N2, typename... Ts1, typename... Ts2, size_t... Is1, size_t... Is2>
+constexpr descr<N1 + N2, Ts1..., Ts2...> plus_impl(const descr<N1, Ts1...> &a, const descr<N2, Ts2...> &b,
+ index_sequence<Is1...>, index_sequence<Is2...>) {
+ return {a.text[Is1]..., b.text[Is2]...};
+}
+
+template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
+constexpr descr<N1 + N2, Ts1..., Ts2...> operator+(const descr<N1, Ts1...> &a, const descr<N2, Ts2...> &b) {
+ return plus_impl(a, b, make_index_sequence<N1>(), make_index_sequence<N2>());
}
+template <size_t N>
+constexpr descr<N - 1> _(char const(&text)[N]) { return descr<N - 1>(text); }
+constexpr descr<0> _(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...> {
- static constexpr auto digits = descr<sizeof...(Digits), 0>({ ('0' + Digits)..., '\0' }, { nullptr });
+ static constexpr auto digits = descr<sizeof...(Digits)>(('0' + Digits)...);
};
// Ternary description (like std::conditional)
-template <bool B, size_t Size1, size_t Size2>
-constexpr enable_if_t<B, descr<Size1 - 1, 0>> _(char const(&text1)[Size1], char const(&)[Size2]) {
+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);
}
-template <bool B, size_t Size1, size_t Size2>
-constexpr enable_if_t<!B, descr<Size2 - 1, 0>> _(char const(&)[Size1], char const(&text2)[Size2]) {
+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);
}
-template <bool B, size_t SizeA1, size_t SizeA2, size_t SizeB1, size_t SizeB2>
-constexpr enable_if_t<B, descr<SizeA1, SizeA2>> _(descr<SizeA1, SizeA2> d, descr<SizeB1, SizeB2>) { return d; }
-template <bool B, size_t SizeA1, size_t SizeA2, size_t SizeB1, size_t SizeB2>
-constexpr enable_if_t<!B, descr<SizeB1, SizeB2>> _(descr<SizeA1, SizeA2>, descr<SizeB1, SizeB2> d) { return d; }
+
+template <bool B, typename T1, typename T2>
+constexpr enable_if_t<B, T1> _(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; }
template <size_t Size> auto constexpr _() -> decltype(int_to_str<Size / 10, Size % 10>::digits) {
return int_to_str<Size / 10, Size % 10>::digits;
}
-template <typename Type> constexpr descr<1, 1> _() {
- return descr<1, 1>({ '%', '\0' }, { &typeid(Type), nullptr });
-}
-
-inline constexpr descr<0, 0> concat() { return _(""); }
-template <size_t Size1, size_t Size2, typename... Args> auto constexpr concat(descr<Size1, Size2> descr) { return descr; }
-template <size_t Size1, size_t Size2, typename... Args> auto constexpr concat(descr<Size1, Size2> descr, Args&&... args) { return descr + _(", ") + concat(args...); }
-template <size_t Size1, size_t Size2> auto constexpr type_descr(descr<Size1, Size2> descr) { return _("{") + descr + _("}"); }
-
-#define PYBIND11_DESCR constexpr auto
-
-#else /* Simpler C++11 implementation based on run-time memory allocation and copying */
-
-class descr {
-public:
- PYBIND11_NOINLINE descr(const char *text, const std::type_info * const * types) {
- size_t nChars = len(text), nTypes = len(types);
- m_text = new char[nChars];
- m_types = new const std::type_info *[nTypes];
- memcpy(m_text, text, nChars * sizeof(char));
- memcpy(m_types, types, nTypes * sizeof(const std::type_info *));
- }
-
- PYBIND11_NOINLINE descr operator+(descr &&d2) && {
- descr r;
-
- size_t nChars1 = len(m_text), nTypes1 = len(m_types);
- size_t nChars2 = len(d2.m_text), nTypes2 = len(d2.m_types);
-
- r.m_text = new char[nChars1 + nChars2 - 1];
- r.m_types = new const std::type_info *[nTypes1 + nTypes2 - 1];
- memcpy(r.m_text, m_text, (nChars1-1) * sizeof(char));
- memcpy(r.m_text + nChars1 - 1, d2.m_text, nChars2 * sizeof(char));
- memcpy(r.m_types, m_types, (nTypes1-1) * sizeof(std::type_info *));
- memcpy(r.m_types + nTypes1 - 1, d2.m_types, nTypes2 * sizeof(std::type_info *));
+template <typename Type> constexpr descr<1, Type> _() { return {'%'}; }
- delete[] m_text; delete[] m_types;
- delete[] d2.m_text; delete[] d2.m_types;
-
- return r;
- }
+constexpr descr<0> concat() { return {}; }
- char *text() { return m_text; }
- const std::type_info * * types() { return m_types; }
+template <size_t N, typename... Ts>
+constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) { return descr; }
-protected:
- PYBIND11_NOINLINE descr() { }
-
- template <typename T> static size_t len(const T *ptr) { // return length including null termination
- const T *it = ptr;
- while (*it++ != (T) 0)
- ;
- return static_cast<size_t>(it - ptr);
- }
-
- const std::type_info **m_types = nullptr;
- char *m_text = nullptr;
-};
-
-/* The 'PYBIND11_NOINLINE inline' combinations below are intentional to get the desired linkage while producing as little object code as possible */
-
-PYBIND11_NOINLINE inline descr _(const char *text) {
- const std::type_info *types[1] = { nullptr };
- return descr(text, types);
-}
-
-template <bool B> PYBIND11_NOINLINE enable_if_t<B, descr> _(const char *text1, const char *) { return _(text1); }
-template <bool B> PYBIND11_NOINLINE enable_if_t<!B, descr> _(char const *, const char *text2) { return _(text2); }
-template <bool B> PYBIND11_NOINLINE enable_if_t<B, descr> _(descr d, descr) { return d; }
-template <bool B> PYBIND11_NOINLINE enable_if_t<!B, descr> _(descr, descr d) { return d; }
-
-template <typename Type> PYBIND11_NOINLINE descr _() {
- const std::type_info *types[2] = { &typeid(Type), nullptr };
- return descr("%", types);
+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...);
}
-template <size_t Size> PYBIND11_NOINLINE descr _() {
- const std::type_info *types[1] = { nullptr };
- return descr(std::to_string(Size).c_str(), types);
+template <size_t N, typename... Ts>
+constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
+ return _("{") + descr + _("}");
}
-PYBIND11_NOINLINE inline descr concat() { return _(""); }
-PYBIND11_NOINLINE inline descr concat(descr &&d) { return d; }
-template <typename... Args> PYBIND11_NOINLINE descr concat(descr &&d, Args&&... args) { return std::move(d) + _(", ") + concat(std::forward<Args>(args)...); }
-PYBIND11_NOINLINE inline descr type_descr(descr&& d) { return _("{") + std::move(d) + _("}"); }
-
-#define PYBIND11_DESCR ::pybind11::detail::descr
-#endif
-
NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/detail/init.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/detail/init.h b/thirdparty/pybind11/include/pybind11/detail/init.h
index c3594a1..acfe00b 100644
--- a/thirdparty/pybind11/include/pybind11/detail/init.h
+++ b/thirdparty/pybind11/include/pybind11/detail/init.h
@@ -24,7 +24,7 @@ public:
template <typename> using cast_op_type = value_and_holder &;
operator value_and_holder &() { return *value; }
- static PYBIND11_DESCR name() { return type_descr(_<value_and_holder>()); }
+ static constexpr auto name = _<value_and_holder>();
private:
value_and_holder *value = nullptr;
@@ -52,6 +52,16 @@ bool is_alias(Cpp<Class> *ptr) {
template <typename /*Class*/>
constexpr bool is_alias(void *) { return false; }
+// Constructs and returns a new object; if the given arguments don't map to a constructor, we fall
+// back to brace aggregate initiailization so that for aggregate initialization can be used with
+// py::init, e.g. `py::init<int, int>` to initialize a `struct T { int a; int b; }`. For
+// non-aggregate types, we need to use an ordinary T(...) constructor (invoking as `T{...}` usually
+// works, but will not do the expected thing when `T` has an `initializer_list<T>` constructor).
+template <typename Class, typename... Args, detail::enable_if_t<std::is_constructible<Class, Args...>::value, int> = 0>
+inline Class *construct_or_initialize(Args &&...args) { return new Class(std::forward<Args>(args)...); }
+template <typename Class, typename... Args, detail::enable_if_t<!std::is_constructible<Class, Args...>::value, int> = 0>
+inline Class *construct_or_initialize(Args &&...args) { return new Class{std::forward<Args>(args)...}; }
+
// Attempts to constructs an alias using a `Alias(Cpp &&)` constructor. This allows types with
// an alias to provide only a single Cpp factory function as long as the Alias can be
// constructed from an rvalue reference of the base Cpp type. This means that Alias classes
@@ -161,7 +171,7 @@ struct constructor {
template <typename Class, typename... Extra, enable_if_t<!Class::has_alias, int> = 0>
static void execute(Class &cl, const Extra&... extra) {
cl.def("__init__", [](value_and_holder &v_h, Args... args) {
- v_h.value_ptr() = new Cpp<Class>{std::forward<Args>(args)...};
+ v_h.value_ptr() = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...);
}, is_new_style_constructor(), extra...);
}
@@ -171,9 +181,9 @@ struct constructor {
static void execute(Class &cl, const Extra&... extra) {
cl.def("__init__", [](value_and_holder &v_h, Args... args) {
if (Py_TYPE(v_h.inst) == v_h.type->type)
- v_h.value_ptr() = new Cpp<Class>{std::forward<Args>(args)...};
+ v_h.value_ptr() = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...);
else
- v_h.value_ptr() = new Alias<Class>{std::forward<Args>(args)...};
+ v_h.value_ptr() = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...);
}, is_new_style_constructor(), extra...);
}
@@ -182,7 +192,7 @@ struct constructor {
!std::is_constructible<Cpp<Class>, Args...>::value, int> = 0>
static void execute(Class &cl, const Extra&... extra) {
cl.def("__init__", [](value_and_holder &v_h, Args... args) {
- v_h.value_ptr() = new Alias<Class>{std::forward<Args>(args)...};
+ v_h.value_ptr() = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...);
}, is_new_style_constructor(), extra...);
}
};
@@ -193,7 +203,7 @@ template <typename... Args> struct alias_constructor {
enable_if_t<Class::has_alias && std::is_constructible<Alias<Class>, Args...>::value, int> = 0>
static void execute(Class &cl, const Extra&... extra) {
cl.def("__init__", [](value_and_holder &v_h, Args... args) {
- v_h.value_ptr() = new Alias<Class>{std::forward<Args>(args)...};
+ v_h.value_ptr() = construct_or_initialize<Alias<Class>>(std::forward<Args>(args)...);
}, is_new_style_constructor(), extra...);
}
};
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/detail/internals.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/detail/internals.h b/thirdparty/pybind11/include/pybind11/detail/internals.h
index 213cbae..e6f851a 100644
--- a/thirdparty/pybind11/include/pybind11/detail/internals.h
+++ b/thirdparty/pybind11/include/pybind11/detail/internals.h
@@ -18,6 +18,25 @@ inline PyTypeObject *make_static_property_type();
inline PyTypeObject *make_default_metaclass();
inline PyObject *make_object_base_type(PyTypeObject *metaclass);
+// The old Python Thread Local Storage (TLS) API is deprecated in Python 3.7 in favor of the new
+// Thread Specific Storage (TSS) API.
+#if PY_VERSION_HEX >= 0x03070000
+ #define PYBIND11_TLS_KEY_INIT(var) Py_tss_t *var = nullptr
+ #define PYBIND11_TLS_GET_VALUE(key) PyThread_tss_get((key))
+ #define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_tss_set((key), (tstate))
+ #define PYBIND11_TLS_DELETE_VALUE(key) PyThread_tss_set((key), nullptr)
+#else
+ // Usually an int but a long on Cygwin64 with Python 3.x
+ #define PYBIND11_TLS_KEY_INIT(var) decltype(PyThread_create_key()) var = 0
+ #define PYBIND11_TLS_GET_VALUE(key) PyThread_get_key_value((key))
+ #if PY_MAJOR_VERSION < 3
+ #define PYBIND11_TLS_REPLACE_VALUE(key, value) do { PyThread_delete_key_value((key)); PyThread_set_key_value((key), (value)); } while (false)
+ #else
+ #define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_set_key_value((key), (value))
+ #endif
+ #define PYBIND11_TLS_DELETE_VALUE(key) PyThread_set_key_value((key), nullptr)
+#endif
+
// Python loads modules by default with dlopen with the RTLD_LOCAL flag; under libc++ and possibly
// other STLs, this means `typeid(A)` from one module won't equal `typeid(A)` from another module
// even when `A` is the same, non-hidden-visibility type (e.g. from a common include). Under
@@ -79,7 +98,7 @@ struct internals {
PyTypeObject *default_metaclass;
PyObject *instance_base;
#if defined(WITH_THREAD)
- decltype(PyThread_create_key()) tstate = 0; // Usually an int but a long on Cygwin64 with Python 3.x
+ PYBIND11_TLS_KEY_INIT(tstate);
PyInterpreterState *istate = nullptr;
#endif
};
@@ -111,7 +130,7 @@ struct type_info {
};
/// Tracks the `internals` and `type_info` ABI version independent of the main library version
-#define PYBIND11_INTERNALS_VERSION 1
+#define PYBIND11_INTERNALS_VERSION 2
#if defined(WITH_THREAD)
# define PYBIND11_INTERNALS_KIND ""
@@ -127,21 +146,21 @@ struct type_info {
/// Each module locally stores a pointer to the `internals` data. The data
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.
-inline internals *&get_internals_ptr() {
- static internals *internals_ptr = nullptr;
- return internals_ptr;
+inline internals **&get_internals_pp() {
+ static internals **internals_pp = nullptr;
+ return internals_pp;
}
/// Return a reference to the current `internals` data
PYBIND11_NOINLINE inline internals &get_internals() {
- auto *&internals_ptr = get_internals_ptr();
- if (internals_ptr)
- return *internals_ptr;
+ auto **&internals_pp = get_internals_pp();
+ if (internals_pp && *internals_pp)
+ return **internals_pp;
constexpr auto *id = PYBIND11_INTERNALS_ID;
auto builtins = handle(PyEval_GetBuiltins());
if (builtins.contains(id) && isinstance<capsule>(builtins[id])) {
- internals_ptr = *static_cast<internals **>(capsule(builtins[id]));
+ internals_pp = static_cast<internals **>(capsule(builtins[id]));
// We loaded builtins through python's builtins, which means that our `error_already_set`
// and `builtin_exception` may be different local classes than the ones set up in the
@@ -149,7 +168,7 @@ PYBIND11_NOINLINE inline internals &get_internals() {
//
// libstdc++ doesn't require this (types there are identified only by name)
#if !defined(__GLIBCXX__)
- internals_ptr->registered_exception_translators.push_front(
+ (*internals_pp)->registered_exception_translators.push_front(
[](std::exception_ptr p) -> void {
try {
if (p) std::rethrow_exception(p);
@@ -160,15 +179,26 @@ PYBIND11_NOINLINE inline internals &get_internals() {
);
#endif
} else {
+ if (!internals_pp) internals_pp = new internals*();
+ auto *&internals_ptr = *internals_pp;
internals_ptr = new internals();
#if defined(WITH_THREAD)
PyEval_InitThreads();
PyThreadState *tstate = PyThreadState_Get();
- internals_ptr->tstate = PyThread_create_key();
- PyThread_set_key_value(internals_ptr->tstate, tstate);
+ #if PY_VERSION_HEX >= 0x03070000
+ internals_ptr->tstate = PyThread_tss_alloc();
+ if (!internals_ptr->tstate || PyThread_tss_create(internals_ptr->tstate))
+ pybind11_fail("get_internals: could not successfully initialize the TSS key!");
+ PyThread_tss_set(internals_ptr->tstate, tstate);
+ #else
+ internals_ptr->tstate = PyThread_create_key();
+ if (internals_ptr->tstate == -1)
+ pybind11_fail("get_internals: could not successfully initialize the TLS key!");
+ PyThread_set_key_value(internals_ptr->tstate, tstate);
+ #endif
internals_ptr->istate = tstate->interp;
#endif
- builtins[id] = capsule(&internals_ptr);
+ builtins[id] = capsule(internals_pp);
internals_ptr->registered_exception_translators.push_front(
[](std::exception_ptr p) -> void {
try {
@@ -192,7 +222,7 @@ PYBIND11_NOINLINE inline internals &get_internals() {
internals_ptr->default_metaclass = make_default_metaclass();
internals_ptr->instance_base = make_object_base_type(internals_ptr->default_metaclass);
}
- return *internals_ptr;
+ return **internals_pp;
}
/// Works like `internals.registered_types_cpp`, but for module-local registered types:
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/eigen.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/eigen.h b/thirdparty/pybind11/include/pybind11/eigen.h
index a702bf3..d963d96 100644
--- a/thirdparty/pybind11/include/pybind11/eigen.h
+++ b/thirdparty/pybind11/include/pybind11/eigen.h
@@ -17,19 +17,25 @@
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wconversion"
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+# ifdef __clang__
+// Eigen generates a bunch of implicit-copy-constructor-is-deprecated warnings with -Wdeprecated
+// under Clang, so disable that warning here:
+# pragma GCC diagnostic ignored "-Wdeprecated"
+# endif
# if __GNUC__ >= 7
# pragma GCC diagnostic ignored "-Wint-in-bool-context"
# endif
#endif
-#include <Eigen/Core>
-#include <Eigen/SparseCore>
-
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
+# pragma warning(disable: 4996) // warning C4996: std::unary_negate is deprecated in C++17
#endif
+#include <Eigen/Core>
+#include <Eigen/SparseCore>
+
// Eigen prior to 3.2.7 doesn't have proper move constructors--but worse, some classes get implicit
// move constructors that break things. We could detect this an explicitly copy, but an extra copy
// of matrices seems highly undesirable.
@@ -180,28 +186,26 @@ template <typename Type_> struct EigenProps {
}
}
- static PYBIND11_DESCR descriptor() {
- constexpr bool show_writeable = is_eigen_dense_map<Type>::value && is_eigen_mutable_map<Type>::value;
- constexpr bool show_order = is_eigen_dense_map<Type>::value;
- constexpr bool show_c_contiguous = show_order && requires_row_major;
- constexpr bool show_f_contiguous = !show_c_contiguous && show_order && requires_col_major;
-
- return type_descr(_("numpy.ndarray[") + npy_format_descriptor<Scalar>::name() +
- _("[") + _<fixed_rows>(_<(size_t) rows>(), _("m")) +
- _(", ") + _<fixed_cols>(_<(size_t) cols>(), _("n")) +
- _("]") +
- // 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", "") +
- _("]")
- );
- }
+ static constexpr bool show_writeable = is_eigen_dense_map<Type>::value && is_eigen_mutable_map<Type>::value;
+ static constexpr bool show_order = is_eigen_dense_map<Type>::value;
+ static constexpr bool show_c_contiguous = show_order && requires_row_major;
+ 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")) +
+ _("]") +
+ // 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", "") +
+ _("]");
};
// Casts an Eigen type to numpy array. If given a base, the numpy array references the src data,
@@ -272,6 +276,7 @@ struct type_caster<Type, enable_if_t<is_eigen_dense_plain<Type>::value>> {
value = Type(fits.rows, fits.cols);
auto ref = reinterpret_steal<array>(eigen_ref_array<props>(value));
if (dims == 1) ref = ref.squeeze();
+ else if (ref.ndim() == 1) buf = buf.squeeze();
int result = detail::npy_api::get().PyArray_CopyInto_(ref.ptr(), buf.ptr());
@@ -337,7 +342,7 @@ public:
return cast_impl(src, policy, parent);
}
- static PYBIND11_DESCR name() { return props::descriptor(); }
+ static constexpr auto name = props::descriptor;
operator Type*() { return &value; }
operator Type&() { return value; }
@@ -348,14 +353,6 @@ private:
Type value;
};
-// Eigen Ref/Map classes have slightly different policy requirements, meaning we don't want to force
-// `move` when a Ref/Map rvalue is returned; we treat Ref<> sort of like a pointer (we care about
-// the underlying data, not the outer shell).
-template <typename Return>
-struct return_value_policy_override<Return, enable_if_t<is_eigen_dense_map<Return>::value>> {
- static return_value_policy policy(return_value_policy p) { return p; }
-};
-
// Base class for casting reference/map/block/etc. objects back to python.
template <typename MapType> struct eigen_map_caster {
private:
@@ -385,7 +382,7 @@ public:
}
}
- static PYBIND11_DESCR name() { return props::descriptor(); }
+ static constexpr auto name = props::descriptor;
// Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return
// types but not bound arguments). We still provide them (with an explicitly delete) so that
@@ -530,7 +527,7 @@ public:
}
static handle cast(const Type *src, return_value_policy policy, handle parent) { return cast(*src, policy, parent); }
- static PYBIND11_DESCR name() { return props::descriptor(); }
+ static constexpr auto name = props::descriptor;
// Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return
// types but not bound arguments). We still provide them (with an explicitly delete) so that
@@ -597,7 +594,7 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
}
PYBIND11_TYPE_CASTER(Type, _<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", "scipy.sparse.csc_matrix[")
- + npy_format_descriptor<Scalar>::name() + _("]"));
+ + npy_format_descriptor<Scalar>::name + _("]"));
};
NAMESPACE_END(detail)
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/embed.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/embed.h b/thirdparty/pybind11/include/pybind11/embed.h
index 6664967..9abc61c 100644
--- a/thirdparty/pybind11/include/pybind11/embed.h
+++ b/thirdparty/pybind11/include/pybind11/embed.h
@@ -145,7 +145,7 @@ inline void finalize_interpreter() {
// Get the internals pointer (without creating it if it doesn't exist). It's possible for the
// internals to be created during Py_Finalize() (e.g. if a py::capsule calls `get_internals()`
// during destruction), so we get the pointer-pointer here and check it after Py_Finalize().
- detail::internals **internals_ptr_ptr = &detail::get_internals_ptr();
+ detail::internals **internals_ptr_ptr = detail::get_internals_pp();
// It could also be stashed in builtins, so look there too:
if (builtins.contains(id) && isinstance<capsule>(builtins[id]))
internals_ptr_ptr = capsule(builtins[id]);
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/functional.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/functional.h b/thirdparty/pybind11/include/pybind11/functional.h
index eda14ba..9cdf21f 100644
--- a/thirdparty/pybind11/include/pybind11/functional.h
+++ b/thirdparty/pybind11/include/pybind11/functional.h
@@ -75,10 +75,8 @@ public:
return cpp_function(std::forward<Func>(f_), policy).release();
}
- PYBIND11_TYPE_CASTER(type, _("Callable[[") +
- argument_loader<Args...>::arg_names() + _("], ") +
- make_caster<retval_type>::name() +
- _("]"));
+ PYBIND11_TYPE_CASTER(type, _("Callable[[") + concat(make_caster<Args>::name...) + _("], ")
+ + make_caster<retval_type>::name + _("]"));
};
NAMESPACE_END(detail)
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/1a3136b7/thirdparty/pybind11/include/pybind11/numpy.h
----------------------------------------------------------------------
diff --git a/thirdparty/pybind11/include/pybind11/numpy.h b/thirdparty/pybind11/include/pybind11/numpy.h
index 55bb816..0d92af2 100644
--- a/thirdparty/pybind11/include/pybind11/numpy.h
+++ b/thirdparty/pybind11/include/pybind11/numpy.h
@@ -18,9 +18,9 @@
#include <cstring>
#include <sstream>
#include <string>
-#include <initializer_list>
#include <functional>
#include <utility>
+#include <vector>
#include <typeindex>
#if defined(_MSC_VER)
@@ -250,7 +250,7 @@ template <typename T> struct array_info_scalar {
typedef T type;
static constexpr bool is_array = false;
static constexpr bool is_empty = false;
- static PYBIND11_DESCR extents() { return _(""); }
+ static constexpr auto extents = _("");
static void append_extents(list& /* shape */) { }
};
// Computes underlying type and a comma-separated list of extents for array
@@ -269,15 +269,9 @@ template <typename T, size_t N> struct array_info<std::array<T, N>> {
array_info<T>::append_extents(shape);
}
- template<typename T2 = T, enable_if_t<!array_info<T2>::is_array, int> = 0>
- static PYBIND11_DESCR extents() {
- return _<N>();
- }
-
- template<typename T2 = T, enable_if_t<array_info<T2>::is_array, int> = 0>
- static PYBIND11_DESCR extents() {
- return concat(_<N>(), array_info<T>::extents());
- }
+ static constexpr auto extents = _<array_info<T>::is_array>(
+ concat(_<N>(), array_info<T>::extents), _<N>()
+ );
};
// For numpy we have special handling for arrays of characters, so we don't include
// the size in the array extents.
@@ -446,7 +440,7 @@ public:
/// This is essentially the same as calling numpy.dtype(args) in Python.
static dtype from_args(object args) {
PyObject *ptr = nullptr;
- if (!detail::npy_api::get().PyArray_DescrConverter_(args.release().ptr(), &ptr) || !ptr)
+ if (!detail::npy_api::get().PyArray_DescrConverter_(args.ptr(), &ptr) || !ptr)
throw error_already_set();
return reinterpret_steal<dtype>(ptr);
}
@@ -764,8 +758,9 @@ protected:
static std::vector<ssize_t> c_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) {
auto ndim = shape.size();
std::vector<ssize_t> strides(ndim, itemsize);
- for (size_t i = ndim - 1; i > 0; --i)
- strides[i - 1] = strides[i] * shape[i];
+ if (ndim > 0)
+ for (size_t i = ndim - 1; i > 0; --i)
+ strides[i - 1] = strides[i] * shape[i];
return strides;
}
@@ -946,9 +941,9 @@ struct format_descriptor<T, detail::enable_if_t<std::is_enum<T>::value>> {
template <typename T>
struct format_descriptor<T, detail::enable_if_t<detail::array_info<T>::is_array>> {
static std::string format() {
- using detail::_;
- PYBIND11_DESCR extents = _("(") + detail::array_info<T>::extents() + _(")");
- return extents.text() + format_descriptor<detail::remove_all_extents_t<T>>::format();
+ using namespace detail;
+ static constexpr auto extents = _("(") + array_info<T>::extents + _(")");
+ return extents.text + format_descriptor<remove_all_extents_t<T>>::format();
}
};
@@ -967,7 +962,7 @@ struct pyobject_caster<array_t<T, ExtraFlags>> {
static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) {
return src.inc_ref();
}
- PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name());
+ PYBIND11_TYPE_CASTER(type, handle_type_name<type>::name);
};
template <typename T>
@@ -977,7 +972,34 @@ struct compare_buffer_info<T, detail::enable_if_t<detail::is_pod_struct<T>::valu
}
};
-template <typename T> struct npy_format_descriptor<T, enable_if_t<satisfies_any_of<T, std::is_arithmetic, is_complex>::value>> {
+template <typename T, typename = void>
+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>("int", "uint") + _<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 || std::is_same<T, double>::value>(
+ _("float") + _<sizeof(T)*8>(), _("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
+ || std::is_same<typename T::value_type, double>::value>(
+ _("complex") + _<sizeof(typename T::value_type)*16>(), _("longcomplex")
+ );
+};
+
+template <typename T>
+struct npy_format_descriptor<T, enable_if_t<satisfies_any_of<T, std::is_arithmetic, is_complex>::value>>
+ : npy_format_descriptor_name<T> {
private:
// NB: the order here must match the one in common.h
constexpr static const int values[15] = {
@@ -996,25 +1018,10 @@ public:
return reinterpret_borrow<pybind11::dtype>(ptr);
pybind11_fail("Unsupported buffer format!");
}
- template <typename T2 = T, enable_if_t<std::is_integral<T2>::value, int> = 0>
- static PYBIND11_DESCR name() {
- return _<std::is_same<T, bool>::value>(_("bool"),
- _<std::is_signed<T>::value>("int", "uint") + _<sizeof(T)*8>());
- }
- template <typename T2 = T, enable_if_t<std::is_floating_point<T2>::value, int> = 0>
- static PYBIND11_DESCR name() {
- return _<std::is_same<T, float>::value || std::is_same<T, double>::value>(
- _("float") + _<sizeof(T)*8>(), _("longdouble"));
- }
- template <typename T2 = T, enable_if_t<is_complex<T2>::value, int> = 0>
- static PYBIND11_DESCR name() {
- return _<std::is_same<typename T2::value_type, float>::value || std::is_same<typename T2::value_type, double>::value>(
- _("complex") + _<sizeof(typename T2::value_type)*16>(), _("longcomplex"));
- }
};
#define PYBIND11_DECL_CHAR_FMT \
- static PYBIND11_DESCR name() { return _("S") + _<N>(); } \
+ static constexpr auto name = _("S") + _<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 };
@@ -1026,7 +1033,7 @@ private:
public:
static_assert(!array_info<T>::is_empty, "Zero-sized arrays are not supported");
- static PYBIND11_DESCR name() { return _("(") + array_info<T>::extents() + _(")") + base_descr::name(); }
+ static constexpr auto name = _("(") + array_info<T>::extents + _(")") + base_descr::name;
static pybind11::dtype dtype() {
list shape;
array_info<T>::append_extents(shape);
@@ -1038,7 +1045,7 @@ template<typename T> struct npy_format_descriptor<T, enable_if_t<std::is_enum<T>
private:
using base_descr = npy_format_descriptor<typename std::underlying_type<T>::type>;
public:
- static PYBIND11_DESCR name() { return base_descr::name(); }
+ static constexpr auto name = base_descr::name;
static pybind11::dtype dtype() { return base_descr::dtype(); }
};
@@ -1051,7 +1058,7 @@ struct field_descriptor {
};
inline PYBIND11_NOINLINE void register_structured_dtype(
- const std::initializer_list<field_descriptor>& fields,
+ any_container<field_descriptor> fields,
const std::type_info& tinfo, ssize_t itemsize,
bool (*direct_converter)(PyObject *, void *&)) {
@@ -1060,7 +1067,7 @@ inline PYBIND11_NOINLINE void register_structured_dtype(
pybind11_fail("NumPy: dtype is already registered");
list names, formats, offsets;
- for (auto field : fields) {
+ for (auto field : *fields) {
if (!field.descr)
pybind11_fail(std::string("NumPy: unsupported field dtype: `") +
field.name + "` @ " + tinfo.name());
@@ -1077,7 +1084,7 @@ inline PYBIND11_NOINLINE void register_structured_dtype(
// - https://github.com/numpy/numpy/pull/7798
// Because of this, we won't use numpy's logic to generate buffer format
// strings and will just do it ourselves.
- std::vector<field_descriptor> ordered_fields(fields);
+ std::vector<field_descriptor> ordered_fields(std::move(fields));
std::sort(ordered_fields.begin(), ordered_fields.end(),
[](const field_descriptor &a, const field_descriptor &b) { return a.offset < b.offset; });
ssize_t offset = 0;
@@ -1113,7 +1120,7 @@ inline PYBIND11_NOINLINE void register_structured_dtype(
template <typename T, typename SFINAE> struct npy_format_descriptor {
static_assert(is_pod_struct<T>::value, "Attempt to use a non-POD or unimplemented POD type as a numpy dtype");
- static PYBIND11_DESCR name() { return make_caster<T>::name(); }
+ static constexpr auto name = make_caster<T>::name;
static pybind11::dtype dtype() {
return reinterpret_borrow<pybind11::dtype>(dtype_ptr());
@@ -1124,8 +1131,8 @@ template <typename T, typename SFINAE> struct npy_format_descriptor {
return format_str;
}
- static void register_dtype(const std::initializer_list<field_descriptor>& fields) {
- register_structured_dtype(fields, typeid(typename std::remove_cv<T>::type),
+ static void register_dtype(any_container<field_descriptor> fields) {
+ register_structured_dtype(std::move(fields), typeid(typename std::remove_cv<T>::type),
sizeof(T), &direct_converter);
}
@@ -1198,7 +1205,8 @@ private:
#define PYBIND11_NUMPY_DTYPE(Type, ...) \
::pybind11::detail::npy_format_descriptor<Type>::register_dtype \
- ({PYBIND11_MAP_LIST (PYBIND11_FIELD_DESCRIPTOR, Type, __VA_ARGS__)})
+ (::std::vector<::pybind11::detail::field_descriptor> \
+ {PYBIND11_MAP_LIST (PYBIND11_FIELD_DESCRIPTOR, Type, __VA_ARGS__)})
#ifdef _MSC_VER
#define PYBIND11_MAP2_LIST_NEXT1(test, next) \
@@ -1219,7 +1227,8 @@ private:
#define PYBIND11_NUMPY_DTYPE_EX(Type, ...) \
::pybind11::detail::npy_format_descriptor<Type>::register_dtype \
- ({PYBIND11_MAP2_LIST (PYBIND11_FIELD_DESCRIPTOR_EX, Type, __VA_ARGS__)})
+ (::std::vector<::pybind11::detail::field_descriptor> \
+ {PYBIND11_MAP2_LIST (PYBIND11_FIELD_DESCRIPTOR_EX, Type, __VA_ARGS__)})
#endif // __CLION_IDE__
@@ -1558,9 +1567,7 @@ vectorize_extractor(const Func &f, Return (*) (Args ...)) {
}
template <typename T, int Flags> struct handle_type_name<array_t<T, Flags>> {
- static PYBIND11_DESCR name() {
- return _("numpy.ndarray[") + npy_format_descriptor<T>::name() + _("]");
- }
+ static constexpr auto name = _("numpy.ndarray[") + npy_format_descriptor<T>::name + _("]");
};
NAMESPACE_END(detail)