μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros | Functions
class.h File Reference
#include "../attr.h"
#include "../options.h"
Include dependency graph for class.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj)    setattr((PyObject *) obj, "__qualname__", nameobj)
 

Functions

std::string get_fully_qualified_tp_name (PyTypeObject *type)
 
PyTypeObject * type_incref (PyTypeObject *type)
 
PyObject * pybind11_static_get (PyObject *self, PyObject *, PyObject *cls)
 pybind11_static_property.__get__(): Always pass the class instead of the instance. More...
 
int pybind11_static_set (PyObject *self, PyObject *obj, PyObject *value)
 pybind11_static_property.__set__(): Just like the above __get__(). More...
 
PyTypeObject * make_static_property_type ()
 A static_property is the same as a property but the __get__() and __set__() methods are modified to always use the object type instead of a concrete instance. More...
 
int pybind11_meta_setattro (PyObject *obj, PyObject *name, PyObject *value)
 Types with static properties need to handle Type.static_prop = x in a specific way. More...
 
PyObject * pybind11_meta_call (PyObject *type, PyObject *args, PyObject *kwargs)
 metaclass __call__ function that is used to create all pybind11 objects. More...
 
void pybind11_meta_dealloc (PyObject *obj)
 Cleanup the type-info for a pybind11-registered type. More...
 
PyTypeObject * make_default_metaclass ()
 This metaclass is assigned by default to all pybind11 types and is required in order for static properties to function correctly. More...
 
void traverse_offset_bases (void *valueptr, const detail::type_info *tinfo, instance *self, bool(*f)(void *, instance *))
 For multiple inheritance types we need to recursively register/deregister base pointers for any base classes with pointers that are difference from the instance value pointer so that we can correctly recognize an offset base class pointer. More...
 
bool register_instance_impl (void *ptr, instance *self)
 
bool deregister_instance_impl (void *ptr, instance *self)
 
void register_instance (instance *self, void *valptr, const type_info *tinfo)
 
bool deregister_instance (instance *self, void *valptr, const type_info *tinfo)
 
PyObject * make_new_instance (PyTypeObject *type)
 Instance creation function for all pybind11 types. More...
 
PyObject * pybind11_object_new (PyTypeObject *type, PyObject *, PyObject *)
 Instance creation function for all pybind11 types. More...
 
int pybind11_object_init (PyObject *self, PyObject *, PyObject *)
 An __init__ function constructs the C++ object. More...
 
void add_patient (PyObject *nurse, PyObject *patient)
 
void clear_patients (PyObject *self)
 
void clear_instance (PyObject *self)
 Clears all internal data from the instance and removes it from registered instances in preparation for deallocation. More...
 
void pybind11_object_dealloc (PyObject *self)
 Instance destructor function for all pybind11 types. More...
 
PyObject * make_object_base_type (PyTypeObject *metaclass)
 Create the type which can be used as a common base for all classes. More...
 
PyObject * pybind11_get_dict (PyObject *self, void *)
 dynamic_attr: Support for d = instance.__dict__. More...
 
int pybind11_set_dict (PyObject *self, PyObject *new_dict, void *)
 dynamic_attr: Support for instance.__dict__ = dict(). More...
 
int pybind11_traverse (PyObject *self, visitproc visit, void *arg)
 dynamic_attr: Allow the garbage collector to traverse the internal instance __dict__. More...
 
int pybind11_clear (PyObject *self)
 dynamic_attr: Allow the GC to clear the dictionary. More...
 
void enable_dynamic_attributes (PyHeapTypeObject *heap_type)
 Give instances of this type a __dict__ and opt into garbage collection. More...
 
int pybind11_getbuffer (PyObject *obj, Py_buffer *view, int flags)
 buffer_protocol: Fill in the view as specified by flags. More...
 
void pybind11_releasebuffer (PyObject *, Py_buffer *view)
 buffer_protocol: Release the resources of the buffer. More...
 
void enable_buffer_protocol (PyHeapTypeObject *heap_type)
 Give this type a buffer interface. More...
 
PyObject * make_new_python_type (const type_record &rec)
 Create a brand new Python type according to the type_record specification. More...
 

Macro Definition Documentation

◆ PYBIND11_SET_OLDPY_QUALNAME

#define PYBIND11_SET_OLDPY_QUALNAME (   obj,
  nameobj 
)     setattr((PyObject *) obj, "__qualname__", nameobj)

Definition at line 24 of file class.h.

Function Documentation

◆ add_patient()

void add_patient ( PyObject *  nurse,
PyObject *  patient 
)
inline

Definition at line 376 of file class.h.

References get_internals(), instance::has_patients, and internals::patients.

Referenced by keep_alive_impl().

◆ clear_instance()

void clear_instance ( PyObject *  self)
inline

Clears all internal data from the instance and removes it from registered instances in preparation for deallocation.

Definition at line 402 of file class.h.

References clear_patients(), instance::deallocate_layout(), deregister_instance(), instance::has_patients, instance::owned, pybind11_fail(), self, and instance::weakrefs.

Referenced by pybind11_object_dealloc().

◆ clear_patients()

void clear_patients ( PyObject *  self)
inline

Definition at line 384 of file class.h.

References get_internals(), instance::has_patients, internals::patients, and self.

Referenced by clear_instance().

◆ deregister_instance()

bool deregister_instance ( instance self,
void *  valptr,
const type_info tinfo 
)
inline

◆ deregister_instance_impl()

bool deregister_instance_impl ( void *  ptr,
instance self 
)
inline

Definition at line 313 of file class.h.

References get_internals(), internals::registered_instances, and self.

Referenced by deregister_instance().

◆ enable_buffer_protocol()

void enable_buffer_protocol ( PyHeapTypeObject *  heap_type)
inline

Give this type a buffer interface.

Definition at line 614 of file class.h.

References pybind11_getbuffer(), and pybind11_releasebuffer().

Referenced by make_new_python_type().

◆ enable_dynamic_attributes()

void enable_dynamic_attributes ( PyHeapTypeObject *  heap_type)
inline

Give instances of this type a __dict__ and opt into garbage collection.

Definition at line 547 of file class.h.

References pybind11_clear(), pybind11_get_dict(), pybind11_set_dict(), and pybind11_traverse().

Referenced by make_new_python_type(), and make_static_property_type().

◆ get_fully_qualified_tp_name()

std::string get_fully_qualified_tp_name ( PyTypeObject *  type)
inline

◆ make_default_metaclass()

PyTypeObject * make_default_metaclass ( )
inline

This metaclass is assigned by default to all pybind11 types and is required in order for static properties to function correctly.

Users may override this using py::metaclass. Return value: New reference.

Definition at line 243 of file class.h.

References pybind11_fail(), PYBIND11_FROM_STRING, pybind11_meta_call(), pybind11_meta_dealloc(), pybind11_meta_getattro(), pybind11_meta_setattro(), PYBIND11_SET_OLDPY_QUALNAME, setattr(), and type_incref().

◆ make_new_instance()

PyObject * make_new_instance ( PyTypeObject *  type)
inline

Instance creation function for all pybind11 types.

It allocates the internal instance layout for holding C++ objects and holders. Allocation is done lazily (the first time the instance is cast to a reference or pointer), and initialization is done by an __init__ function.

Definition at line 343 of file class.h.

References instance::allocate_layout(), and self.

Referenced by pybind11_object_new().

◆ make_new_python_type()

PyObject * make_new_python_type ( const type_record rec)
inline

◆ make_object_base_type()

PyObject * make_object_base_type ( PyTypeObject *  metaclass)
inline

Create the type which can be used as a common base for all classes.

This is needed in order to satisfy Python's requirements for multiple inheritance. Return value: New reference.

Definition at line 465 of file class.h.

References error_string(), pybind11_fail(), PYBIND11_FROM_STRING, pybind11_object_dealloc(), pybind11_object_init(), pybind11_object_new(), PYBIND11_SET_OLDPY_QUALNAME, setattr(), and type_incref().

◆ make_static_property_type()

PyTypeObject * make_static_property_type ( )
inline

A static_property is the same as a property but the __get__() and __set__() methods are modified to always use the object type instead of a concrete instance.

Return value: New reference.

Definition at line 61 of file class.h.

References pybind11_fail(), PYBIND11_FROM_STRING, PYBIND11_SET_OLDPY_QUALNAME, pybind11_static_get(), pybind11_static_set(), setattr(), and type_incref().

◆ pybind11_clear()

int pybind11_clear ( PyObject *  self)
inline

dynamic_attr: Allow the GC to clear the dictionary.

Definition at line 540 of file class.h.

References self.

Referenced by enable_dynamic_attributes().

◆ pybind11_get_dict()

PyObject * pybind11_get_dict ( PyObject *  self,
void *   
)
inline

dynamic_attr: Support for d = instance.__dict__.

Definition at line 508 of file class.h.

References self.

Referenced by enable_dynamic_attributes().

◆ pybind11_getbuffer()

int pybind11_getbuffer ( PyObject *  obj,
Py_buffer *  view,
int  flags 
)
inline

◆ pybind11_meta_call()

