@@ -53,8 +53,7 @@ static inline PyObject* bytes_get_empty(void)
53
53
// Return a strong reference to the empty bytes string singleton.
54
54
static inline PyObject * bytes_new_empty (void )
55
55
{
56
- Py_INCREF (EMPTY );
57
- return (PyObject * )EMPTY ;
56
+ return Py_NewRef (EMPTY );
58
57
}
59
58
60
59
@@ -126,8 +125,7 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
126
125
}
127
126
if (size == 1 && str != NULL ) {
128
127
op = CHARACTER (* str & 255 );
129
- Py_INCREF (op );
130
- return (PyObject * )op ;
128
+ return Py_NewRef (op );
131
129
}
132
130
if (size == 0 ) {
133
131
return bytes_new_empty ();
@@ -162,8 +160,7 @@ PyBytes_FromString(const char *str)
162
160
}
163
161
else if (size == 1 ) {
164
162
op = CHARACTER (* str & 255 );
165
- Py_INCREF (op );
166
- return (PyObject * )op ;
163
+ return Py_NewRef (op );
167
164
}
168
165
169
166
/* Inline PyObject_NewVar */
@@ -527,14 +524,12 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
527
524
if (PyBytes_Check (v )) {
528
525
* pbuf = PyBytes_AS_STRING (v );
529
526
* plen = PyBytes_GET_SIZE (v );
530
- Py_INCREF (v );
531
- return v ;
527
+ return Py_NewRef (v );
532
528
}
533
529
if (PyByteArray_Check (v )) {
534
530
* pbuf = PyByteArray_AS_STRING (v );
535
531
* plen = PyByteArray_GET_SIZE (v );
536
- Py_INCREF (v );
537
- return v ;
532
+ return Py_NewRef (v );
538
533
}
539
534
/* does it support __bytes__? */
540
535
func = _PyObject_LookupSpecial (v , & _Py_ID (__bytes__ ));
@@ -1411,13 +1406,11 @@ bytes_concat(PyObject *a, PyObject *b)
1411
1406
1412
1407
/* Optimize end cases */
1413
1408
if (va .len == 0 && PyBytes_CheckExact (b )) {
1414
- result = b ;
1415
- Py_INCREF (result );
1409
+ result = Py_NewRef (b );
1416
1410
goto done ;
1417
1411
}
1418
1412
if (vb .len == 0 && PyBytes_CheckExact (a )) {
1419
- result = a ;
1420
- Py_INCREF (result );
1413
+ result = Py_NewRef (a );
1421
1414
goto done ;
1422
1415
}
1423
1416
@@ -1458,8 +1451,7 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
1458
1451
}
1459
1452
size = Py_SIZE (a ) * n ;
1460
1453
if (size == Py_SIZE (a ) && PyBytes_CheckExact (a )) {
1461
- Py_INCREF (a );
1462
- return (PyObject * )a ;
1454
+ return Py_NewRef (a );
1463
1455
}
1464
1456
nbytes = (size_t )size ;
1465
1457
if (nbytes + PyBytesObject_SIZE <= nbytes ) {
@@ -1625,8 +1617,7 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
1625
1617
else if (start == 0 && step == 1 &&
1626
1618
slicelength == PyBytes_GET_SIZE (self ) &&
1627
1619
PyBytes_CheckExact (self )) {
1628
- Py_INCREF (self );
1629
- return (PyObject * )self ;
1620
+ return Py_NewRef (self );
1630
1621
}
1631
1622
else if (step == 1 ) {
1632
1623
return PyBytes_FromStringAndSize (
@@ -1696,8 +1687,7 @@ bytes___bytes___impl(PyBytesObject *self)
1696
1687
/*[clinic end generated code: output=63a306a9bc0caac5 input=34ec5ddba98bd6bb]*/
1697
1688
{
1698
1689
if (PyBytes_CheckExact (self )) {
1699
- Py_INCREF (self );
1700
- return (PyObject * )self ;
1690
+ return Py_NewRef (self );
1701
1691
}
1702
1692
else {
1703
1693
return PyBytes_FromStringAndSize (self -> ob_sval , Py_SIZE (self ));
@@ -1922,8 +1912,7 @@ do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
1922
1912
PyBuffer_Release (& vsep );
1923
1913
1924
1914
if (i == 0 && j == len && PyBytes_CheckExact (self )) {
1925
- Py_INCREF (self );
1926
- return (PyObject * )self ;
1915
+ return Py_NewRef (self );
1927
1916
}
1928
1917
else
1929
1918
return PyBytes_FromStringAndSize (s + i , j - i );
@@ -1952,8 +1941,7 @@ do_strip(PyBytesObject *self, int striptype)
1952
1941
}
1953
1942
1954
1943
if (i == 0 && j == len && PyBytes_CheckExact (self )) {
1955
- Py_INCREF (self );
1956
- return (PyObject * )self ;
1944
+ return Py_NewRef (self );
1957
1945
}
1958
1946
else
1959
1947
return PyBytes_FromStringAndSize (s + i , j - i );
@@ -2152,8 +2140,7 @@ bytes_translate_impl(PyBytesObject *self, PyObject *table,
2152
2140
}
2153
2141
if (!changed && PyBytes_CheckExact (input_obj )) {
2154
2142
Py_DECREF (result );
2155
- Py_INCREF (input_obj );
2156
- return input_obj ;
2143
+ return Py_NewRef (input_obj );
2157
2144
}
2158
2145
/* Fix the size of the resulting byte string */
2159
2146
if (inlen > 0 )
@@ -2245,8 +2232,7 @@ bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix)
2245
2232
}
2246
2233
2247
2234
if (PyBytes_CheckExact (self )) {
2248
- Py_INCREF (self );
2249
- return (PyObject * )self ;
2235
+ return Py_NewRef (self );
2250
2236
}
2251
2237
2252
2238
return PyBytes_FromStringAndSize (self_start , self_len );
@@ -2284,8 +2270,7 @@ bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix)
2284
2270
}
2285
2271
2286
2272
if (PyBytes_CheckExact (self )) {
2287
- Py_INCREF (self );
2288
- return (PyObject * )self ;
2273
+ return Py_NewRef (self );
2289
2274
}
2290
2275
2291
2276
return PyBytes_FromStringAndSize (self_start , self_len );
@@ -2844,8 +2829,7 @@ PyBytes_FromObject(PyObject *x)
2844
2829
}
2845
2830
2846
2831
if (PyBytes_CheckExact (x )) {
2847
- Py_INCREF (x );
2848
- return x ;
2832
+ return Py_NewRef (x );
2849
2833
}
2850
2834
2851
2835
/* Use the modern buffer interface */
@@ -3269,8 +3253,7 @@ bytes_iter(PyObject *seq)
3269
3253
if (it == NULL )
3270
3254
return NULL ;
3271
3255
it -> it_index = 0 ;
3272
- Py_INCREF (seq );
3273
- it -> it_seq = (PyBytesObject * )seq ;
3256
+ it -> it_seq = (PyBytesObject * )Py_NewRef (seq );
3274
3257
_PyObject_GC_TRACK (it );
3275
3258
return (PyObject * )it ;
3276
3259
}
0 commit comments