-// Copyright (C) 2021-2023 CEA, EDF
+// Copyright (C) 2021-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
PyObject *get() { return _pyobj; }
bool isNull() const { return _pyobj==0; }
PyObject *retn() { if(_pyobj) Py_XINCREF(_pyobj); return _pyobj; }
-private:
- void release() { if(_pyobj) Py_XDECREF(_pyobj); _pyobj=0; }
+protected:
+ void release() { if(_pyobj) Py_XDECREF(_pyobj); _pyobj=nullptr; }
private:
PyObject *_pyobj = nullptr;
};
+
+class AutoPyRefGilSafe : public AutoPyRef
+{
+public:
+ AutoPyRefGilSafe(PyObject *pyobj=nullptr):AutoPyRef(pyobj) { }
+ ~AutoPyRefGilSafe() { AutoGIL agil; release(); }
+};
+
+class AutoPyYielder
+{
+private:
+ PyThreadState *_save = nullptr;
+public:
+ AutoPyYielder() { _save = PyEval_SaveThread(); }
+ ~AutoPyYielder() { PyEval_RestoreThread(_save); }
+};