[Python-checkins] python/dist/src/Modules _sre.c, 2.99, 2.100 almodule.c, 1.38, 1.39 arraymodule.c, 2.91, 2.92 cPickle.c, 2.147, 2.148 cStringIO.c, 2.44, 2.45 datetimemodule.c, 1.67, 1.68 flmodule.c, 1.51, 1.52 mathmodule.c, 2.71, 2.72 posixmodule.c, 2.304, 2.305 pyexpat.c, 2.83, 2.84 regexmodule.c, 1.49, 1.50 selectmodule.c, 2.74, 2.75 socketmodule.c, 1.275, 1.276 svmodule.c, 2.19, 2.20 symtablemodule.c, 1.7, 1.8

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Oct 12 15:09:39 EDT 2003


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv411/Modules

Modified Files:
	_sre.c almodule.c arraymodule.c cPickle.c cStringIO.c 
	datetimemodule.c flmodule.c mathmodule.c posixmodule.c 
	pyexpat.c regexmodule.c selectmodule.c socketmodule.c 
	svmodule.c symtablemodule.c 
Log Message:
Simplify and speedup uses of Py_BuildValue():

* Py_BuildValue("(OOO)",a,b,c)  -->  PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a)         -->  PyTuple_New(0)
* Py_BuildValue("O", a)         -->  Py_INCREF(a)



Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.99
retrieving revision 2.100
diff -C2 -d -r2.99 -r2.100
*** _sre.c	26 Jun 2003 14:41:08 -0000	2.99
--- _sre.c	12 Oct 2003 19:09:36 -0000	2.100
***************
*** 1908,1912 ****
      copy = call(
          "copy", "deepcopy",
!         Py_BuildValue("OO", *object, memo)
          );
      if (!copy)
--- 1908,1912 ----
      copy = call(
          "copy", "deepcopy",
!         PyTuple_Pack(2, *object, memo)
          );
      if (!copy)
***************
*** 1969,1973 ****
      result = call(
          "string", "join",
!         Py_BuildValue("OO", list, joiner)
          );
  #endif
--- 1969,1973 ----
      result = call(
          "string", "join",
!         PyTuple_Pack(2, list, joiner)
          );
  #endif
***************
*** 2256,2260 ****
              filter = call(
                  SRE_MODULE, "_subx",
!                 Py_BuildValue("OO", self, template)
                  );
              if (!filter)
--- 2256,2260 ----
              filter = call(
                  SRE_MODULE, "_subx",
!                 PyTuple_Pack(2, self, template)
                  );
              if (!filter)
***************
*** 2322,2326 ****
              if (!match)
                  goto error;
!             args = Py_BuildValue("(O)", match);
              if (!args) {
                  Py_DECREF(match);
--- 2322,2326 ----
              if (!match)
                  goto error;
!             args = PyTuple_Pack(1, match);
              if (!args) {
                  Py_DECREF(match);
***************
*** 2611,2615 ****
      return call(
          SRE_MODULE, "_expand",
!         Py_BuildValue("OOO", self->pattern, self, template)
          );
  }
--- 2611,2615 ----
      return call(
          SRE_MODULE, "_expand",
!         PyTuple_Pack(3, self->pattern, self, template)
          );
  }

Index: almodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/almodule.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** almodule.c	30 Mar 2003 21:49:18 -0000	1.38
--- almodule.c	12 Oct 2003 19:09:36 -0000	1.39
***************
*** 902,906 ****
  		return NULL;
  	}
! 	ret = Py_BuildValue("(OO)", v0, v1);
  	Py_DECREF(v0);
  	Py_DECREF(v1);
--- 902,906 ----
  		return NULL;
  	}
! 	ret = PyTuple_Pack(2, v0, v1);
  	Py_DECREF(v0);
  	Py_DECREF(v1);

