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

Tim Peters python-dev@python.org
Sat, 9 Sep 2000 22:22:57 -0700


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

Modified Files:
	arraymodule.c 
Log Message:
General cleanup in preparation for a bugfix:  removed unused code, useless
declarations, added some comments where I had to think too hard to
understand what was happening, and changed the primary internal get/set
functions to assert they're passed objects of the correct type instead of
doing runtime tests for that (it's an internal error that "should never
happen", so it's good enough to check it only in the debug build).


Index: arraymodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v
retrieving revision 2.55
retrieving revision 2.56
diff -C2 -r2.55 -r2.56
*** arraymodule.c	2000/09/01 23:29:26	2.55
--- arraymodule.c	2000/09/10 05:22:54	2.56
***************
*** 1,3 ****
- 
  /* Array object implementation */
  
--- 1,2 ----
***************
*** 20,23 ****
--- 19,26 ----
  struct arrayobject; /* Forward */
  
+ /* All possible arraydescr values are defined in the vector "descriptors"
+  * below.  That's defined later because the appropriate get and set
+  * functions aren't visible yet.
+  */
  struct arraydescr {
  	int typecode;
***************
*** 37,51 ****
  #define is_arrayobject(op) ((op)->ob_type == &Arraytype)
  
! /* Forward */
! static PyObject *newarrayobject(int, struct arraydescr *);
! #if 0
! static int getarraysize(PyObject *);
! #endif
! static PyObject *getarrayitem(PyObject *, int);
! static int setarrayitem(PyObject *, int, PyObject *);
! #if 0
! static int insarrayitem(PyObject *, int, PyObject *);
! static int addarrayitem(PyObject *, PyObject *);
! #endif
  
  static PyObject *
--- 40,54 ----
  #define is_arrayobject(op) ((op)->ob_type == &Arraytype)
  
! /****************************************************************************
! Get and Set functions for each type.
! A Get function takes an arrayobject* and an integer index, returning the
! array value at that index wrapped in an appropriate PyObject*.
! A Set function takes an arrayobject, integer index, and PyObject*; sets
! the array value at that index to the raw C data extracted from the PyObject*,
! and returns 0 if successful, else nonzero on failure (PyObject* not of an
! appropriate type or value).
! Note that the basic Get and Set functions do NOT check that the index is
! in bounds; that's the responsibility of the caller.
! ****************************************************************************/
  
  static PyObject *
***************
*** 209,213 ****
  		}
  		x = (unsigned long)y;
! 						
  	}
  	if (x > UINT_MAX) {
--- 212,216 ----
  		}
  		x = (unsigned long)y;
! 
  	}
  	if (x > UINT_MAX) {
***************
*** 264,268 ****
  		}
  		x = (unsigned long)y;
! 						
  	}
  	if (x > ULONG_MAX) {
--- 267,271 ----
  		}
  		x = (unsigned long)y;
! 
  	}
  	if (x > ULONG_MAX) {
***************
*** 271,275 ****
  		return -1;
  	}
! 		
  	if (i >= 0)
  		((unsigned long *)ap->ob_item)[i] = x;
--- 274,278 ----
  		return -1;
  	}
! 
  	if (i >= 0)
  		((unsigned long *)ap->ob_item)[i] = x;
***************
*** 327,331 ****
  };
  /* If we ever allow items larger than double, we must change reverse()! */
! 	
  
  static PyObject *
--- 330,337 ----
  };
  /* If we ever allow items larger than double, we must change reverse()! */
! 
! /****************************************************************************
! Implementations of array object methods.
! ****************************************************************************/
  
  static PyObject *
***************
*** 361,384 ****
  }
  
- #if 0
- static int
- getarraysize(PyObject *op)
- {
- 	if (!is_arrayobject(op)) {
- 		PyErr_BadInternalCall();
- 		return -1;
- 	}
- 	return ((arrayobject *)op) -> ob_size;
- }
- #endif
- 
  static PyObject *
  getarrayitem(PyObject *op, int i)
  {
  	register arrayobject *ap;
! 	if (!is_arrayobject(op)) {
! 		PyErr_BadInternalCall();
! 		return NULL;
! 	}
  	ap = (arrayobject *)op;
  	if (i < 0 || i >= ap->ob_size) {
--- 367,375 ----
  }
  
  static PyObject *
  getarrayitem(PyObject *op, int i)
  {
  	register arrayobject *ap;
! 	assert(is_arrayobject(op));
  	ap = (arrayobject *)op;
  	if (i < 0 || i >= ap->ob_size) {
***************
*** 418,444 ****
  }
  
- #if 0
- static int
- insarrayitem(PyObject *op, int where, PyObject *newitem)
- {
- 	if (!is_arrayobject(op)) {
- 		PyErr_BadInternalCall();
- 		return -1;
- 	}
- 	return ins1((arrayobject *)op, where, newitem);
- }
- 
- static int
- addarrayitem(PyObject *op, PyObject *newitem)
- {
- 	if (!is_arrayobject(op)) {
- 		PyErr_BadInternalCall();
- 		return -1;
- 	}
- 	return ins1((arrayobject *)op,
- 		(int) ((arrayobject *)op)->ob_size, newitem);
- }
- #endif
- 
  /* Methods */
  
--- 409,412 ----
***************
*** 649,656 ****
  setarrayitem(PyObject *a, int i, PyObject *v)
  {
! 	if (!is_arrayobject(a)) {
! 		PyErr_BadInternalCall();
! 		return -1;
! 	}
  	return array_ass_item((arrayobject *)a, i, v);
  }
--- 617,621 ----
  setarrayitem(PyObject *a, int i, PyObject *v)
  {
! 	assert(is_arrayobject(a));
  	return array_ass_item((arrayobject *)a, i, v);
  }
***************
*** 784,791 ****
  	int size;
          PyObject    *bb;
!         
  	if (!PyArg_ParseTuple(args, "O:extend", &bb))
              return NULL;
!         
  	if (!is_arrayobject(bb)) {
  		PyErr_Format(PyExc_TypeError,
--- 749,756 ----
  	int size;
          PyObject    *bb;
! 
  	if (!PyArg_ParseTuple(args, "O:extend", &bb))
              return NULL;
! 
  	if (!is_arrayobject(bb)) {
  		PyErr_Format(PyExc_TypeError,
***************
*** 952,956 ****
  		}
  	}
! 	
  	Py_INCREF(Py_None);
  	return Py_None;
--- 917,921 ----
  		}
  	}
! 
  	Py_INCREF(Py_None);
  	return Py_None;
***************
*** 1337,1343 ****
  	(getsegcountproc)array_buffer_getsegcount,
  };
- 
- 
- 
  
  static PyObject *
--- 1302,1305 ----