#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 3fa256e..27f0a81 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -34,7 +34,7 @@
*/
if (allocated >= newsize && newsize >= (allocated >> 1)) {
assert(self->ob_item != NULL || newsize == 0);
- Py_Size(self) = newsize;
+ Py_SIZE(self) = newsize;
return 0;
}
@@ -58,7 +58,7 @@
return -1;
}
self->ob_item = items;
- Py_Size(self) = newsize;
+ Py_SIZE(self) = newsize;
self->allocated = new_allocated;
return 0;
}
@@ -114,7 +114,7 @@
}
memset(op->ob_item, 0, nbytes);
}
- Py_Size(op) = size;
+ Py_SIZE(op) = size;
op->allocated = size;
_PyObject_GC_TRACK(op);
return (PyObject *) op;
@@ -128,7 +128,7 @@
return -1;
}
else
- return Py_Size(op);
+ return Py_SIZE(op);
}
static PyObject *indexerr = NULL;
@@ -140,7 +140,7 @@
PyErr_BadInternalCall();
return NULL;
}
- if (i < 0 || i >= Py_Size(op)) {
+ if (i < 0 || i >= Py_SIZE(op)) {
if (indexerr == NULL)
indexerr = PyString_FromString(
"list index out of range");
@@ -161,7 +161,7 @@
PyErr_BadInternalCall();
return -1;
}
- if (i < 0 || i >= Py_Size(op)) {
+ if (i < 0 || i >= Py_SIZE(op)) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
@@ -177,7 +177,7 @@
static int
ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
{
- Py_ssize_t i, n = Py_Size(self);
+ Py_ssize_t i, n = Py_SIZE(self);
PyObject **items;
if (v == NULL) {
PyErr_BadInternalCall();
@@ -259,7 +259,7 @@
There's a simple test case where somehow this reduces
thrashing when a *very* large list is created and
immediately deleted. */
- i = Py_Size(op);
+ i = Py_SIZE(op);
while (--i >= 0) {
Py_XDECREF(op->ob_item[i]);
}
@@ -268,7 +268,7 @@
if (num_free_lists < MAXFREELISTS && PyList_CheckExact(op))
free_lists[num_free_lists++] = op;
else
- Py_Type(op)->tp_free((PyObject *)op);
+ Py_TYPE(op)->tp_free((PyObject *)op);
Py_TRASHCAN_SAFE_END(op)
}
@@ -290,7 +290,7 @@
Py_BEGIN_ALLOW_THREADS
fprintf(fp, "[");
Py_END_ALLOW_THREADS
- for (i = 0; i < Py_Size(op); i++) {
+ for (i = 0; i < Py_SIZE(op); i++) {
if (i > 0) {
Py_BEGIN_ALLOW_THREADS
fprintf(fp, ", ");
@@ -320,7 +320,7 @@
return i > 0 ? PyString_FromString("[...]") : NULL;
}
- if (Py_Size(v) == 0) {
+ if (Py_SIZE(v) == 0) {
result = PyString_FromString("[]");
goto Done;
}
@@ -331,7 +331,7 @@
/* Do repr() on each element. Note that this may mutate the list,
so must refetch the list size on each iteration. */
- for (i = 0; i < Py_Size(v); ++i) {
+ for (i = 0; i < Py_SIZE(v); ++i) {
int status;
if (Py_EnterRecursiveCall(" while getting the repr of a list"))
goto Done;
@@ -381,7 +381,7 @@
static Py_ssize_t
list_length(PyListObject *a)
{
- return Py_Size(a);
+ return Py_SIZE(a);
}
static int
@@ -390,7 +390,7 @@
Py_ssize_t i;
int cmp;
- for (i = 0, cmp = 0 ; cmp == 0 && i < Py_Size(a); ++i)
+ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
Py_EQ);
return cmp;
@@ -399,7 +399,7 @@
static PyObject *
list_item(PyListObject *a, Py_ssize_t i)
{
- if (i < 0 || i >= Py_Size(a)) {
+ if (i < 0 || i >= Py_SIZE(a)) {
if (indexerr == NULL)
indexerr = PyString_FromString(
"list index out of range");
@@ -418,12 +418,12 @@
Py_ssize_t i, len;
if (ilow < 0)
ilow = 0;
- else if (ilow > Py_Size(a))
- ilow = Py_Size(a);
+ else if (ilow > Py_SIZE(a))
+ ilow = Py_SIZE(a);
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > Py_Size(a))
- ihigh = Py_Size(a);
+ else if (ihigh > Py_SIZE(a))
+ ihigh = Py_SIZE(a);
len = ihigh - ilow;
np = (PyListObject *) PyList_New(len);
if (np == NULL)
@@ -463,7 +463,7 @@
return NULL;
}
#define b ((PyListObject *)bb)
- size = Py_Size(a) + Py_Size(b);
+ size = Py_SIZE(a) + Py_SIZE(b);
if (size < 0)
return PyErr_NoMemory();
np = (PyListObject *) PyList_New(size);
@@ -472,14 +472,14 @@
}
src = a->ob_item;
dest = np->ob_item;
- for (i = 0; i < Py_Size(a); i++) {
+ for (i = 0; i < Py_SIZE(a); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
}
src = b->ob_item;
- dest = np->ob_item + Py_Size(a);
- for (i = 0; i < Py_Size(b); i++) {
+ dest = np->ob_item + Py_SIZE(a);
+ for (i = 0; i < Py_SIZE(b); i++) {
PyObject *v = src[i];
Py_INCREF(v);
dest[i] = v;
@@ -498,8 +498,8 @@
PyObject *elem;
if (n < 0)
n = 0;
- size = Py_Size(a) * n;
- if (n && size/n != Py_Size(a))
+ size = Py_SIZE(a) * n;
+ if (n && size/n != Py_SIZE(a))
return PyErr_NoMemory();
if (size == 0)
return PyList_New(0);
@@ -508,7 +508,7 @@
return NULL;
items = np->ob_item;
- if (Py_Size(a) == 1) {
+ if (Py_SIZE(a) == 1) {
elem = a->ob_item[0];
for (i = 0; i < n; i++) {
items[i] = elem;
@@ -519,7 +519,7 @@
p = np->ob_item;
items = a->ob_item;
for (i = 0; i < n; i++) {
- for (j = 0; j < Py_Size(a); j++) {
+ for (j = 0; j < Py_SIZE(a); j++) {
*p = items[j];
Py_INCREF(*p);
p++;
@@ -536,8 +536,8 @@
if (item != NULL) {
/* Because XDECREF can recursively invoke operations on
this list, we make it empty first. */
- i = Py_Size(a);
- Py_Size(a) = 0;
+ i = Py_SIZE(a);
+ Py_SIZE(a) = 0;
a->ob_item = NULL;
a->allocated = 0;
while (--i >= 0) {
@@ -583,7 +583,7 @@
else {
if (a == b) {
/* Special case "a[i:j] = a" -- copy b first */
- v = list_slice(b, 0, Py_Size(b));
+ v = list_slice(b, 0, Py_SIZE(b));
if (v == NULL)
return result;
result = list_ass_slice(a, ilow, ihigh, v);
@@ -598,18 +598,18 @@
}
if (ilow < 0)
ilow = 0;
- else if (ilow > Py_Size(a))
- ilow = Py_Size(a);
+ else if (ilow > Py_SIZE(a))
+ ilow = Py_SIZE(a);
if (ihigh < ilow)
ihigh = ilow;
- else if (ihigh > Py_Size(a))
- ihigh = Py_Size(a);
+ else if (ihigh > Py_SIZE(a))
+ ihigh = Py_SIZE(a);
norig = ihigh - ilow;
assert(norig >= 0);
d = n - norig;
- if (Py_Size(a) + d == 0) {
+ if (Py_SIZE(a) + d == 0) {
Py_XDECREF(v_as_SF);
return list_clear(a);
}
@@ -627,12 +627,12 @@
if (d < 0) { /* Delete -d items */
memmove(&item[ihigh+d], &item[ihigh],
- (Py_Size(a) - ihigh)*sizeof(PyObject *));
- list_resize(a, Py_Size(a) + d);
+ (Py_SIZE(a) - ihigh)*sizeof(PyObject *));
+ list_resize(a, Py_SIZE(a) + d);
item = a->ob_item;
}
else if (d > 0) { /* Insert d items */
- k = Py_Size(a);
+ k = Py_SIZE(a);
if (list_resize(a, k+d) < 0)
goto Error;
item = a->ob_item;
@@ -707,7 +707,7 @@
list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
{
PyObject *old_value;
- if (i < 0 || i >= Py_Size(a)) {
+ if (i < 0 || i >= Py_SIZE(a)) {
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
return -1;
@@ -766,7 +766,7 @@
Py_DECREF(b);
Py_RETURN_NONE;
}
- m = Py_Size(self);
+ m = Py_SIZE(self);
if (list_resize(self, m + n) == -1) {
Py_DECREF(b);
return NULL;
@@ -795,14 +795,14 @@
/* Guess a result list size. */
n = _PyObject_LengthHint(b, 8);
- m = Py_Size(self);
+ m = Py_SIZE(self);
mn = m + n;
if (mn >= m) {
/* Make room. */
if (list_resize(self, mn) == -1)
goto error;
/* Make the list sane again. */
- Py_Size(self) = m;
+ Py_SIZE(self) = m;
}
/* Else m + n overflowed; on the chance that n lied, and there really
* is enough room, ignore it. If n was telling the truth, we'll
@@ -821,10 +821,10 @@
}
break;
}
- if (Py_Size(self) < self->allocated) {
+ if (Py_SIZE(self) < self->allocated) {
/* steals ref */
- PyList_SET_ITEM(self, Py_Size(self), item);
- ++Py_Size(self);
+ PyList_SET_ITEM(self, Py_SIZE(self), item);
+ ++Py_SIZE(self);
}
else {
int status = app1(self, item);
@@ -835,8 +835,8 @@
}
/* Cut back result list if initial guess was too large. */
- if (Py_Size(self) < self->allocated)
- list_resize(self, Py_Size(self)); /* shrinking can't fail */
+ if (Py_SIZE(self) < self->allocated)
+ list_resize(self, Py_SIZE(self)); /* shrinking can't fail */
Py_DECREF(it);
Py_RETURN_NONE;
@@ -875,20 +875,20 @@
if (!PyArg_ParseTuple(args, "|n:pop", &i))
return NULL;
- if (Py_Size(self) == 0) {
+ if (Py_SIZE(self) == 0) {
/* Special-case most common failure cause */
PyErr_SetString(PyExc_IndexError, "pop from empty list");
return NULL;
}
if (i < 0)
- i += Py_Size(self);
- if (i < 0 || i >= Py_Size(self)) {
+ i += Py_SIZE(self);
+ if (i < 0 || i >= Py_SIZE(self)) {
PyErr_SetString(PyExc_IndexError, "pop index out of range");
return NULL;
}
v = self->ob_item[i];
- if (i == Py_Size(self) - 1) {
- status = list_resize(self, Py_Size(self) - 1);
+ if (i == Py_SIZE(self) - 1) {
+ status = list_resize(self, Py_SIZE(self) - 1);
assert(status >= 0);
return v; /* and v now owns the reference the list had */
}
@@ -2018,10 +2018,10 @@
* sorting (allowing mutations during sorting is a core-dump
* factory, since ob_item may change).
*/
- saved_ob_size = Py_Size(self);
+ saved_ob_size = Py_SIZE(self);
saved_ob_item = self->ob_item;
saved_allocated = self->allocated;
- Py_Size(self) = 0;
+ Py_SIZE(self) = 0;
self->ob_item = NULL;
self->allocated = -1; /* any operation will reset it to >= 0 */
@@ -2127,8 +2127,8 @@
dsu_fail:
final_ob_item = self->ob_item;
- i = Py_Size(self);
- Py_Size(self) = saved_ob_size;
+ i = Py_SIZE(self);
+ Py_SIZE(self) = saved_ob_size;
self->ob_item = saved_ob_item;
self->allocated = saved_allocated;
if (final_ob_item != NULL) {
@@ -2163,8 +2163,8 @@
static PyObject *
listreverse(PyListObject *self)
{
- if (Py_Size(self) > 1)
- reverse_slice(self->ob_item, self->ob_item + Py_Size(self));
+ if (Py_SIZE(self) > 1)
+ reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
Py_RETURN_NONE;
}
@@ -2177,8 +2177,8 @@
PyErr_BadInternalCall();
return -1;
}
- if (Py_Size(self) > 1)
- reverse_slice(self->ob_item, self->ob_item + Py_Size(self));
+ if (Py_SIZE(self) > 1)
+ reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
return 0;
}
@@ -2192,7 +2192,7 @@
PyErr_BadInternalCall();
return NULL;
}
- n = Py_Size(v);
+ n = Py_SIZE(v);
w = PyTuple_New(n);
if (w == NULL)
return NULL;
@@ -2210,7 +2210,7 @@
static PyObject *
listindex(PyListObject *self, PyObject *args)
{
- Py_ssize_t i, start=0, stop=Py_Size(self);
+ Py_ssize_t i, start=0, stop=Py_SIZE(self);
PyObject *v;
if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
@@ -2218,16 +2218,16 @@
_PyEval_SliceIndex, &stop))
return NULL;
if (start < 0) {
- start += Py_Size(self);
+ start += Py_SIZE(self);
if (start < 0)
start = 0;
}
if (stop < 0) {
- stop += Py_Size(self);
+ stop += Py_SIZE(self);
if (stop < 0)
stop = 0;
}
- for (i = start; i < stop && i < Py_Size(self); i++) {
+ for (i = start; i < stop && i < Py_SIZE(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
return PyInt_FromSsize_t(i);
@@ -2244,7 +2244,7 @@
Py_ssize_t count = 0;
Py_ssize_t i;
- for (i = 0; i < Py_Size(self); i++) {
+ for (i = 0; i < Py_SIZE(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
count++;
@@ -2259,7 +2259,7 @@
{
Py_ssize_t i;
- for (i = 0; i < Py_Size(self); i++) {
+ for (i = 0; i < Py_SIZE(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0) {
if (list_ass_slice(self, i, i+1,
@@ -2279,7 +2279,7 @@
{
Py_ssize_t i;
- for (i = Py_Size(o); --i >= 0; )
+ for (i = Py_SIZE(o); --i >= 0; )
Py_VISIT(o->ob_item[i]);
return 0;
}
@@ -2298,7 +2298,7 @@
vl = (PyListObject *)v;
wl = (PyListObject *)w;
- if (Py_Size(vl) != Py_Size(wl) && (op == Py_EQ || op == Py_NE)) {
+ if (Py_SIZE(vl) != Py_SIZE(wl) && (op == Py_EQ || op == Py_NE)) {
/* Shortcut: if the lengths differ, the lists differ */
PyObject *res;
if (op == Py_EQ)
@@ -2310,7 +2310,7 @@
}
/* Search for the first index where items are different */
- for (i = 0; i < Py_Size(vl) && i < Py_Size(wl); i++) {
+ for (i = 0; i < Py_SIZE(vl) && i < Py_SIZE(wl); i++) {
int k = PyObject_RichCompareBool(vl->ob_item[i],
wl->ob_item[i], Py_EQ);
if (k < 0)
@@ -2319,10 +2319,10 @@
break;
}
- if (i >= Py_Size(vl) || i >= Py_Size(wl)) {
+ if (i >= Py_SIZE(vl) || i >= Py_SIZE(wl)) {
/* No more items to compare -- compare sizes */
- Py_ssize_t vs = Py_Size(vl);
- Py_ssize_t ws = Py_Size(wl);
+ Py_ssize_t vs = Py_SIZE(vl);
+ Py_ssize_t ws = Py_SIZE(wl);
int cmp;
PyObject *res;
switch (op) {
@@ -2366,8 +2366,8 @@
return -1;
/* Verify list invariants established by PyType_GenericAlloc() */
- assert(0 <= Py_Size(self));
- assert(Py_Size(self) <= self->allocated || self->allocated == -1);
+ assert(0 <= Py_SIZE(self));
+ assert(Py_SIZE(self) <= self->allocated || self->allocated == -1);
assert(self->ob_item != NULL ||
self->allocated == 0 || self->allocated == -1);
@@ -2464,7 +2464,7 @@
PyObject* it;
PyObject **src, **dest;
- if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
&start, &stop, &step, &slicelength) < 0) {
return NULL;
}
@@ -2513,7 +2513,7 @@
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx((PySliceObject*)item, Py_Size(self),
+ if (PySlice_GetIndicesEx((PySliceObject*)item, Py_SIZE(self),
&start, &stop, &step, &slicelength) < 0) {
return -1;
}
@@ -2561,8 +2561,8 @@
garbage[i] = PyList_GET_ITEM(self, cur);
- if (cur + step >= Py_Size(self)) {
- lim = Py_Size(self) - cur - 1;
+ if (cur + step >= Py_SIZE(self)) {
+ lim = Py_SIZE(self) - cur - 1;
}
memmove(self->ob_item + cur - i,
@@ -2570,15 +2570,15 @@
lim * sizeof(PyObject *));
}
cur = start + slicelength*step;
- if (cur < Py_Size(self)) {
+ if (cur < Py_SIZE(self)) {
memmove(self->ob_item + cur - slicelength,
self->ob_item + cur,
- (Py_Size(self) - cur) *
+ (Py_SIZE(self) - cur) *
sizeof(PyObject *));
}
- Py_Size(self) -= slicelength;
- list_resize(self, Py_Size(self));
+ Py_SIZE(self) -= slicelength;
+ list_resize(self, Py_SIZE(self));
for (i = 0; i < slicelength; i++) {
Py_DECREF(garbage[i]);