From 4890f929915b27e94cce04d19ab4e72cfbe93715 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sun, 27 Feb 2005 04:57:47 +0000 Subject: 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 --- externals/grill/py/license.txt | 2 +- externals/grill/py/readme.txt | 3 ++- externals/grill/py/source/clmeth.cpp | 6 +++--- externals/grill/py/source/main.cpp | 2 ++ externals/grill/py/source/main.h | 8 ++++++-- externals/grill/py/source/pyargs.cpp | 7 ++++--- externals/grill/py/source/pyext.cpp | 2 ++ 7 files changed, 20 insertions(+), 10 deletions(-) (limited to 'externals') diff --git a/externals/grill/py/license.txt b/externals/grill/py/license.txt index 8d768d93..f3813962 100644 --- a/externals/grill/py/license.txt +++ b/externals/grill/py/license.txt @@ -1,5 +1,5 @@ py/pyext - python script objects for PD and MaxMSP -Copyright (C) 2002-2003 Thomas Grill +Copyright (C) 2002-2005 Thomas Grill This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt index ba16e3ff..e7aae3f0 100644 --- a/externals/grill/py/readme.txt +++ b/externals/grill/py/readme.txt @@ -82,6 +82,7 @@ Version history: - FIX: bound instance methods weren't correctly decref'd - ADD: Python symbol type - ADD: _del method in pyext-derived class can be used to clean up things on exit +- FIX: solved py->py messaging problem with lock count instead of message queuing 0.1.4: - ADD: better (and independent) handling of inlet and outlet count (as class variables or dynamically initialized in __init__) @@ -120,7 +121,7 @@ Version history: - CHANGE: updates for flext 0.4.0 - FIX: crash when module couldn't be loaded - FIX: GetBound method (modmeth.cpp, line 138) doesn't exist in flext any more -- FIX: deadlock occured when connecting to py/pyext boxes in non-detached mode +- FIX: deadlock occured when connecting two py/pyext boxes in non-detached mode - ADD: current path and path of the canvas is added to the python path - FIX: path is not added to python path if already included 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 -- cgit v1.2.1