Lines Matching refs:self
35 * Failure is impossible if newsize <= self.allocated on entry, although
40 * Note that self->ob_item may change, and even if newsize is less
44 list_resize(PyListObject *self, Py_ssize_t newsize)
48 Py_ssize_t allocated = self->allocated;
55 assert(self->ob_item != NULL || newsize == 0);
56 Py_SET_SIZE(self, newsize);
74 if (newsize - Py_SIZE(self) > (Py_ssize_t)(new_allocated - newsize))
81 items = (PyObject **)PyMem_Realloc(self->ob_item, num_allocated_bytes);
91 self->ob_item = items;
92 Py_SET_SIZE(self, newsize);
93 self->allocated = new_allocated;
98 list_preallocate_exact(PyListObject *self, Py_ssize_t size)
100 assert(self->ob_item == NULL);
114 self->ob_item = items;
115 self->allocated = size;
279 ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
281 Py_ssize_t i, n = Py_SIZE(self);
289 if (list_resize(self, n+1) < 0)
299 items = self->ob_item;
319 _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem)
321 Py_ssize_t len = PyList_GET_SIZE(self);
322 assert(self->allocated == -1 || self->allocated == len);
323 if (list_resize(self, len + 1) < 0) {
327 PyList_SET_ITEM(self, len, newitem);
750 list_inplace_repeat(PyListObject *self, Py_ssize_t n)
756 size = PyList_GET_SIZE(self);
758 Py_INCREF(self);
759 return (PyObject *)self;
763 (void)_list_clear(self);
764 Py_INCREF(self);
765 return (PyObject *)self;
772 if (list_resize(self, size*n) < 0)
776 items = self->ob_item;
784 Py_INCREF(self);
785 return (PyObject *)self;
814 list_insert_impl(PyListObject *self, Py_ssize_t index, PyObject *object)
817 if (ins1(self, index, object) == 0)
829 list_clear_impl(PyListObject *self)
832 _list_clear(self);
843 list_copy_impl(PyListObject *self)
846 return list_slice(self, 0, Py_SIZE(self));
859 list_append(PyListObject *self, PyObject *object)
862 if (_PyList_AppendTakeRef(self, Py_NewRef(object)) < 0) {
878 list_extend(PyListObject *self, PyObject *iterable)
882 Py_ssize_t m; /* size of self */
889 2) extending self to self requires making a copy first
892 (PyObject *)self == iterable) {
903 m = Py_SIZE(self);
907 if (self->ob_item == NULL) {
908 if (list_preallocate_exact(self, n) < 0) {
911 Py_SET_SIZE(self, n);
913 else if (list_resize(self, m + n) < 0) {
917 /* note that we may still have self == iterable here for the
919 * in that case too. Just make sure to resize self
922 /* populate the end of self with iterable's items */
924 dest = self->ob_item + m;
945 m = Py_SIZE(self);
952 else if (self->ob_item == NULL) {
953 if (n && list_preallocate_exact(self, n) < 0)
958 if (list_resize(self, m + n) < 0)
961 Py_SET_SIZE(self, m);
976 if (Py_SIZE(self) < self->allocated) {
978 PyList_SET_ITEM(self, Py_SIZE(self), item);
979 Py_SET_SIZE(self, Py_SIZE(self) + 1);
982 if (_PyList_AppendTakeRef(self, item) < 0)
988 if (Py_SIZE(self) < self->allocated) {
989 if (list_resize(self, Py_SIZE(self)) < 0)
1002 _PyList_Extend(PyListObject *self, PyObject *iterable)
1004 return list_extend(self, iterable);
1008 list_inplace_concat(PyListObject *self, PyObject *other)
1012 result = list_extend(self, other);
1016 Py_INCREF(self);
1017 return (PyObject *)self;
1032 list_pop_impl(PyListObject *self, Py_ssize_t index)
1038 if (Py_SIZE(self) == 0) {
1044 index += Py_SIZE(self);
1045 if (!valid_index(index, Py_SIZE(self))) {
1049 v = self->ob_item[index];
1050 if (index == Py_SIZE(self) - 1) {
1051 status = list_resize(self, Py_SIZE(self) - 1);
1058 status = list_ass_slice(self, index, index+1, (PyObject *)NULL);
2268 list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
2282 assert(self != NULL);
2283 assert(PyList_Check(self));
2292 saved_ob_size = Py_SIZE(self);
2293 saved_ob_item = self->ob_item;
2294 saved_allocated = self->allocated;
2295 Py_SET_SIZE(self, 0);
2296 self->ob_item = NULL;
2297 self->allocated = -1; /* any operation will reset it to >= 0 */
2499 if (self->allocated != -1 && result != NULL) {
2513 final_ob_item = self->ob_item;
2514 i = Py_SIZE(self);
2515 Py_SET_SIZE(self, saved_ob_size);
2516 self->ob_item = saved_ob_item;
2517 self->allocated = saved_allocated;
2553 list_reverse_impl(PyListObject *self)
2556 if (Py_SIZE(self) > 1)
2557 reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
2564 PyListObject *self = (PyListObject *)v;
2570 if (Py_SIZE(self) > 1)
2571 reverse_slice(self->ob_item, self->ob_item + Py_SIZE(self));
2599 list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
2606 start += Py_SIZE(self);
2611 stop += Py_SIZE(self);
2615 for (i = start; i < stop && i < Py_SIZE(self); i++) {
2616 PyObject *obj = self->ob_item[i];
2639 list_count(PyListObject *self, PyObject *value)
2645 for (i = 0; i < Py_SIZE(self); i++) {
2646 PyObject *obj = self->ob_item[i];
2674 list_remove(PyListObject *self, PyObject *value)
2679 for (i = 0; i < Py_SIZE(self); i++) {
2680 PyObject *obj = self->ob_item[i];
2685 if (list_ass_slice(self, i, i+1,
2776 list___init___impl(PyListObject *self, PyObject *iterable)
2780 assert(0 <= Py_SIZE(self));
2781 assert(Py_SIZE(self) <= self->allocated || self->allocated == -1);
2782 assert(self->ob_item != NULL ||
2783 self->allocated == 0 || self->allocated == -1);
2786 if (self->ob_item != NULL) {
2787 (void)_list_clear(self);
2790 PyObject *rv = list_extend(self, iterable);
2831 list___sizeof___impl(PyListObject *self)
2836 res = _PyObject_SIZE(Py_TYPE(self)) + self->allocated * sizeof(void*);
2876 list_subscript(PyListObject* self, PyObject* item)
2884 i += PyList_GET_SIZE(self);
2885 return list_item(self, i);
2897 slicelength = PySlice_AdjustIndices(Py_SIZE(self), &start, &stop,
2904 return list_slice(self, start, stop);
2910 src = self->ob_item;
2931 list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
2938 i += PyList_GET_SIZE(self);
2939 return list_ass_item(self, i, value);
2947 slicelength = PySlice_AdjustIndices(Py_SIZE(self), &start, &stop,
2951 return list_ass_slice(self, start, stop, value);
2993 garbage[i] = PyList_GET_ITEM(self, cur);
2995 if (cur + step >= (size_t)Py_SIZE(self)) {
2996 lim = Py_SIZE(self) - cur - 1;
2999 memmove(self->ob_item + cur - i,
3000 self->ob_item + cur + 1,
3004 if (cur < (size_t)Py_SIZE(self)) {
3005 memmove(self->ob_item + cur - slicelength,
3006 self->ob_item + cur,
3007 (Py_SIZE(self) - cur) *
3011 Py_SET_SIZE(self, Py_SIZE(self) - slicelength);
3012 res = list_resize(self, Py_SIZE(self));
3029 if (self == (PyListObject*)value) {
3065 selfitems = self->ob_item;
3359 list___reversed___impl(PyListObject *self)
3367 assert(PyList_Check(self));
3368 it->it_index = PyList_GET_SIZE(self) - 1;
3369 Py_INCREF(self);
3370 it->it_seq = self;