[PD-cvs] externals/grill/py/source bound.cpp, 1.17, 1.18 clmeth.cpp, 1.25, 1.26 pybase.cpp, 1.9, 1.10 pyext.h, 1.28, 1.29

Thomas Grill xovo at users.sourceforge.net
Wed Sep 21 12:52:35 CEST 2005


Update of /cvsroot/pure-data/externals/grill/py/source
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16551/source

Modified Files:
	bound.cpp clmeth.cpp pybase.cpp pyext.h 
Log Message:
__str__ method for pyext, to enable print self calls
python-like dotted module.function syntax
multiply inlets for py (hot and cold inlets)
enable symbol binding for all callables (not only functions and methods)
enable optimization of Python code in reease build
_isthreaded is now a data member instead of a method
compiler flag to exclude DSP objects
some ASSERTs for explicitly created pyext classes (should be runtime checks i guess)
cleaned up float vs. int pyext tags
more safety for calls where association python-pd has already been removed
open editor for module file on "edit" message (or click)
let _inlets and _outlets default to 0


Index: clmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** clmeth.cpp	20 Sep 2005 20:50:40 -0000	1.25
--- clmeth.cpp	21 Sep 2005 10:52:33 -0000	1.26
***************
*** 18,21 ****
--- 18,22 ----
      {"__del__", pyext::pyext__del__, METH_VARARGS, "Destructor"},
  */
+     {"__str__", pyext::pyext__str__, METH_VARARGS, "stringify"},
      {"_outlet", pyext::pyext_outlet, METH_VARARGS,"Send message to outlet"},
  #if FLEXT_SYS == FLEXT_SYS_PD
***************
*** 29,34 ****
  	{ "_stop", pyext::pyext_stop, METH_VARARGS,"Stop running threads" },
  #endif
- 	{ "_isthreaded", pyext::pyext_isthreaded, METH_O,"Query whether threading is enabled" },
- 
  	{ "_invec", pyext::pyext_invec, METH_VARARGS,"Get input vector" },
  	{ "_outvec", pyext::pyext_outvec, METH_VARARGS,"Get output vector" },
--- 30,33 ----
***************
*** 54,62 ****
  	"_bind(self,name,func): Bind a python function to a symbol\n"
  	"_unbind(self,name,func): Unbind a python function from a symbol\n"
  #ifdef FLEXT_THREADS
  	"_detach(self,int): Define whether a called Python method has its own thread\n"
  	"_stop(self): Stop running threads\n"
  #endif
- 	"_isthreaded(self): Query whether threading is enabled\n"
  ;
  
--- 53,62 ----
  	"_bind(self,name,func): Bind a python function to a symbol\n"
  	"_unbind(self,name,func): Unbind a python function from a symbol\n"
+     "_isthreaded: Query whether threading is enabled\n"
  #ifdef FLEXT_THREADS
  	"_detach(self,int): Define whether a called Python method has its own thread\n"
  	"_stop(self): Stop running threads\n"
+     "_shouldexit: Query whether threads should terminate\n"
  #endif
  ;
  
