\rst Holds a reference to a Python object (with reference counting) More...
#include </builds/ipbus/ipbus-software/uhal/python/pybind11-python2/include/pybind11/pytypes.h>
Inherited by anyset, bool_, bool_, buffer, buffer, bytearray, bytearray, bytes, bytes, capsule, capsule, conftest.Capture, conftest.Output, conftest.SanitizedString, dict, dict, dtype, dtype, ellipsis, ellipsis, exception< type >, exception< type >, float_, float_, function, function, generic_type, generic_type, int_, int_, iterable, iterable, iterator, iterator, list, list, memoryview, memoryview, module_, module_, none, none, sequence, sequence, set, slice, slice, staticmethod, staticmethod, str, str, tuple, tuple, type, type, weakref, and weakref.
Classes | |
struct | borrowed_t |
struct | stolen_t |
Public Member Functions | |
object ()=default | |
PYBIND11_DEPRECATED ("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h | |
object (const object &o) | |
Copy constructor; always increases the reference count. More... | |
object (object &&other) noexcept | |
Move constructor; steals the object from other and preserves its reference count. More... | |
~object () | |
Destructor; automatically calls handle::dec_ref() More... | |
handle | release () |
\rst Resets the internal pointer to nullptr without decreasing the object's reference count. More... | |
object & | operator= (const object &other) |
object & | operator= (object &&other) noexcept |
template<typename T > | |
T | cast () const & |
template<typename T > | |
T | cast () && |
object (handle h, borrowed_t) | |
object (handle h, stolen_t) | |
object ()=default | |
PYBIND11_DEPRECATED ("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h | |
object (const object &o) | |
Copy constructor; always increases the reference count. More... | |
object (object &&other) noexcept | |
Move constructor; steals the object from other and preserves its reference count. More... | |
~object () | |
Destructor; automatically calls handle::dec_ref() More... | |
handle | release () |
\rst Resets the internal pointer to nullptr without decreasing the object's reference count. More... | |
object & | operator= (const object &other) |
object & | operator= (object &&other) noexcept |
template<typename T > | |
T | cast () const & |
template<typename T > | |
T | cast () && |
object (handle h, borrowed_t) | |
object (handle h, stolen_t) | |
template<typename T > | |
T | cast () const & |
template<typename T > | |
T | cast () && |
template<> | |
void | cast () const & |
template<> | |
void | cast () && |
![]() | |
handle ()=default | |
The default constructor creates a handle with a nullptr -valued pointer. More... | |
handle (PyObject *ptr) | |
Creates a handle from the given raw Python object pointer. More... | |
PyObject * | ptr () const |
Return the underlying PyObject * pointer. More... | |
PyObject *& | ptr () |
const handle & | inc_ref () const & |
\rst Manually increase the reference count of the Python object. More... | |
const handle & | dec_ref () const & |
\rst Manually decrease the reference count of the Python object. More... | |
template<typename T > | |
T | cast () const |
\rst Attempt to cast the Python object into the given C++ type. More... | |
operator bool () const | |
Return true when the handle wraps a valid Python object. More... | |
bool | operator== (const handle &h) const |
\rst Deprecated: Check that the underlying pointers are the same. More... | |
bool | operator!= (const handle &h) const |
bool | check () const |
handle ()=default | |
The default constructor creates a handle with a nullptr -valued pointer. More... | |
template<typename T , detail::enable_if_t< detail::is_pyobj_ptr_or_nullptr_t< T >::value, int > = 0> | |
handle (T ptr) | |
Enable implicit conversion from PyObject * and nullptr . More... | |
template<typename T , detail::enable_if_t< detail::all_of< detail::none_of< std::is_base_of< handle, T >, detail::is_pyobj_ptr_or_nullptr_t< T > >, std::is_convertible< T, PyObject * > >::value, int > = 0> | |
handle (T &obj) | |
Enable implicit conversion through T::operator PyObject *() . More... | |
PyObject * | ptr () const |
Return the underlying PyObject * pointer. More... | |
PyObject *& | ptr () |
const handle & | inc_ref () const & |
\rst Manually increase the reference count of the Python object. More... | |
const handle & | dec_ref () const & |
\rst Manually decrease the reference count of the Python object. More... | |
template<typename T > | |
T | cast () const |
\rst Attempt to cast the Python object into the given C++ type. More... | |
operator bool () const | |
Return true when the handle wraps a valid Python object. More... | |
bool | operator== (const handle &h) const |
\rst Deprecated: Check that the underlying pointers are the same. More... | |
bool | operator!= (const handle &h) const |
bool | check () const |
template<> | |
void | cast () const |
Public Attributes | |
bool | is_borrowed: handle(h) { if (is_borrowed) { inc_ref() |
Additional Inherited Members | |
![]() | |
static std::size_t | inc_ref_counter () |
![]() | |
PyObject * | m_ptr = nullptr |
\rst Holds a reference to a Python object (with reference counting)
Like handle
, the object
class is a thin wrapper around an arbitrary Python object (i.e. a PyObject *
in Python's C API). In contrast to handle
, it optionally increases the object's reference count upon construction, and it always* decreases the reference count when the object
instance goes out of scope and is destructed. When using object
instances consistently, it is much easier to get reference counting right at the first attempt. \endrst
Like handle
, the object
class is a thin wrapper around an arbitrary Python object (i.e. a PyObject *
in Python's C API). In contrast to handle
, it optionally increases the object's reference count upon construction, and it always* decreases the reference count when the object
instance goes out of scope and is destructed. When using object
instances consistently, it is much easier to get reference counting right at the first attempt. \endrst
|
default |
Referenced by slice::index_to_object().
|
inline |
Copy constructor; always increases the reference count.
Definition at line 269 of file pytypes.h.
References handle::inc_ref().
|
inlinenoexcept |
Move constructor; steals the object from other
and preserves its reference count.
Definition at line 271 of file pytypes.h.
References handle::m_ptr.
|
inline |
Destructor; automatically calls handle::dec_ref()
Definition at line 276 of file pytypes.h.
References handle::dec_ref().
|
inline |
Definition at line 330 of file pytypes.h.
References handle::inc_ref().
|
default |
|
inline |
Copy constructor; always increases the reference count.
Definition at line 352 of file pytypes.h.
References handle::inc_ref().
|
inlinenoexcept |
|
inline |
Destructor; automatically calls handle::dec_ref()
Definition at line 356 of file pytypes.h.
References handle::dec_ref().
|
inline |
Definition at line 427 of file pytypes.h.
References handle::inc_ref().
T object::cast | ( | ) | && |
T object::cast | ( | ) | && |
T object::cast | ( | ) | const & |
Referenced by dtype::_dtype_from_pep3118(), cpp_function::initialize_generic(), operator<<(), print(), dtype::strip_padding(), and TEST_CASE().
T object::cast | ( | ) | const & |
Definition at line 289 of file pytypes.h.
References handle::dec_ref(), handle::inc_ref(), and handle::m_ptr.
Definition at line 369 of file pytypes.h.
References handle::dec_ref(), handle::inc_ref(), and handle::m_ptr.
Definition at line 299 of file pytypes.h.
References handle::dec_ref(), and handle::m_ptr.
Definition at line 382 of file pytypes.h.
References handle::dec_ref(), and handle::m_ptr.
object::PYBIND11_DEPRECATED | ( | "Use reinterpret_borrow<object>() or reinterpret_steal<object>()" | ) |
object::PYBIND11_DEPRECATED | ( | "Use reinterpret_borrow<object>() or reinterpret_steal<object>()" | ) |
References handle::inc_ref(), and is_borrowed.
|
inline |
\rst Resets the internal pointer to nullptr
without decreasing the object's reference count.
The function returns a raw handle to the original Python object. \endrst
Definition at line 283 of file pytypes.h.
References handle::handle(), and handle::m_ptr.
Referenced by dtype::_dtype_from_pep3118(), all_type_info_get_cache(), pybind11::detail::type_caster< ArgInspector1 >::cast(), PYBIND11_NAMESPACE::detail::type_caster< ArgInspector1 >::cast(), pybind11::detail::type_caster< ArgInspector2 >::cast(), PYBIND11_NAMESPACE::detail::type_caster< ArgInspector2 >::cast(), type_caster< CopyOnlyInt >::cast(), type_caster< Type, enable_if_t< is_eigen_sparse< Type >::value > >::cast(), type_caster_generic::cast(), type_caster< void >::cast(), type_caster< std::function< Return(Args...)> >::cast(), map_caster< Type, Key, Value >::cast(), list_caster< Type, Value >::cast(), array_caster< ArrayType, Value, Resizable, Size >::cast(), optional_caster< Type, Value >::cast(), tuple_caster< Tuple, Ts >::cast(), void_caster< T >::cast(), class_< type_, options >::def_buffer(), cpp_function::dispatcher(), dtype::dtype(), eigen_array_cast(), load_stream_data_seek(), make_new_python_type(), array_t< T, ExtraFlags >::raw_array_t(), array::view(), and error_already_set::~error_already_set().
|
inline |
\rst Resets the internal pointer to nullptr
without decreasing the object's reference count.
The function returns a raw handle to the original Python object. \endrst
Definition at line 363 of file pytypes.h.
References handle::handle(), and handle::m_ptr.
bool object::is_borrowed |
Definition at line 263 of file pytypes.h.
Referenced by PYBIND11_DEPRECATED().