Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27140/source
Modified Files: clmeth.cpp main.cpp main.h pyargs.cpp pyext.cpp Log Message: better error reporting use lock count instead of message queuing to avoid py->py messaging deadlock must clear Python error...
Index: clmeth.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** clmeth.cpp 11 Jan 2005 04:59:27 -0000 1.13 --- clmeth.cpp 27 Feb 2005 04:57:30 -0000 1.14 *************** *** 176,184 **** // 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); else if(lst->Count() > 1) ! ext->ToQueueList(o-1,*lst); else ! ext->ToQueueAtom(o-1,*lst->Atoms()); } else --- 176,184 ---- // deadlock would occur if this was another py/pyext object! if(lst->Count() && IsSymbol((*lst)[0])) ! ext->ToOutAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1); else if(lst->Count() > 1) ! ext->ToOutList(o-1,*lst); else ! ext->ToOutAtom(o-1,*lst->Atoms()); } else
Index: pyargs.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyargs.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** pyargs.cpp 19 Jan 2005 04:58:36 -0000 1.12 --- pyargs.cpp 27 Feb 2005 04:57:47 -0000 1.13 *************** *** 15,20 **** 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)) { // if a number can be an integer... let at be an integer! int ival = flext::GetAInt(at); --- 15,19 ---- if(flext::IsSymbol(at)) return pySymbol_FromSymbol(flext::GetSymbol(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); *************** *** 22,29 **** return (double)ival == fval?PyInt_FromLong(ival):PyFloat_FromDouble(fval); } // 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; } --- 21,30 ---- 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; }
Index: pyext.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** pyext.cpp 26 Feb 2005 04:57:48 -0000 1.27 --- pyext.cpp 27 Feb 2005 04:57:47 -0000 1.28 *************** *** 240,243 **** --- 240,245 ---- Py_DECREF(objdel); } + else + PyErr_Clear();
gcrun = pyobj->ob_refcnt > 1;
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** main.cpp 26 Feb 2005 04:57:48 -0000 1.24 --- main.cpp 27 Feb 2005 04:57:47 -0000 1.25 *************** *** 28,31 **** --- 28,33 ---- static PyThrMap pythrmap;
+ int py::lockcount = 0; + PyThreadState *py::FindThreadState() {
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** main.h 26 Feb 2005 04:57:48 -0000 1.31 --- main.h 27 Feb 2005 04:57:47 -0000 1.32 *************** *** 160,166 **** inline void Unlock() { mutex.Unlock(); }
inline PyThreadState *PyLock() { ! PyEval_AcquireLock(); return PyThreadState_Swap(FindThreadState()); } --- 160,170 ---- 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() { ! if(!lockcount++) PyEval_AcquireLock(); return PyThreadState_Swap(FindThreadState()); } *************** *** 169,173 **** { PyThreadState_Swap(st); ! PyEval_ReleaseLock(); } #else --- 173,177 ---- { PyThreadState_Swap(st); ! if(!--lockcount) PyEval_ReleaseLock(); } #else