Lines Matching defs:self
67 _canresize(PyByteArrayObject *self)
69 if (self->ob_exports > 0) {
152 PyByteArray_Size(PyObject *self)
154 assert(self != NULL);
155 assert(PyByteArray_Check(self));
157 return PyByteArray_GET_SIZE(self);
161 PyByteArray_AsString(PyObject *self)
163 assert(self != NULL);
164 assert(PyByteArray_Check(self));
166 return PyByteArray_AS_STRING(self);
170 PyByteArray_Resize(PyObject *self, Py_ssize_t requested_size)
173 PyByteArrayObject *obj = ((PyByteArrayObject *)self);
180 assert(self != NULL);
181 assert(PyByteArray_Check(self));
185 if (requested_size == Py_SIZE(self)) {
201 Py_SET_SIZE(self, size);
202 PyByteArray_AS_STRING(self)[size] = '\0'; /* Trailing null */
228 memcpy(sval, PyByteArray_AS_STRING(self),
229 Py_MIN((size_t)requested_size, (size_t)Py_SIZE(self)));
241 Py_SET_SIZE(self, size);
288 bytearray_length(PyByteArrayObject *self)
290 return Py_SIZE(self);
294 bytearray_iconcat(PyByteArrayObject *self, PyObject *other)
301 Py_TYPE(other)->tp_name, Py_TYPE(self)->tp_name);
305 size = Py_SIZE(self);
310 if (PyByteArray_Resize((PyObject *)self, size + vo.len) < 0) {
314 memcpy(PyByteArray_AS_STRING(self) + size, vo.buf, vo.len);
316 Py_INCREF(self);
317 return (PyObject *)self;
321 bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
325 const Py_ssize_t mysize = Py_SIZE(self);
330 const char* buf = PyByteArray_AS_STRING(self);
338 bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
343 Py_INCREF(self);
344 return (PyObject*)self;
347 const Py_ssize_t mysize = Py_SIZE(self);
351 if (PyByteArray_Resize((PyObject *)self, size) < 0)
354 char* buf = PyByteArray_AS_STRING(self);
357 Py_INCREF(self);
358 return (PyObject *)self;
362 bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i)
364 if (i < 0 || i >= Py_SIZE(self)) {
368 return _PyLong_FromUnsignedChar((unsigned char)(self->ob_start[i]));
372 bytearray_subscript(PyByteArrayObject *self, PyObject *index)
381 i += PyByteArray_GET_SIZE(self);
383 if (i < 0 || i >= Py_SIZE(self)) {
387 return _PyLong_FromUnsignedChar((unsigned char)(self->ob_start[i]));
395 slicelength = PySlice_AdjustIndices(PyByteArray_GET_SIZE(self),
402 PyByteArray_AS_STRING(self) + start, slicelength);
405 char *source_buf = PyByteArray_AS_STRING(self);
430 bytearray_setslice_linear(PyByteArrayObject *self,
435 char *buf = PyByteArray_AS_STRING(self);
441 if (!_canresize(self))
446 self->ob_start -= growth;
462 Py_SIZE(self) - hi);
464 if (PyByteArray_Resize((PyObject *)self,
465 Py_SIZE(self) + growth) < 0) {
476 self->ob_start += growth;
481 Py_SET_SIZE(self, Py_SIZE(self) + growth);
484 buf = PyByteArray_AS_STRING(self);
487 if (Py_SIZE(self) > (Py_ssize_t)PY_SSIZE_T_MAX - growth) {
492 if (PyByteArray_Resize((PyObject *)self,
493 Py_SIZE(self) + growth) < 0) {
496 buf = PyByteArray_AS_STRING(self);
505 Py_SIZE(self) - lo - bytes_len);
514 bytearray_setslice(PyByteArrayObject *self, Py_ssize_t lo, Py_ssize_t hi,
523 if (values == (PyObject *)self) {
530 err = bytearray_setslice(self, lo, hi, values);
554 if (hi > Py_SIZE(self))
555 hi = Py_SIZE(self);
557 res = bytearray_setslice_linear(self, lo, hi, bytes, needed);
564 bytearray_setitem(PyByteArrayObject *self, Py_ssize_t i, PyObject *value)
575 i += Py_SIZE(self);
578 if (i < 0 || i >= Py_SIZE(self)) {
584 return bytearray_setslice(self, i, i+1, NULL);
588 PyByteArray_AS_STRING(self)[i] = ival;
593 bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *values)
597 buf = PyByteArray_AS_STRING(self);
615 i += PyByteArray_GET_SIZE(self);
618 if (i < 0 || i >= Py_SIZE(self)) {
640 slicelen = PySlice_AdjustIndices(PyByteArray_GET_SIZE(self), &start,
654 else if (values == (PyObject *)self || !PyByteArray_Check(values)) {
666 err = bytearray_ass_subscript(self, index, values);
680 return bytearray_setslice_linear(self, start, stop, bytes, needed);
688 if (!_canresize(self))
704 if (cur + step >= (size_t)PyByteArray_GET_SIZE(self))
705 lim = PyByteArray_GET_SIZE(self) - cur - 1;
712 if (cur < (size_t)PyByteArray_GET_SIZE(self)) {
715 PyByteArray_GET_SIZE(self) - cur);
717 if (PyByteArray_Resize((PyObject *)self,
718 PyByteArray_GET_SIZE(self) - slicelen) < 0)
752 bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
760 if (Py_SIZE(self) != 0) {
762 if (PyByteArray_Resize((PyObject *)self, 0) < 0)
790 new = bytearray_iconcat(self, encoded);
821 if (PyByteArray_Resize((PyObject *)self, count))
823 memset(PyByteArray_AS_STRING(self), 0, count);
836 if (PyByteArray_Resize((PyObject *)self, size) < 0) goto fail;
837 if (PyBuffer_ToContiguous(PyByteArray_AS_STRING(self),
849 if (PyByteArray_Resize((PyObject *)self, size) < 0) {
853 char *s = PyByteArray_AS_STRING(self);
858 if (Py_SIZE(self) != 0) {
859 if (PyByteArray_Resize((PyObject *)self, 0) < 0) {
909 if (Py_SIZE(self) + 1 < self->ob_alloc) {
910 Py_SET_SIZE(self, Py_SIZE(self) + 1);
911 PyByteArray_AS_STRING(self)[Py_SIZE(self)] = '\0';
913 else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
915 PyByteArray_AS_STRING(self)[Py_SIZE(self)-1] = value;
931 bytearray_repr(PyByteArrayObject *self)
933 const char *className = _PyType_Name(Py_TYPE(self));
936 Py_ssize_t length = Py_SIZE(self);
964 start = PyByteArray_AS_STRING(self);
981 bytes = PyByteArray_AS_STRING(self);
1030 bytearray_richcompare(PyObject *self, PyObject *other, int op)
1036 if (!PyObject_CheckBuffer(self) || !PyObject_CheckBuffer(other)) {
1037 if (PyUnicode_Check(self) || PyUnicode_Check(other)) {
1048 if (PyObject_GetBuffer(self, &self_bytes, PyBUF_SIMPLE) != 0) {
1085 bytearray_dealloc(PyByteArrayObject *self)
1087 if (self->ob_exports > 0) {
1092 if (self->ob_bytes != 0) {
1093 PyObject_Free(self->ob_bytes);
1095 Py_TYPE(self)->tp_free((PyObject *)self);
1126 bytearray_find(PyByteArrayObject *self, PyObject *args)
1128 return _Py_bytes_find(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1132 bytearray_count(PyByteArrayObject *self, PyObject *args)
1134 return _Py_bytes_count(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1144 bytearray_clear_impl(PyByteArrayObject *self)
1147 if (PyByteArray_Resize((PyObject *)self, 0) < 0)
1159 bytearray_copy_impl(PyByteArrayObject *self)
1162 return PyByteArray_FromStringAndSize(PyByteArray_AS_STRING((PyObject *)self),
1163 PyByteArray_GET_SIZE(self));
1167 bytearray_index(PyByteArrayObject *self, PyObject *args)
1169 return _Py_bytes_index(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1173 bytearray_rfind(PyByteArrayObject *self, PyObject *args)
1175 return _Py_bytes_rfind(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1179 bytearray_rindex(PyByteArrayObject *self, PyObject *args)
1181 return _Py_bytes_rindex(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1185 bytearray_contains(PyObject *self, PyObject *arg)
1187 return _Py_bytes_contains(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), arg);
1191 bytearray_startswith(PyByteArrayObject *self, PyObject *args)
1193 return _Py_bytes_startswith(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1197 bytearray_endswith(PyByteArrayObject *self, PyObject *args)
1199 return _Py_bytes_endswith(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1216 bytearray_removeprefix_impl(PyByteArrayObject *self, Py_buffer *prefix)
1219 const char *self_start = PyByteArray_AS_STRING(self);
1220 Py_ssize_t self_len = PyByteArray_GET_SIZE(self);
1248 bytearray_removesuffix_impl(PyByteArrayObject *self, Py_buffer *suffix)
1251 const char *self_start = PyByteArray_AS_STRING(self);
1252 Py_ssize_t self_len = PyByteArray_GET_SIZE(self);
1283 bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
1290 PyObject *input_obj = (PyObject*)self;
1414 bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
1418 return stringlib_replace((PyObject *)self,
1438 bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
1442 Py_ssize_t len = PyByteArray_GET_SIZE(self), n;
1443 const char *s = PyByteArray_AS_STRING(self), *sub;
1451 return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit);
1459 (PyObject*) self, s, len, sub, n, maxsplit
1482 bytearray_partition(PyByteArrayObject *self, PyObject *sep)
1492 (PyObject*) self,
1493 PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self),
1520 bytearray_rpartition(PyByteArrayObject *self, PyObject *sep)
1530 (PyObject*) self,
1531 PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self),
1549 bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
1553 Py_ssize_t len = PyByteArray_GET_SIZE(self), n;
1554 const char *s = PyByteArray_AS_STRING(self), *sub;
1562 return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit);
1570 (PyObject*) self, s, len, sub, n, maxsplit
1583 bytearray_reverse_impl(PyByteArrayObject *self)
1587 Py_ssize_t i, j, n = Py_SIZE(self);
1590 head = PyByteArray_AS_STRING(self);
1623 bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item)
1626 Py_ssize_t n = Py_SIZE(self);
1634 if (PyByteArray_Resize((PyObject *)self, n + 1) < 0)
1636 buf = PyByteArray_AS_STRING(self);
1662 bytearray_append_impl(PyByteArrayObject *self, int item)
1665 Py_ssize_t n = Py_SIZE(self);
1672 if (PyByteArray_Resize((PyObject *)self, n + 1) < 0)
1675 PyByteArray_AS_STRING(self)[n] = item;
1691 bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
1701 if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), iterable_of_ints) == -1)
1776 if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) {
1800 bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index)
1804 Py_ssize_t n = Py_SIZE(self);
1813 index += Py_SIZE(self);
1814 if (index < 0 || index >= Py_SIZE(self)) {
1818 if (!_canresize(self))
1821 buf = PyByteArray_AS_STRING(self);
1824 if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
1841 bytearray_remove_impl(PyByteArrayObject *self, int value)
1844 Py_ssize_t where, n = Py_SIZE(self);
1845 char *buf = PyByteArray_AS_STRING(self);
1852 if (!_canresize(self))
1856 if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
1867 bytearray_strip_impl_helper(PyByteArrayObject* self, PyObject* bytes, int striptype)
1884 myptr = PyByteArray_AS_STRING(self);
1885 mysize = Py_SIZE(self);
1916 bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes)
1919 return bytearray_strip_impl_helper(self, bytes, BOTHSTRIP);
1934 bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes)
1937 return bytearray_strip_impl_helper(self, bytes, LEFTSTRIP);
1952 bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes)
1955 return bytearray_strip_impl_helper(self, bytes, RIGHTSTRIP);
1974 bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
1980 return PyUnicode_FromEncodedObject((PyObject*)self, encoding, errors);
1989 bytearray_alloc(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
1991 return PyLong_FromSsize_t(self->ob_alloc);
2008 bytearray_join(PyByteArrayObject *self, PyObject *iterable_of_bytes)
2011 return stringlib_bytes_join((PyObject*)self, iterable_of_bytes);
2026 bytearray_splitlines_impl(PyByteArrayObject *self, int keepends)
2030 (PyObject*) self, PyByteArray_AS_STRING(self),
2031 PyByteArray_GET_SIZE(self), keepends
2083 bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep)
2086 char* argbuf = PyByteArray_AS_STRING(self);
2087 Py_ssize_t arglen = PyByteArray_GET_SIZE(self);
2092 _common_reduce(PyByteArrayObject *self, int proto)
2097 state = _PyObject_GetState((PyObject *)self);
2102 if (!Py_SIZE(self)) {
2103 return Py_BuildValue("(O()N)", Py_TYPE(self), state);
2105 buf = PyByteArray_AS_STRING(self);
2108 PyObject *latin1 = PyUnicode_DecodeLatin1(buf, Py_SIZE(self), NULL);
2109 return Py_BuildValue("(O(Ns)N)", Py_TYPE(self), latin1, "latin-1", state);
2113 return Py_BuildValue("(O(y#)N)", Py_TYPE(self), buf, Py_SIZE(self), state);
2124 bytearray_reduce_impl(PyByteArrayObject *self)
2127 return _common_reduce(self, 2);
2140 bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto)
2143 return _common_reduce(self, proto);
2153 bytearray_sizeof_impl(PyByteArrayObject *self)
2158 res = _PyObject_SIZE(Py_TYPE(self)) + self->ob_alloc * sizeof(char);