Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/pybind11/attr.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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