μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
instance Struct Reference

The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') More...

#include </builds/ipbus/ipbus-software/uhal/python/pybind11-python2/include/pybind11/detail/common.h>

Collaboration diagram for instance:
[legend]

Public Member Functions

void allocate_layout ()
 Initializes all of the above type/values/holders data (but not the instance values themselves) More...
 
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)
 Returns the value_and_holder wrapper for the given type (or the first, if find_type omitted). More...
 
void allocate_layout ()
 Initializes all of the above type/values/holders data (but not the instance values themselves) More...
 
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)
 Returns the value_and_holder wrapper for the given type (or the first, if find_type omitted). More...
 

Public Attributes

union {
   void *   simple_value_holder [1+instance_simple_holder_in_ptrs()]
 
   nonsimple_values_and_holders   nonsimple
 
}; 
 Storage for pointers and holder; see simple_layout, below, for a description. More...
 
PyObject * weakrefs
 Weak references. More...
 
bool owned: 1
 If true, the pointer is owned which means we're free to manage it with a holder. More...
 
bool simple_layout: 1
 An instance has two possible value/holder layouts. 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 has_patients: 1
 If true, get_internals().patients has an entry for this object. More...
 
union {
   void *   simple_value_holder [1+instance_simple_holder_in_ptrs()]
 
   nonsimple_values_and_holders   nonsimple
 
}; 
 Storage for pointers and holder; see simple_layout, below, for a description. 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
 

Detailed Description

The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')

Definition at line 554 of file common.h.

Member Function Documentation

◆ allocate_layout() [1/2]

PYBIND11_NOINLINE void instance::allocate_layout ( )

◆ allocate_layout() [2/2]

void instance::allocate_layout ( )

Initializes all of the above type/values/holders data (but not the instance values themselves)

◆ deallocate_layout() [1/2]

PYBIND11_NOINLINE void instance::deallocate_layout ( )

Destroys/deallocates all of the above.

Definition at line 464 of file type_caster_base.h.

References nonsimple, simple_layout, and nonsimple_values_and_holders::values_and_holders.

Referenced by clear_instance().

◆ deallocate_layout() [2/2]

void instance::deallocate_layout ( )

Destroys/deallocates all of the above.

◆ get_value_and_holder() [1/2]

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).

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.

Returns a default-constructed (with .inst = nullptr) object on failure if throw_if_missing is false.

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.

References get_fully_qualified_tp_name(), pybind11_fail(), and type_info::type.

Referenced by cpp_function::dispatcher(), and type_caster_generic::load_impl().

◆ get_value_and_holder() [2/2]

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.

Member Data Documentation

◆ 

PyObject_HEAD union { ... } instance::@1

Storage for pointers and holder; see simple_layout, below, for a description.

◆ 

PyObject_HEAD union { ... } instance::@4

Storage for pointers and holder; see simple_layout, below, for a description.

◆ has_patients

bool instance::has_patients

If true, get_internals().patients has an entry for this object.

Definition at line 594 of file common.h.

Referenced by add_patient(), clear_instance(), and clear_patients().

◆ nonsimple

nonsimple_values_and_holders instance::nonsimple

◆ owned

bool instance::owned

If true, the pointer is owned which means we're free to manage it with a holder.

Definition at line 564 of file common.h.

Referenced by allocate_layout(), type_caster_generic::cast(), and clear_instance().

◆ simple_holder_constructed

bool instance::simple_holder_constructed

For simple layout, tracks whether the holder has been constructed.

Definition at line 590 of file common.h.

Referenced by allocate_layout(), value_and_holder::holder_constructed(), and value_and_holder::set_holder_constructed().

◆ simple_instance_registered

bool instance::simple_instance_registered

For simple layout, tracks whether the instance is registered in registered_instances

Definition at line 592 of file common.h.

Referenced by allocate_layout(), value_and_holder::instance_registered(), and value_and_holder::set_instance_registered().

◆ simple_layout

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 588 of file common.h.

Referenced by allocate_layout(), deallocate_layout(), value_and_holder::holder_constructed(), value_and_holder::instance_registered(), values_and_holders::iterator::operator++(), value_and_holder::set_holder_constructed(), and value_and_holder::set_instance_registered().

◆ simple_value_holder

void* instance::simple_value_holder[1+instance_simple_holder_in_ptrs()]

Definition at line 558 of file common.h.

Referenced by allocate_layout().

◆ status_holder_constructed

static constexpr uint8_t instance::status_holder_constructed = 1
staticconstexpr

Bit values for the non-simple status flags.

Definition at line 610 of file common.h.

Referenced by value_and_holder::holder_constructed(), and value_and_holder::set_holder_constructed().

◆ status_instance_registered

static constexpr uint8_t instance::status_instance_registered = 2
staticconstexpr

◆ weakrefs

PyObject * instance::weakrefs

Weak references.

Definition at line 562 of file common.h.

Referenced by clear_instance().


The documentation for this struct was generated from the following files: