All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pyobject_deleter< T > Class Template Reference

Used as a std::shared_ptr deleter (second argument) to overload delete ptr with Py_DECREF(ptr). More...

#include <util.h>

Public Member Functions

 pyobject_deleter (PyObject *pyobj)
 Creates a pyobject_deleter and calls Py_INCREF(ptr).
 
void operator() (T const *)
 Called by std::shared_ptr when its reference count reaches zero.
 

Detailed Description

template<typename T>
class pyobject_deleter< T >

Used as a std::shared_ptr deleter (second argument) to overload delete ptr with Py_DECREF(ptr).

This allows data to be shared between C++ and Python that will be deleted when both reference counts reach zero.

The effective reference count is a lexicographical tuple of (Python reference count, C++ reference count), where the Python reference count is the most significant digit. A single Python reference count is held for all C++ references to the object.

See also

  • array_deleter, which frees array buffers, rather than objects.

Constructor & Destructor Documentation

◆ pyobject_deleter()

pyobject_deleter ( PyObject *  pyobj)
inline

Creates a pyobject_deleter and calls Py_INCREF(ptr).

Member Function Documentation

◆ operator()()

void operator() ( T const *  )
inline

Called by std::shared_ptr when its reference count reaches zero.


The documentation for this class was generated from the following file: