diff options
author | Thomas Grill <xovo@users.sourceforge.net> | 2005-02-27 04:57:47 +0000 |
---|---|---|
committer | Thomas Grill <xovo@users.sourceforge.net> | 2005-02-27 04:57:47 +0000 |
commit | 4890f929915b27e94cce04d19ab4e72cfbe93715 (patch) | |
tree | 93f48861ce0c1b46acd3e8f13a277785f13e77dd /externals/grill/py/source | |
parent | 3e90874e5d63137c195c3b3c1ce90b542deb8a51 (diff) |
better error reporting
use lock count instead of message queuing to avoid py->py messaging deadlock
must clear Python error...
svn path=/trunk/; revision=2585
Diffstat (limited to 'externals/grill/py/source')
-rw-r--r-- | externals/grill/py/source/clmeth.cpp | 6 | ||||
-rw-r--r-- | externals/grill/py/source/main.cpp | 2 | ||||
-rw-r--r-- | externals/grill/py/source/main.h | 8 | ||||
-rw-r--r-- | externals/grill/py/source/pyargs.cpp | 7 | ||||
-rw-r--r-- | externals/grill/py/source/pyext.cpp | 2 |
5 files changed, 17 insertions, 8 deletions
diff --git a/externals/grill/py/source/clmeth.cpp b/externals/grill/py/source/clmeth.cpp index 92c6b4d3..489b7dc5 100644 --- a/externals/grill/py/source/clmeth.cpp +++ b/externals/grill/py/source/clmeth.cpp @@ -175,11 +175,11 @@ PyObject *pyext::pyext_outlet(PyObject *,PyObject *args) // by using the queue there is no immediate call of the next object // deadlock would occur if this was another py/pyext object! if(lst->Count() && IsSymbol((*lst)[0])) - ext->ToQueueAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1); + ext->ToOutAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1); else if(lst->Count() > 1) - ext->ToQueueList(o-1,*lst); + ext->ToOutList(o-1,*lst); else - ext->ToQueueAtom(o-1,*lst->Atoms()); + ext->ToOutAtom(o-1,*lst->Atoms()); } else post("pyext: outlet index out of range"); diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp index 3b75f419..a0919132 100644 --- a/externals/grill/py/source/main.cpp +++ b/externals/grill/py/source/main.cpp @@ -27,6 +27,8 @@ static PyInterpreterState *pymain = NULL; static PyThreadState *pythrmain = NULL; static PyThrMap pythrmap; +int py::lockcount = 0; + PyThreadState *py::FindThreadState() { flext::thrid_t id = flext::GetThreadId(); diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h index b7000bae..e1ae64a4 100644 --- a/externals/grill/py/source/main.h +++ b/externals/grill/py/source/main.h @@ -159,16 +159,20 @@ public: inline void Lock() { mutex.Unlock(); } inline void Unlock() { mutex.Unlock(); } + // this is respecially needed when one py/pyext object calls another one + // we don't want the message to be queued, but otoh we have to avoid deadlock + static int lockcount; + inline PyThreadState *PyLock() { - PyEval_AcquireLock(); + if(!lockcount++) PyEval_AcquireLock(); return PyThreadState_Swap(FindThreadState()); } inline void PyUnlock(PyThreadState *st) { PyThreadState_Swap(st); - PyEval_ReleaseLock(); + if(!--lockcount) PyEval_ReleaseLock(); } #else inline void Lock() {} diff --git a/externals/grill/py/source/pyargs.cpp b/externals/grill/py/source/pyargs.cpp index aee12a17..a040feac 100644 --- a/externals/grill/py/source/pyargs.cpp +++ b/externals/grill/py/source/pyargs.cpp @@ -14,17 +14,18 @@ static PyObject *MakePyAtom(const t_atom &at) { if(flext::IsSymbol(at)) return pySymbol_FromSymbol(flext::GetSymbol(at)); -// else if(flext::IsPointer(at)) return NULL; // not handled - else if(flext::CanbeInt(at) && flext::CanbeFloat(at)) { + else if(flext::CanbeInt(at) || flext::CanbeFloat(at)) { // if a number can be an integer... let at be an integer! int ival = flext::GetAInt(at); double fval = flext::GetAFloat(at); return (double)ival == fval?PyInt_FromLong(ival):PyFloat_FromDouble(fval); } +// else if(flext::IsPointer(at)) return NULL; // not handled +/* // these following should never happen else if(flext::IsFloat(at)) return PyFloat_FromDouble((double)flext::GetFloat(at)); else if(flext::IsInt(at)) return PyInt_FromLong(flext::GetInt(at)); - +*/ return NULL; } diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp index 5a870d10..72ae41fd 100644 --- a/externals/grill/py/source/pyext.cpp +++ b/externals/grill/py/source/pyext.cpp @@ -239,6 +239,8 @@ void pyext::DoExit() Py_DECREF(args); Py_DECREF(objdel); } + else + PyErr_Clear(); gcrun = pyobj->ob_refcnt > 1; Py_DECREF(pyobj); // opposite of SetClssMeth |