Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27244/source
Modified Files: bound.cpp clmeth.cpp main.cpp main.h modmeth.cpp py.cpp pyargs.cpp pyext.cpp pyext.h register.cpp Log Message: support for Python threads, at last
Index: clmeth.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** clmeth.cpp 31 Aug 2004 04:07:35 -0000 1.9 --- clmeth.cpp 10 Nov 2004 03:31:34 -0000 1.10 *************** *** 3,7 **** py/pyext - python external object for PD and Max/MSP
! Copyright (c) 2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and Max/MSP
! Copyright (c) 2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.
Index: pyargs.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyargs.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pyargs.cpp 20 Sep 2004 04:06:08 -0000 1.8 --- pyargs.cpp 10 Nov 2004 03:31:34 -0000 1.9 *************** *** 3,7 **** py/pyext - python external object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** main.cpp 26 Sep 2004 23:03:16 -0000 1.17 --- main.cpp 10 Nov 2004 03:31:34 -0000 1.18 *************** *** 3,7 **** py/pyext - python external object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 10,14 ****
#include "main.h" !
static PyMethodDef StdOut_Methods[] = --- 10,14 ----
#include "main.h" ! #include <map>
static PyMethodDef StdOut_Methods[] = *************** *** 18,21 **** --- 18,59 ---- };
+ + #ifdef FLEXT_THREADS + typedef std::map<flext::thrid_t,PyThreadState *> PyThrMap; + + static PyInterpreterState *pystate = NULL; + static PyThreadState *pythrmain = NULL; + static PyThrMap pythrmap; + + PyThreadState *FindThreadState() + { + flext::thrid_t id = flext::GetThreadId(); + PyThrMap::iterator it = pythrmap.find(id); + if(it == pythrmap.end()) { + // Make new thread state + PyThreadState *st = PyThreadState_New(pystate); + pythrmap[id] = st; + return st; + } + else + return it->second; + } + + void FreeThreadState() + { + flext::thrid_t id = flext::GetThreadId(); + PyThrMap::iterator it = pythrmap.find(id); + if(it != pythrmap.end()) { + // clear out any cruft from thread state object + PyThreadState_Clear(it->second); + // delete my thread state object + PyThreadState_Delete(it->second); + // delete from map + pythrmap.erase(it); + } + } + #endif + + V py::lib_setup() { *************** *** 73,82 ****
- #ifdef FLEXT_THREADS - PyInterpreterState *py::pystate = NULL; - PyThreadState *py::pythrmain = NULL; - PyThrMap py::pythrmap; - #endif - PyObject *py::module_obj = NULL; PyObject *py::module_dict = NULL; --- 111,114 ----
Index: pyext.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** pyext.h 9 Sep 2004 04:06:33 -0000 1.16 --- pyext.h 10 Nov 2004 03:31:34 -0000 1.17 *************** *** 3,7 **** py/pyext - python external object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.
Index: modmeth.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/modmeth.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** modmeth.cpp 20 Sep 2004 04:06:08 -0000 1.11 --- modmeth.cpp 10 Nov 2004 03:31:34 -0000 1.12 *************** *** 3,7 **** py/pyext - python external object for PD and Max/MSP
! Copyright (c) 2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and Max/MSP
! Copyright (c) 2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.
Index: bound.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/bound.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** bound.cpp 9 Sep 2004 04:06:33 -0000 1.11 --- bound.cpp 10 Nov 2004 03:31:34 -0000 1.12 *************** *** 3,7 **** py/pyext - python external object for PD and MaxMSP
! Copyright (c) 2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and MaxMSP
! Copyright (c) 2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.
Index: register.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/register.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** register.cpp 31 Aug 2004 04:07:35 -0000 1.3 --- register.cpp 10 Nov 2004 03:31:34 -0000 1.4 *************** *** 3,7 **** py/pyext - python external object for PD and MaxMSP
! Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python external object for PD and MaxMSP
! Copyright (c) 2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** main.h 26 Sep 2004 23:03:16 -0000 1.23 --- main.h 10 Nov 2004 03:31:34 -0000 1.24 *************** *** 3,7 **** py/pyext - python script object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python script object for PD and MaxMSP
! Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 20,24 **** #include <Python.h> #endif - #include <map>
#if FLEXT_OS == FLEXT_LINUX || FLEXT_OS == FLEXT_IRIX --- 20,23 ---- *************** *** 30,34 **** #endif
! #define PY__VERSION "0.1.4"
--- 29,33 ---- #endif
! #define PY__VERSION "0.2.0pre"
*************** *** 51,58 **** #include "main.h"
- #ifdef FLEXT_THREADS - typedef std::map<flext::thrid_t,PyThreadState *> PyThrMap; - #endif - class py: public flext_base --- 50,53 ---- *************** *** 135,141 ****
#ifdef FLEXT_THREADS - static PyInterpreterState *pystate; - static PyThreadState *pythrmain; - static PyThrMap pythrmap; ThrMutex mutex; inline V Lock() { mutex.Unlock(); } --- 130,133 ---- *************** *** 162,173 **** #ifdef FLEXT_THREADS
! // if thread is not found in the thread map, the state of the system thread is used ! // we have yet to see if this has bad side-effects
#define PY_LOCK \ { \ PyEval_AcquireLock(); \ ! PyThrMap::iterator it = pythrmap.find(GetThreadId()); \ ! PyThreadState *__st = it != pythrmap.end()?it->second:pythrmain; \ PyThreadState *__oldst = PyThreadState_Swap(__st);
--- 154,164 ---- #ifdef FLEXT_THREADS
! PyThreadState *FindThreadState(); ! void FreeThreadState();
#define PY_LOCK \ { \ PyEval_AcquireLock(); \ ! PyThreadState *__st = FindThreadState(); \ PyThreadState *__oldst = PyThreadState_Swap(__st);
Index: pyext.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** pyext.cpp 26 Sep 2004 23:03:16 -0000 1.21 --- pyext.cpp 10 Nov 2004 03:31:34 -0000 1.22 *************** *** 3,7 **** py/pyext - python script object for PD and Max/MSP
! Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python script object for PD and Max/MSP
! Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 257,264 ****
ClearBinding(); ! Unregister("_pyext"); ! UnimportModule();
! Py_XDECREF(pyobj); // opposite of SetClssMeth
PY_UNLOCK --- 257,268 ----
ClearBinding(); ! ! if(pyobj) { ! if(pyobj->ob_refcnt > 1) post("%s - Python object is still referenced",thisName()); ! Py_DECREF(pyobj); // opposite of SetClssMeth ! }
! Unregister("_pyext"); ! UnimportModule();
PY_UNLOCK *************** *** 496,506 **** PyEval_AcquireLock(); // create a thread state object for this thread ! PyThreadState *newthr = PyThreadState_New(pystate); // free the lock PyEval_ReleaseLock(); - // ----------------------------- - - // store new thread state - pythrmap[GetThreadId()] = newthr; #endif { --- 500,506 ---- PyEval_AcquireLock(); // create a thread state object for this thread ! PyThreadState *newthr = FindThreadState(); // free the lock PyEval_ReleaseLock(); #endif { *************** *** 512,518 ****
#ifdef FLEXT_THREADS - // delete mapped thread state - pythrmap.erase(GetThreadId()); - // --- delete Python thread --- // grab the lock --- 512,515 ---- *************** *** 520,527 **** // swap my thread state out of the interpreter PyThreadState_Swap(NULL); ! // clear out any cruft from thread state object ! PyThreadState_Clear(newthr); ! // delete my thread state object ! PyThreadState_Delete(newthr); // release the lock PyEval_ReleaseLock(); --- 517,522 ---- // swap my thread state out of the interpreter PyThreadState_Swap(NULL); ! // delete mapped thread state ! FreeThreadState(); // release the lock PyEval_ReleaseLock();
Index: py.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/py.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** py.cpp 20 Sep 2004 04:06:08 -0000 1.14 --- py.cpp 10 Nov 2004 03:31:34 -0000 1.15 *************** *** 3,7 **** py/pyext - python script object for PD and Max/MSP
! Copyright (c)2002-2004 Thomas Grill (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. --- 3,7 ---- py/pyext - python script object for PD and Max/MSP
! Copyright (c)2002-2004 Thomas Grill (gr@grrrr.org) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution.