69PyObjectPlus::PyObjectPlus()
74 _Py_NewReference(
this );
77PyObjectPlus::~PyObjectPlus()
79 if (this->ob_refcnt>0)
81 if (this->ob_refcnt>1)
83 std::cerr <<
"[LASS RUN MSG] DANGLING REFERENCE to lass::python::PyObjectPlus"
88 LASS_ASSERT(this->ob_refcnt==0);
93 LockGIL LASS_UNUSED(lock);
94 this->ob_type = other.ob_type;
95 Py_XINCREF(this->ob_type);
96 _Py_NewReference(
this );
101 LASS_ASSERT(!this->ob_type || this->ob_type == iOther.ob_type);
112bool checkSequenceSize(PyObject* obj, Py_ssize_t expectedSize)
114 LockGIL LASS_UNUSED(lock);
115 if (!PySequence_Check(obj))
117 PyErr_SetString(PyExc_TypeError,
"not a python sequence (tuple, list, ...)");
120 const Py_ssize_t size = PySequence_Size(obj);
121 if (size != expectedSize)
123 std::ostringstream buffer;
124 buffer <<
"tuple/list is not of expected size " << expectedSize <<
" (size is " << size <<
")";
125 PyErr_SetString(PyExc_TypeError, buffer.str().c_str());
135TPyObjPtr checkedFastSequence(PyObject* obj)
137 LockGIL LASS_UNUSED(lock);
138 return TPyObjPtr(PySequence_Fast(obj,
"expected a sequence (tuple, list, ...)"));
145TPyObjPtr checkedFastSequence(PyObject* obj, Py_ssize_t expectedSize)
147 LockGIL LASS_UNUSED(lock);
148 TPyObjPtr result = checkedFastSequence(obj);
151 const Py_ssize_t size = PySequence_Fast_GET_SIZE(result.get());
152 if (size != expectedSize)
154 std::ostringstream buffer;
155 buffer <<
"expected a sequence of size " << expectedSize <<
" (your size is " << size <<
")";
156 PyErr_SetString(PyExc_TypeError, buffer.str().c_str());
167TPyObjPtr checkedFastSequence(PyObject* obj, Py_ssize_t minimumSize, Py_ssize_t maximumSize)
169 LockGIL LASS_UNUSED(lock);
170 TPyObjPtr result = checkedFastSequence(obj);
173 const Py_ssize_t size = PySequence_Fast_GET_SIZE(result.get());
174 if (size < minimumSize || size > maximumSize)
176 std::ostringstream buffer;
177 buffer <<
"expected a sequence of size between " << minimumSize <<
" and " << maximumSize
178 <<
" inclusive (your size is " << size <<
")";
179 PyErr_SetString(PyExc_TypeError, buffer.str().c_str());
194 if (PyIteratorRange::_lassPyClassDef.isFrozen_ && result->ob_type == PyIteratorRange::_lassPyClassDef.type())
acquire the GIL for the current scope.
void setOwner(const TPyObjPtr &owner)
Owner object of the iterators.
const TPyObjPtr & owner() const
Owner object of the iterators.
static void _lassPyClassRegisterHook()
This function can be used to execute some code at injection time.
Definition of a Python class.
friend LASS_PYTHON_DLL PyObject *LASS_CALL establishMagicalBackLinks(PyObject *result, PyObject *self)
Here, we try to fix some lifetime issues to guarantee some lifetime requirements on self.
PyObjectPtr< PyObject >::Type TPyObjPtr
PyObjectPtr to a PyObject.
lass::util::SharedPtr< T, PyObjectStorage, PyObjectCounter > fromNakedToSharedPtrCast(PyObject *object)
fromNakedToSharedPtrCast.
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.