Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18952/source
Modified Files: main.cpp main.h py.cpp pybuffer.cpp pydsp.cpp pyext.cpp Log Message: fixes for OSX docs optimizations and fixes use optimized version optimized function calls adjust pd and py files for correct argument passing more optimizations
Index: pybuffer.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pybuffer.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** pybuffer.cpp 13 Mar 2005 04:59:47 -0000 1.3 --- pybuffer.cpp 14 Mar 2005 04:58:13 -0000 1.4 *************** *** 12,16 **** --- 12,20 ----
#ifdef PY_NUMARRAY + #if FLEXT_OS == FLEXT_OS_MAC + #include <Python/numarray/numarray.h> + #else #include <numarray/numarray.h> + #endif static bool nasupport = false; static NumarrayType numtype; *************** *** 19,24 **** // PD defines a T_OBJECT symbol #undef T_OBJECT ! #include "structmember.h" #include "bufferobject.h"
static PyObject *buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds) --- 23,34 ---- // PD defines a T_OBJECT symbol #undef T_OBJECT ! ! #if FLEXT_OS == FLEXT_OS_MAC ! #include "Python/bufferobject.h" ! #include "Python/structmember.h" ! #else #include "bufferobject.h" + #include "structmember.h" + #endif
static PyObject *buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Index: pydsp.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pydsp.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pydsp.cpp 13 Mar 2005 04:59:47 -0000 1.1 --- pydsp.cpp 14 Mar 2005 04:58:13 -0000 1.2 *************** *** 27,31 **** virtual PyObject *GetSig(int ix,bool in);
! void NewBuffers(bool update = false); void FreeBuffers();
--- 27,31 ---- virtual PyObject *GetSig(int ix,bool in);
! void NewBuffers(); void FreeBuffers();
*************** *** 47,52 **** if(pyobj) { - NewBuffers(); - dspfun = PyObject_GetAttrString(pyobj,"_dsp"); // get ref if(dspfun && !PyMethod_Check(dspfun)) { --- 47,50 ---- *************** *** 54,62 **** dspfun = NULL; } - sigfun = PyObject_GetAttrString(pyobj,"_signal"); // get ref - if(sigfun && !PyMethod_Check(sigfun)) { - Py_DECREF(sigfun); - sigfun = NULL; - } } return true; --- 52,55 ---- *************** *** 73,77 **** PyObject *NAFromBuffer(PyObject *buf,int c,int n);
! void pydsp::NewBuffers(bool update) { int i,n = Blocksize(); --- 66,70 ---- PyObject *NAFromBuffer(PyObject *buf,int c,int n);
! void pydsp::NewBuffers() { int i,n = Blocksize(); *************** *** 80,93 **** t_sample *const *outsigs = OutSig();
if(!buffers) { int cnt = ins+outs; ! if(cnt) { ! buffers = new PyObject *[cnt]; ! memset(buffers,0,cnt*sizeof(*buffers)); ! } }
for(i = 0; i < ins; ++i) { ! if(update) Py_XDECREF(buffers[i]); PyObject *b = PyBuffer_FromReadWriteMemory(insigs[i],n*sizeof(t_sample)); buffers[i] = NAFromBuffer(b,1,n); --- 73,85 ---- t_sample *const *outsigs = OutSig();
+ // inlet/outlet count can't change so we don't have to deallocate if(!buffers) { int cnt = ins+outs; ! buffers = new PyObject *[cnt]; ! memset(buffers,0,cnt*sizeof(*buffers)); }
for(i = 0; i < ins; ++i) { ! Py_XDECREF(buffers[i]); PyObject *b = PyBuffer_FromReadWriteMemory(insigs[i],n*sizeof(t_sample)); buffers[i] = NAFromBuffer(b,1,n); *************** *** 95,99 **** } for(i = 0; i < outs; ++i) { ! if(update) Py_XDECREF(buffers[ins+i]); if(i < ins && outsigs[i] == insigs[i]) { // same vectors - share the objects! --- 87,91 ---- } for(i = 0; i < outs; ++i) { ! Py_XDECREF(buffers[ins+i]); if(i < ins && outsigs[i] == insigs[i]) { // same vectors - share the objects! *************** *** 121,133 **** bool pydsp::CbDsp() { ! if(CntInSig() || CntOutSig()) { ! NewBuffers(true);
if(dspfun) { ! PyThreadState *state = PyLock(); ! // Py_INCREF(emptytuple); ! PyObject *ret = PyObject_Call(dspfun,emptytuple,NULL); ! // Py_DECREF(emptytuple); if(ret) Py_DECREF(ret); --- 113,124 ---- bool pydsp::CbDsp() { ! if(pyobj && (CntInSig() || CntOutSig())) { ! PyThreadState *state = PyLockSys(); ! ! NewBuffers();
if(dspfun) { ! PyObject *ret = PyObject_CallObject(dspfun,NULL); if(ret) Py_DECREF(ret); *************** *** 139,145 **** #endif } - PyUnlock(state); } ! return true; } else --- 130,147 ---- #endif } } ! ! // do that here instead of where dspfun is initialized, so that ! // _signal can be assigned in _dsp ! // optimizations may be done there to assign the right _signal version ! Py_XDECREF(sigfun); ! sigfun = PyObject_GetAttrString(pyobj,"_signal"); // get ref ! if(sigfun && !PyMethod_Check(sigfun)) { ! Py_DECREF(sigfun); ! sigfun = NULL; ! } ! ! PyUnlock(state); ! return sigfun != NULL; } else *************** *** 150,172 **** void pydsp::CbSignal() { ! if(sigfun) { ! PyThreadState *state = PyLock(); ! // Py_INCREF(emptytuple); ! PyObject *ret = PyObject_Call(sigfun,emptytuple,NULL); ! // Py_DECREF(emptytuple);
! if(ret) ! Py_DECREF(ret); ! else { #ifdef FLEXT_DEBUG ! PyErr_Print(); #else ! PyErr_Clear(); #endif - } - PyUnlock(state); } ! else ! flext_dsp::CbSignal(); }
--- 152,168 ---- void pydsp::CbSignal() { ! PyThreadState *state = PyLockSys(); ! PyObject *ret = PyObject_CallObject(sigfun,NULL);
! if(ret) ! Py_DECREF(ret); ! else { #ifdef FLEXT_DEBUG ! PyErr_Print(); #else ! PyErr_Clear(); #endif } ! PyUnlock(state); }
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** main.h 13 Mar 2005 04:59:47 -0000 1.36 --- main.h 14 Mar 2005 04:58:13 -0000 1.37 *************** *** 93,98 **** enum retval { nothing,atom,sequ };
- static PyObject *emptytuple; - // --- module stuff -----
--- 93,96 ---- *************** *** 155,161 **** --- 153,162 ---- PyFifo qufifo; ThrCond qucond; + static PyThreadState *pythrsys;
static PyThreadState *FindThreadState(); static void FreeThreadState(); + #else + static PyThreadState *FindThreadState() { return NULL; } #endif
*************** *** 167,191 **** 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 // (recursive calls can only happen in the system thread) static int lockcount;
! inline PyThreadState *PyLock() { if(!IsSystemThread() || !lockcount++) PyEval_AcquireLock(); ! return PyThreadState_Swap(FindThreadState()); }
inline void PyUnlock(PyThreadState *st) { ! PyThreadState_Swap(st); ! if(!IsSystemThread() || !--lockcount) PyEval_ReleaseLock(); } #else inline void Lock() {} inline void Unlock() {}
! inline PyThreadState *PyLock() { return NULL; } inline void PyUnlock(PyThreadState *st) {} #endif --- 168,200 ---- inline void Unlock() { mutex.Unlock(); }
! // this is especially 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 // (recursive calls can only happen in the system thread) static int lockcount;
! inline PyThreadState *PyLock(PyThreadState *st = FindThreadState()) { if(!IsSystemThread() || !lockcount++) PyEval_AcquireLock(); ! return PyThreadState_Swap(st); ! } ! ! inline PyThreadState *PyLockSys() ! { ! if(!lockcount++) PyEval_AcquireLock(); ! return PyThreadState_Swap(pythrsys); }
inline void PyUnlock(PyThreadState *st) { ! PyThreadState *old = PyThreadState_Swap(st); ! if(old != pythrsys || !--lockcount) PyEval_ReleaseLock(); } + #else inline void Lock() {} inline void Unlock() {}
! inline PyThreadState *PyLock(PyThreadState *) { return NULL; } ! inline PyThreadState *PyLockSys() { return NULL; } inline void PyUnlock(PyThreadState *st) {} #endif
Index: pyext.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** pyext.cpp 13 Mar 2005 04:59:47 -0000 1.29 --- pyext.cpp 14 Mar 2005 04:58:13 -0000 1.30 *************** *** 132,136 **** const t_atom *clname = NULL;
! PyThreadState *state = PyLock();
// init script module --- 132,136 ---- const t_atom *clname = NULL;
! PyThreadState *state = PyLockSys();
// init script module *************** *** 189,193 **** bool pyext::Init() { ! PyThreadState *state = PyLock();
if(methname) { --- 189,193 ---- bool pyext::Init() { ! PyThreadState *state = PyLockSys();
if(methname) { *************** *** 216,220 **** pybase::Exit(); // exit threads
! PyThreadState *state = PyLock(); DoExit(); Unregister("_pyext"); --- 216,220 ---- pybase::Exit(); // exit threads
! PyThreadState *state = PyLockSys(); DoExit(); Unregister("_pyext"); *************** *** 260,265 **** PyObject *objdel = PyObject_GetAttrString(pyobj,"_del"); if(objdel) { ! Py_INCREF(emptytuple); ! PyObject *ret = PyObject_Call(objdel,emptytuple,NULL); if(ret) Py_DECREF(ret); --- 260,264 ---- PyObject *objdel = PyObject_GetAttrString(pyobj,"_del"); if(objdel) { ! PyObject *ret = PyObject_CallObject(objdel,NULL); if(ret) Py_DECREF(ret); *************** *** 268,272 **** post("%s - Could not call _del method",thisName()); #endif - Py_DECREF(emptytuple); Py_DECREF(objdel); } --- 267,270 ---- *************** *** 382,386 **** void pyext::m_reload() { ! PyThreadState *state = PyLock();
Unregister("_pyext"); // self --- 380,384 ---- void pyext::m_reload() { ! PyThreadState *state = PyLockSys();
Unregister("_pyext"); // self *************** *** 404,408 **** void pyext::m_get(const t_symbol *s) { ! PyThreadState *state = PyLock();
PyObject *pvar = PyObject_GetAttrString(pyobj,const_cast<char *>(GetString(s))); /* fetch bound method */ --- 402,406 ---- void pyext::m_get(const t_symbol *s) { ! PyThreadState *state = PyLockSys();
PyObject *pvar = PyObject_GetAttrString(pyobj,const_cast<char *>(GetString(s))); /* fetch bound method */ *************** *** 432,436 **** void pyext::m_set(int argc,const t_atom *argv) { ! PyThreadState *state = PyLock();
if(argc < 2 || !IsString(argv[0])) --- 430,434 ---- void pyext::m_set(int argc,const t_atom *argv) { ! PyThreadState *state = PyLockSys();
if(argc < 2 || !IsString(argv[0])) *************** *** 507,511 **** bool pyext::callpy(PyObject *fun,PyObject *args) { ! PyObject *ret = PyObject_Call(fun,args,NULL); if(ret == NULL) { // function not found resp. arguments not matching --- 505,509 ---- bool pyext::callpy(PyObject *fun,PyObject *args) { ! PyObject *ret = PyObject_CallObject(fun,args); if(ret == NULL) { // function not found resp. arguments not matching
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** main.cpp 13 Mar 2005 04:59:47 -0000 1.30 --- main.cpp 14 Mar 2005 04:58:13 -0000 1.31 *************** *** 25,30 ****
static PyInterpreterState *pymain = NULL; - static PyThreadState *pythrmain = NULL; static PyThrMap pythrmap;
int pybase::lockcount = 0; --- 25,30 ----
static PyInterpreterState *pymain = NULL; static PyThrMap pythrmap; + PyThreadState *pybase::pythrsys = NULL;
int pybase::lockcount = 0; *************** *** 63,68 **** PyObject *pybase::module_dict = NULL;
- PyObject *pybase::emptytuple = NULL; -
void initsymbol(); --- 63,66 ---- *************** *** 96,105 ****
// get thread state ! pythrmain = PyThreadState_Get(); // get main interpreter state ! pymain = pythrmain->interp;
// add thread state of main thread to map ! pythrmap[GetThreadId()] = pythrmain; #endif
--- 94,103 ----
// get thread state ! pythrsys = PyThreadState_Get(); // get main interpreter state ! pymain = pythrsys->interp;
// add thread state of main thread to map ! pythrmap[GetThreadId()] = pythrsys; #endif
*************** *** 144,149 **** PyModule_AddObject(module_obj,"Buffer",(PyObject *)&pySamplebuffer_Type);
- emptytuple = PyTuple_New(0); - // -------------------------------------------------------------
--- 142,145 ---- *************** *** 170,174 **** #endif { ! PyThreadState *state = PyLock(); Py_INCREF(module_obj); PyUnlock(state); --- 166,170 ---- #endif { ! PyThreadState *state = PyLockSys(); Py_INCREF(module_obj); PyUnlock(state); *************** *** 177,181 **** pybase::~pybase() { ! PyThreadState *state = PyLock(); Py_XDECREF(module_obj); PyUnlock(state); --- 173,177 ---- pybase::~pybase() { ! PyThreadState *state = PyLockSys(); Py_XDECREF(module_obj); PyUnlock(state); *************** *** 528,532 **** { FifoEl *el; ! PyThreadState *state;
++thrcount; --- 524,528 ---- { FifoEl *el; ! PyThreadState *my = FindThreadState(),*state;
++thrcount; *************** *** 534,538 **** while(el = qufifo.Get()) { ++thrcount; ! state = PyLock(); callpy(el->fun,el->args); Py_XDECREF(el->fun); --- 530,534 ---- while(el = qufifo.Get()) { ++thrcount; ! state = PyLock(my); callpy(el->fun,el->args); Py_XDECREF(el->fun); *************** *** 548,552 **** }
! state = PyLock(); // unref remaining Python objects while(el = qufifo.Get()) { --- 544,548 ---- }
! state = PyLock(my); // unref remaining Python objects while(el = qufifo.Get()) { *************** *** 576,582 **** { if(gcollect) { ! Py_INCREF(emptytuple); ! PyObject *ret = PyObject_Call(gcollect,emptytuple,NULL); ! Py_DECREF(emptytuple); if(ret) { #ifdef FLEXT_DEBUG --- 572,576 ---- { if(gcollect) { ! PyObject *ret = PyObject_CallObject(gcollect,NULL); if(ret) { #ifdef FLEXT_DEBUG
Index: py.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/py.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** py.cpp 13 Mar 2005 04:59:47 -0000 1.20 --- py.cpp 14 Mar 2005 04:58:13 -0000 1.21 *************** *** 134,138 **** #endif
! PyThreadState *state = PyLock();
if(argc > 2) --- 134,138 ---- #endif
! PyThreadState *state = PyLockSys();
if(argc > 2) *************** *** 189,193 **** pyobj::~pyobj() { ! PyThreadState *state = PyLock(); Unregister("_py"); PyUnlock(state); --- 189,193 ---- pyobj::~pyobj() { ! PyThreadState *state = PyLockSys(); Unregister("_py"); PyUnlock(state); *************** *** 209,213 **** void pyobj::m_reload() { ! PyThreadState *state = PyLock();
Unregister("_py"); --- 209,213 ---- void pyobj::m_reload() { ! PyThreadState *state = PyLockSys();
Unregister("_py"); *************** *** 223,227 **** void pyobj::m_reload_(int argc,const t_atom *argv) { ! PyThreadState *state = PyLock(); SetArgs(argc,argv); PyUnlock(state); --- 223,227 ---- void pyobj::m_reload_(int argc,const t_atom *argv) { ! PyThreadState *state = PyLockSys(); SetArgs(argc,argv); PyUnlock(state); *************** *** 232,236 **** void pyobj::m_set(int argc,const t_atom *argv) { ! PyThreadState *state = PyLock();
int ix = 0; --- 232,236 ---- void pyobj::m_set(int argc,const t_atom *argv) { ! PyThreadState *state = PyLockSys();
int ix = 0; *************** *** 329,333 **** bool pyobj::callpy(PyObject *fun,PyObject *args) { ! PyObject *ret = PyObject_Call(fun,args,NULL); if(ret == NULL) { // function not found resp. arguments not matching --- 329,333 ---- bool pyobj::callpy(PyObject *fun,PyObject *args) { ! PyObject *ret = PyObject_CallObject(fun,args); if(ret == NULL) { // function not found resp. arguments not matching