Shiboken::PyObjectHolder Class

class Shiboken::PyObjectHolder

Keeps a reference to a PyObject. More...

Header: #include <pyobjectholder.h>

Public Functions

PyObjectHolder()
PyObjectHolder(PyObject *pyObj)
~PyObjectHolder()
PyObject *object() const

Detailed Description

PyObjectHolder holds a PyObject pointer, keeping a reference decrementing its reference counter when destroyed. It makes sure to hold the GIL when releasing and when copying. If the interpreter has already been finalized, which can happen for a holder stored in a global C++ object, the reference is leaked instead. It implements copy/move semantics and is mainly intended as a base class for functors holding a callable which can be passed around and stored in containers or moved from freely. For one-shot functors, release() can be invoked after the call.

Member Function Documentation

[constexpr noexcept default] PyObjectHolder::PyObjectHolder()

Default-constructs an instance of PyObjectHolder.

[explicit noexcept] PyObjectHolder::PyObjectHolder(PyObject *pyObj)

Constructs a PyObjectHolder holding a new reference to the Python object pyObj.

[noexcept] PyObjectHolder::~PyObjectHolder()

Decrements the reference count of the held Python object, unless the interpreter is already gone.

PyObject *PyObjectHolder::object() const

Returns the pointer of the Python object being held.