Index: arraymodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v
retrieving revision 2.91
retrieving revision 2.92
diff -C2 -d -r2.91 -r2.92
*** arraymodule.c	5 Aug 2003 11:23:59 -0000	2.91
--- arraymodule.c	12 Oct 2003 19:09:36 -0000	2.92
***************
*** 1771,1775 ****
  				}
  			} else if (initial != NULL && PyString_Check(initial)) {
! 				PyObject *t_initial = Py_BuildValue("(O)",
  								    initial);
  				PyObject *v =
--- 1771,1775 ----
  				}
  			} else if (initial != NULL && PyString_Check(initial)) {
! 				PyObject *t_initial = PyTuple_Pack(1,
  								    initial);
  				PyObject *v =

Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.147
retrieving revision 2.148
diff -C2 -d -r2.147 -r2.148
*** cPickle.c	11 Jul 2003 19:42:49 -0000	2.147
--- cPickle.c	12 Oct 2003 19:09:36 -0000	2.148
***************
*** 3628,3632 ****
  
  		PyErr_Fetch(&tp, &v, &tb);
! 		if ((r=Py_BuildValue("OOO",v,cls,args))) {
  			Py_XDECREF(v);
  			v=r;
--- 3628,3632 ----
  
  		PyErr_Fetch(&tp, &v, &tb);
! 		if ((r=PyTuple_Pack(3,v,cls,args))) {
  			Py_XDECREF(v);
  			v=r;

Index: cStringIO.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cStringIO.c,v
retrieving revision 2.44
retrieving revision 2.45
diff -C2 -d -r2.44 -r2.45
*** cStringIO.c	11 Aug 2003 14:51:15 -0000	2.44
--- cStringIO.c	12 Oct 2003 19:09:36 -0000	2.45
***************
*** 440,444 ****
          UNLESS (tmp) return NULL;
  
!         args = Py_BuildValue("(O)", tmp);
          Py_DECREF(tmp);
          UNLESS (args) return NULL;
--- 440,444 ----
          UNLESS (tmp) return NULL;
  
!         args = PyTuple_Pack(1, tmp);
          Py_DECREF(tmp);
          UNLESS (args) return NULL;

Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -d -r1.67 -r1.68
*** datetimemodule.c	27 Jun 2003 08:14:17 -0000	1.67
--- datetimemodule.c	12 Oct 2003 19:09:36 -0000	1.68
***************
*** 3373,3379 ****
  	if (basestate != NULL) {
  		if (! HASTZINFO(self) || self->tzinfo == Py_None)
! 			result = Py_BuildValue("(O)", basestate);
  		else
! 			result = Py_BuildValue("OO", basestate, self->tzinfo);
  		Py_DECREF(basestate);
  	}
--- 3373,3379 ----
  	if (basestate != NULL) {
  		if (! HASTZINFO(self) || self->tzinfo == Py_None)
! 			result = PyTuple_Pack(1, basestate);
  		else
! 			result = PyTuple_Pack(2, basestate, self->tzinfo);
  		Py_DECREF(basestate);
  	}
***************
*** 4351,4357 ****
  	if (basestate != NULL) {
  		if (! HASTZINFO(self) || self->tzinfo == Py_None)
! 			result = Py_BuildValue("(O)", basestate);
  		else
! 			result = Py_BuildValue("OO", basestate, self->tzinfo);
  		Py_DECREF(basestate);
  	}
--- 4351,4357 ----
  	if (basestate != NULL) {
  		if (! HASTZINFO(self) || self->tzinfo == Py_None)
! 			result = PyTuple_Pack(1, basestate);
  		else
! 			result = PyTuple_Pack(2, basestate, self->tzinfo);
  		Py_DECREF(basestate);
  	}

Index: flmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/flmodule.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -d -r1.51 -r1.52
*** flmodule.c	2 Aug 2002 02:27:13 -0000	1.51
--- flmodule.c	12 Oct 2003 19:09:36 -0000	1.52
***************
*** 1715,1719 ****
  			return ((PyObject *) g);
  		}
! 		arg = Py_BuildValue("(OO)", (PyObject *)g, g->ob_callback_arg);
  		if (arg == NULL)
  			return NULL;
--- 1715,1719 ----
  			return ((PyObject *) g);
  		}
! 		arg = PyTuple_Pack(2, (PyObject *)g, g->ob_callback_arg);
  		if (arg == NULL)
  			return NULL;

Index: mathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v
retrieving revision 2.71
retrieving revision 2.72
diff -C2 -d -r2.71 -r2.72
*** mathmodule.c	29 Dec 2002 16:31:06 -0000	2.71
--- mathmodule.c	12 Oct 2003 19:09:36 -0000	2.72
***************
*** 260,268 ****
  		return loghelper(args, log, "d:log", arg);
  
! 	newargs = PyTuple_New(1);
  	if (newargs == NULL)
  		return NULL;
- 	Py_INCREF(arg);
- 	PyTuple_SET_ITEM(newargs, 0, arg);
  	num = loghelper(newargs, log, "d:log", arg);
  	Py_DECREF(newargs);
--- 260,266 ----
  		return loghelper(args, log, "d:log", arg);
  
! 	newargs = PyTuple_Pack(1, arg);
  	if (newargs == NULL)
  		return NULL;
  	num = loghelper(newargs, log, "d:log", arg);
  	Py_DECREF(newargs);
***************
*** 270,280 ****
  		return NULL;
  
! 	newargs = PyTuple_New(1);
  	if (newargs == NULL) {
  		Py_DECREF(num);
  		return NULL;
  	}
- 	Py_INCREF(base);
- 	PyTuple_SET_ITEM(newargs, 0, base);
  	den = loghelper(newargs, log, "d:log", base);
  	Py_DECREF(newargs);
--- 268,276 ----
  		return NULL;
  
! 	newargs = PyTuple_Pack(1, base);
  	if (newargs == NULL) {
  		Py_DECREF(num);
  		return NULL;
  	}
  	den = loghelper(newargs, log, "d:log", base);
  	Py_DECREF(newargs);

Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.304
retrieving revision 2.305
diff -C2 -d -r2.304 -r2.305
*** posixmodule.c	20 Sep 2003 11:20:30 -0000	2.304
--- posixmodule.c	12 Oct 2003 19:09:36 -0000	2.305
***************
*** 3377,3384 ****
  		if ((p_f[2] = PyFile_FromFile(p_s[2], cmdstring, rd_mode, _PyPclose)) != NULL)
  			PyFile_SetBufSize(p_f[0], bufsize);
! 		f = Py_BuildValue("OOO", p_f[0], p_f[1], p_f[2]);
  	}
  	else