PyObject * pybind11_meta_call ( PyObject *  type,
PyObject *  args,
PyObject *  kwargs 
)
inline

metaclass __call__ function that is used to create all pybind11 objects.

Definition at line 176 of file class.h.

References get_fully_qualified_tp_name(), and self.

Referenced by make_default_metaclass().

◆ pybind11_meta_dealloc()

void pybind11_meta_dealloc ( PyObject *  obj)
inline

◆ pybind11_meta_setattro()

int pybind11_meta_setattro ( PyObject *  obj,
PyObject *  name,
PyObject *  value 
)
inline

Types with static properties need to handle Type.static_prop = x in a specific way.

By default, Python replaces the static_property itself, but for wrapped C++ types we need to call static_property.__set__() in order to propagate the new value to the underlying C++ data structure.

Definition at line 127 of file class.h.

References get_internals(), and internals::static_property_type.

Referenced by make_default_metaclass().

◆ pybind11_object_dealloc()

void pybind11_object_dealloc ( PyObject *  self)
inline

Instance destructor function for all pybind11 types.

It calls type_info.dealloc to destroy the C++ object itself, while the rest is Python bookkeeping.

Definition at line 441 of file class.h.

References clear_instance(), get_internals(), internals::instance_base, and self.

Referenced by make_object_base_type().

◆ pybind11_object_init()

int pybind11_object_init ( PyObject *  self,
PyObject *  ,
PyObject *   
)
inline

An __init__ function constructs the C++ object.

Users should provide at least one of these using py::init or directly with .def(__init__, ...). Otherwise, the following default function will be used which simply throws an exception.

Definition at line 369 of file class.h.

References get_fully_qualified_tp_name(), and self.

Referenced by make_new_python_type(), and make_object_base_type().

◆ pybind11_object_new()

PyObject * pybind11_object_new ( PyTypeObject *  type,
PyObject *  ,
PyObject *   
)
inline

Instance creation function for all pybind11 types.

It only allocates space for the C++ object, but doesn't call the constructor – an __init__ function must do that.

Definition at line 362 of file class.h.

References make_new_instance().

Referenced by make_object_base_type().

◆ pybind11_releasebuffer()

void pybind11_releasebuffer ( PyObject *  ,
Py_buffer *  view 
)
inline

buffer_protocol: Release the resources of the buffer.

Definition at line 609 of file class.h.

Referenced by enable_buffer_protocol().

◆ pybind11_set_dict()

int pybind11_set_dict ( PyObject *  self,
PyObject *  new_dict,
void *   
)
inline

dynamic_attr: Support for instance.__dict__ = dict().

Definition at line 518 of file class.h.

References c_str(), get_fully_qualified_tp_name(), and self.

Referenced by enable_dynamic_attributes().

◆ pybind11_static_get()

PyObject * pybind11_static_get ( PyObject *  self,
PyObject *  ,
PyObject *  cls 
)
inline

pybind11_static_property.__get__(): Always pass the class instead of the instance.

Definition at line 48 of file class.h.

References self.

Referenced by make_static_property_type().

◆ pybind11_static_set()

int pybind11_static_set ( PyObject *  self,
PyObject *  obj,
PyObject *  value 
)
inline

pybind11_static_property.__set__(): Just like the above __get__().

Definition at line 53 of file class.h.

References self.

Referenced by make_static_property_type().

◆ pybind11_traverse()

int pybind11_traverse ( PyObject *  self,
visitproc  visit,
void *  arg 
)
inline

dynamic_attr: Allow the garbage collector to traverse the internal instance __dict__.

Definition at line 533 of file class.h.

References self.

Referenced by enable_dynamic_attributes().

◆ register_instance()

void register_instance ( instance self,
void *  valptr,
const type_info tinfo 
)
inline

◆ register_instance_impl()

bool register_instance_impl ( void *  ptr,
instance self 
)
inline

Definition at line 309 of file class.h.

References get_internals(), internals::registered_instances, and self.

Referenced by register_instance().

◆ traverse_offset_bases()

void traverse_offset_bases ( void *  valueptr,
const detail::type_info *  tinfo,
instance self,
bool(*)(void *, instance *)  f 
)
inline

For multiple inheritance types we need to recursively register/deregister base pointers for any base classes with pointers that are difference from the instance value pointer so that we can correctly recognize an offset base class pointer.

This calls a function with any offset base ptrs.

Definition at line 289 of file class.h.

References get_type_info(), self, and traverse_offset_bases().

Referenced by deregister_instance(), register_instance(), and traverse_offset_bases().

◆ type_incref()

PyTypeObject * type_incref ( PyTypeObject *  type)
inline