diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-19 02:45:37 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-19 02:45:37 (GMT) |
commit | 90aa7646affbaee9628ca6ea6a702aec17b3b550 (patch) | |
tree | e820962e9658a92c7147b686f8aa88c7658c5949 /Objects/listobject.c | |
parent | 99170a5dbf4cfee78b578672b6821e855f92594b (diff) | |
download | cpython-90aa7646affbaee9628ca6ea6a702aec17b3b550.zip cpython-90aa7646affbaee9628ca6ea6a702aec17b3b550.tar.gz cpython-90aa7646affbaee9628ca6ea6a702aec17b3b550.tar.bz2 |
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 9fbc463..b62bba5 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -34,7 +34,7 @@ list_resize(PyListObject *self, Py_ssize_t newsize) */ 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 @@ list_resize(PyListObject *self, Py_ssize_t newsize) return -1; } self->ob_item = items; - Py_Size(self) = newsize; + Py_SIZE(self) = newsize; self->allocated = new_allocated; return 0; } @@ -114,7 +114,7 @@ PyList_New(Py_ssize_t size) } 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 @@ PyList_Size(PyObject *op) return -1; } else - return Py_Size(op); + return Py_SIZE(op); } static PyObject *indexerr = NULL; @@ -140,7 +140,7 @@ PyList_GetItem(PyObject *op, Py_ssize_t i) PyErr_BadInternalCall(); return NULL; } - if (i < 0 || i >= Py_Size(op)) { + if (i < 0 || i >= Py_SIZE(op)) { if (indexerr == NULL) indexerr = PyUnicode_FromString( "list index out of range"); @@ -161,7 +161,7 @@ PyList_SetItem(register PyObject *op, register Py_ssize_t i, 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 @@ PyList_SetItem(register PyObject *op, register Py_ssize_t i, 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 @@ list_dealloc(PyListObject *op) 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 @@ list_dealloc(PyListObject *op) 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) } @@ -284,7 +284,7 @@ list_repr(PyListObject *v) return i > 0 ? PyUnicode_FromString("[...]") : NULL; } - if (Py_Size(v) == 0) { + if (Py_SIZE(v) == 0) { result = PyUnicode_FromString("[]"); goto Done; } @@ -295,7 +295,7 @@ list_repr(PyListObject *v) /* 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; @@ -345,7 +345,7 @@ Done: static Py_ssize_t list_length(PyListObject *a) { - return Py_Size(a); + return Py_SIZE(a); } static int @@ -354,7 +354,7 @@ list_contains(PyListObject *a, PyObject *el) 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; @@ -363,7 +363,7 @@ list_contains(PyListObject *a, PyObject *el) 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 = PyUnicode_FromString( "list index out of range"); @@ -382,12 +382,12 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh) 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) @@ -427,7 +427,7 @@ list_concat(PyListObject *a, PyObject *bb) 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); @@ -436,14 +436,14 @@ list_concat(PyListObject *a, PyObject *bb) } 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; @@ -462,8 +462,8 @@ list_repeat(PyListObject *a, Py_ssize_t n) 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); @@ -472,7 +472,7 @@ list_repeat(PyListObject *a, Py_ssize_t n) 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; @@ -483,7 +483,7 @@ list_repeat(PyListObject *a, Py_ssize_t n) 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++; @@ -500,8 +500,8 @@ list_clear(PyListObject *a) 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) { @@ -547,7 +547,7 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) 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); @@ -562,18 +562,18 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) } 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); } @@ -591,12 +591,12 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) 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; @@ -671,7 +671,7 @@ static int 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; @@ -730,7 +730,7 @@ listextend(PyListObject *self, PyObject *b) 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; @@ -759,14 +759,14 @@ listextend(PyListObject *self, PyObject *b) /* 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 @@ -785,10 +785,10 @@ listextend(PyListObject *self, PyObject *b) } 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); @@ -799,8 +799,8 @@ listextend(PyListObject *self, PyObject *b) } /* 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; @@ -839,20 +839,20 @@ listpop(PyListObject *self, PyObject *args) 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 */ } @@ -2009,10 +2009,10 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds) * 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 */ @@ -2118,8 +2118,8 @@ fail: 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) { @@ -2154,8 +2154,8 @@ PyList_Sort(PyObject *v) 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; } @@ -2168,8 +2168,8 @@ PyList_Reverse(PyObject *v) 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; } @@ -2183,7 +2183,7 @@ PyList_AsTuple(PyObject *v) PyErr_BadInternalCall(); return NULL; } - n = Py_Size(v); + n = Py_SIZE(v); w = PyTuple_New(n); if (w == NULL) return NULL; @@ -2201,7 +2201,7 @@ PyList_AsTuple(PyObject *v) 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, @@ -2209,16 +2209,16 @@ listindex(PyListObject *self, PyObject *args) _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 PyLong_FromSsize_t(i); @@ -2235,7 +2235,7 @@ listcount(PyListObject *self, PyObject *v) 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++; @@ -2250,7 +2250,7 @@ listremove(PyListObject *self, PyObject *v) { 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, @@ -2270,7 +2270,7 @@ list_traverse(PyListObject *o, visitproc visit, void *arg) { 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; } @@ -2289,7 +2289,7 @@ list_richcompare(PyObject *v, PyObject *w, int op) 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) @@ -2301,7 +2301,7 @@ list_richcompare(PyObject *v, PyObject *w, int op) } /* 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) @@ -2310,10 +2310,10 @@ list_richcompare(PyObject *v, PyObject *w, int op) 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) { @@ -2357,8 +2357,8 @@ list_init(PyListObject *self, PyObject *args, PyObject *kw) 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); @@ -2454,7 +2454,7 @@ list_subscript(PyListObject* self, PyObject* item) 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; } @@ -2503,7 +2503,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) 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; } @@ -2551,8 +2551,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) 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, @@ -2560,15 +2560,15 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) 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]); |