summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c238
1 files changed, 118 insertions, 120 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 3ba5cf8..21a5e5b 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -39,7 +39,7 @@ typedef struct arrayobject {
static PyTypeObject Arraytype;
#define array_Check(op) PyObject_TypeCheck(op, &Arraytype)
-#define array_CheckExact(op) ((op)->ob_type == &Arraytype)
+#define array_CheckExact(op) (Py_Type(op) == &Arraytype)
static int
array_resize(arrayobject *self, Py_ssize_t newsize)
@@ -53,9 +53,9 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
*/
if (self->allocated >= newsize &&
- self->ob_size < newsize + 16 &&
+ Py_Size(self) < newsize + 16 &&
self->ob_item != NULL) {
- self->ob_size = newsize;
+ Py_Size(self) = newsize;
return 0;
}
@@ -71,7 +71,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
* memory critical.
*/
- _new_size = (newsize >> 4) + (self->ob_size < 8 ? 3 : 7) + newsize;
+ _new_size = (newsize >> 4) + (Py_Size(self) < 8 ? 3 : 7) + newsize;
items = self->ob_item;
/* XXX The following multiplication and division does not optimize away
like it does for lists since the size is not known at compile time */
@@ -84,7 +84,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
return -1;
}
self->ob_item = items;
- self->ob_size = newsize;
+ Py_Size(self) = newsize;
self->allocated = _new_size;
return 0;
}
@@ -432,7 +432,7 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr)
if (op == NULL) {
return NULL;
}
- op->ob_size = size;
+ Py_Size(op) = size;
if (size <= 0) {
op->ob_item = NULL;
}
@@ -455,7 +455,7 @@ getarrayitem(PyObject *op, Py_ssize_t i)
register arrayobject *ap;
assert(array_Check(op));
ap = (arrayobject *)op;
- assert(i>=0 && i<ap->ob_size);
+ assert(i>=0 && i<Py_Size(ap));
return (*ap->ob_descr->getitem)(ap, i);
}
@@ -463,7 +463,7 @@ static int
ins1(arrayobject *self, Py_ssize_t where, PyObject *v)
{
char *items;
- Py_ssize_t n = self->ob_size;
+ Py_ssize_t n = Py_Size(self);
if (v == NULL) {
PyErr_BadInternalCall();
return -1;
@@ -498,7 +498,7 @@ array_dealloc(arrayobject *op)
PyObject_ClearWeakRefs((PyObject *) op);
if (op->ob_item != NULL)
PyMem_DEL(op->ob_item);
- op->ob_type->tp_free((PyObject *)op);
+ Py_Type(op)->tp_free((PyObject *)op);
}
static PyObject *
@@ -518,7 +518,7 @@ array_richcompare(PyObject *v, PyObject *w, int op)
va = (arrayobject *)v;
wa = (arrayobject *)w;
- if (va->ob_size != wa->ob_size && (op == Py_EQ || op == Py_NE)) {
+ if (Py_Size(va) != Py_Size(wa) && (op == Py_EQ || op == Py_NE)) {
/* Shortcut: if the lengths differ, the arrays differ */
if (op == Py_EQ)
res = Py_False;
@@ -530,7 +530,7 @@ array_richcompare(PyObject *v, PyObject *w, int op)
/* Search for the first index where items are different */
k = 1;
- for (i = 0; i < va->ob_size && i < wa->ob_size; i++) {
+ for (i = 0; i < Py_Size(va) && i < Py_Size(wa); i++) {
vi = getarrayitem(v, i);
wi = getarrayitem(w, i);
if (vi == NULL || wi == NULL) {
@@ -549,8 +549,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
if (k) {
/* No more items to compare -- compare sizes */
- Py_ssize_t vs = va->ob_size;
- Py_ssize_t ws = wa->ob_size;
+ Py_ssize_t vs = Py_Size(va);
+ Py_ssize_t ws = Py_Size(wa);
int cmp;
switch (op) {
case Py_LT: cmp = vs < ws; break;
@@ -590,13 +590,13 @@ array_richcompare(PyObject *v, PyObject *w, int op)
static Py_ssize_t
array_length(arrayobject *a)
{
- return a->ob_size;
+ return Py_Size(a);
}
static PyObject *
array_item(arrayobject *a, Py_ssize_t i)
{
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError, "array index out of range");
return NULL;
}
@@ -609,14 +609,14 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
arrayobject *np;
if (ilow < 0)
ilow = 0;
- else if (ilow > a->ob_size)
- ilow = a->ob_size;
+ else if (ilow > Py_Size(a))
+ ilow = Py_Size(a);
if (ihigh < 0)
ihigh = 0;
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ else if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr);
if (np == NULL)
return NULL;
@@ -628,7 +628,7 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
static PyObject *
array_copy(arrayobject *a, PyObject *unused)
{
- return array_slice(a, 0, a->ob_size);
+ return array_slice(a, 0, Py_Size(a));
}
PyDoc_STRVAR(copy_doc,
@@ -644,7 +644,7 @@ array_concat(arrayobject *a, PyObject *bb)
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
"can only append array (not \"%.200s\") to array",
- bb->ob_type->tp_name);
+ Py_Type(bb)->tp_name);
return NULL;
}
#define b ((arrayobject *)bb)
@@ -652,14 +652,14 @@ array_concat(arrayobject *a, PyObject *bb)
PyErr_BadArgument();
return NULL;
}
- size = a->ob_size + b->ob_size;
+ size = Py_Size(a) + Py_Size(b);
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL) {
return NULL;
}
- memcpy(np->ob_item, a->ob_item, a->ob_size*a->ob_descr->itemsize);
- memcpy(np->ob_item + a->ob_size*a->ob_descr->itemsize,
- b->ob_item, b->ob_size*b->ob_descr->itemsize);
+ memcpy(np->ob_item, a->ob_item, Py_Size(a)*a->ob_descr->itemsize);
+ memcpy(np->ob_item + Py_Size(a)*a->ob_descr->itemsize,
+ b->ob_item, Py_Size(b)*b->ob_descr->itemsize);
return (PyObject *)np;
#undef b
}
@@ -674,12 +674,12 @@ array_repeat(arrayobject *a, Py_ssize_t n)
Py_ssize_t nbytes;
if (n < 0)
n = 0;
- size = a->ob_size * n;
+ size = Py_Size(a) * n;
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL)
return NULL;
p = np->ob_item;
- nbytes = a->ob_size * a->ob_descr->itemsize;
+ nbytes = Py_Size(a) * a->ob_descr->itemsize;
for (i = 0; i < n; i++) {
memcpy(p, a->ob_item, nbytes);
p += nbytes;
@@ -697,7 +697,7 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
if (v == NULL)
n = 0;
else if (array_Check(v)) {
- n = b->ob_size;
+ n = Py_Size(b);
if (a == b) {
/* Special case "a[i:j] = a" -- copy b first */
int ret;
@@ -716,44 +716,44 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
else {
PyErr_Format(PyExc_TypeError,
"can only assign array (not \"%.200s\") to array slice",
- v->ob_type->tp_name);
+ Py_Type(v)->tp_name);
return -1;
}
if (ilow < 0)
ilow = 0;
- else if (ilow > a->ob_size)
- ilow = a->ob_size;
+ else if (ilow > Py_Size(a))
+ ilow = Py_Size(a);
if (ihigh < 0)
ihigh = 0;
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > a->ob_size)
- ihigh = a->ob_size;
+ else if (ihigh > Py_Size(a))
+ ihigh = Py_Size(a);
item = a->ob_item;
d = n - (ihigh-ilow);
if (d < 0) { /* Delete -d items */
memmove(item + (ihigh+d)*a->ob_descr->itemsize,
item + ihigh*a->ob_descr->itemsize,
- (a->ob_size-ihigh)*a->ob_descr->itemsize);
- a->ob_size += d;
- PyMem_RESIZE(item, char, a->ob_size*a->ob_descr->itemsize);
+ (Py_Size(a)-ihigh)*a->ob_descr->itemsize);
+ Py_Size(a) += d;
+ PyMem_RESIZE(item, char, Py_Size(a)*a->ob_descr->itemsize);
/* Can't fail */
a->ob_item = item;
- a->allocated = a->ob_size;
+ a->allocated = Py_Size(a);
}
else if (d > 0) { /* Insert d items */
PyMem_RESIZE(item, char,
- (a->ob_size + d)*a->ob_descr->itemsize);
+ (Py_Size(a) + d)*a->ob_descr->itemsize);
if (item == NULL) {
PyErr_NoMemory();
return -1;
}
memmove(item + (ihigh+d)*a->ob_descr->itemsize,
item + ihigh*a->ob_descr->itemsize,
- (a->ob_size-ihigh)*a->ob_descr->itemsize);
+ (Py_Size(a)-ihigh)*a->ob_descr->itemsize);
a->ob_item = item;
- a->ob_size += d;
- a->allocated = a->ob_size;
+ Py_Size(a) += d;
+ a->allocated = Py_Size(a);
}
if (n > 0)
memcpy(item + ilow*a->ob_descr->itemsize, b->ob_item,
@@ -765,7 +765,7 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
static int
array_ass_item(arrayobject *a, Py_ssize_t i, PyObject *v)
{
- if (i < 0 || i >= a->ob_size) {
+ if (i < 0 || i >= Py_Size(a)) {
PyErr_SetString(PyExc_IndexError,
"array assignment index out of range");
return -1;
@@ -792,7 +792,7 @@ array_iter_extend(arrayobject *self, PyObject *bb)
return -1;
while ((v = PyIter_Next(it)) != NULL) {
- if (ins1(self, (int) self->ob_size, v) != 0) {
+ if (ins1(self, (int) Py_Size(self), v) != 0) {
Py_DECREF(v);
Py_DECREF(it);
return -1;
@@ -818,16 +818,16 @@ array_do_extend(arrayobject *self, PyObject *bb)
"can only extend with array of same kind");
return -1;
}
- size = self->ob_size + b->ob_size;
+ size = Py_Size(self) + Py_Size(b);
PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize);
if (self->ob_item == NULL) {
PyObject_Del(self);
PyErr_NoMemory();
return -1;
}
- memcpy(self->ob_item + self->ob_size*self->ob_descr->itemsize,
- b->ob_item, b->ob_size*b->ob_descr->itemsize);
- self->ob_size = size;
+ memcpy(self->ob_item + Py_Size(self)*self->ob_descr->itemsize,
+ b->ob_item, Py_Size(b)*b->ob_descr->itemsize);
+ Py_Size(self) = size;
self->allocated = size;
return 0;
@@ -840,7 +840,7 @@ array_inplace_concat(arrayobject *self, PyObject *bb)
if (!array_Check(bb)) {
PyErr_Format(PyExc_TypeError,
"can only extend array with array (not \"%.200s\")",
- bb->ob_type->tp_name);
+ Py_Type(bb)->tp_name);
return NULL;
}
if (array_do_extend(self, bb) == -1)
@@ -855,15 +855,15 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
char *items, *p;
Py_ssize_t size, i;
- if (self->ob_size > 0) {
+ if (Py_Size(self) > 0) {
if (n < 0)
n = 0;
items = self->ob_item;
- size = self->ob_size * self->ob_descr->itemsize;
+ size = Py_Size(self) * self->ob_descr->itemsize;
if (n == 0) {
PyMem_FREE(items);
self->ob_item = NULL;
- self->ob_size = 0;
+ Py_Size(self) = 0;
self->allocated = 0;
}
else {
@@ -876,8 +876,8 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
memcpy(p, items, size);
}
self->ob_item = items;
- self->ob_size *= n;
- self->allocated = self->ob_size;
+ Py_Size(self) *= n;
+ self->allocated = Py_Size(self);
}
}
Py_INCREF(self);
@@ -900,7 +900,7 @@ array_count(arrayobject *self, PyObject *v)
Py_ssize_t count = 0;
Py_ssize_t i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -922,7 +922,7 @@ array_index(arrayobject *self, PyObject *v)
{
Py_ssize_t i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -947,7 +947,7 @@ array_contains(arrayobject *self, PyObject *v)
Py_ssize_t i;
int cmp;
- for (i = 0, cmp = 0 ; cmp == 0 && i < self->ob_size; i++) {
+ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self, i);
cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -960,7 +960,7 @@ array_remove(arrayobject *self, PyObject *v)
{
int i;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *selfi = getarrayitem((PyObject *)self,i);
int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
Py_DECREF(selfi);
@@ -990,14 +990,14 @@ array_pop(arrayobject *self, PyObject *args)
PyObject *v;
if (!PyArg_ParseTuple(args, "|n:pop", &i))
return NULL;
- if (self->ob_size == 0) {
+ if (Py_Size(self) == 0) {
/* Special-case most common failure cause */
PyErr_SetString(PyExc_IndexError, "pop from empty array");
return NULL;
}
if (i < 0)
- i += self->ob_size;
- if (i < 0 || i >= self->ob_size) {
+ i += Py_Size(self);
+ if (i < 0 || i >= Py_Size(self)) {
PyErr_SetString(PyExc_IndexError, "pop index out of range");
return NULL;
}
@@ -1053,7 +1053,7 @@ array_buffer_info(arrayobject *self, PyObject *unused)
return NULL;
PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
- PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(self->ob_size)));
+ PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(Py_Size(self))));
return retval;
}
@@ -1070,7 +1070,7 @@ the buffer length in bytes.");
static PyObject *
array_append(arrayobject *self, PyObject *v)
{
- return ins(self, (int) self->ob_size, v);
+ return ins(self, (int) Py_Size(self), v);
}
PyDoc_STRVAR(append_doc,
@@ -1089,14 +1089,14 @@ array_byteswap(arrayobject *self, PyObject *unused)
case 1:
break;
case 2:
- for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 2) {
+ for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 2) {
char p0 = p[0];
p[0] = p[1];
p[1] = p0;
}
break;
case 4:
- for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 4) {
+ for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 4) {
char p0 = p[0];
char p1 = p[1];
p[0] = p[3];
@@ -1106,7 +1106,7 @@ array_byteswap(arrayobject *self, PyObject *unused)
}
break;
case 8:
- for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 8) {
+ for (p = self->ob_item, i = Py_Size(self); --i >= 0; p += 8) {
char p0 = p[0];
char p1 = p[1];
char p2 = p[2];
@@ -1147,16 +1147,16 @@ array_reduce(arrayobject *array)
dict = Py_None;
Py_INCREF(dict);
}
- if (array->ob_size > 0) {
+ if (Py_Size(array) > 0) {
result = Py_BuildValue("O(cs#)O",
- array->ob_type,
+ Py_Type(array),
array->ob_descr->typecode,
array->ob_item,
- array->ob_size * array->ob_descr->itemsize,
+ Py_Size(array) * array->ob_descr->itemsize,
dict);
} else {
result = Py_BuildValue("O(c)O",
- array->ob_type,
+ Py_Type(array),
array->ob_descr->typecode,
dict);
}
@@ -1175,9 +1175,9 @@ array_reverse(arrayobject *self, PyObject *unused)
char tmp[256]; /* 8 is probably enough -- but why skimp */
assert((size_t)itemsize <= sizeof(tmp));
- if (self->ob_size > 1) {
+ if (Py_Size(self) > 1) {
for (p = self->ob_item,
- q = self->ob_item + (self->ob_size - 1)*itemsize;
+ q = self->ob_item + (Py_Size(self) - 1)*itemsize;
p < q;
p += itemsize, q -= itemsize) {
/* memory areas guaranteed disjoint, so memcpy
@@ -1218,7 +1218,7 @@ array_fromfile(arrayobject *self, PyObject *args)
Py_ssize_t newlength;
size_t newbytes;
/* Be careful here about overflow */
- if ((newlength = self->ob_size + n) <= 0 ||
+ if ((newlength = Py_Size(self) + n) <= 0 ||
(newbytes = newlength * itemsize) / itemsize !=
(size_t)newlength)
goto nomem;
@@ -1229,15 +1229,15 @@ array_fromfile(arrayobject *self, PyObject *args)
return NULL;
}
self->ob_item = item;
- self->ob_size += n;
- self->allocated = self->ob_size;
- nread = fread(item + (self->ob_size - n) * itemsize,
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
+ nread = fread(item + (Py_Size(self) - n) * itemsize,
itemsize, n, fp);
if (nread < (size_t)n) {
- self->ob_size -= (n - nread);
- PyMem_RESIZE(item, char, self->ob_size*itemsize);
+ Py_Size(self) -= (n - nread);
+ PyMem_RESIZE(item, char, Py_Size(self)*itemsize);
self->ob_item = item;
- self->allocated = self->ob_size;
+ self->allocated = Py_Size(self);
PyErr_SetString(PyExc_EOFError,
"not enough items in file");
return NULL;
@@ -1297,23 +1297,23 @@ array_fromlist(arrayobject *self, PyObject *list)
if (n > 0) {
char *item = self->ob_item;
Py_ssize_t i;
- PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize);
+ PyMem_RESIZE(item, char, (Py_Size(self) + n) * itemsize);
if (item == NULL) {
PyErr_NoMemory();
return NULL;
}
self->ob_item = item;
- self->ob_size += n;
- self->allocated = self->ob_size;
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
for (i = 0; i < n; i++) {
PyObject *v = PyList_GetItem(list, i);
if ((*self->ob_descr->setitem)(self,
- self->ob_size - n + i, v) != 0) {
- self->ob_size -= n;
+ Py_Size(self) - n + i, v) != 0) {
+ Py_Size(self) -= n;
PyMem_RESIZE(item, char,
- self->ob_size * itemsize);
+ Py_Size(self) * itemsize);
self->ob_item = item;
- self->allocated = self->ob_size;
+ self->allocated = Py_Size(self);
return NULL;
}
}
@@ -1331,12 +1331,12 @@ Append items to array from list.");
static PyObject *
array_tolist(arrayobject *self, PyObject *unused)
{
- PyObject *list = PyList_New(self->ob_size);
+ PyObject *list = PyList_New(Py_Size(self));
Py_ssize_t i;
if (list == NULL)
return NULL;
- for (i = 0; i < self->ob_size; i++) {
+ for (i = 0; i < Py_Size(self); i++) {
PyObject *v = getarrayitem((PyObject *)self, i);
if (v == NULL) {
Py_DECREF(list);
@@ -1369,15 +1369,15 @@ array_fromstring(arrayobject *self, PyObject *args)
n = n / itemsize;
if (n > 0) {
char *item = self->ob_item;
- PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize);
+ PyMem_RESIZE(item, char, (Py_Size(self) + n) * itemsize);
if (item == NULL) {
PyErr_NoMemory();
return NULL;
}
self->ob_item = item;
- self->ob_size += n;
- self->allocated = self->ob_size;
- memcpy(item + (self->ob_size - n) * itemsize,
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
+ memcpy(item + (Py_Size(self) - n) * itemsize,
str, itemsize*n);
}
Py_INCREF(Py_None);
@@ -1395,7 +1395,7 @@ static PyObject *
array_tostring(arrayobject *self, PyObject *unused)
{
return PyString_FromStringAndSize(self->ob_item,
- self->ob_size * self->ob_descr->itemsize);
+ Py_Size(self) * self->ob_descr->itemsize);
}
PyDoc_STRVAR(tostring_doc,
@@ -1423,15 +1423,15 @@ array_fromunicode(arrayobject *self, PyObject *args)
}
if (n > 0) {
Py_UNICODE *item = (Py_UNICODE *) self->ob_item;
- PyMem_RESIZE(item, Py_UNICODE, self->ob_size + n);
+ PyMem_RESIZE(item, Py_UNICODE, Py_Size(self) + n);
if (item == NULL) {
PyErr_NoMemory();
return NULL;
}
self->ob_item = (char *) item;
- self->ob_size += n;
- self->allocated = self->ob_size;
- memcpy(item + self->ob_size - n,
+ Py_Size(self) += n;
+ self->allocated = Py_Size(self);
+ memcpy(item + Py_Size(self) - n,
ustr, n * sizeof(Py_UNICODE));
}
@@ -1456,7 +1456,7 @@ array_tounicode(arrayobject *self, PyObject *unused)
"tounicode() may only be called on type 'u' arrays");
return NULL;
}
- return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, self->ob_size);
+ return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_Size(self));
}
PyDoc_STRVAR(tounicode_doc,
@@ -1554,7 +1554,7 @@ array_repr(arrayobject *a)
PyObject *s, *t, *v = NULL;
Py_ssize_t len;
- len = a->ob_size;
+ len = Py_Size(a);
typecode = a->ob_descr->typecode;
if (len == 0) {
PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode);
@@ -1588,7 +1588,7 @@ array_subscr(arrayobject* self, PyObject* item)
return NULL;
}
if (i < 0)
- i += self->ob_size;
+ i += Py_Size(self);
return array_item(self, i);
}
else if (PySlice_Check(item)) {
@@ -1597,7 +1597,7 @@ array_subscr(arrayobject* self, PyObject* item)
arrayobject* ar;
int itemsize = self->ob_descr->itemsize;
- if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
&start, &stop, &step, &slicelength) < 0) {
return NULL;
}
@@ -1636,14 +1636,14 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (i==-1 && PyErr_Occurred())
return -1;
if (i < 0)
- i += self->ob_size;
+ i += Py_Size(self);
return array_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
int itemsize = self->ob_descr->itemsize;
- if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size,
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
&start, &stop, &step, &slicelength) < 0) {
return -1;
}
@@ -1671,17 +1671,17 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
self->ob_item + (cur + 1)*itemsize,
(step - 1) * itemsize);
}
- extra = self->ob_size - (cur + 1);
+ extra = Py_Size(self) - (cur + 1);
if (extra > 0) {
memmove(self->ob_item + (cur - i)*itemsize,
self->ob_item + (cur + 1)*itemsize,
extra*itemsize);
}
- self->ob_size -= slicelength;
+ Py_Size(self) -= slicelength;
self->ob_item = (char *)PyMem_REALLOC(self->ob_item,
- itemsize*self->ob_size);
- self->allocated = self->ob_size;
+ itemsize*Py_Size(self));
+ self->allocated = Py_Size(self);
return 0;
}
@@ -1693,16 +1693,16 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if (!array_Check(value)) {
PyErr_Format(PyExc_TypeError,
"must assign array (not \"%.200s\") to slice",
- value->ob_type->tp_name);
+ Py_Type(value)->tp_name);
return -1;
}
av = (arrayobject*)value;
- if (av->ob_size != slicelength) {
+ if (Py_Size(av) != slicelength) {
PyErr_Format(PyExc_ValueError,
"attempt to assign array of size %ld to extended slice of size %ld",
- /*XXX*/(long)av->ob_size, /*XXX*/(long)slicelength);
+ /*XXX*/(long)Py_Size(av), /*XXX*/(long)slicelength);
return -1;
}
@@ -1711,7 +1711,7 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
/* protect against a[::-1] = a */
if (self == av) {
- value = array_slice(av, 0, av->ob_size);
+ value = array_slice(av, 0, Py_Size(av));
av = (arrayobject*)value;
if (!av)
return -1;
@@ -1758,7 +1758,7 @@ array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr)
*ptr = (void *)self->ob_item;
if (*ptr == NULL)
*ptr = emptybuf;
- return self->ob_size*self->ob_descr->itemsize;
+ return Py_Size(self)*self->ob_descr->itemsize;
}
static Py_ssize_t
@@ -1772,14 +1772,14 @@ array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr)
*ptr = (void *)self->ob_item;
if (*ptr == NULL)
*ptr = emptybuf;
- return self->ob_size*self->ob_descr->itemsize;
+ return Py_Size(self)*self->ob_descr->itemsize;
}
static Py_ssize_t
array_buffer_getsegcount(arrayobject *self, Py_ssize_t *lenp)
{
if ( lenp )
- *lenp = self->ob_size*self->ob_descr->itemsize;
+ *lenp = Py_Size(self)*self->ob_descr->itemsize;
return 1;
}
@@ -1888,9 +1888,9 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
self->ob_item = item;
- self->ob_size = n / sizeof(Py_UNICODE);
+ Py_Size(self) = n / sizeof(Py_UNICODE);
memcpy(item, PyUnicode_AS_DATA(initial), n);
- self->allocated = self->ob_size;
+ self->allocated = Py_Size(self);
}
#endif
}
@@ -1978,8 +1978,7 @@ itemsize -- the length in bytes of one array item\n\
static PyObject *array_iter(arrayobject *ao);
static PyTypeObject Arraytype = {
- PyObject_HEAD_INIT(NULL)
- 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
"array.array",
sizeof(arrayobject),
0,
@@ -2060,7 +2059,7 @@ static PyObject *
arrayiter_next(arrayiterobject *it)
{
assert(PyArrayIter_Check(it));
- if (it->index < it->ao->ob_size)
+ if (it->index < Py_Size(it->ao))
return (*it->getitem)(it->ao, it->index++);
return NULL;
}
@@ -2081,8 +2080,7 @@ arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
}
static PyTypeObject PyArrayIter_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(NULL, 0)
"arrayiterator", /* tp_name */
sizeof(arrayiterobject), /* tp_basicsize */
0, /* tp_itemsize */