The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') More...
#include <common.h>
Public Member Functions | |
void | allocate_layout () |
void | deallocate_layout () |
Destroys/deallocates all of the above. More... | |
value_and_holder | get_value_and_holder (const type_info *find_type=nullptr, bool throw_if_missing=true) |
Public Attributes | |
union { | |
nonsimple_values_and_holders nonsimple | |
void * simple_value_holder [1+instance_simple_holder_in_ptrs()] | |
}; | |
Storage for pointers and holder; see simple_layout, below, for a description. More... | |
bool | has_patients: 1 |
If true, get_internals().patients has an entry for this object. More... | |
bool | owned: 1 |
If true, the pointer is owned which means we're free to manage it with a holder. More... | |
bool | simple_holder_constructed: 1 |
For simple layout, tracks whether the holder has been constructed. More... | |
bool | simple_instance_registered: 1 |
For simple layout, tracks whether the instance is registered in registered_instances More... | |
bool | simple_layout: 1 |
PyObject * | weakrefs |
Weak references. More... | |
Static Public Attributes | |
static constexpr uint8_t | status_holder_constructed = 1 |
Bit values for the non-simple status flags. More... | |
static constexpr uint8_t | status_instance_registered = 2 |
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
Definition at line 499 of file wrap/pybind11/include/pybind11/detail/common.h.
PYBIND11_NOINLINE void instance::allocate_layout | ( | ) |
Initializes all of the above type/values/holders data (but not the instance values themselves)
Definition at line 410 of file type_caster_base.h.
PYBIND11_NOINLINE void instance::deallocate_layout | ( | ) |
Destroys/deallocates all of the above.
Definition at line 459 of file type_caster_base.h.
PYBIND11_NOINLINE value_and_holder instance::get_value_and_holder | ( | const type_info * | find_type = nullptr , |
bool | throw_if_missing = true |
||
) |
Returns the value_and_holder wrapper for the given type (or the first, if find_type
omitted). Returns a default-constructed (with .inst = nullptr
) object on failure if throw_if_missing
is false.
Extracts C++ value and holder pointer references from an instance (which may contain multiple values/holders for python-side multiple inheritance) that match the given type. Throws an error if the given type (or ValueType, if omitted) is not a pybind11 base of the given instance. If find_type
is omitted (or explicitly specified as nullptr) the first value/holder are returned, regardless of type (and the resulting .type will be nullptr).
The returned object should be short-lived: in particular, it must not outlive the called-upon instance.
Definition at line 380 of file type_caster_base.h.
PyObject_HEAD { ... } |
Storage for pointers and holder; see simple_layout, below, for a description.
bool instance::has_patients |
If true, get_internals().patients has an entry for this object.
Definition at line 539 of file wrap/pybind11/include/pybind11/detail/common.h.
nonsimple_values_and_holders instance::nonsimple |
Definition at line 504 of file wrap/pybind11/include/pybind11/detail/common.h.
bool instance::owned |
If true, the pointer is owned which means we're free to manage it with a holder.
Definition at line 509 of file wrap/pybind11/include/pybind11/detail/common.h.
bool instance::simple_holder_constructed |
For simple layout, tracks whether the holder has been constructed.
Definition at line 535 of file wrap/pybind11/include/pybind11/detail/common.h.
bool instance::simple_instance_registered |
For simple layout, tracks whether the instance is registered in registered_instances
Definition at line 537 of file wrap/pybind11/include/pybind11/detail/common.h.
bool instance::simple_layout |
An instance has two possible value/holder layouts.
Simple layout (when this flag is true), means the simple_value_holder
is set with a pointer and the holder object governing that pointer, i.e. [val1*][holder]. This layout is applied whenever there is no python-side multiple inheritance of bound C++ types and the type's holder will fit in the default space (which is large enough to hold either a std::unique_ptr or std::shared_ptr).
Non-simple layout applies when using custom holders that require more space than shared_ptr
(which is typically the size of two pointers), or when multiple inheritance is used on the python side. Non-simple layout allocates the required amount of memory to have multiple bound C++ classes as parents. Under this layout, nonsimple.values_and_holders
is set to a pointer to allocated space of the required space to hold a sequence of value pointers and holders followed status
, a set of bit flags (1 byte each), i.e. [val1*][holder1][val2*][holder2]...[bb...] where each [block] is rounded up to a multiple of sizeof(void *)
. nonsimple.status
is, for convenience, a pointer to the beginning of the [bb...] block (but not independently allocated).
Status bits indicate whether the associated holder is constructed (& status_holder_constructed) and whether the value pointer is registered (& status_instance_registered) in registered_instances
.
Definition at line 533 of file wrap/pybind11/include/pybind11/detail/common.h.
void* instance::simple_value_holder[1+instance_simple_holder_in_ptrs()] |
Definition at line 503 of file wrap/pybind11/include/pybind11/detail/common.h.
|
static |
Bit values for the non-simple status flags.
Definition at line 555 of file wrap/pybind11/include/pybind11/detail/common.h.
|
static |
Definition at line 556 of file wrap/pybind11/include/pybind11/detail/common.h.
PyObject* instance::weakrefs |
Weak references.
Definition at line 507 of file wrap/pybind11/include/pybind11/detail/common.h.