69PyObjectPlus::PyObjectPlus()
74 _Py_NewReference(
this );
77PyObjectPlus::~PyObjectPlus()
79 LASS_ASSERT(Py_REFCNT(
this) <= 1);
80 if (Py_REFCNT(
this) > 1)
82 std::cerr <<
"[LASS RUN MSG] DANGLING REFERENCE to lass::python::PyObjectPlus" << std::endl;
89 this->ob_type = other.ob_type;
90 Py_XINCREF(this->ob_type);
91 _Py_NewReference(
this );
96 LASS_ASSERT(!this->ob_type || this->ob_type == iOther.ob_type);
107bool checkSequenceSize(PyObject* obj, Py_ssize_t expectedSize)
110 if (!PySequence_Check(obj))
112 PyErr_SetString(PyExc_TypeError,
"not a python sequence (tuple, list, ...)");
115 const Py_ssize_t size = PySequence_Size(obj);
116 if (size != expectedSize)
118 std::ostringstream buffer;
119 buffer <<
"tuple/list is not of expected size " << expectedSize <<
" (size is " << size <<
")";
120 PyErr_SetString(PyExc_TypeError, buffer.str().c_str());
130TPyObjPtr checkedFastSequence(PyObject* obj)
133 return TPyObjPtr(PySequence_Fast(obj,
"expected a sequence (tuple, list, ...)"));
140TPyObjPtr checkedFastSequence(PyObject* obj, Py_ssize_t expectedSize)
143 TPyObjPtr result = checkedFastSequence(obj);
146 const Py_ssize_t size = PySequence_Fast_GET_SIZE(result.get());
147 if (size != expectedSize)
149 std::ostringstream buffer;
150 buffer <<
"expected a sequence of size " << expectedSize <<
" (your size is " << size <<
")";
151 PyErr_SetString(PyExc_TypeError, buffer.str().c_str());
162TPyObjPtr checkedFastSequence(PyObject* obj, Py_ssize_t minimumSize, Py_ssize_t maximumSize)
165 TPyObjPtr result = checkedFastSequence(obj);
168 const Py_ssize_t size = PySequence_Fast_GET_SIZE(result.get());
169 if (size < minimumSize || size > maximumSize)
171 std::ostringstream buffer;
172 buffer <<
"expected a sequence of size between " << minimumSize <<
" and " << maximumSize
173 <<
" inclusive (your size is " << size <<
")";
174 PyErr_SetString(PyExc_TypeError, buffer.str().c_str());
189 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.