Commit 88d20250 authored by Tim Peters's avatar Tim Peters

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).
parent 06c2bcbb
/* Array object implementation */ /* Array object implementation */
/* An array is a uniform list -- all items have the same type. /* An array is a uniform list -- all items have the same type.
...@@ -19,6 +18,10 @@ ...@@ -19,6 +18,10 @@
struct arrayobject; /* Forward */ 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 { struct arraydescr {
int typecode; int typecode;
int itemsize; int itemsize;
...@@ -36,17 +39,17 @@ staticforward PyTypeObject Arraytype; ...@@ -36,17 +39,17 @@ staticforward PyTypeObject Arraytype;
#define is_arrayobject(op) ((op)->ob_type == &Arraytype) #define is_arrayobject(op) ((op)->ob_type == &Arraytype)
/* Forward */ /****************************************************************************
static PyObject *newarrayobject(int, struct arraydescr *); Get and Set functions for each type.
#if 0 A Get function takes an arrayobject* and an integer index, returning the
static int getarraysize(PyObject *); array value at that index wrapped in an appropriate PyObject*.
#endif A Set function takes an arrayobject, integer index, and PyObject*; sets
static PyObject *getarrayitem(PyObject *, int); the array value at that index to the raw C data extracted from the PyObject*,
static int setarrayitem(PyObject *, int, PyObject *); and returns 0 if successful, else nonzero on failure (PyObject* not of an
#if 0 appropriate type or value).
static int insarrayitem(PyObject *, int, PyObject *); Note that the basic Get and Set functions do NOT check that the index is
static int addarrayitem(PyObject *, PyObject *); in bounds; that's the responsibility of the caller.
#endif ****************************************************************************/
static PyObject * static PyObject *
c_getitem(arrayobject *ap, int i) c_getitem(arrayobject *ap, int i)
...@@ -208,7 +211,7 @@ II_setitem(arrayobject *ap, int i, PyObject *v) ...@@ -208,7 +211,7 @@ II_setitem(arrayobject *ap, int i, PyObject *v)
return -1; return -1;
} }
x = (unsigned long)y; x = (unsigned long)y;
} }
if (x > UINT_MAX) { if (x > UINT_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
...@@ -263,14 +266,14 @@ LL_setitem(arrayobject *ap, int i, PyObject *v) ...@@ -263,14 +266,14 @@ LL_setitem(arrayobject *ap, int i, PyObject *v)
return -1; return -1;
} }
x = (unsigned long)y; x = (unsigned long)y;
} }
if (x > ULONG_MAX) { if (x > ULONG_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"unsigned long is greater than maximum"); "unsigned long is greater than maximum");
return -1; return -1;
} }
if (i >= 0) if (i >= 0)
((unsigned long *)ap->ob_item)[i] = x; ((unsigned long *)ap->ob_item)[i] = x;
return 0; return 0;
...@@ -326,7 +329,10 @@ static struct arraydescr descriptors[] = { ...@@ -326,7 +329,10 @@ static struct arraydescr descriptors[] = {
{'\0', 0, 0, 0} /* Sentinel */ {'\0', 0, 0, 0} /* Sentinel */
}; };
/* If we ever allow items larger than double, we must change reverse()! */ /* If we ever allow items larger than double, we must change reverse()! */
/****************************************************************************
Implementations of array object methods.
****************************************************************************/
static PyObject * static PyObject *
newarrayobject(int size, struct arraydescr *descr) newarrayobject(int size, struct arraydescr *descr)
...@@ -360,26 +366,11 @@ newarrayobject(int size, struct arraydescr *descr) ...@@ -360,26 +366,11 @@ newarrayobject(int size, struct arraydescr *descr)
return (PyObject *) op; return (PyObject *) op;
} }
#if 0
static int
getarraysize(PyObject *op)
{
if (!is_arrayobject(op)) {
PyErr_BadInternalCall();
return -1;
}
return ((arrayobject *)op) -> ob_size;
}
#endif
static PyObject * static PyObject *
getarrayitem(PyObject *op, int i) getarrayitem(PyObject *op, int i)
{ {
register arrayobject *ap; register arrayobject *ap;
if (!is_arrayobject(op)) { assert(is_arrayobject(op));
PyErr_BadInternalCall();
return NULL;
}
ap = (arrayobject *)op; ap = (arrayobject *)op;
if (i < 0 || i >= ap->ob_size) { if (i < 0 || i >= ap->ob_size) {
PyErr_SetString(PyExc_IndexError, "array index out of range"); PyErr_SetString(PyExc_IndexError, "array index out of range");
...@@ -417,29 +408,6 @@ ins1(arrayobject *self, int where, PyObject *v) ...@@ -417,29 +408,6 @@ ins1(arrayobject *self, int where, PyObject *v)
return (*self->ob_descr->setitem)(self, where, v); return (*self->ob_descr->setitem)(self, where, v);
} }
#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 */ /* Methods */
static void static void
...@@ -648,10 +616,7 @@ array_ass_item(arrayobject *a, int i, PyObject *v) ...@@ -648,10 +616,7 @@ array_ass_item(arrayobject *a, int i, PyObject *v)
static int static int
setarrayitem(PyObject *a, int i, PyObject *v) setarrayitem(PyObject *a, int i, PyObject *v)
{ {
if (!is_arrayobject(a)) { assert(is_arrayobject(a));
PyErr_BadInternalCall();
return -1;
}
return array_ass_item((arrayobject *)a, i, v); return array_ass_item((arrayobject *)a, i, v);
} }
...@@ -783,10 +748,10 @@ array_extend(arrayobject *self, PyObject *args) ...@@ -783,10 +748,10 @@ array_extend(arrayobject *self, PyObject *args)
{ {
int size; int size;
PyObject *bb; PyObject *bb;
if (!PyArg_ParseTuple(args, "O:extend", &bb)) if (!PyArg_ParseTuple(args, "O:extend", &bb))
return NULL; return NULL;
if (!is_arrayobject(bb)) { if (!is_arrayobject(bb)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"can only extend array with array (not \"%.200s\")", "can only extend array with array (not \"%.200s\")",
...@@ -951,7 +916,7 @@ array_reverse(arrayobject *self, PyObject *args) ...@@ -951,7 +916,7 @@ array_reverse(arrayobject *self, PyObject *args)
memmove(q, tmp, itemsize); memmove(q, tmp, itemsize);
} }
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
...@@ -1337,9 +1302,6 @@ static PyBufferProcs array_as_buffer = { ...@@ -1337,9 +1302,6 @@ static PyBufferProcs array_as_buffer = {
(getsegcountproc)array_buffer_getsegcount, (getsegcountproc)array_buffer_getsegcount,
}; };
static PyObject * static PyObject *
a_array(PyObject *self, PyObject *args) a_array(PyObject *self, PyObject *args)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment