summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 8066088..91c89bb 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -53,8 +53,7 @@ static inline PyObject* bytes_get_empty(void)
// Return a strong reference to the empty bytes string singleton.
static inline PyObject* bytes_new_empty(void)
{
- Py_INCREF(EMPTY);
- return (PyObject *)EMPTY;
+ return Py_NewRef(EMPTY);
}
@@ -126,8 +125,7 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
}
if (size == 1 && str != NULL) {
op = CHARACTER(*str & 255);
- Py_INCREF(op);
- return (PyObject *)op;
+ return Py_NewRef(op);
}
if (size == 0) {
return bytes_new_empty();
@@ -162,8 +160,7 @@ PyBytes_FromString(const char *str)
}
else if (size == 1) {
op = CHARACTER(*str & 255);
- Py_INCREF(op);
- return (PyObject *)op;
+ return Py_NewRef(op);
}
/* Inline PyObject_NewVar */
@@ -527,14 +524,12 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
if (PyBytes_Check(v)) {
*pbuf = PyBytes_AS_STRING(v);
*plen = PyBytes_GET_SIZE(v);
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
if (PyByteArray_Check(v)) {
*pbuf = PyByteArray_AS_STRING(v);
*plen = PyByteArray_GET_SIZE(v);
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
/* does it support __bytes__? */
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
@@ -1411,13 +1406,11 @@ bytes_concat(PyObject *a, PyObject *b)
/* Optimize end cases */
if (va.len == 0 && PyBytes_CheckExact(b)) {
- result = b;
- Py_INCREF(result);
+ result = Py_NewRef(b);
goto done;
}
if (vb.len == 0 && PyBytes_CheckExact(a)) {
- result = a;
- Py_INCREF(result);
+ result = Py_NewRef(a);
goto done;
}
@@ -1458,8 +1451,7 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
}
size = Py_SIZE(a) * n;
if (size == Py_SIZE(a) && PyBytes_CheckExact(a)) {
- Py_INCREF(a);
- return (PyObject *)a;
+ return Py_NewRef(a);
}
nbytes = (size_t)size;
if (nbytes + PyBytesObject_SIZE <= nbytes) {
@@ -1625,8 +1617,7 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
else if (start == 0 && step == 1 &&
slicelength == PyBytes_GET_SIZE(self) &&
PyBytes_CheckExact(self)) {
- Py_INCREF(self);
- return (PyObject *)self;
+ return Py_NewRef(self);
}
else if (step == 1) {
return PyBytes_FromStringAndSize(
@@ -1696,8 +1687,7 @@ bytes___bytes___impl(PyBytesObject *self)
/*[clinic end generated code: output=63a306a9bc0caac5 input=34ec5ddba98bd6bb]*/
{
if (PyBytes_CheckExact(self)) {
- Py_INCREF(self);
- return (PyObject *)self;
+ return Py_NewRef(self);
}
else {
return PyBytes_FromStringAndSize(self->ob_sval, Py_SIZE(self));
@@ -1922,8 +1912,7 @@ do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
PyBuffer_Release(&vsep);
if (i == 0 && j == len && PyBytes_CheckExact(self)) {
- Py_INCREF(self);
- return (PyObject*)self;
+ return Py_NewRef(self);
}
else
return PyBytes_FromStringAndSize(s+i, j-i);
@@ -1952,8 +1941,7 @@ do_strip(PyBytesObject *self, int striptype)
}
if (i == 0 && j == len && PyBytes_CheckExact(self)) {
- Py_INCREF(self);
- return (PyObject*)self;
+ return Py_NewRef(self);
}
else
return PyBytes_FromStringAndSize(s+i, j-i);
@@ -2152,8 +2140,7 @@ bytes_translate_impl(PyBytesObject *self, PyObject *table,
}
if (!changed && PyBytes_CheckExact(input_obj)) {
Py_DECREF(result);
- Py_INCREF(input_obj);
- return input_obj;
+ return Py_NewRef(input_obj);
}
/* Fix the size of the resulting byte string */
if (inlen > 0)
@@ -2245,8 +2232,7 @@ bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix)
}
if (PyBytes_CheckExact(self)) {
- Py_INCREF(self);
- return (PyObject *)self;
+ return Py_NewRef(self);
}
return PyBytes_FromStringAndSize(self_start, self_len);
@@ -2284,8 +2270,7 @@ bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix)
}
if (PyBytes_CheckExact(self)) {
- Py_INCREF(self);
- return (PyObject *)self;
+ return Py_NewRef(self);
}
return PyBytes_FromStringAndSize(self_start, self_len);
@@ -2844,8 +2829,7 @@ PyBytes_FromObject(PyObject *x)
}
if (PyBytes_CheckExact(x)) {
- Py_INCREF(x);
- return x;
+ return Py_NewRef(x);
}
/* Use the modern buffer interface */
@@ -3269,8 +3253,7 @@ bytes_iter(PyObject *seq)
if (it == NULL)
return NULL;
it->it_index = 0;
- Py_INCREF(seq);
- it->it_seq = (PyBytesObject *)seq;
+ it->it_seq = (PyBytesObject *)Py_NewRef(seq);
_PyObject_GC_TRACK(it);
return (PyObject *)it;
}