Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:46

0001 /*
0002     pybind11/attr.h: Infrastructure for processing custom
0003     type and function attributes
0004 
0005     Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
0006 
0007     All rights reserved. Use of this source code is governed by a
0008     BSD-style license that can be found in the LICENSE file.
0009 */
0010 
0011 #pragma once
0012 
0013 #include "detail/common.h"
0014 #include "cast.h"
0015 
0016 #include <functional>
0017 
0018 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
0019 
0020 /// \addtogroup annotations
0021 /// @{
0022 
0023 /// Annotation for methods
0024 struct is_method {
0025     handle class_;
0026     explicit is_method(const handle &c) : class_(c) {}
0027 };
0028 
0029 /// Annotation for operators
0030 struct is_operator {};
0031 
0032 /// Annotation for classes that cannot be subclassed
0033 struct is_final {};
0034 
0035 /// Annotation for parent scope
0036 struct scope {
0037     handle value;
0038     explicit scope(const handle &s) : value(s) {}
0039 };
0040 
0041 /// Annotation for documentation
0042 struct doc {
0043     const char *value;
0044     explicit doc(const char *value) : value(value) {}
0045 };
0046 
0047 /// Annotation for function names
0048 struct name {
0049     const char *value;
0050     explicit name(const char *value) : value(value) {}
0051 };
0052 
0053 /// Annotation indicating that a function is an overload associated with a given "sibling"
0054 struct sibling {
0055     handle value;
0056     explicit sibling(const handle &value) : value(value.ptr()) {}
0057 };
0058 
0059 /// Annotation indicating that a class derives from another given type
0060 template <typename T>
0061 struct base {
0062 
0063     PYBIND11_DEPRECATED(
0064         "base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
0065     base() = default;
0066 };
0067 
0068 /// Keep patient alive while nurse lives
0069 template <size_t Nurse, size_t Patient>
0070 struct keep_alive {};
0071 
0072 /// Annotation indicating that a class is involved in a multiple inheritance relationship
0073 struct multiple_inheritance {};
0074 
0075 /// Annotation which enables dynamic attributes, i.e. adds `__dict__` to a class
0076 struct dynamic_attr {};
0077 
0078 /// Annotation which enables the buffer protocol for a type
0079 struct buffer_protocol {};
0080 
0081 /// Annotation which requests that a special metaclass is created for a type
0082 struct metaclass {
0083     handle value;
0084 
0085     PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.")
0086     metaclass() = default;
0087 
0088     /// Override pybind11's default metaclass
0089     explicit metaclass(handle value) : value(value) {}
0090 };
0091 
0092 /// Specifies a custom callback with signature `void (PyHeapTypeObject*)` that
0093 /// may be used to customize the Python type.
0094 ///
0095 /// The callback is invoked immediately before `PyType_Ready`.
0096 ///
0097 /// Note: This is an advanced interface, and uses of it may require changes to
0098 /// work with later versions of pybind11.  You may wish to consult the
0099 /// implementation of `make_new_python_type` in `detail/classes.h` to understand
0100 /// the context in which the callback will be run.
0101 struct custom_type_setup {
0102     using callback = std::function<void(PyHeapTypeObject *heap_type)>;
0103 
0104     explicit custom_type_setup(callback value) : value(std::move(value)) {}
0105 
0106     callback value;
0107 };
0108 
0109 /// Annotation that marks a class as local to the module:
0110 struct module_local {
0111     const bool value;
0112     constexpr explicit module_local(bool v = true) : value(v) {}
0113 };
0114 
0115 /// Annotation to mark enums as an arithmetic type
0116 struct arithmetic {};
0117 
0118 /// Mark a function for addition at the beginning of the existing overload chain instead of the end
0119 struct prepend {};
0120 
0121 /** \rst
0122     A call policy which places one or more guard variables (``Ts...``) around the function call.
0123 
0124     For example, this definition:
0125 
0126     .. code-block:: cpp
0127 
0128         m.def("foo", foo, py::call_guard<T>());
0129 
0130     is equivalent to the following pseudocode:
0131 
0132     .. code-block:: cpp
0133 
0134         m.def("foo", [](args...) {
0135             T scope_guard;
0136             return foo(args...); // forwarded arguments
0137         });
0138  \endrst */
0139 template <typename... Ts>
0140 struct call_guard;
0141 
0142 template <>
0143 struct call_guard<> {
0144     using type = detail::void_type;
0145 };
0146 
0147 template <typename T>
0148 struct call_guard<T> {
0149     static_assert(std::is_default_constructible<T>::value,
0150                   "The guard type must be default constructible");
0151 
0152     using type = T;
0153 };
0154 
0155 template <typename T, typename... Ts>
0156 struct call_guard<T, Ts...> {
0157     struct type {
0158         T guard{}; // Compose multiple guard types with left-to-right default-constructor order
0159         typename call_guard<Ts...>::type next{};
0160     };
0161 };
0162 
0163 /// @} annotations
0164 
0165 PYBIND11_NAMESPACE_BEGIN(detail)
0166 /* Forward declarations */
0167 enum op_id : int;
0168 enum op_type : int;
0169 struct undefined_t;
0170 template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t>
0171 struct op_;
0172 void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret);
0173 
0174 /// Internal data structure which holds metadata about a keyword argument
0175 struct argument_record {
0176     const char *name;  ///< Argument name
0177     const char *descr; ///< Human-readable version of the argument value
0178     handle value;      ///< Associated Python object
0179     bool convert : 1;  ///< True if the argument is allowed to convert when loading
0180     bool none : 1;     ///< True if None is allowed when loading
0181 
0182     argument_record(const char *name, const char *descr, handle value, bool convert, bool none)
0183         : name(name), descr(descr), value(value), convert(convert), none(none) {}
0184 };
0185 
0186 /// Internal data structure which holds metadata about a bound function (signature, overloads,
0187 /// etc.)
0188 struct function_record {
0189     function_record()
0190         : is_constructor(false), is_new_style_constructor(false), is_stateless(false),
0191           is_operator(false), is_method(false), has_args(false), has_kwargs(false),
0192           prepend(false) {}
0193 
0194     /// Function name
0195     char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
0196 
0197     // User-specified documentation string
0198     char *doc = nullptr;
0199 
0200     /// Human-readable version of the function signature
0201     char *signature = nullptr;
0202 
0203     /// List of registered keyword arguments
0204     std::vector<argument_record> args;
0205 
0206     /// Pointer to lambda function which converts arguments and performs the actual call
0207     handle (*impl)(function_call &) = nullptr;
0208 
0209     /// Storage for the wrapped function pointer and captured data, if any
0210     void *data[3] = {};
0211 
0212     /// Pointer to custom destructor for 'data' (if needed)
0213     void (*free_data)(function_record *ptr) = nullptr;
0214 
0215     /// Return value policy associated with this function
0216     return_value_policy policy = return_value_policy::automatic;
0217 
0218     /// True if name == '__init__'
0219     bool is_constructor : 1;
0220 
0221     /// True if this is a new-style `__init__` defined in `detail/init.h`
0222     bool is_new_style_constructor : 1;
0223 
0224     /// True if this is a stateless function pointer
0225     bool is_stateless : 1;
0226 
0227     /// True if this is an operator (__add__), etc.
0228     bool is_operator : 1;
0229 
0230     /// True if this is a method
0231     bool is_method : 1;
0232 
0233     /// True if the function has a '*args' argument
0234     bool has_args : 1;
0235 
0236     /// True if the function has a '**kwargs' argument
0237     bool has_kwargs : 1;
0238 
0239     /// True if this function is to be inserted at the beginning of the overload resolution chain
0240     bool prepend : 1;
0241 
0242     /// Number of arguments (including py::args and/or py::kwargs, if present)
0243     std::uint16_t nargs;
0244 
0245     /// Number of leading positional arguments, which are terminated by a py::args or py::kwargs
0246     /// argument or by a py::kw_only annotation.
0247     std::uint16_t nargs_pos = 0;
0248 
0249     /// Number of leading arguments (counted in `nargs`) that are positional-only
0250     std::uint16_t nargs_pos_only = 0;
0251 
0252     /// Python method object
0253     PyMethodDef *def = nullptr;
0254 
0255     /// Python handle to the parent scope (a class or a module)
0256     handle scope;
0257 
0258     /// Python handle to the sibling function representing an overload chain
0259     handle sibling;
0260 
0261     /// Pointer to next overload
0262     function_record *next = nullptr;
0263 };
0264 
0265 /// Special data structure which (temporarily) holds metadata about a bound class
0266 struct type_record {
0267     PYBIND11_NOINLINE type_record()
0268         : multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false),
0269           default_holder(true), module_local(false), is_final(false) {}
0270 
0271     /// Handle to the parent scope
0272     handle scope;
0273 
0274     /// Name of the class
0275     const char *name = nullptr;
0276 
0277     // Pointer to RTTI type_info data structure
0278     const std::type_info *type = nullptr;
0279 
0280     /// How large is the underlying C++ type?
0281     size_t type_size = 0;
0282 
0283     /// What is the alignment of the underlying C++ type?
0284     size_t type_align = 0;
0285 
0286     /// How large is the type's holder?
0287     size_t holder_size = 0;
0288 
0289     /// The global operator new can be overridden with a class-specific variant
0290     void *(*operator_new)(size_t) = nullptr;
0291 
0292     /// Function pointer to class_<..>::init_instance
0293     void (*init_instance)(instance *, const void *) = nullptr;
0294 
0295     /// Function pointer to class_<..>::dealloc
0296     void (*dealloc)(detail::value_and_holder &) = nullptr;
0297 
0298     /// List of base classes of the newly created type
0299     list bases;
0300 
0301     /// Optional docstring
0302     const char *doc = nullptr;
0303 
0304     /// Custom metaclass (optional)
0305     handle metaclass;
0306 
0307     /// Custom type setup.
0308     custom_type_setup::callback custom_type_setup_callback;
0309 
0310     /// Multiple inheritance marker
0311     bool multiple_inheritance : 1;
0312 
0313     /// Does the class manage a __dict__?
0314     bool dynamic_attr : 1;
0315 
0316     /// Does the class implement the buffer protocol?
0317     bool buffer_protocol : 1;
0318 
0319     /// Is the default (unique_ptr) holder type used?
0320     bool default_holder : 1;
0321 
0322     /// Is the class definition local to the module shared object?
0323     bool module_local : 1;
0324 
0325     /// Is the class inheritable from python classes?
0326     bool is_final : 1;
0327 
0328     PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *) ) {
0329         auto *base_info = detail::get_type_info(base, false);
0330         if (!base_info) {
0331             std::string tname(base.name());
0332             detail::clean_type_id(tname);
0333             pybind11_fail("generic_type: type \"" + std::string(name)
0334                           + "\" referenced unknown base type \"" + tname + "\"");
0335         }
0336 
0337         if (default_holder != base_info->default_holder) {
0338             std::string tname(base.name());
0339             detail::clean_type_id(tname);
0340             pybind11_fail("generic_type: type \"" + std::string(name) + "\" "
0341                           + (default_holder ? "does not have" : "has")
0342                           + " a non-default holder type while its base \"" + tname + "\" "
0343                           + (base_info->default_holder ? "does not" : "does"));
0344         }
0345 
0346         bases.append((PyObject *) base_info->type);
0347 
0348 #if PY_VERSION_HEX < 0x030B0000
0349         dynamic_attr |= base_info->type->tp_dictoffset != 0;
0350 #else
0351         dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0;
0352 #endif
0353 
0354         if (caster) {
0355             base_info->implicit_casts.emplace_back(type, caster);
0356         }
0357     }
0358 };
0359 
0360 inline function_call::function_call(const function_record &f, handle p) : func(f), parent(p) {
0361     args.reserve(f.nargs);
0362     args_convert.reserve(f.nargs);
0363 }
0364 
0365 /// Tag for a new-style `__init__` defined in `detail/init.h`
0366 struct is_new_style_constructor {};
0367 
0368 /**
0369  * Partial template specializations to process custom attributes provided to
0370  * cpp_function_ and class_. These are either used to initialize the respective
0371  * fields in the type_record and function_record data structures or executed at
0372  * runtime to deal with custom call policies (e.g. keep_alive).
0373  */
0374 template <typename T, typename SFINAE = void>
0375 struct process_attribute;
0376 
0377 template <typename T>
0378 struct process_attribute_default {
0379     /// Default implementation: do nothing
0380     static void init(const T &, function_record *) {}
0381     static void init(const T &, type_record *) {}
0382     static void precall(function_call &) {}
0383     static void postcall(function_call &, handle) {}
0384 };
0385 
0386 /// Process an attribute specifying the function's name
0387 template <>
0388 struct process_attribute<name> : process_attribute_default<name> {
0389     static void init(const name &n, function_record *r) { r->name = const_cast<char *>(n.value); }
0390 };
0391 
0392 /// Process an attribute specifying the function's docstring
0393 template <>
0394 struct process_attribute<doc> : process_attribute_default<doc> {
0395     static void init(const doc &n, function_record *r) { r->doc = const_cast<char *>(n.value); }
0396 };
0397 
0398 /// Process an attribute specifying the function's docstring (provided as a C-style string)
0399 template <>
0400 struct process_attribute<const char *> : process_attribute_default<const char *> {
0401     static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); }
0402     static void init(const char *d, type_record *r) { r->doc = d; }
0403 };
0404 template <>
0405 struct process_attribute<char *> : process_attribute<const char *> {};
0406 
0407 /// Process an attribute indicating the function's return value policy
0408 template <>
0409 struct process_attribute<return_value_policy> : process_attribute_default<return_value_policy> {
0410     static void init(const return_value_policy &p, function_record *r) { r->policy = p; }
0411 };
0412 
0413 /// Process an attribute which indicates that this is an overloaded function associated with a
0414 /// given sibling
0415 template <>
0416 struct process_attribute<sibling> : process_attribute_default<sibling> {
0417     static void init(const sibling &s, function_record *r) { r->sibling = s.value; }
0418 };
0419 
0420 /// Process an attribute which indicates that this function is a method
0421 template <>
0422 struct process_attribute<is_method> : process_attribute_default<is_method> {
0423     static void init(const is_method &s, function_record *r) {
0424         r->is_method = true;
0425         r->scope = s.class_;
0426     }
0427 };
0428 
0429 /// Process an attribute which indicates the parent scope of a method
0430 template <>
0431 struct process_attribute<scope> : process_attribute_default<scope> {
0432     static void init(const scope &s, function_record *r) { r->scope = s.value; }
0433 };
0434 
0435 /// Process an attribute which indicates that this function is an operator
0436 template <>
0437 struct process_attribute<is_operator> : process_attribute_default<is_operator> {
0438     static void init(const is_operator &, function_record *r) { r->is_operator = true; }
0439 };
0440 
0441 template <>
0442 struct process_attribute<is_new_style_constructor>
0443     : process_attribute_default<is_new_style_constructor> {
0444     static void init(const is_new_style_constructor &, function_record *r) {
0445         r->is_new_style_constructor = true;
0446     }
0447 };
0448 
0449 inline void check_kw_only_arg(const arg &a, function_record *r) {
0450     if (r->args.size() > r->nargs_pos && (!a.name || a.name[0] == '\0')) {
0451         pybind11_fail("arg(): cannot specify an unnamed argument after a kw_only() annotation or "
0452                       "args() argument");
0453     }
0454 }
0455 
0456 inline void append_self_arg_if_needed(function_record *r) {
0457     if (r->is_method && r->args.empty()) {
0458         r->args.emplace_back("self", nullptr, handle(), /*convert=*/true, /*none=*/false);
0459     }
0460 }
0461 
0462 /// Process a keyword argument attribute (*without* a default value)
0463 template <>
0464 struct process_attribute<arg> : process_attribute_default<arg> {
0465     static void init(const arg &a, function_record *r) {
0466         append_self_arg_if_needed(r);
0467         r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none);
0468 
0469         check_kw_only_arg(a, r);
0470     }
0471 };
0472 
0473 /// Process a keyword argument attribute (*with* a default value)
0474 template <>
0475 struct process_attribute<arg_v> : process_attribute_default<arg_v> {
0476     static void init(const arg_v &a, function_record *r) {
0477         if (r->is_method && r->args.empty()) {
0478             r->args.emplace_back(
0479                 "self", /*descr=*/nullptr, /*parent=*/handle(), /*convert=*/true, /*none=*/false);
0480         }
0481 
0482         if (!a.value) {
0483 #if defined(PYBIND11_DETAILED_ERROR_MESSAGES)
0484             std::string descr("'");
0485             if (a.name) {
0486                 descr += std::string(a.name) + ": ";
0487             }
0488             descr += a.type + "'";
0489             if (r->is_method) {
0490                 if (r->name) {
0491                     descr += " in method '" + (std::string) str(r->scope) + "."
0492                              + (std::string) r->name + "'";
0493                 } else {
0494                     descr += " in method of '" + (std::string) str(r->scope) + "'";
0495                 }
0496             } else if (r->name) {
0497                 descr += " in function '" + (std::string) r->name + "'";
0498             }
0499             pybind11_fail("arg(): could not convert default argument " + descr
0500                           + " into a Python object (type not registered yet?)");
0501 #else
0502             pybind11_fail("arg(): could not convert default argument "
0503                           "into a Python object (type not registered yet?). "
0504                           "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for "
0505                           "more information.");
0506 #endif
0507         }
0508         r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none);
0509 
0510         check_kw_only_arg(a, r);
0511     }
0512 };
0513 
0514 /// Process a keyword-only-arguments-follow pseudo argument
0515 template <>
0516 struct process_attribute<kw_only> : process_attribute_default<kw_only> {
0517     static void init(const kw_only &, function_record *r) {
0518         append_self_arg_if_needed(r);
0519         if (r->has_args && r->nargs_pos != static_cast<std::uint16_t>(r->args.size())) {
0520             pybind11_fail("Mismatched args() and kw_only(): they must occur at the same relative "
0521                           "argument location (or omit kw_only() entirely)");
0522         }
0523         r->nargs_pos = static_cast<std::uint16_t>(r->args.size());
0524     }
0525 };
0526 
0527 /// Process a positional-only-argument maker
0528 template <>
0529 struct process_attribute<pos_only> : process_attribute_default<pos_only> {
0530     static void init(const pos_only &, function_record *r) {
0531         append_self_arg_if_needed(r);
0532         r->nargs_pos_only = static_cast<std::uint16_t>(r->args.size());
0533         if (r->nargs_pos_only > r->nargs_pos) {
0534             pybind11_fail("pos_only(): cannot follow a py::args() argument");
0535         }
0536         // It also can't follow a kw_only, but a static_assert in pybind11.h checks that
0537     }
0538 };
0539 
0540 /// Process a parent class attribute.  Single inheritance only (class_ itself already guarantees
0541 /// that)
0542 template <typename T>
0543 struct process_attribute<T, enable_if_t<is_pyobject<T>::value>>
0544     : process_attribute_default<handle> {
0545     static void init(const handle &h, type_record *r) { r->bases.append(h); }
0546 };
0547 
0548 /// Process a parent class attribute (deprecated, does not support multiple inheritance)
0549 template <typename T>
0550 struct process_attribute<base<T>> : process_attribute_default<base<T>> {
0551     static void init(const base<T> &, type_record *r) { r->add_base(typeid(T), nullptr); }
0552 };
0553 
0554 /// Process a multiple inheritance attribute
0555 template <>
0556 struct process_attribute<multiple_inheritance> : process_attribute_default<multiple_inheritance> {
0557     static void init(const multiple_inheritance &, type_record *r) {
0558         r->multiple_inheritance = true;
0559     }
0560 };
0561 
0562 template <>
0563 struct process_attribute<dynamic_attr> : process_attribute_default<dynamic_attr> {
0564     static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; }
0565 };
0566 
0567 template <>
0568 struct process_attribute<custom_type_setup> {
0569     static void init(const custom_type_setup &value, type_record *r) {
0570         r->custom_type_setup_callback = value.value;
0571     }
0572 };
0573 
0574 template <>
0575 struct process_attribute<is_final> : process_attribute_default<is_final> {
0576     static void init(const is_final &, type_record *r) { r->is_final = true; }
0577 };
0578 
0579 template <>
0580 struct process_attribute<buffer_protocol> : process_attribute_default<buffer_protocol> {
0581     static void init(const buffer_protocol &, type_record *r) { r->buffer_protocol = true; }
0582 };
0583 
0584 template <>
0585 struct process_attribute<metaclass> : process_attribute_default<metaclass> {
0586     static void init(const metaclass &m, type_record *r) { r->metaclass = m.value; }
0587 };
0588 
0589 template <>
0590 struct process_attribute<module_local> : process_attribute_default<module_local> {
0591     static void init(const module_local &l, type_record *r) { r->module_local = l.value; }
0592 };
0593 
0594 /// Process a 'prepend' attribute, putting this at the beginning of the overload chain
0595 template <>
0596 struct process_attribute<prepend> : process_attribute_default<prepend> {
0597     static void init(const prepend &, function_record *r) { r->prepend = true; }
0598 };
0599 
0600 /// Process an 'arithmetic' attribute for enums (does nothing here)
0601 template <>
0602 struct process_attribute<arithmetic> : process_attribute_default<arithmetic> {};
0603 
0604 template <typename... Ts>
0605 struct process_attribute<call_guard<Ts...>> : process_attribute_default<call_guard<Ts...>> {};
0606 
0607 /**
0608  * Process a keep_alive call policy -- invokes keep_alive_impl during the
0609  * pre-call handler if both Nurse, Patient != 0 and use the post-call handler
0610  * otherwise
0611  */
0612 template <size_t Nurse, size_t Patient>
0613 struct process_attribute<keep_alive<Nurse, Patient>>
0614     : public process_attribute_default<keep_alive<Nurse, Patient>> {
0615     template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
0616     static void precall(function_call &call) {
0617         keep_alive_impl(Nurse, Patient, call, handle());
0618     }
0619     template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
0620     static void postcall(function_call &, handle) {}
0621     template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
0622     static void precall(function_call &) {}
0623     template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
0624     static void postcall(function_call &call, handle ret) {
0625         keep_alive_impl(Nurse, Patient, call, ret);
0626     }
0627 };
0628 
0629 /// Recursively iterate over variadic template arguments
0630 template <typename... Args>
0631 struct process_attributes {
0632     static void init(const Args &...args, function_record *r) {
0633         PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
0634         PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r);
0635         using expander = int[];
0636         (void) expander{
0637             0, ((void) process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...};
0638     }
0639     static void init(const Args &...args, type_record *r) {
0640         PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r);
0641         PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(r);
0642         using expander = int[];
0643         (void) expander{0,
0644                         (process_attribute<typename std::decay<Args>::type>::init(args, r), 0)...};
0645     }
0646     static void precall(function_call &call) {
0647         PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call);
0648         using expander = int[];
0649         (void) expander{0,
0650                         (process_attribute<typename std::decay<Args>::type>::precall(call), 0)...};
0651     }
0652     static void postcall(function_call &call, handle fn_ret) {
0653         PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call, fn_ret);
0654         PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(fn_ret);
0655         using expander = int[];
0656         (void) expander{
0657             0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0)...};
0658     }
0659 };
0660 
0661 template <typename T>
0662 using is_call_guard = is_instantiation<call_guard, T>;
0663 
0664 /// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found)
0665 template <typename... Extra>
0666 using extract_guard_t = typename exactly_one_t<is_call_guard, call_guard<>, Extra...>::type;
0667 
0668 /// Check the number of named arguments at compile time
0669 template <typename... Extra,
0670           size_t named = constexpr_sum(std::is_base_of<arg, Extra>::value...),
0671           size_t self = constexpr_sum(std::is_same<is_method, Extra>::value...)>
0672 constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
0673     PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(nargs, has_args, has_kwargs);
0674     return named == 0 || (self + named + size_t(has_args) + size_t(has_kwargs)) == nargs;
0675 }
0676 
0677 PYBIND11_NAMESPACE_END(detail)
0678 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)