[PD-cvs] externals/grill/py/source clmeth.cpp,1.5,1.6 main.h,1.16,1.17 modmeth.cpp,1.7,1.8 py.cpp,1.9,1.10 pyext.cpp,1.14,1.15

xovo at users.sourceforge.net xovo at users.sourceforge.net
Thu Jan 22 04:38:39 CET 2004


Update of /cvsroot/pure-data/externals/grill/py/source
In directory sc8-pr-cvs1:/tmp/cvs-serv30144/source

Modified Files:
	clmeth.cpp main.h modmeth.cpp py.cpp pyext.cpp 
Log Message:
 ""

Index: clmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** clmeth.cpp	21 Oct 2003 02:38:31 -0000	1.5
--- clmeth.cpp	22 Jan 2004 03:38:36 -0000	1.6
***************
*** 1,7 ****
  /* 
  
! py/pyext - python external object for PD and MaxMSP
  
! Copyright (c) 2002-2003 Thomas Grill (xovo at gmx.net)
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "license.txt," in this distribution.  
--- 1,7 ----
  /* 
  
! py/pyext - python external object for PD and Max/MSP
  
! Copyright (c) 2002-2004 Thomas Grill (xovo at gmx.net)
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "license.txt," in this distribution.  
***************
*** 41,54 ****
  
  const C *pyext::pyext_doc =
! 	"py/pyext - python external object for PD and MaxMSP, (C)2002 Thomas Grill\n"
  	"\n"
  	"This is the pyext base class. Available methods:\n"
  	"_outlet(self,ix,args...): Send a message to an indexed outlet\n"
  	"_tocanvas(self,args...): Send a message to the parent canvas\n"
- #ifdef FLEXT_THREADS
- 	"_detach(self,int): Define whether a called Python method has its own thread\n"
  #endif
  	"_bind(self,name,func): Bind a python function to a symbol\n"
  	"_unbind(self,name,func): Unbind a python function from a symbol\n"
  ;
  
--- 41,58 ----
  
  const C *pyext::pyext_doc =
! 	"py/pyext - python external object for PD and Max/MSP, (C)2002-2004 Thomas Grill\n"
  	"\n"
  	"This is the pyext base class. Available methods:\n"
  	"_outlet(self,ix,args...): Send a message to an indexed outlet\n"
+ #if FLEXT_SYS == FLEXT_SYS_PD
  	"_tocanvas(self,args...): Send a message to the parent canvas\n"
  #endif
  	"_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"
  ;
  

Index: main.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** main.h	14 Jan 2004 03:38:02 -0000	1.16
--- main.h	22 Jan 2004 03:38:37 -0000	1.17
***************
*** 91,94 ****
--- 91,96 ----
  	virtual V Reload() = 0;
  
+     V Respond(BL b) { if(respond) { t_atom a[1]; SetBool(a[0],b); ToOutAnything(GetOutAttr(),MakeSymbol("response"),1,a); } }
+ 
  	static BL IsAnything(const t_symbol *s) { return s && s != sym_bang && s != sym_float && s != sym_int && s != sym_symbol && s != sym_list && s != sym_pointer; }
  
***************
*** 115,119 ****
  	virtual V m_stop(int argc,const t_atom *argv);
  
! 	BL detach,shouldexit;
  	I thrcount;
  	I stoptick;
--- 117,121 ----
  	virtual V m_stop(int argc,const t_atom *argv);
  
! 	BL detach,shouldexit,respond;
  	I thrcount;
  	I stoptick;
***************
*** 139,142 ****
--- 141,145 ----
  
  	FLEXT_ATTRVAR_B(detach)
+ 	FLEXT_ATTRVAR_B(respond)
  	FLEXT_CALLBACK_V(m_stop)
  	FLEXT_CALLBACK(m_dir)

Index: modmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/modmeth.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** modmeth.cpp	20 Oct 2003 02:38:10 -0000	1.7
--- modmeth.cpp	22 Jan 2004 03:38:37 -0000	1.8
***************
*** 1,7 ****
  /* 
  
! py/pyext - python external object for PD and MaxMSP
  
! Copyright (c) 2002-2003 Thomas Grill (xovo at gmx.net)
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "license.txt," in this distribution.  
--- 1,7 ----
  /* 
  
! py/pyext - python external object for PD and Max/MSP
  
! Copyright (c) 2002-2004 Thomas Grill (xovo at gmx.net)
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "license.txt," in this distribution.  
***************
*** 29,33 ****
  
  const C *py::py_doc =
! 	"py/pyext - python external object for PD and MaxMSP, (C)2002 Thomas Grill\n"
  	"\n"
  	"This is the pyext module. Available function:\n"
--- 29,33 ----
  
  const C *py::py_doc =
! 	"py/pyext - python external object for PD and Max/MSP, (C)2002-2004 Thomas Grill\n"
  	"\n"
  	"This is the pyext module. Available function:\n"

Index: py.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/py.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** py.cpp	20 Jan 2004 03:38:46 -0000	1.9
--- py.cpp	22 Jan 2004 03:38:37 -0000	1.10
***************
*** 1,7 ****
  /* 
  
! py/pyext - python script object for PD and MaxMSP
  
! Copyright (c) 2002-2003 Thomas Grill (xovo at gmx.net)
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "license.txt," in this distribution.  
--- 1,7 ----
  /* 
  
! py/pyext - python script object for PD and Max/MSP
  
! Copyright (c) 2002-2004 Thomas Grill (xovo at gmx.net)
  For information on usage and redistribution, and for a DISCLAIMER OF ALL
  WARRANTIES, see the file, "license.txt," in this distribution.  
***************
*** 24,30 ****
  	BL m_method_(I n,const t_symbol *s,I argc,const t_atom *argv);
  
! 	V work(const t_symbol *s,I argc,const t_atom *argv); 
  
! 	V m_bang() { work(sym_bang,0,NULL); }
  	V m_reload();
  	V m_reload_(I argc,const t_atom *argv);
--- 24,30 ----
  	BL m_method_(I n,const t_symbol *s,I argc,const t_atom *argv);
  
! 	BL work(const t_symbol *s,I argc,const t_atom *argv); 
  
! 	V m_bang() { callwork(sym_bang,0,NULL); }
  	V m_reload();
  	V m_reload_(I argc,const t_atom *argv);
***************
*** 95,98 ****
--- 95,100 ----
  	FLEXT_CADDMETHOD(c,1,m_py_list);
  	FLEXT_CADDMETHOD(c,1,m_py_any);
+ 
+   	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  }
  
***************
*** 228,231 ****
--- 230,235 ----
  	post("\tdoc: display module doc string");
  	post("\tdoc+: display function doc string");
+ 	post("\tdir: dump module dictionary");
+ 	post("\tdir+: dump function dictionary");
  #ifdef FLEXT_THREADS
  	post("\tdetach 0/1: detach threads");
***************
*** 272,278 ****
  
  
! V pyobj::work(const t_symbol *s,I argc,const t_atom *argv)
  {
  	AtomList *rargs = NULL;
  
  	++thrcount;
--- 276,283 ----
  
  
! BL pyobj::work(const t_symbol *s,I argc,const t_atom *argv)
  {
  	AtomList *rargs = NULL;
+     BL ret;
  
  	++thrcount;
***************
*** 288,294 ****
--- 293,301 ----
  		Py_XDECREF(pArgs);
  		Py_XDECREF(pValue);
+         ret = true;
  	}
  	else {
  		post("%s: no function defined",thisName());
+         ret = false;
  	}
  
***************
*** 302,318 ****
  		delete rargs;
  	}
  }
  
  V pyobj::callwork(const t_symbol *s,I argc,const t_atom *argv)
  {
  	if(detach) {
  		if(shouldexit)
  			post("%s - New threads can't be launched now!",thisName());
! 		else
! 			if(!FLEXT_CALLMETHOD_A(work,s,argc,argv))
! 				post("%s - Failed to launch thread!",thisName());
  	}
! 	else
! 		work(s,argc,argv);
  }
  
--- 309,330 ----
  		delete rargs;
  	}
+ 
+     return ret;
  }
  
  V pyobj::callwork(const t_symbol *s,I argc,const t_atom *argv)
  {
+     BL ret = false;
  	if(detach) {
  		if(shouldexit)
  			post("%s - New threads can't be launched now!",thisName());
! 		else {
! 			ret = FLEXT_CALLMETHOD_A(work,s,argc,argv);
! 			if(!ret) post("%s - Failed to launch thread!",thisName());
!         }
  	}
!     else
! 		ret = work(s,argc,argv);
!     Respond(ret);
  }
  

Index: pyext.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** pyext.cpp	20 Jan 2004 03:38:46 -0000	1.14
--- pyext.cpp	22 Jan 2004 03:38:37 -0000	1.15
***************
*** 1,5 ****
  /* 
  
! py/pyext - python script object for PD and MaxMSP
  
  Copyright (c)2002-2004 Thomas Grill (xovo at gmx.net)
--- 1,5 ----
  /* 
  
! py/pyext - python script object for PD and Max/MSP
  
  Copyright (c)2002-2004 Thomas Grill (xovo at gmx.net)
***************
*** 33,36 ****
--- 33,38 ----
  	FLEXT_CADDMETHOD_(c,0,"get",m_get);
  	FLEXT_CADDMETHOD_(c,0,"set",m_set);
+ 
+   	FLEXT_CADDATTR_VAR1(c,"respond",respond);
  }
  
***************
*** 225,229 ****
  
  	Py_XDECREF(pyobj);
- 
  	Py_XDECREF(class_obj);
  	Py_XDECREF(class_dict);
--- 227,230 ----
***************
*** 245,281 ****
  		if(!pref) 
  			PyErr_Print();
! 		else if(PyClass_Check(pref)) {
! 			// make instance, but don't call __init__ 
! 			pyobj = PyInstance_NewRaw(pref,NULL);
  
! 			Py_DECREF(pref);
! 			if(pyobj == NULL) 
! 				PyErr_Print();
! 			else {
! 				// remember the this pointer
! 				PyObject *th = PyLong_FromVoidPtr(this); 
! 				int ret = PyObject_SetAttrString(pyobj,"_this",th); // ref is taken
  
! 				// call init now, after _this has been set, which is
! 				// important for eventual callbacks from __init__ to c
! 				PyObject *pargs = MakePyArgs(NULL,args,-1,true);
! 				if (pargs == NULL) PyErr_Print();
  
! 				PyObject *init;
! 				init = PyObject_GetAttrString(pyobj,"__init__"); // get ref
! 				if(init && PyCallable_Check(init)) {
! 					PyObject *res = PyEval_CallObject(init,pargs);
! 					if(!res)
! 						PyErr_Print();
! 					else
! 						Py_DECREF(res);
!                     Py_DECREF(init);
! 				}
! 				
! 				Py_XDECREF(pargs);
! 			}
  		}
- 		else 
- 			post("%s - Type of \"%s\" is unhandled!",thisName(),GetString(methname));
  		return true;
  	}
--- 246,288 ----
  		if(!pref) 
  			PyErr_Print();
!         else {
!             if(PyClass_Check(pref)) {
! 			    // make instance, but don't call __init__ 
! 			    pyobj = PyInstance_NewRaw(pref,NULL);
  
! 			    Py_DECREF(pref);
! 			    if(pyobj == NULL) 
! 				    PyErr_Print();
! 			    else {
! 				    // remember the this pointer
! 				    PyObject *th = PyLong_FromVoidPtr(this); 
! 				    int ret = PyObject_SetAttrString(pyobj,"_this",th); // ref is taken
  
! 				    // call init now, after _this has been set, which is
! 				    // important for eventual callbacks from __init__ to c
! 				    PyObject *pargs = MakePyArgs(NULL,args,-1,true);
! 				    if (pargs == NULL) PyErr_Print();
  
! 				    PyObject *init;
! 				    init = PyObject_GetAttrString(pyobj,"__init__"); // get ref
!                     if(init) {
!                         if(PyCallable_Check(init)) {
! 					        PyObject *res = PyEval_CallObject(init,pargs);
! 					        if(!res)
! 						        PyErr_Print();
! 					        else
! 						        Py_DECREF(res);
!                         }
!                         Py_DECREF(init);
! 				    }
!     				
! 				    Py_XDECREF(pargs);
! 			    }
!             }
!             else
! 			    post("%s - Type of \"%s\" is unhandled!",thisName(),GetString(methname));
! 
! 		    Py_DECREF(pref);
  		}
  		return true;
  	}
***************
*** 288,291 ****
--- 295,299 ----
  	ClearBinding();
  	Py_XDECREF(pyobj);
+ 
  	// by here, the Python class destructor should have been called!
  
***************
*** 322,326 ****
  
  	PyObject *pvar  = PyObject_GetAttrString(pyobj,const_cast<char *>(GetString(s))); /* fetch bound method */
! 	if(pvar == NULL) {
  		PyErr_Clear(); // no method found
          post("%s - get: Python variable %s not found",thisName(),GetString(s));
--- 330,334 ----
  
  	PyObject *pvar  = PyObject_GetAttrString(pyobj,const_cast<char *>(GetString(s))); /* fetch bound method */
! 	if(!pvar) {
  		PyErr_Clear(); // no method found
          post("%s - get: Python variable %s not found",thisName(),GetString(s));
***************
*** 385,395 ****
  BL pyext::m_method_(I n,const t_symbol *s,I argc,const t_atom *argv)
  {
! 	if(pyobj && n >= 1) {
! 		return callwork(n,s,argc,argv);
! 	}
! 	else {
  		post("%s - no method for type '%s' into inlet %i",thisName(),GetString(s),n);
! 		return false;
! 	}
  }
  
--- 393,402 ----
  BL pyext::m_method_(I n,const t_symbol *s,I argc,const t_atom *argv)
  {
!     BL ret = false;
! 	if(pyobj && n >= 1)
! 		ret = callwork(n,s,argc,argv);
!     else
  		post("%s - no method for type '%s' into inlet %i",thisName(),GetString(s),n);
!     return ret;
  }
  
***************
*** 414,417 ****
--- 421,426 ----
  	post("\tdoc: display module doc string");
  	post("\tdoc+: display class doc string");
+ 	post("\tdir: dump module dictionary");
+ 	post("\tdir+: dump class dictionary");
  #ifdef FLEXT_THREADS
  	post("\tdetach 0/1: detach threads");
***************
*** 503,519 ****
  BL pyext::callwork(I n,const t_symbol *s,I argc,const t_atom *argv)
  {
! 	if(detach) {
! 		if(shouldexit) {
  			post("%s - Stopping.... new threads can't be launched now!",thisName());
- 			return true;
- 		}
  		else {
! 			BL ret = FLEXT_CALLMETHOD_X(work_wrapper,new work_data(n,s,argc,argv));
  			if(!ret) post("%s - Failed to launch thread!",thisName());
- 			return true;
  		}
  	}
! 	else 
! 		return work(n,s,argc,argv);
  }
  
--- 512,528 ----
  BL pyext::callwork(I n,const t_symbol *s,I argc,const t_atom *argv)
  {
!     BL ret = true,ok = false;
!     if(detach) {
! 		if(shouldexit)
  			post("%s - Stopping.... new threads can't be launched now!",thisName());
  		else {
! 			ret = FLEXT_CALLMETHOD_X(work_wrapper,new work_data(n,s,argc,argv));
  			if(!ret) post("%s - Failed to launch thread!",thisName());
  		}
  	}
!     else
! 		ret = ok = work(n,s,argc,argv);
!     Respond(ok);
!     return ret;
  }
  






More information about the Pd-cvs mailing list