***************
*** 79,86 ****
  */
  
  PyObject* pyext::pyext_setattr(PyObject *,PyObject *args)
  {
      PyObject *self,*name,*val;
!     if(!PyArg_ParseTuple(args, "OOO:test_foo", &self,&name,&val)) {
          // handle error
  		ERRINTERNAL();
--- 79,98 ----
  */
  
+ PyObject* pyext::pyext__str__(PyObject *,PyObject *args)
+ {
+ 	PyObject *self; 
+     if(!PyArg_ParseTuple(args, "O:pyext__str__",&self)) {
+         // handle error
+ 		ERRINTERNAL();
+         return NULL;
+     }
+ 
+     return PyString_FromFormat("<pyext object %p>",self);
+ }
+ 
  PyObject* pyext::pyext_setattr(PyObject *,PyObject *args)
  {
      PyObject *self,*name,*val;
!     if(!PyArg_ParseTuple(args, "OOO:pyext_setattr", &self,&name,&val)) {
          // handle error
  		ERRINTERNAL();
***************
*** 112,124 ****
  {
      PyObject *self,*name,*ret = NULL;
!     if(!PyArg_ParseTuple(args, "OO:test_foo", &self,&name)) {
          // handle error
  		ERRINTERNAL();
      }
  
- #ifdef FLEXT_THREADS
      if(PyString_Check(name)) {
  	    char* sname = PyString_AS_STRING(name);
  		if(sname) {
  			if(!strcmp(sname,"_shouldexit")) {
  				pyext *ext = GetThis(self); 
--- 124,136 ----
  {
      PyObject *self,*name,*ret = NULL;
!     if(!PyArg_ParseTuple(args, "OO:pyext_getattr", &self,&name)) {
          // handle error
  		ERRINTERNAL();
      }
  
      if(PyString_Check(name)) {
  	    char* sname = PyString_AS_STRING(name);
  		if(sname) {
+ #ifdef FLEXT_THREADS
  			if(!strcmp(sname,"_shouldexit")) {
  				pyext *ext = GetThis(self); 
***************
*** 126,137 ****
  					ret = PyLong_FromLong(ext->shouldexit?1:0);
                  else {
                      Py_INCREF(Py_True);
                      ret = Py_True;
                  }
  			}
! //			post("pyext::getattr %s",sname);
  		}
  	}
- #endif
  
  	if(!ret) { 
--- 138,159 ----
  					ret = PyLong_FromLong(ext->shouldexit?1:0);
                  else {
+                     // return true for _shouldexit if association has been removed
                      Py_INCREF(Py_True);
                      ret = Py_True;
                  }
  			}
!             else 
! #endif
! 			if(!strcmp(sname,"_isthreaded")) {
!             #ifdef FLEXT_THREADS
!                 Py_INCREF(Py_True);
!                 ret = Py_True;
!             #else
!                 Py_INCREF(Py_False);
!                 ret = Py_False;
!             #endif
!             }
  		}
  	}
  
  	if(!ret) { 
***************
*** 166,170 ****
  	) {
  		pyext *ext = GetThis(self);
!         FLEXT_ASSERT(ext);
  
  		PyObject *val;
--- 188,195 ----
  	) {
  		pyext *ext = GetThis(self);
!         if(!ext) {    
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _outlet: instance not associated with pd object");
!             return NULL;
!         }
  
  		PyObject *val;
***************
*** 231,235 ****
  	else {
  		pyext *ext = GetThis(self);
!         FLEXT_ASSERT(ext);
          ext->detach = val;
  	}
--- 256,264 ----
  	else {
  		pyext *ext = GetThis(self);
!         if(!ext) {    
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _detach: instance not associated with pd object");
!             return NULL;
!         }
! 
          ext->detach = val;
  	}
***************
*** 255,259 ****
  	else {
  		pyext *ext = GetThis(self);
!         FLEXT_ASSERT(ext);
          int cnt;
  		t_atom at;
--- 284,292 ----
  	else {
  		pyext *ext = GetThis(self);
!         if(!ext) {    
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _stop: instance not associated with pd object");
!             return NULL;
!         }
! 
          int cnt;
  		t_atom at;
***************
*** 269,283 ****
  #endif
  
- //! Query whether threading is enabled
- PyObject *pyext::pyext_isthreaded(PyObject *,PyObject *)
- {
- 	return PyInt_FromLong(
- #ifdef FLEXT_THREADED
-         1
- #else
-         0
- #endif
-         );
- }
  
  #if FLEXT_SYS == FLEXT_SYS_PD
--- 302,305 ----
***************
*** 296,300 ****
      ) {
  		pyext *ext = GetThis(self);
!         FLEXT_ASSERT(ext);
  		PyObject *val;
  
--- 318,326 ----
      ) {
  		pyext *ext = GetThis(self);
!         if(!ext) {
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _tocanvas: instance not associated with pd object");
!             return NULL;
!         }
! 
  		PyObject *val;
  
***************
*** 311,318 ****
          const t_symbol *sym = GetPyArgs(lst,val);
          if(sym) {
! 			t_glist *gl = ext->thisCanvas(); //canvas_getcurrent();
! 			t_class **cl = (t_pd *)gl;
! 			if(cl)
! 			    pd_forwardmess(cl,lst.Count(),lst.Atoms());
  #ifdef FLEXT_DEBUG
  			else
--- 337,347 ----
          const t_symbol *sym = GetPyArgs(lst,val);
          if(sym) {
! 			t_glist *gl = ext->thisCanvas();
!             if(gl) {
!                 // \TODO find a flext-based non-locking method
!                 sys_lock();
! 			    pd_forwardmess((t_class **)gl,lst.Count(),lst.Atoms());
!                 sys_unlock();
!             }
  #ifdef FLEXT_DEBUG
  			else
***************
*** 352,358 ****
  	else {
  		pyext *ext = GetThis(self);
!         FLEXT_ASSERT(ext);
!         PyObject *b = ext->GetSig(val,true);
!         if(b) return b;
  	}
  
--- 381,392 ----
  	else {
  		pyext *ext = GetThis(self);
!         if(ext) {
!             PyObject *b = ext->GetSig(val,true);
!             if(b) return b;
!         }
!         else {
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _invec: instance not associated with pd object");
!             return NULL;
!         }
  	}
  
***************
*** 376,382 ****
  	else {
  		pyext *ext = GetThis(self);
!         FLEXT_ASSERT(ext);
!         PyObject *b = ext->GetSig(val,false);
!         if(b) return b;
  	}
  
--- 410,421 ----
  	else {
  		pyext *ext = GetThis(self);
!         if(ext) {
!             PyObject *b = ext->GetSig(val,false);
!             if(b) return b;
!         }
!         else {
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _outvec: instance not associated with pd object");
!             return NULL;
!         }
  	}
  

Index: pybase.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pybase.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** pybase.cpp	20 Sep 2005 20:50:40 -0000	1.9
--- pybase.cpp	21 Sep 2005 10:52:33 -0000	1.10
***************
*** 102,106 ****
--- 102,109 ----
  
  #ifdef FLEXT_DEBUG
+ 	Py_DebugFlag = 1;
  //	Py_VerboseFlag = 1;
+ #else
+     Py_OptimizeFlag = 1;
  #endif
  

Index: bound.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/bound.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** bound.cpp	8 Jul 2005 14:30:30 -0000	1.17
--- bound.cpp	21 Sep 2005 10:52:33 -0000	1.18
***************
*** 47,51 ****
                  return true;
              else
!                 // both are functions
                  return a < b;
      }
--- 47,51 ----
                  return true;
              else
!                 // both are non-method callables
                  return a < b;
      }
***************
*** 89,98 ****
      if(!PyArg_ParseTuple(args, "OOO:pyext_bind", &self,&name,&meth)) // borrowed references
  		post("py/pyext - Wrong arguments!");
! 	else if(!PyInstance_Check(self) || !(PyMethod_Check(meth) || PyFunction_Check(meth))) {
  		post("py/pyext - Wrong argument types!");
      }
  	else {
          pyext *th = GetThis(self);
!         FLEXT_ASSERT(th);
  
  		const t_symbol *recv = pyObject_AsSymbol(name);
--- 89,101 ----
      if(!PyArg_ParseTuple(args, "OOO:pyext_bind", &self,&name,&meth)) // borrowed references
  		post("py/pyext - Wrong arguments!");
! 	else if(!PyInstance_Check(self) || !PyCallable_Check(meth)) {
  		post("py/pyext - Wrong argument types!");
      }
  	else {
          pyext *th = GetThis(self);
!         if(!th) {    
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _bind: instance not associated with pd object");
!             return NULL;
!         }
  
  		const t_symbol *recv = pyObject_AsSymbol(name);
***************
*** 131,140 ****
      if(!PyArg_ParseTuple(args, "OOO:pyext_bind", &self,&name,&meth))  // borrowed references
  		post("py/pyext - Wrong arguments!");
! 	else if(!PyInstance_Check(self) || !(PyMethod_Check(meth) || PyFunction_Check(meth))) {
  		post("py/pyext - Wrong argument types!");
      }
  	else {
          pyext *th = GetThis(self);
!         FLEXT_ASSERT(th);
  
  		const t_symbol *recv = pyObject_AsSymbol(name);
--- 134,146 ----
      if(!PyArg_ParseTuple(args, "OOO:pyext_bind", &self,&name,&meth))  // borrowed references
  		post("py/pyext - Wrong arguments!");
! 	else if(!PyInstance_Check(self) || !PyCallable_Check(meth)) {
  		post("py/pyext - Wrong argument types!");
      }
  	else {
          pyext *th = GetThis(self);
!         if(!th) {    
!             PyErr_SetString(PyExc_RuntimeError,"pyext - _unbind: instance not associated with pd object");
!             return NULL;
!         }
  
  		const t_symbol *recv = pyObject_AsSymbol(name);
***************
*** 176,180 ****
  
      pyext *th = GetThis(pyobj);
!     FLEXT_ASSERT(th);
  
      void *data = NULL;
--- 182,186 ----
  
      pyext *th = GetThis(pyobj);
!     if(!th) return;
  
      void *data = NULL;

Index: pyext.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** pyext.h	1 Aug 2005 11:58:01 -0000	1.28
--- pyext.h	21 Sep 2005 10:52:33 -0000	1.29
***************
*** 23,29 ****
  	pyext(int argc,const t_atom *argv,bool sig = false);
  
! 	static PyObject *pyext__doc__(PyObject *,PyObject *args);
! 	static PyObject *pyext__init__(PyObject *,PyObject *args);
! 	static PyObject *pyext__del__(PyObject *,PyObject *args);
  
  	static PyObject *pyext_outlet(PyObject *,PyObject *args);
--- 23,27 ----
  	pyext(int argc,const t_atom *argv,bool sig = false);
  
! 	static PyObject *pyext__str__(PyObject *,PyObject *args);
  
  	static PyObject *pyext_outlet(PyObject *,PyObject *args);





More information about the Pd-cvs mailing list