From c6ba54641bcf5e44fa914476d72455a524ed172f Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sun, 10 Apr 2005 22:24:13 +0000 Subject: added xcode project cleaner error reporting added generic numpy support (not working) use lock count instead of message queuing to avoid py->py messaging deadlock fixing strange gcc behavior fixes for maxmsp support for buffer objects (preliminary) fixed reference count bug use optimized version updates for DSP processing adjust pd and py files for correct argument passing more optimizations fixed numarray headers little restructuring svn path=/trunk/; revision=2708 --- externals/grill/py/source/clmeth.cpp | 2 +- externals/grill/py/source/main.cpp | 5 ++-- externals/grill/py/source/main.h | 1 + externals/grill/py/source/modmeth.cpp | 1 + externals/grill/py/source/py.cpp | 2 +- externals/grill/py/source/pybuffer.cpp | 46 ++++++++++++++++++---------------- externals/grill/py/source/pydsp.cpp | 28 +++++++++++++++------ externals/grill/py/source/pyext.cpp | 7 +++--- 8 files changed, 56 insertions(+), 36 deletions(-) (limited to 'externals/grill/py/source') diff --git a/externals/grill/py/source/clmeth.cpp b/externals/grill/py/source/clmeth.cpp index 267d2da9..3f856f57 100644 --- a/externals/grill/py/source/clmeth.cpp +++ b/externals/grill/py/source/clmeth.cpp @@ -80,7 +80,7 @@ PyObject* pyext::pyext__del__(PyObject *,PyObject *args) PyObject* pyext::pyext_setattr(PyObject *,PyObject *args) { - PyObject *self,*name,*val,*ret = NULL; + PyObject *self,*name,*val; if(!PyArg_ParseTuple(args, "OOO:test_foo", &self,&name,&val)) { // handle error ERRINTERNAL(); diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp index 608ecdd7..fadb0173 100644 --- a/externals/grill/py/source/main.cpp +++ b/externals/grill/py/source/main.cpp @@ -160,10 +160,11 @@ FLEXT_LIB_SETUP(py,pybase::lib_setup) pybase::pybase() - : module(NULL),detach(0) + : module(NULL) #ifdef FLEXT_THREADS , shouldexit(false),thrcount(0),stoptick(0) #endif + , detach(0) { PyThreadState *state = PyLockSys(); Py_INCREF(module_obj); @@ -244,7 +245,7 @@ void pybase::m__doc(PyObject *obj) } else { // copy string before newline to temp buffer and post - int l = nl-s; + unsigned int l = nl-s; if(l >= sizeof(buf)) l = sizeof buf-1; strncpy(buf,s,l); // copy all but newline buf[l] = 0; diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h index 538e577d..b828f47b 100644 --- a/externals/grill/py/source/main.h +++ b/externals/grill/py/source/main.h @@ -107,6 +107,7 @@ protected: static PyObject *py_priority(PyObject *,PyObject *args); #endif + static PyObject *py_arraysupport(PyObject *,PyObject *args); static PyObject *py_samplerate(PyObject *,PyObject *args); static PyObject *py_blocksize(PyObject *,PyObject *args); diff --git a/externals/grill/py/source/modmeth.cpp b/externals/grill/py/source/modmeth.cpp index 983176bf..33f0fc7b 100644 --- a/externals/grill/py/source/modmeth.cpp +++ b/externals/grill/py/source/modmeth.cpp @@ -19,6 +19,7 @@ PyMethodDef pybase::func_tbl[] = { "_priority", pybase::py_priority, METH_VARARGS,"Set priority of current thread" }, #endif + { "_arraysupport", pybase::py_arraysupport, METH_NOARGS,"Query Python array support" }, { "_samplerate", pybase::py_samplerate, METH_NOARGS,"Get system sample rate" }, { "_blocksize", pybase::py_blocksize, METH_NOARGS,"Get system block size" }, diff --git a/externals/grill/py/source/py.cpp b/externals/grill/py/source/py.cpp index 44d7a608..93309b37 100644 --- a/externals/grill/py/source/py.cpp +++ b/externals/grill/py/source/py.cpp @@ -122,7 +122,7 @@ void pyobj::Setup(t_classid c) } pyobj::pyobj(int argc,const t_atom *argv): - function(NULL),funname(NULL),withfunction(false) + funname(NULL),function(NULL),withfunction(false) { AddInAnything(2); AddOutAnything(); diff --git a/externals/grill/py/source/pybuffer.cpp b/externals/grill/py/source/pybuffer.cpp index 42e23557..0893b983 100644 --- a/externals/grill/py/source/pybuffer.cpp +++ b/externals/grill/py/source/pybuffer.cpp @@ -15,43 +15,47 @@ WARRANTIES, see the file, "license.txt," in this distribution. #if defined(PY_NUMERIC) #define PY_ARRAYS 1 - - #if FLEXT_OS == FLEXT_OS_MAC - #include - #else - #include - #endif #elif defined(PY_NUMARRAY) #define PY_ARRAYS 1 #define NA +#endif + +#ifdef PY_ARRAYS #ifdef NA #if FLEXT_OS == FLEXT_OS_MAC - #include + #include #else - #include + #include #endif + +static NumarrayType numtype = tAny; +inline bool arrsupport() { return numtype != tAny; } + #else #if FLEXT_OS == FLEXT_OS_MAC #include #else #include #endif + +static PyArray_TYPES numtype = PyArray_NOTYPE; +inline bool arrsupport() { return numtype != PyArray_NOTYPE; } #endif #endif +PyObject *pybase::py_arraysupport(PyObject *self,PyObject *args) +{ + PyObject *ret; #ifdef PY_ARRAYS - -#ifdef NA -static NumarrayType numtype = tAny; -inline bool arrsupport() { return numtype != tAny; } + ret = Py_True; #else -static PyArray_TYPES numtype = PyArray_NOTYPE; -inline bool arrsupport() { return numtype != PyArray_NOTYPE; } -#endif - + ret = Py_False; #endif + Py_INCREF(ret); + return ret; +} // PD defines a T_OBJECT symbol @@ -408,13 +412,13 @@ static PyObject *buffer_repeat(pySamplebuffer *self,int rep) static PySequenceMethods buffer_as_seq = { - (inquiry)buffer_length, /* inquiry sq_length; /* __len__ */ + (inquiry)buffer_length, /* inquiry sq_length; __len__ */ (binaryfunc)buffer_concat, /* __add__ */ (intargfunc)buffer_repeat, /* __mul__ */ - (intargfunc)buffer_item, /* intargfunc sq_item; /* __getitem__ */ - (intintargfunc)buffer_slice, /* intintargfunc sq_slice; /* __getslice__ */ - (intobjargproc)buffer_ass_item, /* intobjargproc sq_ass_item; /* __setitem__ */ - (intintobjargproc)buffer_ass_slice, /* intintobjargproc sq_ass_slice; /* __setslice__ */ + (intargfunc)buffer_item, /* intargfunc sq_item; __getitem__ */ + (intintargfunc)buffer_slice, /* intintargfunc sq_slice; __getslice__ */ + (intobjargproc)buffer_ass_item, /* intobjargproc sq_ass_item; __setitem__ */ + (intintobjargproc)buffer_ass_slice, /* intintobjargproc sq_ass_slice; __setslice__ */ }; static PyObject *buffer_iter(PyObject *obj) diff --git a/externals/grill/py/source/pydsp.cpp b/externals/grill/py/source/pydsp.cpp index 28d7d49b..cecefbe2 100644 --- a/externals/grill/py/source/pydsp.cpp +++ b/externals/grill/py/source/pydsp.cpp @@ -47,10 +47,12 @@ bool pydsp::DoInit() if(pyobj) { dspfun = PyObject_GetAttrString(pyobj,"_dsp"); // get ref - if(dspfun && !PyMethod_Check(dspfun)) { + if(!dspfun) + PyErr_Clear(); + else if(!PyMethod_Check(dspfun)) { Py_DECREF(dspfun); dspfun = NULL; - } + } } return true; } @@ -118,10 +120,13 @@ bool pydsp::CbDsp() NewBuffers(); + bool dodsp = true; if(dspfun) { PyObject *ret = PyObject_CallObject(dspfun,NULL); - if(ret) + if(ret) { + dodsp = PyObject_IsTrue(ret); Py_DECREF(ret); + } else { #ifdef FLEXT_DEBUG PyErr_Print(); @@ -135,11 +140,18 @@ bool pydsp::CbDsp() // _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; - } + + if(dodsp) { + sigfun = PyObject_GetAttrString(pyobj,"_signal"); // get ref + if(!sigfun) + PyErr_Clear(); + else if(!PyMethod_Check(sigfun)) { + Py_DECREF(sigfun); + sigfun = NULL; + } + } + else + sigfun = NULL; PyUnlock(state); return sigfun != NULL; diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp index 2fd0ee22..eb58d1a0 100644 --- a/externals/grill/py/source/pyext.cpp +++ b/externals/grill/py/source/pyext.cpp @@ -97,7 +97,7 @@ void pyext::SetThis() { // remember the this pointer PyObject *th = PyLong_FromVoidPtr(this); - int ret = PyObject_SetAttrString(pyobj,"_this",th); // ref is taken + /*int ret =*/ PyObject_SetAttrString(pyobj,"_this",th); // ref is taken } @@ -105,10 +105,11 @@ PyObject *pyext::class_obj = NULL; PyObject *pyext::class_dict = NULL; pyext::pyext(int argc,const t_atom *argv,bool sig): - pyobj(NULL),pythr(NULL), + methname(NULL), + pyobj(NULL), inlets(-1),outlets(-1), siginlets(0),sigoutlets(0), - methname(NULL) + pythr(NULL) { #ifdef FLEXT_THREADS FLEXT_ADDTIMER(stoptmr,tick); -- cgit v1.2.1