Commit 0d135ec8 authored by Atkins, Charles Vernon's avatar Atkins, Charles Vernon
Browse files

Merge branch 'upstream-pybind11' into update-third-party

# By PyBind11 Upstream
* upstream-pybind11:
  pybind11 2022-03-28 (42d8593a)
parents 3b9297a7 fbdf8404
Loading
Loading
Loading
Loading
+234 −111
Original line number Diff line number Diff line
@@ -12,13 +12,18 @@

#include "cast.h"

#include <functional>

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

/// \addtogroup annotations
/// @{

/// Annotation for methods
struct is_method { handle class_; is_method(const handle &c) : class_(c) { } };
struct is_method {
    handle class_;
    explicit is_method(const handle &c) : class_(c) {}
};

/// Annotation for operators
struct is_operator {};
@@ -27,26 +32,41 @@ struct is_operator { };
struct is_final {};

/// Annotation for parent scope
struct scope { handle value; scope(const handle &s) : value(s) { } };
struct scope {
    handle value;
    explicit scope(const handle &s) : value(s) {}
};

/// Annotation for documentation
struct doc { const char *value; doc(const char *value) : value(value) { } };
struct doc {
    const char *value;
    explicit doc(const char *value) : value(value) {}
};

/// Annotation for function names
struct name { const char *value; name(const char *value) : value(value) { } };
struct name {
    const char *value;
    explicit name(const char *value) : value(value) {}
};

/// Annotation indicating that a function is an overload associated with a given "sibling"
struct sibling { handle value; sibling(const handle &value) : value(value.ptr()) { } };
struct sibling {
    handle value;
    explicit sibling(const handle &value) : value(value.ptr()) {}
};

/// Annotation indicating that a class derives from another given type
template <typename T> struct base {
template <typename T>
struct base {

    PYBIND11_DEPRECATED("base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
    base() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
    PYBIND11_DEPRECATED(
        "base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
    base() = default;
};

/// Keep patient alive while nurse lives
template <size_t Nurse, size_t Patient> struct keep_alive { };
template <size_t Nurse, size_t Patient>
struct keep_alive {};

/// Annotation indicating that a class is involved in a multiple inheritance relationship
struct multiple_inheritance {};
@@ -62,14 +82,34 @@ struct metaclass {
    handle value;

    PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.")
    metaclass() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
    metaclass() = default;

    /// Override pybind11's default metaclass
    explicit metaclass(handle value) : value(value) {}
};

/// Specifies a custom callback with signature `void (PyHeapTypeObject*)` that
/// may be used to customize the Python type.
///
/// The callback is invoked immediately before `PyType_Ready`.
///
/// Note: This is an advanced interface, and uses of it may require changes to
/// work with later versions of pybind11.  You may wish to consult the
/// implementation of `make_new_python_type` in `detail/classes.h` to understand
/// the context in which the callback will be run.
struct custom_type_setup {
    using callback = std::function<void(PyHeapTypeObject *heap_type)>;

    explicit custom_type_setup(callback value) : value(std::move(value)) {}

    callback value;
};

/// Annotation that marks a class as local to the module:
struct module_local { const bool value; constexpr module_local(bool v = true) : value(v) { } };
struct module_local {
    const bool value;
    constexpr explicit module_local(bool v = true) : value(v) {}
};

/// Annotation to mark enums as an arithmetic type
struct arithmetic {};
@@ -95,9 +135,13 @@ struct prepend { };
            return foo(args...); // forwarded arguments
        });
 \endrst */
template <typename... Ts> struct call_guard;
template <typename... Ts>
struct call_guard;

template <> struct call_guard<> { using type = detail::void_type; };
template <>
struct call_guard<> {
    using type = detail::void_type;
};

template <typename T>
struct call_guard<T> {
@@ -122,8 +166,9 @@ PYBIND11_NAMESPACE_BEGIN(detail)
enum op_id : int;
enum op_type : int;
struct undefined_t;
template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t> struct op_;
inline void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret);
template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t>
struct op_;
void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret);

/// Internal data structure which holds metadata about a keyword argument
struct argument_record {
@@ -137,12 +182,13 @@ struct argument_record {
        : name(name), descr(descr), value(value), convert(convert), none(none) {}
};

/// Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
/// Internal data structure which holds metadata about a bound function (signature, overloads,
/// etc.)
struct function_record {
    function_record()
        : is_constructor(false), is_new_style_constructor(false), is_stateless(false),
          is_operator(false), is_method(false), has_args(false),
          has_kwargs(false), has_kw_only_args(false), prepend(false) { }
          is_operator(false), is_method(false), has_args(false), has_kwargs(false),
          prepend(false) {}

    /// Function name
    char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
@@ -189,17 +235,15 @@ struct function_record {
    /// True if the function has a '**kwargs' argument
    bool has_kwargs : 1;

    /// True once a 'py::kw_only' is encountered (any following args are keyword-only)
    bool has_kw_only_args : 1;

    /// True if this function is to be inserted at the beginning of the overload resolution chain
    bool prepend : 1;

    /// Number of arguments (including py::args and/or py::kwargs, if present)
    std::uint16_t nargs;

    /// Number of trailing arguments (counted in `nargs`) that are keyword-only
    std::uint16_t nargs_kw_only = 0;
    /// Number of leading positional arguments, which are terminated by a py::args or py::kwargs
    /// argument or by a py::kw_only annotation.
    std::uint16_t nargs_pos = 0;

    /// Number of leading arguments (counted in `nargs`) that are positional-only
    std::uint16_t nargs_pos_only = 0;
@@ -259,6 +303,9 @@ struct type_record {
    /// Custom metaclass (optional)
    handle metaclass;

    /// Custom type setup.
    custom_type_setup::callback custom_type_setup_callback;

    /// Multiple inheritance marker
    bool multiple_inheritance : 1;

@@ -278,35 +325,36 @@ struct type_record {
    bool is_final : 1;

    PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *) ) {
        auto base_info = detail::get_type_info(base, false);
        auto *base_info = detail::get_type_info(base, false);
        if (!base_info) {
            std::string tname(base.name());
            detail::clean_type_id(tname);
            pybind11_fail("generic_type: type \"" + std::string(name) +
                          "\" referenced unknown base type \"" + tname + "\"");
            pybind11_fail("generic_type: type \"" + std::string(name)
                          + "\" referenced unknown base type \"" + tname + "\"");
        }

        if (default_holder != base_info->default_holder) {
            std::string tname(base.name());
            detail::clean_type_id(tname);
            pybind11_fail("generic_type: type \"" + std::string(name) + "\" " +
                    (default_holder ? "does not have" : "has") +
                    " a non-default holder type while its base \"" + tname + "\" " +
                    (base_info->default_holder ? "does not" : "does"));
            pybind11_fail("generic_type: type \"" + std::string(name) + "\" "
                          + (default_holder ? "does not have" : "has")
                          + " a non-default holder type while its base \"" + tname + "\" "
                          + (base_info->default_holder ? "does not" : "does"));
        }

        bases.append((PyObject *) base_info->type);

        if (base_info->type->tp_dictoffset != 0)
        if (base_info->type->tp_dictoffset != 0) {
            dynamic_attr = true;
        }

        if (caster)
        if (caster) {
            base_info->implicit_casts.emplace_back(type, caster);
        }
    }
};

inline function_call::function_call(const function_record &f, handle p) :
        func(f), parent(p) {
inline function_call::function_call(const function_record &f, handle p) : func(f), parent(p) {
    args.reserve(f.nargs);
    args_convert.reserve(f.nargs);
}
@@ -320,9 +368,11 @@ struct is_new_style_constructor { };
 * fields in the type_record and function_record data structures or executed at
 * runtime to deal with custom call policies (e.g. keep_alive).
 */
template <typename T, typename SFINAE = void> struct process_attribute;
template <typename T, typename SFINAE = void>
struct process_attribute;

template <typename T> struct process_attribute_default {
template <typename T>
struct process_attribute_default {
    /// Default implementation: do nothing
    static void init(const T &, function_record *) {}
    static void init(const T &, type_record *) {}
@@ -331,89 +381,120 @@ template <typename T> struct process_attribute_default {
};

/// Process an attribute specifying the function's name
template <> struct process_attribute<name> : process_attribute_default<name> {
template <>
struct process_attribute<name> : process_attribute_default<name> {
    static void init(const name &n, function_record *r) { r->name = const_cast<char *>(n.value); }
};

/// Process an attribute specifying the function's docstring
template <> struct process_attribute<doc> : process_attribute_default<doc> {
template <>
struct process_attribute<doc> : process_attribute_default<doc> {
    static void init(const doc &n, function_record *r) { r->doc = const_cast<char *>(n.value); }
};

/// Process an attribute specifying the function's docstring (provided as a C-style string)
template <> struct process_attribute<const char *> : process_attribute_default<const char *> {
template <>
struct process_attribute<const char *> : process_attribute_default<const char *> {
    static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); }
    static void init(const char *d, type_record *r) { r->doc = const_cast<char *>(d); }
};
template <> struct process_attribute<char *> : process_attribute<const char *> { };
template <>
struct process_attribute<char *> : process_attribute<const char *> {};

/// Process an attribute indicating the function's return value policy
template <> struct process_attribute<return_value_policy> : process_attribute_default<return_value_policy> {
template <>
struct process_attribute<return_value_policy> : process_attribute_default<return_value_policy> {
    static void init(const return_value_policy &p, function_record *r) { r->policy = p; }
};

/// Process an attribute which indicates that this is an overloaded function associated with a given sibling
template <> struct process_attribute<sibling> : process_attribute_default<sibling> {
/// Process an attribute which indicates that this is an overloaded function associated with a
/// given sibling
template <>
struct process_attribute<sibling> : process_attribute_default<sibling> {
    static void init(const sibling &s, function_record *r) { r->sibling = s.value; }
};

/// Process an attribute which indicates that this function is a method
template <> struct process_attribute<is_method> : process_attribute_default<is_method> {
    static void init(const is_method &s, function_record *r) { r->is_method = true; r->scope = s.class_; }
template <>
struct process_attribute<is_method> : process_attribute_default<is_method> {
    static void init(const is_method &s, function_record *r) {
        r->is_method = true;
        r->scope = s.class_;
    }
};

/// Process an attribute which indicates the parent scope of a method
template <> struct process_attribute<scope> : process_attribute_default<scope> {
template <>
struct process_attribute<scope> : process_attribute_default<scope> {
    static void init(const scope &s, function_record *r) { r->scope = s.value; }
};

/// Process an attribute which indicates that this function is an operator
template <> struct process_attribute<is_operator> : process_attribute_default<is_operator> {
template <>
struct process_attribute<is_operator> : process_attribute_default<is_operator> {
    static void init(const is_operator &, function_record *r) { r->is_operator = true; }
};

template <> struct process_attribute<is_new_style_constructor> : process_attribute_default<is_new_style_constructor> {
    static void init(const is_new_style_constructor &, function_record *r) { r->is_new_style_constructor = true; }
template <>
struct process_attribute<is_new_style_constructor>
    : process_attribute_default<is_new_style_constructor> {
    static void init(const is_new_style_constructor &, function_record *r) {
        r->is_new_style_constructor = true;
    }
};

inline void process_kw_only_arg(const arg &a, function_record *r) {
    if (!a.name || strlen(a.name) == 0)
        pybind11_fail("arg(): cannot specify an unnamed argument after an kw_only() annotation");
    ++r->nargs_kw_only;
inline void check_kw_only_arg(const arg &a, function_record *r) {
    if (r->args.size() > r->nargs_pos && (!a.name || a.name[0] == '\0')) {
        pybind11_fail("arg(): cannot specify an unnamed argument after a kw_only() annotation or "
                      "args() argument");
    }
}

inline void append_self_arg_if_needed(function_record *r) {
    if (r->is_method && r->args.empty()) {
        r->args.emplace_back("self", nullptr, handle(), /*convert=*/true, /*none=*/false);
    }
}

/// Process a keyword argument attribute (*without* a default value)
template <> struct process_attribute<arg> : process_attribute_default<arg> {
template <>
struct process_attribute<arg> : process_attribute_default<arg> {
    static void init(const arg &a, function_record *r) {
        if (r->is_method && r->args.empty())
            r->args.emplace_back("self", nullptr, handle(), true /*convert*/, false /*none not allowed*/);
        append_self_arg_if_needed(r);
        r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none);

        if (r->has_kw_only_args) process_kw_only_arg(a, r);
        check_kw_only_arg(a, r);
    }
};

/// Process a keyword argument attribute (*with* a default value)
template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
template <>
struct process_attribute<arg_v> : process_attribute_default<arg_v> {
    static void init(const arg_v &a, function_record *r) {
        if (r->is_method && r->args.empty())
            r->args.emplace_back("self", nullptr /*descr*/, handle() /*parent*/, true /*convert*/, false /*none not allowed*/);
        if (r->is_method && r->args.empty()) {
            r->args.emplace_back(
                "self", /*descr=*/nullptr, /*parent=*/handle(), /*convert=*/true, /*none=*/false);
        }

        if (!a.value) {
#if !defined(NDEBUG)
            std::string descr("'");
            if (a.name) descr += std::string(a.name) + ": ";
            if (a.name) {
                descr += std::string(a.name) + ": ";
            }
            descr += a.type + "'";
            if (r->is_method) {
                if (r->name)
                    descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'";
                else
                if (r->name) {
                    descr += " in method '" + (std::string) str(r->scope) + "."
                             + (std::string) r->name + "'";
                } else {
                    descr += " in method of '" + (std::string) str(r->scope) + "'";
                }
            } else if (r->name) {
                descr += " in function '" + (std::string) r->name + "'";
            }
            pybind11_fail("arg(): could not convert default argument "
                          + descr + " into a Python object (type not registered yet?)");
            pybind11_fail("arg(): could not convert default argument " + descr
                          + " into a Python object (type not registered yet?)");
#else
            pybind11_fail("arg(): could not convert default argument "
                          "into a Python object (type not registered yet?). "
@@ -422,27 +503,41 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
        }
        r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none);

        if (r->has_kw_only_args) process_kw_only_arg(a, r);
        check_kw_only_arg(a, r);
    }
};

/// Process a keyword-only-arguments-follow pseudo argument
template <> struct process_attribute<kw_only> : process_attribute_default<kw_only> {
template <>
struct process_attribute<kw_only> : process_attribute_default<kw_only> {
    static void init(const kw_only &, function_record *r) {
        r->has_kw_only_args = true;
        append_self_arg_if_needed(r);
        if (r->has_args && r->nargs_pos != static_cast<std::uint16_t>(r->args.size())) {
            pybind11_fail("Mismatched args() and kw_only(): they must occur at the same relative "
                          "argument location (or omit kw_only() entirely)");
        }
        r->nargs_pos = static_cast<std::uint16_t>(r->args.size());
    }
};

/// Process a positional-only-argument maker
template <> struct process_attribute<pos_only> : process_attribute_default<pos_only> {
template <>
struct process_attribute<pos_only> : process_attribute_default<pos_only> {
    static void init(const pos_only &, function_record *r) {
        append_self_arg_if_needed(r);
        r->nargs_pos_only = static_cast<std::uint16_t>(r->args.size());
        if (r->nargs_pos_only > r->nargs_pos) {
            pybind11_fail("pos_only(): cannot follow a py::args() argument");
        }
        // It also can't follow a kw_only, but a static_assert in pybind11.h checks that
    }
};

/// Process a parent class attribute.  Single inheritance only (class_ itself already guarantees that)
/// Process a parent class attribute.  Single inheritance only (class_ itself already guarantees
/// that)
template <typename T>
struct process_attribute<T, enable_if_t<is_pyobject<T>::value>> : process_attribute_default<handle> {
struct process_attribute<T, enable_if_t<is_pyobject<T>::value>>
    : process_attribute_default<handle> {
    static void init(const handle &h, type_record *r) { r->bases.append(h); }
};

@@ -455,7 +550,9 @@ struct process_attribute<base<T>> : process_attribute_default<base<T>> {
/// Process a multiple inheritance attribute
template <>
struct process_attribute<multiple_inheritance> : process_attribute_default<multiple_inheritance> {
    static void init(const multiple_inheritance &, type_record *r) { r->multiple_inheritance = true; }
    static void init(const multiple_inheritance &, type_record *r) {
        r->multiple_inheritance = true;
    }
};

template <>
@@ -463,6 +560,13 @@ struct process_attribute<dynamic_attr> : process_attribute_default<dynamic_attr>
    static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; }
};

template <>
struct process_attribute<custom_type_setup> {
    static void init(const custom_type_setup &value, type_record *r) {
        r->custom_type_setup_callback = value.value;
    }
};

template <>
struct process_attribute<is_final> : process_attribute_default<is_final> {
    static void init(const is_final &, type_record *r) { r->is_final = true; }
@@ -501,34 +605,52 @@ struct process_attribute<call_guard<Ts...>> : process_attribute_default<call_gua
 * pre-call handler if both Nurse, Patient != 0 and use the post-call handler
 * otherwise
 */
template <size_t Nurse, size_t Patient> struct process_attribute<keep_alive<Nurse, Patient>> : public process_attribute_default<keep_alive<Nurse, Patient>> {
template <size_t Nurse, size_t Patient>
struct process_attribute<keep_alive<Nurse, Patient>>
    : public process_attribute_default<keep_alive<Nurse, Patient>> {
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
    static void precall(function_call &call) { keep_alive_impl(Nurse, Patient, call, handle()); }
    static void precall(function_call &call) {
        keep_alive_impl(Nurse, Patient, call, handle());
    }
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
    static void postcall(function_call &, handle) {}
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
    static void precall(function_call &) {}
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
    static void postcall(function_call &call, handle ret) { keep_alive_impl(Nurse, Patient, call, ret); }
    static void postcall(function_call &call, handle ret) {
        keep_alive_impl(Nurse, Patient, call, ret);
    }
};

/// Recursively iterate over variadic template arguments
template <typename... Args> struct process_attributes {
template <typename... Args>
struct process_attributes {
    static void init(const Args &...args, function_record *r) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
        ignore_unused(unused);
        PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
        PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r);
        using expander = int[];
        (void) expander{
            0, ((void) process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...};
    }
    static void init(const Args &...args, type_record *r) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
        ignore_unused(unused);
        PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
        PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r);
        using expander = int[];
        (void) expander{0,
                        (process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...};
    }
    static void precall(function_call &call) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::precall(call), 0) ... };
        ignore_unused(unused);
        PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call);
        using expander = int[];
        (void) expander{0,
                        (process_attribute<typename std::decay<Args>::type>::precall(call), 0)...};
    }
    static void postcall(function_call &call, handle fn_ret) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0) ... };
        ignore_unused(unused);
        PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call, fn_ret);
        PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(fn_ret);
        using expander = int[];
        (void) expander{
            0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0)...};
    }
};

@@ -544,7 +666,8 @@ template <typename... Extra,
          size_t named = constexpr_sum(std::is_base_of<arg, Extra>::value...),
          size_t self = constexpr_sum(std::is_same<is_method, Extra>::value...)>
constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
    return named == 0 || (self + named + has_args + has_kwargs) == nargs;
    PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(nargs, has_args, has_kwargs);
    return named == 0 || (self + named + size_t(has_args) + size_t(has_kwargs)) == nargs;
}

PYBIND11_NAMESPACE_END(detail)
+89 −42

File changed.

Preview size limit exceeded, changes collapsed.

+780 −1359

File changed.

Preview size limit exceeded, changes collapsed.

+104 −70

File changed.

Preview size limit exceeded, changes collapsed.

+20 −11
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#pragma once

#include "pybind11.h"

#include <complex>

/// glibc defines I as a macro which breaks things, e.g., boost template names
@@ -19,7 +20,8 @@

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
template <typename T>
struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
    static constexpr const char c = format_descriptor<T>::c;
    static constexpr const char value[3] = {'Z', c, '\0'};
    static std::string format() { return std::string(value); }
@@ -27,25 +29,31 @@ template <typename T> struct format_descriptor<std::complex<T>, detail::enable_i

#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];
template <typename T>
constexpr const char
    format_descriptor<std::complex<T>,
                      detail::enable_if_t<std::is_floating_point<T>::value>>::value[3];

#endif

PYBIND11_NAMESPACE_BEGIN(detail)

template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
template <typename T>
struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
    static constexpr bool value = true;
    static constexpr int index = is_fmt_numeric<T>::index + 3;
};

template <typename T> class type_caster<std::complex<T>> {
template <typename T>
class type_caster<std::complex<T>> {
public:
    bool load(handle src, bool convert) {
        if (!src)
        if (!src) {
            return false;
        if (!convert && !PyComplex_Check(src.ptr()))
        }
        if (!convert && !PyComplex_Check(src.ptr())) {
            return false;
        }
        Py_complex result = PyComplex_AsCComplex(src.ptr());
        if (result.real == -1.0 && PyErr_Occurred()) {
            PyErr_Clear();
@@ -55,11 +63,12 @@ public:
        return true;
    }

    static handle cast(const std::complex<T> &src, return_value_policy /* policy */, handle /* parent */) {
    static handle
    cast(const std::complex<T> &src, return_value_policy /* policy */, handle /* parent */) {
        return PyComplex_FromDoubles((double) src.real(), (double) src.imag());
    }

    PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
    PYBIND11_TYPE_CASTER(std::complex<T>, const_name("complex"));
};
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
Loading