summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-07-21 17:22:18 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-07-21 17:22:18 (GMT)
commit9f2e346911988cda95fec7c901e8d10d34fa9563 (patch)
tree1632c78fb8e18b2f789102451bedd15996bff6c5 /Modules/arraymodule.c
parentb972a78e17beeb997d809d87f2e422e6622efd52 (diff)
downloadcpython-9f2e346911988cda95fec7c901e8d10d34fa9563.zip
cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.gz
cpython-9f2e346911988cda95fec7c901e8d10d34fa9563.tar.bz2
Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines Merged revisions 56466-56476 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines PEP 3123: Provide forward compatibility with Python 3.0, while keeping backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT. ........ ................ r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines PEP 3123: Use proper C inheritance for PyObject. ................ r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines Add longintrepr.h to Python.h, so that the compiler can see that PyFalse is really some kind of PyObject*. ................ r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines Qualify SHIFT, MASK, BASE. ................ r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines Correctly refer to _ob_next. ................
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c226
1 files changed, 112 insertions, 114 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 7ddc7e8..89e3f25 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;
}
@@ -410,7 +410,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;
}
@@ -433,7 +433,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);
}
@@ -441,7 +441,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;
@@ -476,7 +476,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 *
@@ -496,7 +496,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;
@@ -508,7 +508,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) {
@@ -527,8 +527,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;
@@ -568,13 +568,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;
}
@@ -587,14 +587,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;
@@ -606,7 +606,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,
@@ -622,7 +622,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)
@@ -630,14 +630,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
}
@@ -652,12 +652,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;
@@ -675,7 +675,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;
@@ -694,44 +694,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,
@@ -743,7 +743,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;
@@ -770,7 +770,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;
@@ -796,16 +796,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;
@@ -818,7 +818,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)
@@ -833,15 +833,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 {
@@ -854,8 +854,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);
@@ -878,7 +878,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);
@@ -900,7 +900,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);
@@ -925,7 +925,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);
@@ -938,7 +938,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);
@@ -968,14 +968,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;
}
@@ -1031,7 +1031,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;
}
@@ -1048,7 +1048,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,
@@ -1067,14 +1067,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];
@@ -1084,7 +1084,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];
@@ -1125,16 +1125,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(cy#)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);
}
@@ -1153,9 +1153,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
@@ -1242,7 +1242,7 @@ array_tofile(arrayobject *self, PyObject *f)
Py_ssize_t nblocks = (nbytes + BLOCKSIZE - 1) / BLOCKSIZE;
Py_ssize_t i;
- if (self->ob_size == 0)
+ if (Py_Size(self) == 0)
goto done;
for (i = 0; i < nblocks; i++) {
@@ -1286,23 +1286,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;
}
}
@@ -1319,12 +1319,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);
@@ -1357,15 +1357,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);
@@ -1410,15 +1410,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));
}
@@ -1443,7 +1443,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,
@@ -1536,7 +1536,7 @@ array_repr(arrayobject *a)
PyObject *s, *v = NULL;
Py_ssize_t len;
- len = a->ob_size;
+ len = Py_Size(a);
typecode = a->ob_descr->typecode;
if (len == 0) {
return PyUnicode_FromFormat("array('%c')", typecode);
@@ -1560,7 +1560,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)) {
@@ -1569,7 +1569,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;
}
@@ -1608,14 +1608,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;
}
@@ -1643,17 +1643,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;
}
@@ -1665,16 +1665,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;
}
@@ -1683,7 +1683,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;
@@ -1730,7 +1730,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
@@ -1744,14 +1744,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;
}
@@ -1861,9 +1861,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);
}
}
if (it != NULL) {
@@ -1949,8 +1949,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,
@@ -2031,7 +2030,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;
}
@@ -2052,8 +2051,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 */
@@ -2100,7 +2098,7 @@ initarray(void)
if (PyType_Ready(&Arraytype) < 0)
return;
- PyArrayIter_Type.ob_type = &PyType_Type;
+ Py_Type(&PyArrayIter_Type) = &PyType_Type;
m = Py_InitModule3("array", a_methods, module_doc);
if (m == NULL)
return;