[PD-cvs] externals/grill/py/source bound.cpp,1.9,1.10 clmeth.cpp,1.8,1.9 main.cpp,1.14,1.15 modmeth.cpp,1.9,1.10 pyargs.cpp,1.6,1.7 pyext.cpp,1.18,1.19 register.cpp,1.2,1.3

Thomas Grill xovo at users.sourceforge.net
Tue Aug 31 06:07:37 CEST 2004


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

Modified Files:
	bound.cpp clmeth.cpp main.cpp modmeth.cpp pyargs.cpp pyext.cpp 
	register.cpp 
Log Message:
 ""

Index: clmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** clmeth.cpp	21 Jun 2004 14:04:15 -0000	1.8
--- clmeth.cpp	31 Aug 2004 04:07:35 -0000	1.9
***************
*** 123,129 ****
--- 123,131 ----
  	if(!ret) { 
  #if PY_VERSION_HEX >= 0x02020000
+         // \todo borrowed or new???
  		ret = PyObject_GenericGetAttr(self,name);
  #else
  		if(PyInstance_Check(self))
+             // borrowed reference
  			ret = PyDict_GetItem(((PyInstanceObject *)self)->in_dict,name);	
  #endif
***************
*** 136,181 ****
  {
  	BL ok = false;
-     if(PySequence_Check(args)) {
- 		PyObject *self = PySequence_GetItem(args,0);
- 		PyObject *outl = PySequence_GetItem(args,1);
- 		if(
- 			self && PyInstance_Check(self) && 
- 			outl && PyInt_Check(outl)
- 		) {
- 			pyext *ext = GetThis(self);
  
! 			I sz = PySequence_Size(args);
! 			PyObject *val;
! 			BL tp = sz == 3 && PySequence_Check(PySequence_GetItem(args,2));
  
! 			if(tp)
! 				val = PySequence_GetItem(args,2); // borrowed
! 			else
! 				val = PySequence_GetSlice(args,2,sz);  // new ref
  
! 			AtomList *lst = GetPyArgs(val);
! 			if(lst) {
! 				I o = PyInt_AsLong(outl);
! 				if(o >= 1 && o <= ext->Outlets()) {
! 					// by using the queue there is no immediate call of the next object
! 					// deadlock would occur if this was another py/pyext object!
! 					if(lst->Count() && IsSymbol((*lst)[0]))
! 						ext->ToQueueAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1);
  //						ext->ToOutAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1);
- 					else
- 						ext->ToQueueList(o-1,*lst);
- //						ext->ToOutList(o-1,*lst);
- 				}
  				else
! 					post("pyext: outlet index out of range");
! 
! 				ok = true;
  			}
! 			else 
! 				post("py/pyext - No data to send");
! 			if(lst) delete lst;
  
! 			if(!tp) Py_DECREF(val);
  		}
  	}
  
--- 138,189 ----
  {
  	BL ok = false;
  
!     // should always be a tuple!
!     FLEXT_ASSERT(PyTuple_Check(args));
  
!     // borrowed references!
! 	PyObject *self = PyTuple_GetItem(args,0);
! 	PyObject *outl = PyTuple_GetItem(args,1);
! 	if(
! 		self && PyInstance_Check(self) && 
! 		outl && PyInt_Check(outl)
! 	) {
! 		pyext *ext = GetThis(self);
  
! 		I sz = PyTuple_Size(args);
! 		PyObject *val;
!         
!         BL tp = 
!             sz == 3 && 
!             PySequence_Check(
!                 val = PyTuple_GetItem(args,2) // borrow reference
!             );
! 
! 		if(!tp)
! 			val = PySequence_GetSlice(args,2,sz);  // new ref
! 
! 		AtomList *lst = GetPyArgs(val);
! 		if(lst) {
! 			I o = PyInt_AsLong(outl);
! 			if(o >= 1 && o <= ext->Outlets()) {
! 				// by using the queue there is no immediate call of the next object
! 				// deadlock would occur if this was another py/pyext object!
! 				if(lst->Count() && IsSymbol((*lst)[0]))
! 					ext->ToQueueAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1);
  //						ext->ToOutAnything(o-1,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1);
  				else
! 					ext->ToQueueList(o-1,*lst);
! //						ext->ToOutList(o-1,*lst);
  			}
! 			else
! 				post("pyext: outlet index out of range");
  
! 			ok = true;
  		}
+ 		else 
+ 			post("py/pyext - No data to send");
+ 		if(lst) delete lst;
+ 
+ 		if(!tp) Py_DECREF(val);
  	}
  
***************
*** 246,283 ****
  PyObject *pyext::pyext_tocanvas(PyObject *,PyObject *args)
  {
  	BL ok = false;
!     if(PySequence_Check(args)) {
! 		PyObject *self = PySequence_GetItem(args,0);
! 		if(self && PyInstance_Check(self)) {
! 			pyext *ext = GetThis(self);
  
! 			I sz = PySequence_Size(args);
! 			PyObject *val;
! 			BL tp = sz == 2 && PySequence_Check(PyTuple_GetItem(args,1));
  
! 			if(tp)
! 				val = PySequence_GetItem(args,1); // borrowed
! 			else
! 				val = PySequence_GetSlice(args,1,sz);  // new ref
  
! 			AtomList *lst = GetPyArgs(val);
! 			if(lst) {
! 				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
! 					post("pyext - no parent canvas?!");
  #endif
! 				ok = true;
! 			}
! 			else 
! 				post("py/pyext - No data to send");
! 			if(lst) delete lst;
! 
! 			if(!tp) Py_DECREF(val);
  		}
  	}
  
--- 254,294 ----
  PyObject *pyext::pyext_tocanvas(PyObject *,PyObject *args)
  {
+     FLEXT_ASSERT(PyTuple_Check(args));
+ 
  	BL ok = false;
! 	PyObject *self = PyTuple_GetItem(args,0); // borrowed ref
! 	if(self && PyInstance_Check(self)) {
! 		pyext *ext = GetThis(self);
  
! 		I sz = PySequence_Size(args);
! 		PyObject *val;
  
!         BL tp = 
!             sz == 2 && 
!             PySequence_Check(
!                 val = PyTuple_GetItem(args,1) // borrowed ref
!             );
  
! 		if(!tp)
! 			val = PyTuple_GetSlice(args,1,sz);  // new ref
! 
! 		AtomList *lst = GetPyArgs(val);
! 		if(lst) {
! 			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
! 				post("pyext - no parent canvas?!");
  #endif
! 			ok = true;
  		}
+ 		else 
+ 			post("py/pyext - No data to send");
+ 		if(lst) delete lst;
+ 
+ 		if(!tp) Py_DECREF(val);
  	}
  

Index: pyargs.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyargs.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** pyargs.cpp	21 Jun 2004 14:04:15 -0000	1.6
--- pyargs.cpp	31 Aug 2004 04:07:35 -0000	1.7
***************
*** 117,124 ****
  	for(I ix = 0; ix < rargc; ++ix) {
  		PyObject *arg;
! 		switch(tp) {
! 			case sequ: arg = PySequence_GetItem(pValue,ix); break;
! 			default: arg = pValue;
! 		}
  
  		if(PyInt_Check(arg)) SetInt((*ret)[ix],PyInt_AsLong(arg));
--- 117,124 ----
  	for(I ix = 0; ix < rargc; ++ix) {
  		PyObject *arg;
! 		if(tp == sequ)
!             arg = PySequence_GetItem(pValue,ix); // new reference
! 		else
!             arg = pValue;
  
  		if(PyInt_Check(arg)) SetInt((*ret)[ix],PyInt_AsLong(arg));
***************
*** 128,131 ****
--- 128,132 ----
  		else if(ix == 0 && self && PyInstance_Check(arg)) {
  			// assumed to be self ... that should be checked _somehow_ !!!
+             Py_INCREF(arg);
  			*self = arg;
  		}
***************
*** 140,144 ****
  			ok = false;
  		}
! 		// No DECREF for arg -> borrowed from pValue!
  	}
  
--- 141,146 ----
  			ok = false;
  		}
! 
! 		if(tp == sequ) Py_DECREF(arg);
  	}
  

Index: main.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** main.cpp	22 Jun 2004 22:45:53 -0000	1.14
--- main.cpp	31 Aug 2004 04:07:35 -0000	1.15
***************
*** 280,284 ****
  			int i,n = PyList_Size(pobj);
  			for(i = 0; i < n; ++i) {
! 				PyObject *pt = PyList_GetItem(pobj,i);
  				if(PyString_Check(pt) && !strcmp(dir,PyString_AS_STRING(pt))) break;
  			}
--- 280,284 ----
  			int i,n = PyList_Size(pobj);
  			for(i = 0; i < n; ++i) {
! 				PyObject *pt = PyList_GetItem(pobj,i); // borrowed reference
  				if(PyString_Check(pt) && !strcmp(dir,PyString_AS_STRING(pt))) break;
  			}
***************
*** 297,327 ****
  PyObject* py::StdOut_Write(PyObject* self, PyObject* args)
  {
!     if(PySequence_Check(args)) {
! 		int sz = PySequence_Size(args);
! 		for(int i = 0; i < sz; ++i) {
! 			PyObject *val = PySequence_GetItem(args,i); // borrowed
! 			PyObject *str = PyObject_Str(val);
! 			char *cstr = PyString_AS_STRING(str);
! 			char *lf = strchr(cstr,'\n');
  
! 			// line feed in string
! 			if(!lf) {
! 				// no -> just append
! 				if(output)
! 					PyString_ConcatAndDel(&output,str);
! 				else
! 					output = str;
! 			}
! 			else {
! 				// yes -> append up to line feed, reset output buffer to string remainder
! 				PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr);
! 				if(output)
! 					PyString_ConcatAndDel(&output,part);			
! 				else
! 					output = part;
! 				post(PyString_AS_STRING(output));
! 				Py_DECREF(output);
! 				output = PyString_FromString(lf+1);
! 			}
  		}
  	}
--- 297,331 ----
  PyObject* py::StdOut_Write(PyObject* self, PyObject* args)
  {
!     // should always be a tuple
!     FLEXT_ASSERT(PyTuple_Check(args));
  
! 	int sz = PyTuple_Size(args);
! 	for(int i = 0; i < sz; ++i) {
! 		PyObject *val = PyTuple_GetItem(args,i); // borrowed reference
! 		PyObject *str = PyObject_Str(val); // new reference
! 		char *cstr = PyString_AS_STRING(str);
! 		char *lf = strchr(cstr,'\n');
! 
! 		// line feed in string
! 		if(!lf) {
! 			// no -> just append
!             if(output)
! 				PyString_ConcatAndDel(&output,str); // str is decrefd
! 			else
! 				output = str; // take str reference
! 		}
! 		else {
! 			// yes -> append up to line feed, reset output buffer to string remainder
! 			PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr); // new reference
!             if(output)
! 				PyString_ConcatAndDel(&output,part); // str is decrefd	
! 			else
! 				output = part; // take str reference
! 
!             // output concatenated string
! 			post(PyString_AS_STRING(output));
! 
! 			Py_DECREF(output);
! 			output = PyString_FromString(lf+1);  // new reference
  		}
  	}

Index: modmeth.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/modmeth.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** modmeth.cpp	21 Jun 2004 14:04:15 -0000	1.9
--- modmeth.cpp	31 Aug 2004 04:07:35 -0000	1.10
***************
*** 105,109 ****
  	I ch = sys_get_inchannels();
  #elif FLEXT_SYS == FLEXT_SYS_MAX
! 	I ch = sys_getch(); // not functioning
  #else
  #pragma message("Not implemented!")
--- 105,109 ----
  	I ch = sys_get_inchannels();
  #elif FLEXT_SYS == FLEXT_SYS_MAX
! 	I ch = sys_getch(); // not working
  #else
  #pragma message("Not implemented!")
***************
*** 118,122 ****
  	I ch = sys_get_outchannels();
  #elif FLEXT_SYS == FLEXT_SYS_MAX
! 	I ch = sys_getch(); // not functioning
  #else
  #pragma message("Not implemented!")
--- 118,122 ----
  	I ch = sys_get_outchannels();
  #elif FLEXT_SYS == FLEXT_SYS_MAX
! 	I ch = sys_getch(); // not working
  #else
  #pragma message("Not implemented!")
***************
*** 128,166 ****
  PyObject *py::py_send(PyObject *,PyObject *args)
  {
!     if(PySequence_Check(args)) {
! 		PyObject *name = PySequence_GetItem(args,0); // borrowed
! 		if(name && PyString_Check(name)) {
! 			const t_symbol *recv = MakeSymbol(PyString_AsString(name));
! 			I sz = PySequence_Size(args);
! 			PyObject *val;
! 			BL tp = sz == 2 && PySequence_Check(PySequence_GetItem(args,1));
  
! 			if(tp)
! 				val = PySequence_GetItem(args,1); // borrowed
! 			else
! 				val = PySequence_GetSlice(args,1,sz);  // new ref
  
! 			AtomList *lst = GetPyArgs(val);
! 			if(lst) {
! 				bool ok;
! 				if(lst->Count() && IsSymbol((*lst)[0]))
! 					ok = Forward(recv,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1);
! 				else
! 					ok = Forward(recv,*lst);
  
  #ifdef FLEXT_DEBUG
!                 if(!ok)
! 					post("py/pyext - Receiver doesn't exist");
  #endif
- 			}
- 			else 
- 				post("py/pyext - No data to send");
- 			if(lst) delete lst;
- 
- 			if(!tp) Py_DECREF(val);
  		}
! 		else
! 			post("py/pyext - Send name is invalid");
  	}
  
      Py_INCREF(Py_None);
--- 128,170 ----
  PyObject *py::py_send(PyObject *,PyObject *args)
  {
!     // should always be a tuple
!     FLEXT_ASSERT(PyTuple_Check(args));
  
! 	PyObject *name = PyTuple_GetItem(args,0); // borrowed reference
!     if(name && PyString_Check(name)) {
! 		const t_symbol *recv = MakeSymbol(PyString_AsString(name));
! 		int sz = PySequence_Size(args);
! 		PyObject *val;
  
! 		bool tp = 
!             sz == 2 && 
!             PySequence_Check(
!                 val = PyTuple_GetItem(args,1) // borrowed ref
!             );
! 
! 		if(!tp)
! 			val = PySequence_GetSlice(args,1,sz);  // new ref
! 
! 		AtomList *lst = GetPyArgs(val);
! 		if(lst) {
! 			bool ok;
! 			if(lst->Count() && IsSymbol((*lst)[0]))
! 				ok = Forward(recv,GetSymbol((*lst)[0]),lst->Count()-1,lst->Atoms()+1);
! 			else
! 				ok = Forward(recv,*lst);
  
  #ifdef FLEXT_DEBUG
!             if(!ok)
! 				post("py/pyext - Receiver doesn't exist");
  #endif
  		}
! 		else 
! 			post("py/pyext - No data to send");
! 		if(lst) delete lst;
! 
! 		if(!tp) Py_DECREF(val);
  	}
+ 	else
+ 		post("py/pyext - Send name is invalid");
  
      Py_INCREF(Py_None);

Index: bound.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/bound.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** bound.cpp	21 Jun 2004 14:04:15 -0000	1.9
--- bound.cpp	31 Aug 2004 04:07:35 -0000	1.10
***************
*** 39,42 ****
--- 39,44 ----
      }
  
+     Py_XDECREF(args);
+ 
  	PY_UNLOCK
      return true;

Index: register.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/register.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** register.cpp	4 Jan 2003 04:36:49 -0000	1.2
--- register.cpp	31 Aug 2004 04:07:35 -0000	1.3
***************
*** 67,71 ****
  			I cnt = PySequence_Size(reg);
  			for(I i = 0; i < cnt; ++i) {
! 				PyObject *it = PySequence_GetItem(reg,i); // borrowed!!
  				if(!it || !PyInt_Check(it)) {
  					post("%s - Corrupt registry?!",thisName());
--- 67,71 ----
  			I cnt = PySequence_Size(reg);
  			for(I i = 0; i < cnt; ++i) {
! 				PyObject *it = PySequence_GetItem(reg,i); // new reference
  				if(!it || !PyInt_Check(it)) {
  					post("%s - Corrupt registry?!",thisName());
***************
*** 77,80 ****
--- 77,82 ----
  					th->Reload();
  				}
+ 
+                 Py_XDECREF(it);
  			}
  		}

Index: pyext.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** pyext.cpp	21 Aug 2004 04:13:48 -0000	1.18
--- pyext.cpp	31 Aug 2004 04:07:35 -0000	1.19
***************
*** 77,84 ****
  {
  	PyObject *th = PyObject_GetAttrString(self,"_this");
! 	pyext *ret = th?(pyext *)PyLong_AsVoidPtr(th):NULL;
! 	PyErr_Clear();
! 	Py_XDECREF(th);
! 	return ret;
  }
  
--- 77,89 ----
  {
  	PyObject *th = PyObject_GetAttrString(self,"_this");
!     if(th) {
! 	    pyext *ret = static_cast<pyext *>(PyLong_AsVoidPtr(th));
! 	    Py_DECREF(th);
!         return ret;
!     }
!     else {
!     	PyErr_Clear();
!         return NULL;
!     }
  }
  
***************
*** 386,390 ****
                      // reduce lists of one element to element itself
  
!                     PyObject *val1 = PySequence_GetItem(pval,0);
                      Py_DECREF(pval);
                      pval = val1;
--- 391,395 ----
                      // reduce lists of one element to element itself
  
!                     PyObject *val1 = PySequence_GetItem(pval,0); // new reference
                      Py_DECREF(pval);
                      pval = val1;





More information about the Pd-cvs mailing list