From 8ac2ac31abb94663c66596ae2ceb55a6c778b972 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Mon, 12 Dec 2005 00:18:42 +0000 Subject: __str__ method for pyext, to enable print self calls added message bundle functionality (pyext.Bundle class) enable symbol binding for all callables (not only functions and methods) small optimizations and fixes enable optimization of Python code in reease build _isthreaded is now a data member instead of a method more safety for calls where association python-pd has already been removed fixes for pthreads V2 svn path=/trunk/; revision=4190 --- externals/grill/py/source/clmeth.cpp | 4 ++-- externals/grill/py/source/modmeth.cpp | 32 ++++++++++++++++++++++++++------ externals/grill/py/source/pybase.cpp | 5 +++++ externals/grill/py/source/pybase.h | 1 + externals/grill/py/source/pyext.h | 4 ++-- externals/grill/py/source/pysymbol.cpp | 4 +++- 6 files changed, 39 insertions(+), 11 deletions(-) (limited to 'externals/grill/py/source') diff --git a/externals/grill/py/source/clmeth.cpp b/externals/grill/py/source/clmeth.cpp index c8d38f81..be003291 100644 --- a/externals/grill/py/source/clmeth.cpp +++ b/externals/grill/py/source/clmeth.cpp @@ -210,10 +210,10 @@ PyObject *pyext::pyext_outlet(PyObject *,PyObject *args) Py_INCREF(val); } else - val = PySequence_GetSlice(args,2,sz); // new ref + val = PyTuple_GetSlice(args,2,sz); // new ref #endif - int o = PyInt_AsLong(outl); + int o = PyInt_AS_LONG(outl); if(o >= 1 && o <= ext->Outlets()) { // offset outlet by signal outlets o += ext->sigoutlets; diff --git a/externals/grill/py/source/modmeth.cpp b/externals/grill/py/source/modmeth.cpp index 44299b0c..a611690f 100644 --- a/externals/grill/py/source/modmeth.cpp +++ b/externals/grill/py/source/modmeth.cpp @@ -118,6 +118,7 @@ PyObject *pybase::py_send(PyObject *,PyObject *args) ) { PyObject *val; +#if 0 bool tp = sz == 2 && PySequence_Check( @@ -126,28 +127,47 @@ PyObject *pybase::py_send(PyObject *,PyObject *args) if(!tp) val = PySequence_GetSlice(args,1,sz); // new ref +#else + if(sz == 2) { + val = PyTuple_GET_ITEM(args,1); // borrow reference + Py_INCREF(val); + } + else + val = PySequence_GetSlice(args,1,sz); // new ref +#endif AtomListStatic<16> lst; const t_symbol *sym = GetPyArgs(lst,val); + Py_DECREF(val); + if(sym) { bool ok = Forward(recv,sym,lst.Count(),lst.Atoms()); #ifdef FLEXT_DEBUG if(!ok) post("py/pyext - Receiver doesn't exist"); #endif + Py_INCREF(Py_None); + return Py_None; } - else if(PyErr_Occurred()) +/* + else if(PyErr_Occurred()) PyErr_Print(); else post("py/pyext - No data to send"); - - if(!tp) Py_DECREF(val); +*/ + else { + FLEXT_ASSERT(PyErr_Occurred()); + return NULL; + } } +/* else post("py/pyext - Send name is invalid"); - - Py_INCREF(Py_None); - return Py_None; +*/ + else { + PyErr_SetString(PyExc_ValueError,"py/pyext - Send name is invalid"); + return NULL; + } } #ifdef FLEXT_THREADS diff --git a/externals/grill/py/source/pybase.cpp b/externals/grill/py/source/pybase.cpp index bdc76099..f20328d8 100644 --- a/externals/grill/py/source/pybase.cpp +++ b/externals/grill/py/source/pybase.cpp @@ -94,6 +94,7 @@ const t_symbol *pybase::sym_response = NULL; void initsymbol(); void initsamplebuffer(); +void initbundle(); void pybase::lib_setup() { @@ -186,6 +187,10 @@ void pybase::lib_setup() initsamplebuffer(); PyModule_AddObject(module_obj,"Buffer",(PyObject *)&pySamplebuffer_Type); + // add message bundle type + initbundle(); + PyModule_AddObject(module_obj,"Bundle",(PyObject *)&pyBundle_Type); + // ------------------------------------------------------------- FLEXT_SETUP(pyobj); diff --git a/externals/grill/py/source/pybase.h b/externals/grill/py/source/pybase.h index 59a1d062..3645a7af 100644 --- a/externals/grill/py/source/pybase.h +++ b/externals/grill/py/source/pybase.h @@ -14,6 +14,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "main.h" #include "pysymbol.h" #include "pybuffer.h" +#include "pybundle.h" class pybase : public flext diff --git a/externals/grill/py/source/pyext.h b/externals/grill/py/source/pyext.h index 672fe5f1..4696c72c 100644 --- a/externals/grill/py/source/pyext.h +++ b/externals/grill/py/source/pyext.h @@ -44,6 +44,8 @@ public: int Inlets() const { return inlets; } int Outlets() const { return outlets; } + static pyext *GetThis(PyObject *self); + protected: virtual bool Init(); @@ -87,8 +89,6 @@ protected: virtual PyObject *GetSig(int ix,bool in); - static pyext *GetThis(PyObject *self); - private: static void Setup(t_classid); diff --git a/externals/grill/py/source/pysymbol.cpp b/externals/grill/py/source/pysymbol.cpp index be7d3139..502606af 100644 --- a/externals/grill/py/source/pysymbol.cpp +++ b/externals/grill/py/source/pysymbol.cpp @@ -36,8 +36,10 @@ static int symbol_init(PyObject *self, PyObject *args, PyObject *kwds) ((pySymbol *)self)->sym = pySymbol_AS_SYMBOL(arg); else if(PyString_Check(arg)) ((pySymbol *)self)->sym = flext::MakeSymbol(PyString_AS_STRING(arg)); - else + else { + PyErr_SetString(PyExc_TypeError,"string or symbol argument expected"); ret = -1; + } Py_DECREF(arg); return ret; -- cgit v1.2.1