! 		f = Py_BuildValue("OO", p_f[0], p_f[1]);
  
  	/*
--- 3377,3384 ----
  		if ((p_f[2] = PyFile_FromFile(p_s[2], cmdstring, rd_mode, _PyPclose)) != NULL)
  			PyFile_SetBufSize(p_f[0], bufsize);
! 		f = PyTuple_Pack(3, p_f[0], p_f[1], p_f[2]);
  	}
  	else
! 		f = PyTuple_Pack(2, p_f[0], p_f[1]);
  
  	/*
***************
*** 4070,4074 ****
  			 CloseHandle(hChildStderrRdDup);
  
! 		 f = Py_BuildValue("OO",p1,p2);
  		 Py_XDECREF(p1);
  		 Py_XDECREF(p2);
--- 4070,4074 ----
  			 CloseHandle(hChildStderrRdDup);
  
! 		 f = PyTuple_Pack(2,p1,p2);
  		 Py_XDECREF(p1);
  		 Py_XDECREF(p2);
***************
*** 4102,4106 ****
  		 PyFile_SetBufSize(p2, 0);
  		 PyFile_SetBufSize(p3, 0);
! 		 f = Py_BuildValue("OOO",p1,p2,p3);
  		 Py_XDECREF(p1);
  		 Py_XDECREF(p2);
--- 4102,4106 ----
  		 PyFile_SetBufSize(p2, 0);
  		 PyFile_SetBufSize(p3, 0);
! 		 f = PyTuple_Pack(3,p1,p2,p3);
  		 Py_XDECREF(p1);
  		 Py_XDECREF(p2);

Index: pyexpat.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pyexpat.c,v
retrieving revision 2.83
retrieving revision 2.84
diff -C2 -d -r2.83 -r2.84
*** pyexpat.c	21 Jul 2003 17:22:43 -0000	2.83
--- pyexpat.c	12 Oct 2003 19:09:37 -0000	2.84
***************
*** 337,341 ****
  	Py_INCREF(value);
      }
!     arg = Py_BuildValue("(OOO)", type, value, traceback);
      if (arg == NULL) {
  	PyErr_Restore(type, value, traceback);
--- 337,341 ----
  	Py_INCREF(value);
      }
!     arg = PyTuple_Pack(3, type, value, traceback);
      if (arg == NULL) {
  	PyErr_Restore(type, value, traceback);

Index: regexmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/regexmodule.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** regexmodule.c	2 Aug 2002 02:27:13 -0000	1.49
--- regexmodule.c	12 Oct 2003 19:09:37 -0000	1.50
***************
*** 552,556 ****
  update_cache(PyObject *pat)
  {
! 	PyObject *tuple = Py_BuildValue("(O)", pat);
  	int status = 0;
  
--- 552,556 ----
  update_cache(PyObject *pat)
  {
! 	PyObject *tuple = PyTuple_Pack(1, pat);
  	int status = 0;
  

Index: selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.74
retrieving revision 2.75
diff -C2 -d -r2.74 -r2.75
*** selectmodule.c	10 Sep 2003 19:37:42 -0000	2.74
--- selectmodule.c	12 Oct 2003 19:09:37 -0000	2.75
***************
*** 285,289 ****
  		ifdlist = PyList_New(0);
  		if (ifdlist) {
! 			ret = Py_BuildValue("OOO", ifdlist, ifdlist, ifdlist);
  			Py_DECREF(ifdlist);
  		}
--- 285,289 ----
  		ifdlist = PyList_New(0);
  		if (ifdlist) {
! 			ret = PyTuple_Pack(3, ifdlist, ifdlist, ifdlist);
  			Py_DECREF(ifdlist);
  		}
***************
*** 300,304 ****
  			ret = NULL;
  		else
! 			ret = Py_BuildValue("OOO", ifdlist, ofdlist, efdlist);
  
  		Py_DECREF(ifdlist);
--- 300,304 ----
  			ret = NULL;
  		else
! 			ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist);
  
  		Py_DECREF(ifdlist);

Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.275
retrieving revision 1.276
diff -C2 -d -r1.275 -r1.276
*** socketmodule.c	4 Oct 2003 08:00:49 -0000	1.275
--- socketmodule.c	12 Oct 2003 19:09:37 -0000	1.276
***************
*** 1162,1166 ****
  		goto finally;
  
! 	res = Py_BuildValue("OO", sock, addr);
  
  finally:
--- 1162,1166 ----
  		goto finally;
  
! 	res = PyTuple_Pack(2, sock, addr);
  
  finally:
***************
*** 1912,1916 ****
  		goto finally;
  
! 	ret = Py_BuildValue("OO", buf, addr);
  
  finally:
--- 1912,1916 ----
  		goto finally;
  
! 	ret = PyTuple_Pack(2, buf, addr);
  
  finally:

Index: svmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/svmodule.c,v
retrieving revision 2.19
retrieving revision 2.20
diff -C2 -d -r2.19 -r2.20
*** svmodule.c	17 Jan 2002 23:15:58 -0000	2.19
--- svmodule.c	12 Oct 2003 19:09:37 -0000	2.20
***************
*** 158,162 ****
  					      fieldsize)))
  		goto finally;
! 	ret = Py_BuildValue("(OO)", f1, f2);
  
    finally:
--- 158,162 ----
  					      fieldsize)))
  		goto finally;
! 	ret = PyTuple_Pack(2, f1, f2);
  
    finally:

Index: symtablemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/symtablemodule.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** symtablemodule.c	13 Aug 2002 22:20:40 -0000	1.7
--- symtablemodule.c	12 Oct 2003 19:09:37 -0000	1.8
***************
*** 32,36 ****
  	if (st == NULL)
  		return NULL;
! 	t = Py_BuildValue("O", st->st_symbols);
  	PyMem_Free((void *)st->st_future);
  	PySymtable_Free(st);
--- 32,37 ----
  	if (st == NULL)
  		return NULL;
! 	t = st->st_symbols;
! 	Py_INCREF(t);
  	PyMem_Free((void *)st->st_future);
  	PySymtable_Free(st);





More information about the Python-checkins mailing list