[Python-checkins] CVS: python/dist/src/Modules arraymodule.c,2.56,2.57

Tim Peters python-dev@python.org
Sat, 16 Sep 2000 15:31:31 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv26393/python/dist/src/Modules

Modified Files:
	arraymodule.c 
Log Message:
arraymodule:  Fix SF bug 113960.
    reverse() didn't work at all due to bad arg check.
    Fixed that.
    Added Brad Chapman to ACKS file, as the proud new owner of two
        implicitly copyrighted lines of Python source code <wink>.
    Repaired buffer_info's total lack of arg-checking.
    Replaced memmove by memcpy in reverse() guts, as memmove is
        often slower and the memory areas are guaranteed disjoint.
    Replaced poke-and-hope unchecked decl of tmp buffer size by
        assert-checked larger tmp buffer.
    Got rid of inconsistent spaces before open paren in docstrings.
    Added reverse() sanity tests to test_array.py.


Index: arraymodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v
retrieving revision 2.56
retrieving revision 2.57
diff -C2 -r2.56 -r2.57
*** arraymodule.c	2000/09/10 05:22:54	2.56
--- arraymodule.c	2000/09/16 22:31:29	2.57
***************
*** 329,333 ****
  	{'\0', 0, 0, 0} /* Sentinel */
  };
- /* If we ever allow items larger than double, we must change reverse()! */
  
  /****************************************************************************
--- 329,332 ----
***************
*** 651,655 ****
  
  static char count_doc [] =
! "count (x)\n\
  \n\
  Return number of occurences of x in the array.";
--- 650,654 ----
  
  static char count_doc [] =
! "count(x)\n\
  \n\
  Return number of occurences of x in the array.";
***************
*** 678,682 ****
  
  static char index_doc [] =
! "index (x)\n\
  \n\
  Return index of first occurence of x in the array.";
--- 677,681 ----
  
  static char index_doc [] =
! "index(x)\n\
  \n\
  Return index of first occurence of x in the array.";
***************
*** 709,713 ****
  
  static char remove_doc [] =
! "remove (x)\n\
  \n\
  Remove the first occurence of x in the array.";
--- 708,712 ----
  
  static char remove_doc [] =
! "remove(x)\n\
  \n\
  Remove the first occurence of x in the array.";
***************
*** 740,744 ****
  
  static char pop_doc [] =
! "pop ([i])\n\
  \n\
  Return the i-th element and delete it from the array. i defaults to -1.";
--- 739,743 ----
  
  static char pop_doc [] =
! "pop([i])\n\
  \n\
  Return the i-th element and delete it from the array. i defaults to -1.";
***************
*** 795,799 ****
  
  static char insert_doc [] =
! "insert (i,x)\n\
  \n\
  Insert a new item x into the array before position i.";
--- 794,798 ----
  
  static char insert_doc [] =
! "insert(i,x)\n\
  \n\
  Insert a new item x into the array before position i.";
***************
*** 803,808 ****
  array_buffer_info(arrayobject *self, PyObject *args)
  {
! 	PyObject* retval = PyTuple_New(2);
! 	if (!retval) return NULL;
  
  	PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
--- 802,811 ----
  array_buffer_info(arrayobject *self, PyObject *args)
  {
! 	PyObject* retval = NULL;
!         if (!PyArg_ParseTuple(args, ":buffer_info"))
!                 return NULL;
! 	retval = PyTuple_New(2);
! 	if (!retval)
! 		return NULL;
  
  	PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
***************
*** 813,817 ****
  
  static char buffer_info_doc [] =
! "buffer_info -> (address, length)\n\
  \n\
  Return a tuple (address, length) giving the current memory address and\n\
--- 816,820 ----
  
  static char buffer_info_doc [] =
! "buffer_info() -> (address, length)\n\
  \n\
  Return a tuple (address, length) giving the current memory address and\n\
***************
*** 899,909 ****
  	register int itemsize = self->ob_descr->itemsize;
  	register char *p, *q;
! 	char tmp[sizeof(double)]; /* Assume that's the max item size */
  
! 	if (args != NULL) {
! 		PyErr_SetString(PyExc_TypeError,
! 		     "<array>.reverse requires exactly 0 arguments");
! 		return NULL;
! 	}
  
  	if (self->ob_size > 1) {
--- 902,911 ----
  	register int itemsize = self->ob_descr->itemsize;
  	register char *p, *q;
! 	/* little buffer to hold items while swapping */
! 	char tmp[256];	/* 8 is probably enough -- but why skimp */
! 	assert(itemsize <= sizeof(tmp));
  
!         if (!PyArg_ParseTuple(args, ":reverse"))
!                 return NULL;
  
  	if (self->ob_size > 1) {
***************
*** 912,918 ****
  		     p < q;
  		     p += itemsize, q -= itemsize) {
! 			memmove(tmp, p, itemsize);
! 			memmove(p, q, itemsize);
! 			memmove(q, tmp, itemsize);
  		}
  	}
--- 914,923 ----
  		     p < q;
  		     p += itemsize, q -= itemsize) {
! 			/* memory areas guaranteed disjoint, so memcpy
! 			 * is safe (& memmove may be slower).
! 			 */
! 			memcpy(tmp, p, itemsize);
! 			memcpy(p, q, itemsize);
! 			memcpy(q, tmp, itemsize);
  		}
  	}