Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1:/tmp/cvs-serv26150/source
Modified Files: main.cpp main.h pyargs.cpp pyext.cpp Log Message: ""
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.cpp 29 Nov 2003 03:38:01 -0000 1.7 --- main.cpp 6 Jan 2004 03:38:37 -0000 1.8 *************** *** 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 (xovo@gmx.net) For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. *************** *** 14,18 **** { post(""); ! post("py/pyext %s - python script objects, (C)2002,2003 Thomas Grill",PY__VERSION); post("");
--- 14,18 ---- { post(""); ! post("py/pyext %s - python script objects, (C)2002-2004 Thomas Grill",PY__VERSION); post("");
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** main.h 29 Dec 2003 21:30:25 -0000 1.12 --- main.h 6 Jan 2004 03:38:37 -0000 1.13 *************** *** 30,34 **** #endif
! #define PY__VERSION "0.1.2"
--- 30,34 ---- #endif
! #define PY__VERSION "0.1.3pre"
Index: pyargs.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyargs.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pyargs.cpp 4 Jan 2003 04:36:49 -0000 1.2 --- pyargs.cpp 6 Jan 2004 03:38:37 -0000 1.3 *************** *** 11,14 **** --- 11,22 ---- #include "main.h"
+ static PyObject *MakePyAtom(const t_atom &at) + { + if(flext::IsFloat(at)) return PyFloat_FromDouble((D)flext::GetFloat(at)); + else if(flext::IsInt(at)) return PyInt_FromLong(flext::GetInt(at)); + else if(flext::IsSymbol(at)) return PyString_FromString(flext::GetString(at)); + // else if(flext::IsPointer(at)) return NULL; // not handled + else return NULL; + }
PyObject *py::MakePyArgs(const t_symbol *s,const AtomList &args,I inlet,BL withself) *************** *** 16,68 **** PyObject *pArgs;
! BL any = IsAnything(s); ! pArgs = PyTuple_New(args.Count()+(any?1:0)+(inlet >= 0?1:0)); ! ! I pix = 0;
! if(inlet >= 0) { ! PyObject *pValue = PyInt_FromLong(inlet); ! ! // reference stolen: ! PyTuple_SetItem(pArgs, pix++, pValue); ! }
! I ix; ! PyObject *tmp; ! if(!withself || args.Count() < (any?1:2)) tmp = pArgs,ix = pix; ! else tmp = PyTuple_New(args.Count()+(any?1:0)),ix = 0;
! if(any) { ! PyObject *pValue = PyString_FromString(GetString(s));
! // reference stolen here: ! PyTuple_SetItem(tmp, ix++, pValue); ! }
! for(I i = 0; i < args.Count(); ++i) { ! PyObject *pValue = NULL; ! ! if(IsFloat(args[i])) pValue = PyFloat_FromDouble((D)GetFloat(args[i])); ! else if(IsInt(args[i])) pValue = PyInt_FromLong(GetInt(args[i])); ! else if(IsSymbol(args[i])) pValue = PyString_FromString(GetString(args[i])); ! else if(IsPointer(args[i])) pValue = NULL; // not handled
! if(!pValue) { ! post("py/pyext: cannot convert argument %i",any?i+1:i); ! continue; ! }
! /* pValue reference stolen here: */ ! PyTuple_SetItem(tmp, ix++, pValue); ! }
! if(tmp != pArgs) { ! PyTuple_SetItem(pArgs, pix++, tmp); ! #if PY_VERSION_HEX >= 0x02020000 ! _PyTuple_Resize(&pArgs,pix); ! #else ! _PyTuple_Resize(&pArgs,pix,0); ! #endif ! }
return pArgs; --- 24,80 ---- PyObject *pArgs;
! /* ! if(!s && args.Count() == 1) { ! pArgs = MakePyAtom(args[0]); ! if(!pArgs) ! post("py/pyext: cannot convert argument(s)"); ! } ! else ! */ ! { ! BL any = IsAnything(s); ! pArgs = PyTuple_New(args.Count()+(any?1:0)+(inlet >= 0?1:0));
! I pix = 0;
! if(inlet >= 0) { ! PyObject *pValue = PyInt_FromLong(inlet); ! ! // reference stolen: ! PyTuple_SetItem(pArgs, pix++, pValue); ! }
! I ix; ! PyObject *tmp; ! if(!withself || args.Count() < (any?1:2)) tmp = pArgs,ix = pix; ! else tmp = PyTuple_New(args.Count()+(any?1:0)),ix = 0;
! if(any) { ! PyObject *pValue = PyString_FromString(GetString(s));
! // reference stolen here: ! PyTuple_SetItem(tmp, ix++, pValue); ! }
! for(I i = 0; i < args.Count(); ++i) { ! PyObject *pValue = MakePyAtom(args[i]); ! if(!pValue) { ! post("py/pyext: cannot convert argument %i",any?i+1:i); ! continue; ! }
! /* pValue reference stolen here: */ ! PyTuple_SetItem(tmp, ix++, pValue); ! }
! if(tmp != pArgs) { ! PyTuple_SetItem(pArgs, pix++, tmp); ! #if PY_VERSION_HEX >= 0x02020000 ! _PyTuple_Resize(&pArgs,pix); ! #else ! _PyTuple_Resize(&pArgs,pix,0); ! #endif ! } ! }
return pArgs;
Index: pyext.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** pyext.cpp 29 Nov 2003 03:38:01 -0000 1.10 --- pyext.cpp 6 Jan 2004 03:38:37 -0000 1.11 *************** *** 3,7 **** py/pyext - python script 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 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. *************** *** 340,347 **** } else { ! PyObject *pval = MakePyArgs(sym_list,AtomList(argc-1,argv+1),-1,false); ! if(!pval) PyErr_Print(); else { PyObject_SetAttrString(pyobj,ch,pval); Py_DECREF(pval); --- 340,356 ---- } else { ! PyObject *pval = MakePyArgs(NULL,AtomList(argc-1,argv+1),-1,false); ! ! if(!pval) PyErr_Print(); else { + if(PySequence_Size(pval) == 1) { + // reduce lists of one element to element itself + + PyObject *val1 = PySequence_GetItem(pval,0); + Py_DECREF(pval); + pval = val1; + } + PyObject_SetAttrString(pyobj,ch,pval); Py_DECREF(pval);