cppyabm  1.0.17
An agent-based library to integrate C++ and Python
attr.h
Go to the documentation of this file.
1 /*
2  pybind11/attr.h: Infrastructure for processing custom
3  type and function attributes
4 
5  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
6 
7  All rights reserved. Use of this source code is governed by a
8  BSD-style license that can be found in the LICENSE file.
9 */
10 
11 #pragma once
12 
13 #include "cast.h"
14 
16 
17 /// \addtogroup annotations
18 /// @{
19 
20 /// Annotation for methods
21 struct is_method { handle class_; is_method(const handle &c) : class_(c) { } };
22 
23 /// Annotation for operators
24 struct is_operator { };
25 
26 /// Annotation for classes that cannot be subclassed
27 struct is_final { };
28 
29 /// Annotation for parent scope
30 struct scope { handle value; scope(const handle &s) : value(s) { } };
31 
32 /// Annotation for documentation
33 struct doc { const char *value; doc(const char *value) : value(value) { } };
34 
35 /// Annotation for function names
36 struct name { const char *value; name(const char *value) : value(value) { } };
37 
38 /// Annotation indicating that a function is an overload associated with a given "sibling"
39 struct sibling { handle value; sibling(const handle &value) : value(value.ptr()) { } };
40 
41 /// Annotation indicating that a class derives from another given type
42 template <typename T> struct base {
43 
44  PYBIND11_DEPRECATED("base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
45  base() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
46 };
47 
48 /// Keep patient alive while nurse lives
49 template <size_t Nurse, size_t Patient> struct keep_alive { };
50 
51 /// Annotation indicating that a class is involved in a multiple inheritance relationship
53 
54 /// Annotation which enables dynamic attributes, i.e. adds `__dict__` to a class
55 struct dynamic_attr { };
56 
57 /// Annotation which enables the buffer protocol for a type
58 struct buffer_protocol { };
59 
60 /// Annotation which requests that a special metaclass is created for a type
61 struct metaclass {
63 
64  PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.")
65  metaclass() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
66 
67  /// Override pybind11's default metaclass
68  explicit metaclass(handle value) : value(value) { }
69 };
70 
71 /// Annotation that marks a class as local to the module:
72 struct module_local { const bool value; constexpr module_local(bool v = true) : value(v) { } };
73 
74 /// Annotation to mark enums as an arithmetic type
75 struct arithmetic { };
76 
77 /// Mark a function for addition at the beginning of the existing overload chain instead of the end
78 struct prepend { };
79 
80 /** \rst
81  A call policy which places one or more guard variables (``Ts...``) around the function call.
82 
83  For example, this definition:
84 
85  .. code-block:: cpp
86 
87  m.def("foo", foo, py::call_guard<T>());
88 
89  is equivalent to the following pseudocode:
90 
91  .. code-block:: cpp
92 
93  m.def("foo", [](args...) {
94  T scope_guard;
95  return foo(args...); // forwarded arguments
96  });
97  \endrst */
98 template <typename... Ts> struct call_guard;
99 
100 template <> struct call_guard<> { using type = detail::void_type; };
101 
102 template <typename T>
103 struct call_guard<T> {
105  "The guard type must be default constructible");
106 
107  using type = T;
108 };
109 
110 template <typename T, typename... Ts>
111 struct call_guard<T, Ts...> {
112  struct type {
113  T guard{}; // Compose multiple guard types with left-to-right default-constructor order
114  typename call_guard<Ts...>::type next{};
115  };
116 };
117 
118 /// @} annotations
119 
121 /* Forward declarations */
122 enum op_id : int;
123 enum op_type : int;
124 struct undefined_t;
125 template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t> struct op_;
126 inline void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret);
127 
128 /// Internal data structure which holds metadata about a keyword argument
130  const char *name; ///< Argument name
131  const char *descr; ///< Human-readable version of the argument value
132  handle value; ///< Associated Python object
133  bool convert : 1; ///< True if the argument is allowed to convert when loading
134  bool none : 1; ///< True if None is allowed when loading
135 
136  argument_record(const char *name, const char *descr, handle value, bool convert, bool none)
138 };
139 
140 /// Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
143  : is_constructor(false), is_new_style_constructor(false), is_stateless(false),
144  is_operator(false), is_method(false), has_args(false),
145  has_kwargs(false), has_kw_only_args(false), prepend(false) { }
146 
147  /// Function name
148  char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
149 
150  // User-specified documentation string
151  char *doc = nullptr;
152 
153  /// Human-readable version of the function signature
154  char *signature = nullptr;
155 
156  /// List of registered keyword arguments
157  std::vector<argument_record> args;
158 
159  /// Pointer to lambda function which converts arguments and performs the actual call
160  handle (*impl) (function_call &) = nullptr;
161 
162  /// Storage for the wrapped function pointer and captured data, if any
163  void *data[3] = { };
164 
165  /// Pointer to custom destructor for 'data' (if needed)
166  void (*free_data) (function_record *ptr) = nullptr;
167 
168  /// Return value policy associated with this function
169  return_value_policy policy = return_value_policy::automatic;
170 
171  /// True if name == '__init__'
172  bool is_constructor : 1;
173 
174  /// True if this is a new-style `__init__` defined in `detail/init.h`
176 
177  /// True if this is a stateless function pointer
178  bool is_stateless : 1;
179 
180  /// True if this is an operator (__add__), etc.
181  bool is_operator : 1;
182 
183  /// True if this is a method
184  bool is_method : 1;
185 
186  /// True if the function has a '*args' argument
187  bool has_args : 1;
188 
189  /// True if the function has a '**kwargs' argument
190  bool has_kwargs : 1;
191 
192  /// True once a 'py::kw_only' is encountered (any following args are keyword-only)
194 
195  /// True if this function is to be inserted at the beginning of the overload resolution chain
196  bool prepend : 1;
197 
198  /// Number of arguments (including py::args and/or py::kwargs, if present)
199  std::uint16_t nargs;
200 
201  /// Number of trailing arguments (counted in `nargs`) that are keyword-only
202  std::uint16_t nargs_kw_only = 0;
203 
204  /// Number of leading arguments (counted in `nargs`) that are positional-only
205  std::uint16_t nargs_pos_only = 0;
206 
207  /// Python method object
208  PyMethodDef *def = nullptr;
209 
210  /// Python handle to the parent scope (a class or a module)
212 
213  /// Python handle to the sibling function representing an overload chain
215 
216  /// Pointer to next overload
217  function_record *next = nullptr;
218 };
219 
220 /// Special data structure which (temporarily) holds metadata about a bound class
221 struct type_record {
223  : multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false),
224  default_holder(true), module_local(false), is_final(false) { }
225 
226  /// Handle to the parent scope
228 
229  /// Name of the class
230  const char *name = nullptr;
231 
232  // Pointer to RTTI type_info data structure
233  const std::type_info *type = nullptr;
234 
235  /// How large is the underlying C++ type?
236  size_t type_size = 0;
237 
238  /// What is the alignment of the underlying C++ type?
239  size_t type_align = 0;
240 
241  /// How large is the type's holder?
242  size_t holder_size = 0;
243 
244  /// The global operator new can be overridden with a class-specific variant
245  void *(*operator_new)(size_t) = nullptr;
246 
247  /// Function pointer to class_<..>::init_instance
248  void (*init_instance)(instance *, const void *) = nullptr;
249 
250  /// Function pointer to class_<..>::dealloc
251  void (*dealloc)(detail::value_and_holder &) = nullptr;
252 
253  /// List of base classes of the newly created type
255 
256  /// Optional docstring
257  const char *doc = nullptr;
258 
259  /// Custom metaclass (optional)
261 
262  /// Multiple inheritance marker
264 
265  /// Does the class manage a __dict__?
266  bool dynamic_attr : 1;
267 
268  /// Does the class implement the buffer protocol?
269  bool buffer_protocol : 1;
270 
271  /// Is the default (unique_ptr) holder type used?
272  bool default_holder : 1;
273 
274  /// Is the class definition local to the module shared object?
275  bool module_local : 1;
276 
277  /// Is the class inheritable from python classes?
278  bool is_final : 1;
279 
280  PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *)) {
281  auto base_info = detail::get_type_info(base, false);
282  if (!base_info) {
283  std::string tname(base.name());
284  detail::clean_type_id(tname);
285  pybind11_fail("generic_type: type \"" + std::string(name) +
286  "\" referenced unknown base type \"" + tname + "\"");
287  }
288 
289  if (default_holder != base_info->default_holder) {
290  std::string tname(base.name());
291  detail::clean_type_id(tname);
292  pybind11_fail("generic_type: type \"" + std::string(name) + "\" " +
293  (default_holder ? "does not have" : "has") +
294  " a non-default holder type while its base \"" + tname + "\" " +
295  (base_info->default_holder ? "does not" : "does"));
296  }
297 
298  bases.append((PyObject *) base_info->type);
299 
300  if (base_info->type->tp_dictoffset != 0)
301  dynamic_attr = true;
302 
303  if (caster)
304  base_info->implicit_casts.emplace_back(type, caster);
305  }
306 };
307 
309  func(f), parent(p) {
310  args.reserve(f.nargs);
311  args_convert.reserve(f.nargs);
312 }
313 
314 /// Tag for a new-style `__init__` defined in `detail/init.h`
316 
317 /**
318  * Partial template specializations to process custom attributes provided to
319  * cpp_function_ and class_. These are either used to initialize the respective
320  * fields in the type_record and function_record data structures or executed at
321  * runtime to deal with custom call policies (e.g. keep_alive).
322  */
323 template <typename T, typename SFINAE = void> struct process_attribute;
324 
325 template <typename T> struct process_attribute_default {
326  /// Default implementation: do nothing
327  static void init(const T &, function_record *) { }
328  static void init(const T &, type_record *) { }
329  static void precall(function_call &) { }
330  static void postcall(function_call &, handle) { }
331 };
332 
333 /// Process an attribute specifying the function's name
334 template <> struct process_attribute<name> : process_attribute_default<name> {
335  static void init(const name &n, function_record *r) { r->name = const_cast<char *>(n.value); }
336 };
337 
338 /// Process an attribute specifying the function's docstring
339 template <> struct process_attribute<doc> : process_attribute_default<doc> {
340  static void init(const doc &n, function_record *r) { r->doc = const_cast<char *>(n.value); }
341 };
342 
343 /// Process an attribute specifying the function's docstring (provided as a C-style string)
344 template <> struct process_attribute<const char *> : process_attribute_default<const char *> {
345  static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); }
346  static void init(const char *d, type_record *r) { r->doc = const_cast<char *>(d); }
347 };
348 template <> struct process_attribute<char *> : process_attribute<const char *> { };
349 
350 /// Process an attribute indicating the function's return value policy
351 template <> struct process_attribute<return_value_policy> : process_attribute_default<return_value_policy> {
352  static void init(const return_value_policy &p, function_record *r) { r->policy = p; }
353 };
354 
355 /// Process an attribute which indicates that this is an overloaded function associated with a given sibling
356 template <> struct process_attribute<sibling> : process_attribute_default<sibling> {
357  static void init(const sibling &s, function_record *r) { r->sibling = s.value; }
358 };
359 
360 /// Process an attribute which indicates that this function is a method
361 template <> struct process_attribute<is_method> : process_attribute_default<is_method> {
362  static void init(const is_method &s, function_record *r) { r->is_method = true; r->scope = s.class_; }
363 };
364 
365 /// Process an attribute which indicates the parent scope of a method
366 template <> struct process_attribute<scope> : process_attribute_default<scope> {
367  static void init(const scope &s, function_record *r) { r->scope = s.value; }
368 };
369 
370 /// Process an attribute which indicates that this function is an operator
371 template <> struct process_attribute<is_operator> : process_attribute_default<is_operator> {
372  static void init(const is_operator &, function_record *r) { r->is_operator = true; }
373 };
374 
375 template <> struct process_attribute<is_new_style_constructor> : process_attribute_default<is_new_style_constructor> {
377 };
378 
379 inline void process_kw_only_arg(const arg &a, function_record *r) {
380  if (!a.name || strlen(a.name) == 0)
381  pybind11_fail("arg(): cannot specify an unnamed argument after an kw_only() annotation");
382  ++r->nargs_kw_only;
383 }
384 
385 /// Process a keyword argument attribute (*without* a default value)
386 template <> struct process_attribute<arg> : process_attribute_default<arg> {
387  static void init(const arg &a, function_record *r) {
388  if (r->is_method && r->args.empty())
389  r->args.emplace_back("self", nullptr, handle(), true /*convert*/, false /*none not allowed*/);
390  r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none);
391 
393  }
394 };
395 
396 /// Process a keyword argument attribute (*with* a default value)
397 template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
398  static void init(const arg_v &a, function_record *r) {
399  if (r->is_method && r->args.empty())
400  r->args.emplace_back("self", nullptr /*descr*/, handle() /*parent*/, true /*convert*/, false /*none not allowed*/);
401 
402  if (!a.value) {
403 #if !defined(NDEBUG)
404  std::string descr("'");
405  if (a.name) descr += std::string(a.name) + ": ";
406  descr += a.type + "'";
407  if (r->is_method) {
408  if (r->name)
409  descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'";
410  else
411  descr += " in method of '" + (std::string) str(r->scope) + "'";
412  } else if (r->name) {
413  descr += " in function '" + (std::string) r->name + "'";
414  }
415  pybind11_fail("arg(): could not convert default argument "
416  + descr + " into a Python object (type not registered yet?)");
417 #else
418  pybind11_fail("arg(): could not convert default argument "
419  "into a Python object (type not registered yet?). "
420  "Compile in debug mode for more information.");
421 #endif
422  }
423  r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none);
424 
426  }
427 };
428 
429 /// Process a keyword-only-arguments-follow pseudo argument
430 template <> struct process_attribute<kw_only> : process_attribute_default<kw_only> {
431  static void init(const kw_only &, function_record *r) {
432  r->has_kw_only_args = true;
433  }
434 };
435 
436 /// Process a positional-only-argument maker
437 template <> struct process_attribute<pos_only> : process_attribute_default<pos_only> {
438  static void init(const pos_only &, function_record *r) {
439  r->nargs_pos_only = static_cast<std::uint16_t>(r->args.size());
440  }
441 };
442 
443 /// Process a parent class attribute. Single inheritance only (class_ itself already guarantees that)
444 template <typename T>
446  static void init(const handle &h, type_record *r) { r->bases.append(h); }
447 };
448 
449 /// Process a parent class attribute (deprecated, does not support multiple inheritance)
450 template <typename T>
452  static void init(const base<T> &, type_record *r) { r->add_base(typeid(T), nullptr); }
453 };
454 
455 /// Process a multiple inheritance attribute
456 template <>
458  static void init(const multiple_inheritance &, type_record *r) { r->multiple_inheritance = true; }
459 };
460 
461 template <>
463  static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; }
464 };
465 
466 template <>
468  static void init(const is_final &, type_record *r) { r->is_final = true; }
469 };
470 
471 template <>
473  static void init(const buffer_protocol &, type_record *r) { r->buffer_protocol = true; }
474 };
475 
476 template <>
478  static void init(const metaclass &m, type_record *r) { r->metaclass = m.value; }
479 };
480 
481 template <>
483  static void init(const module_local &l, type_record *r) { r->module_local = l.value; }
484 };
485 
486 /// Process a 'prepend' attribute, putting this at the beginning of the overload chain
487 template <>
489  static void init(const prepend &, function_record *r) { r->prepend = true; }
490 };
491 
492 /// Process an 'arithmetic' attribute for enums (does nothing here)
493 template <>
495 
496 template <typename... Ts>
497 struct process_attribute<call_guard<Ts...>> : process_attribute_default<call_guard<Ts...>> { };
498 
499 /**
500  * Process a keep_alive call policy -- invokes keep_alive_impl during the
501  * pre-call handler if both Nurse, Patient != 0 and use the post-call handler
502  * otherwise
503  */
504 template <size_t Nurse, size_t Patient> struct process_attribute<keep_alive<Nurse, Patient>> : public process_attribute_default<keep_alive<Nurse, Patient>> {
505  template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
506  static void precall(function_call &call) { keep_alive_impl(Nurse, Patient, call, handle()); }
507  template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
508  static void postcall(function_call &, handle) { }
509  template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
510  static void precall(function_call &) { }
511  template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
512  static void postcall(function_call &call, handle ret) { keep_alive_impl(Nurse, Patient, call, ret); }
513 };
514 
515 /// Recursively iterate over variadic template arguments
516 template <typename... Args> struct process_attributes {
517  static void init(const Args&... args, function_record *r) {
518  int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
519  ignore_unused(unused);
520  }
521  static void init(const Args&... args, type_record *r) {
522  int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
523  ignore_unused(unused);
524  }
525  static void precall(function_call &call) {
526  int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::precall(call), 0) ... };
527  ignore_unused(unused);
528  }
529  static void postcall(function_call &call, handle fn_ret) {
530  int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0) ... };
531  ignore_unused(unused);
532  }
533 };
534 
535 template <typename T>
537 
538 /// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found)
539 template <typename... Extra>
541 
542 /// Check the number of named arguments at compile time
543 template <typename... Extra,
546 constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
547  return named == 0 || (self + named + size_t(has_args) + size_t(has_kwargs)) == nargs;
548 }
549 
buffer_protocol
Annotation which enables the buffer protocol for a type.
Definition: attr.h:58
type_record::doc
const char * doc
Optional docstring.
Definition: attr.h:257
function_record::is_new_style_constructor
bool is_new_style_constructor
True if this is a new-style __init__ defined in detail/init.h
Definition: attr.h:175
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: common.h:504
process_attribute< arg >::init
static void init(const arg &a, function_record *r)
Definition: attr.h:387
process_attribute< doc >::init
static void init(const doc &n, function_record *r)
Definition: attr.h:340
process_attribute_default
Definition: attr.h:325
is_instantiation
Definition: common.h:669
function_record::has_kw_only_args
bool has_kw_only_args
True once a 'py::kw_only' is encountered (any following args are keyword-only)
Definition: attr.h:193
name
Annotation for function names.
Definition: attr.h:36
function_record
Internal data structure which holds metadata about a bound function (signature, overloads,...
Definition: attr.h:141
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: common.h:16
base
Annotation indicating that a class derives from another given type.
Definition: attr.h:42
process_attribute< dynamic_attr >::init
static void init(const dynamic_attr &, type_record *r)
Definition: attr.h:463
function_record::scope
handle scope
Python handle to the parent scope (a class or a module)
Definition: attr.h:211
process_attributes::init
static void init(const Args &... args, type_record *r)
Definition: attr.h:521
cast.h
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: common.h:17
ignore_unused
void ignore_unused(const int *)
Ignore that a variable is unused in compiler warnings.
Definition: common.h:712
process_attribute< name >::init
static void init(const name &n, function_record *r)
Definition: attr.h:335
function_record::sibling
handle sibling
Python handle to the sibling function representing an overload chain.
Definition: attr.h:214
sibling::value
handle value
Definition: attr.h:39
scope
Annotation for parent scope.
Definition: attr.h:30
PYBIND11_NAMESPACE
#define PYBIND11_NAMESPACE
Definition: common.h:26
process_attributes::init
static void init(const Args &... args, function_record *r)
Definition: attr.h:517
function_record::nargs
std::uint16_t nargs
Number of arguments (including py::args and/or py::kwargs, if present)
Definition: attr.h:199
list
Definition: pytypes.h:1345
type_record::dynamic_attr
bool dynamic_attr
Does the class manage a dict?
Definition: attr.h:266
process_attribute< return_value_policy >::init
static void init(const return_value_policy &p, function_record *r)
Definition: attr.h:352
multiple_inheritance
Annotation indicating that a class is involved in a multiple inheritance relationship.
Definition: attr.h:52
is_final
Annotation for classes that cannot be subclassed.
Definition: attr.h:27
is_operator
Annotation for operators.
Definition: attr.h:24
PYBIND11_DEPRECATED
#define PYBIND11_DEPRECATED(reason)
Definition: common.h:94
clean_type_id
PYBIND11_NOINLINE void clean_type_id(std::string &name)
Definition: typeid.h:32
process_attribute< arg_v >::init
static void init(const arg_v &a, function_record *r)
Definition: attr.h:398
argument_record::argument_record
argument_record(const char *name, const char *descr, handle value, bool convert, bool none)
Definition: attr.h:136
process_attribute< const char * >::init
static void init(const char *d, function_record *r)
Definition: attr.h:345
handle::inc_ref
const handle & inc_ref() const &
Definition: pytypes.h:192
process_attribute< metaclass >::init
static void init(const metaclass &m, type_record *r)
Definition: attr.h:478
process_attribute< keep_alive< Nurse, Patient > >::postcall
static void postcall(function_call &, handle)
Definition: attr.h:508
is_method::class_
handle class_
Definition: attr.h:21
PYBIND11_NOINLINE
#define PYBIND11_NOINLINE
Definition: common.h:88
module_local::module_local
constexpr module_local(bool v=true)
Definition: attr.h:72
module_local::value
const bool value
Definition: attr.h:72
type
Definition: pytypes.h:915
metaclass::value
handle value
Definition: attr.h:62
function_record::has_kwargs
bool has_kwargs
True if the function has a '**kwargs' argument.
Definition: attr.h:190
function_call::function_call
function_call(const function_record &f, handle p)
Definition: attr.h:308
type_record::init_instance
void(* init_instance)(instance *, const void *)
Function pointer to class_<..>::init_instance.
Definition: attr.h:248
constexpr_sum
constexpr size_t constexpr_sum()
Compile-time integer sum.
Definition: common.h:589
argument_record::value
handle value
Associated Python object.
Definition: attr.h:132
doc::doc
doc(const char *value)
Definition: attr.h:33
op_
Operator implementation generator.
Definition: operators.h:53
function_record::policy
return_value_policy policy
Return value policy associated with this function.
Definition: attr.h:169
type_record::holder_size
size_t holder_size
How large is the type's holder?
Definition: attr.h:242
op_id
op_id
Enumeration with all supported operator types.
Definition: operators.h:25
is_method
Annotation for methods.
Definition: attr.h:21
arithmetic
Annotation to mark enums as an arithmetic type.
Definition: attr.h:75
function_record::data
void * data[3]
Storage for the wrapped function pointer and captured data, if any.
Definition: attr.h:163
descr
Definition: descr.h:25
process_attribute< T, enable_if_t< is_pyobject< T >::value > >::init
static void init(const handle &h, type_record *r)
Definition: attr.h:446
function_record::def
PyMethodDef * def
Python method object.
Definition: attr.h:208
type_record::module_local
bool module_local
Is the class definition local to the module shared object?
Definition: attr.h:275
process_kw_only_arg
void process_kw_only_arg(const arg &a, function_record *r)
Definition: attr.h:379
process_attribute
Definition: attr.h:323
argument_record
Internal data structure which holds metadata about a keyword argument.
Definition: attr.h:129
type_record::default_holder
bool default_holder
Is the default (unique_ptr) holder type used?
Definition: attr.h:272
instance
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition: common.h:437
function_call
Internal data associated with a single function call.
Definition: cast.h:1989
argument_record::name
const char * name
Argument name.
Definition: attr.h:130
prepend
Mark a function for addition at the beginning of the existing overload chain instead of the end.
Definition: attr.h:78
sibling
Annotation indicating that a function is an overload associated with a given "sibling".
Definition: attr.h:39
type_record::metaclass
handle metaclass
Custom metaclass (optional)
Definition: attr.h:260
process_attribute_default::init
static void init(const T &, type_record *)
Definition: attr.h:328
arg_v::type
std::string type
The C++ type name of the default value (only available when compiled in debug mode)
Definition: cast.h:1956
argument_record::convert
bool convert
True if the argument is allowed to convert when loading.
Definition: attr.h:133
doc
Annotation for documentation.
Definition: attr.h:33
type_record::multiple_inheritance
bool multiple_inheritance
Multiple inheritance marker.
Definition: attr.h:263
arg::name
const char * name
If non-null, this is a named kwargs argument.
Definition: cast.h:1905
dynamic_attr
Annotation which enables dynamic attributes, i.e. adds __dict__ to a class.
Definition: attr.h:55
class_
Definition: pybind11.h:1243
process_attribute< keep_alive< Nurse, Patient > >::precall
static void precall(function_call &)
Definition: attr.h:510
function_record::is_method
bool is_method
True if this is a method.
Definition: attr.h:184
undefined_t
Type for an unused type slot.
Definition: operators.h:44
handle
Definition: pytypes.h:176
process_attribute< pos_only >::init
static void init(const pos_only &, function_record *r)
Definition: attr.h:438
arg_v::value
object value
The default value.
Definition: cast.h:1951
function_record::impl
handle(* impl)(function_call &)
Pointer to lambda function which converts arguments and performs the actual call.
Definition: attr.h:160
arg_v
Definition: cast.h:1912
process_attribute< kw_only >::init
static void init(const kw_only &, function_record *r)
Definition: attr.h:431
name::value
const char * value
Definition: attr.h:36
type_record::bases
list bases
List of base classes of the newly created type.
Definition: attr.h:254
extract_guard_t
typename exactly_one_t< is_call_guard, call_guard<>, Extra... >::type extract_guard_t
Extract the type from the first call_guard in Extras... (or void_type if none found)
Definition: attr.h:540
is_new_style_constructor
Tag for a new-style __init__ defined in detail/init.h
Definition: attr.h:315
metaclass
Annotation which requests that a special metaclass is created for a type.
Definition: attr.h:61
process_attribute< const char * >
Process an attribute specifying the function's docstring (provided as a C-style string)
Definition: attr.h:344
function_record::nargs_kw_only
std::uint16_t nargs_kw_only
Number of trailing arguments (counted in nargs) that are keyword-only.
Definition: attr.h:202
arg::flag_noconvert
bool flag_noconvert
If set, do not allow conversion (requires a supporting type caster!)
Definition: cast.h:1906
function_record::signature
char * signature
Human-readable version of the function signature.
Definition: attr.h:154
function_record::prepend
bool prepend
True if this function is to be inserted at the beginning of the overload resolution chain.
Definition: attr.h:196
type_record
Special data structure which (temporarily) holds metadata about a bound class.
Definition: attr.h:221
arg
Definition: cast.h:1895
module_local
Annotation that marks a class as local to the module:
Definition: attr.h:72
process_attribute< prepend >::init
static void init(const prepend &, function_record *r)
Definition: attr.h:489
process_attribute< is_method >::init
static void init(const is_method &s, function_record *r)
Definition: attr.h:362
process_attributes::postcall
static void postcall(function_call &call, handle fn_ret)
Definition: attr.h:529
process_attribute< is_new_style_constructor >::init
static void init(const is_new_style_constructor &, function_record *r)
Definition: attr.h:376
keep_alive
Keep patient alive while nurse lives.
Definition: attr.h:49
function_record::nargs_pos_only
std::uint16_t nargs_pos_only
Number of leading arguments (counted in nargs) that are positional-only.
Definition: attr.h:205
function_record::is_constructor
bool is_constructor
True if name == 'init'.
Definition: attr.h:172
process_attribute< is_operator >::init
static void init(const is_operator &, function_record *r)
Definition: attr.h:372
type_record::add_base
PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *))
Definition: attr.h:280
arg::flag_none
bool flag_none
If set (the default), allow None to be passed to this argument.
Definition: cast.h:1907
policy
Definition: policy.py:1
function_record::next
function_record * next
Pointer to next overload.
Definition: attr.h:217
argument_record::descr
const char * descr
Human-readable version of the argument value.
Definition: attr.h:131
process_attribute_default::precall
static void precall(function_call &)
Definition: attr.h:329
scope::scope
scope(const handle &s)
Definition: attr.h:30
function_record::doc
char * doc
Definition: attr.h:151
kw_only
Definition: cast.h:1963
argument_record::none
bool none
True if None is allowed when loading.
Definition: attr.h:134
size_t
std::size_t size_t
Definition: common.h:354
function_record::has_args
bool has_args
True if the function has a '*args' argument.
Definition: attr.h:187
pybind11_fail
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Definition: common.h:751
str
Definition: pytypes.h:946
function_record::is_stateless
bool is_stateless
True if this is a stateless function pointer.
Definition: attr.h:178
exactly_one_t
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
Definition: common.h:634
type_record::is_final
bool is_final
Is the class inheritable from python classes?
Definition: attr.h:278
function_record::is_operator
bool is_operator
True if this is an operator (add), etc.
Definition: attr.h:181
arg_v::descr
const char * descr
The (optional) description of the default value.
Definition: cast.h:1953
process_attributes
Recursively iterate over variadic template arguments.
Definition: attr.h:516
call_guard
Definition: attr.h:98
benchmark.nargs
nargs
Definition: benchmark.py:8
list::append
void append(T &&val) const
Definition: pytypes.h:1357
function_record::args
std::vector< argument_record > args
List of registered keyword arguments.
Definition: attr.h:157
handle::ptr
PyObject * ptr() const
Return the underlying PyObject * pointer.
Definition: pytypes.h:184
type_record::dealloc
void(* dealloc)(detail::value_and_holder &)
Function pointer to class_<..>::dealloc.
Definition: attr.h:251
args
Definition: pytypes.h:1366
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: common.h:357
metaclass::metaclass
metaclass(handle value)
Override pybind11's default metaclass.
Definition: attr.h:68
doc::value
const char * value
Definition: attr.h:33
process_attribute< scope >::init
static void init(const scope &s, function_record *r)
Definition: attr.h:367
process_attribute_default::init
static void init(const T &, function_record *)
Default implementation: do nothing.
Definition: attr.h:327
is_pyobject
std::is_base_of< pyobject_tag, remove_reference_t< T > > is_pyobject
Definition: pytypes.h:48
process_attribute< base< T > >::init
static void init(const base< T > &, type_record *r)
Definition: attr.h:452
function_record::free_data
void(* free_data)(function_record *ptr)
Pointer to custom destructor for 'data' (if needed)
Definition: attr.h:166
process_attribute< buffer_protocol >::init
static void init(const buffer_protocol &, type_record *r)
Definition: attr.h:473
name::name
name(const char *value)
Definition: attr.h:36
function_record::function_record
function_record()
Definition: attr.h:142
type_record::type_align
size_t type_align
What is the alignment of the underlying C++ type?
Definition: attr.h:239
keep_alive_impl
void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret)
Definition: pybind11.h:1846
pos_only
Definition: cast.h:1968
type_record::scope
handle scope
Handle to the parent scope.
Definition: attr.h:227
process_attribute< keep_alive< Nurse, Patient > >::precall
static void precall(function_call &call)
Definition: attr.h:506
type_record::buffer_protocol
bool buffer_protocol
Does the class implement the buffer protocol?
Definition: attr.h:269
process_attribute< const char * >::init
static void init(const char *d, type_record *r)
Definition: attr.h:346
process_attribute< module_local >::init
static void init(const module_local &l, type_record *r)
Definition: attr.h:483
type_record::type_size
size_t type_size
How large is the underlying C++ type?
Definition: attr.h:236
function_record::name
char * name
Function name.
Definition: attr.h:148
sibling::sibling
sibling(const handle &value)
Definition: attr.h:39
process_attribute< sibling >::init
static void init(const sibling &s, function_record *r)
Definition: attr.h:357
type_record::type_record
PYBIND11_NOINLINE type_record()
Definition: attr.h:222
process_attributes::precall
static void precall(function_call &call)
Definition: attr.h:525
scope::value
handle value
Definition: attr.h:30
process_attribute< is_final >::init
static void init(const is_final &, type_record *r)
Definition: attr.h:468
none
Definition: pytypes.h:1075
expected_num_args
constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs)
Check the number of named arguments at compile time.
Definition: attr.h:546
is_method::is_method
is_method(const handle &c)
Definition: attr.h:21
process_attribute_default::postcall
static void postcall(function_call &, handle)
Definition: attr.h:330
test_async.m
m
Definition: test_async.py:5
process_attribute< keep_alive< Nurse, Patient > >::postcall
static void postcall(function_call &call, handle ret)
Definition: attr.h:512
test_callbacks.value
value
Definition: test_callbacks.py:126
op_type
op_type
Definition: operators.h:34
process_attribute< multiple_inheritance >::init
static void init(const multiple_inheritance &, type_record *r)
Definition: attr.h:458
function_call::args_convert
std::vector< bool > args_convert
The convert value the arguments should be loaded with.
Definition: cast.h:1999
get_type_info
PYBIND11_NOINLINE detail::type_info * get_type_info(PyTypeObject *type)
Definition: cast.h:164