@@ -1405,8 +1405,9 @@ bytes_str(PyObject *op)
1405
1405
}
1406
1406
1407
1407
static Py_ssize_t
1408
- bytes_length (PyBytesObject * a )
1408
+ bytes_length (PyObject * self )
1409
1409
{
1410
+ PyBytesObject * a = _PyBytes_CAST (self );
1410
1411
return Py_SIZE (a );
1411
1412
}
1412
1413
@@ -1456,11 +1457,9 @@ bytes_concat(PyObject *a, PyObject *b)
1456
1457
}
1457
1458
1458
1459
static PyObject *
1459
- bytes_repeat (PyBytesObject * a , Py_ssize_t n )
1460
+ bytes_repeat (PyObject * self , Py_ssize_t n )
1460
1461
{
1461
- Py_ssize_t size ;
1462
- PyBytesObject * op ;
1463
- size_t nbytes ;
1462
+ PyBytesObject * a = _PyBytes_CAST (self );
1464
1463
if (n < 0 )
1465
1464
n = 0 ;
1466
1465
/* watch out for overflows: the size can overflow int,
@@ -1471,17 +1470,17 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
1471
1470
"repeated bytes are too long" );
1472
1471
return NULL ;
1473
1472
}
1474
- size = Py_SIZE (a ) * n ;
1473
+ Py_ssize_t size = Py_SIZE (a ) * n ;
1475
1474
if (size == Py_SIZE (a ) && PyBytes_CheckExact (a )) {
1476
1475
return Py_NewRef (a );
1477
1476
}
1478
- nbytes = (size_t )size ;
1477
+ size_t nbytes = (size_t )size ;
1479
1478
if (nbytes + PyBytesObject_SIZE <= nbytes ) {
1480
1479
PyErr_SetString (PyExc_OverflowError ,
1481
1480
"repeated bytes are too long" );
1482
1481
return NULL ;
1483
1482
}
1484
- op = ( PyBytesObject * ) PyObject_Malloc (PyBytesObject_SIZE + nbytes );
1483
+ PyBytesObject * op = PyObject_Malloc (PyBytesObject_SIZE + nbytes );
1485
1484
if (op == NULL ) {
1486
1485
return PyErr_NoMemory ();
1487
1486
}
@@ -1504,8 +1503,9 @@ bytes_contains(PyObject *self, PyObject *arg)
1504
1503
}
1505
1504
1506
1505
static PyObject *
1507
- bytes_item (PyBytesObject * a , Py_ssize_t i )
1506
+ bytes_item (PyObject * self , Py_ssize_t i )
1508
1507
{
1508
+ PyBytesObject * a = _PyBytes_CAST (self );
1509
1509
if (i < 0 || i >= Py_SIZE (a )) {
1510
1510
PyErr_SetString (PyExc_IndexError , "index out of range" );
1511
1511
return NULL ;
@@ -1531,29 +1531,28 @@ bytes_compare_eq(PyBytesObject *a, PyBytesObject *b)
1531
1531
}
1532
1532
1533
1533
static PyObject *
1534
- bytes_richcompare (PyBytesObject * a , PyBytesObject * b , int op )
1534
+ bytes_richcompare (PyObject * aa , PyObject * bb , int op )
1535
1535
{
1536
- int c ;
1537
- Py_ssize_t len_a , len_b ;
1538
- Py_ssize_t min_len ;
1539
-
1540
1536
/* Make sure both arguments are strings. */
1541
- if (!(PyBytes_Check (a ) && PyBytes_Check (b ))) {
1537
+ if (!(PyBytes_Check (aa ) && PyBytes_Check (bb ))) {
1542
1538
if (_Py_GetConfig ()-> bytes_warning && (op == Py_EQ || op == Py_NE )) {
1543
- if (PyUnicode_Check (a ) || PyUnicode_Check (b )) {
1539
+ if (PyUnicode_Check (aa ) || PyUnicode_Check (bb )) {
1544
1540
if (PyErr_WarnEx (PyExc_BytesWarning ,
1545
1541
"Comparison between bytes and string" , 1 ))
1546
1542
return NULL ;
1547
1543
}
1548
- if (PyLong_Check (a ) || PyLong_Check (b )) {
1544
+ if (PyLong_Check (aa ) || PyLong_Check (bb )) {
1549
1545
if (PyErr_WarnEx (PyExc_BytesWarning ,
1550
1546
"Comparison between bytes and int" , 1 ))
1551
1547
return NULL ;
1552
1548
}
1553
1549
}
1554
1550
Py_RETURN_NOTIMPLEMENTED ;
1555
1551
}
1556
- else if (a == b ) {
1552
+
1553
+ PyBytesObject * a = _PyBytes_CAST (aa );
1554
+ PyBytesObject * b = _PyBytes_CAST (bb );
1555
+ if (a == b ) {
1557
1556
switch (op ) {
1558
1557
case Py_EQ :
1559
1558
case Py_LE :
@@ -1575,25 +1574,29 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
1575
1574
return PyBool_FromLong (eq );
1576
1575
}
1577
1576
else {
1578
- len_a = Py_SIZE (a );
1579
- len_b = Py_SIZE (b );
1580
- min_len = Py_MIN (len_a , len_b );
1577
+ Py_ssize_t len_a = Py_SIZE (a );
1578
+ Py_ssize_t len_b = Py_SIZE (b );
1579
+ Py_ssize_t min_len = Py_MIN (len_a , len_b );
1580
+ int c ;
1581
1581
if (min_len > 0 ) {
1582
1582
c = Py_CHARMASK (* a -> ob_sval ) - Py_CHARMASK (* b -> ob_sval );
1583
1583
if (c == 0 )
1584
1584
c = memcmp (a -> ob_sval , b -> ob_sval , min_len );
1585
1585
}
1586
- else
1586
+ else {
1587
1587
c = 0 ;
1588
- if (c != 0 )
1588
+ }
1589
+ if (c != 0 ) {
1589
1590
Py_RETURN_RICHCOMPARE (c , 0 , op );
1591
+ }
1590
1592
Py_RETURN_RICHCOMPARE (len_a , len_b , op );
1591
1593
}
1592
1594
}
1593
1595
1594
1596
static Py_hash_t
1595
- bytes_hash (PyBytesObject * a )
1597
+ bytes_hash (PyObject * self )
1596
1598
{
1599
+ PyBytesObject * a = _PyBytes_CAST (self );
1597
1600
_Py_COMP_DIAG_PUSH
1598
1601
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
1599
1602
if (a -> ob_shash == -1 ) {
@@ -1605,8 +1608,9 @@ _Py_COMP_DIAG_POP
1605
1608
}
1606
1609
1607
1610
static PyObject *
1608
- bytes_subscript (PyBytesObject * self , PyObject * item )
1611
+ bytes_subscript (PyObject * op , PyObject * item )
1609
1612
{
1613
+ PyBytesObject * self = _PyBytes_CAST (op );
1610
1614
if (_PyIndex_Check (item )) {
1611
1615
Py_ssize_t i = PyNumber_AsSsize_t (item , PyExc_IndexError );
1612
1616
if (i == -1 && PyErr_Occurred ())
@@ -1670,31 +1674,32 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
1670
1674
}
1671
1675
1672
1676
static int
1673
- bytes_buffer_getbuffer (PyBytesObject * self , Py_buffer * view , int flags )
1677
+ bytes_buffer_getbuffer (PyObject * op , Py_buffer * view , int flags )
1674
1678
{
1679
+ PyBytesObject * self = _PyBytes_CAST (op );
1675
1680
return PyBuffer_FillInfo (view , (PyObject * )self , (void * )self -> ob_sval , Py_SIZE (self ),
1676
1681
1 , flags );
1677
1682
}
1678
1683
1679
1684
static PySequenceMethods bytes_as_sequence = {
1680
- ( lenfunc ) bytes_length , /*sq_length*/
1681
- ( binaryfunc ) bytes_concat , /*sq_concat*/
1682
- ( ssizeargfunc ) bytes_repeat , /*sq_repeat*/
1683
- ( ssizeargfunc ) bytes_item , /*sq_item*/
1685
+ bytes_length , /*sq_length*/
1686
+ bytes_concat , /*sq_concat*/
1687
+ bytes_repeat , /*sq_repeat*/
1688
+ bytes_item , /*sq_item*/
1684
1689
0 , /*sq_slice*/
1685
1690
0 , /*sq_ass_item*/
1686
1691
0 , /*sq_ass_slice*/
1687
- ( objobjproc ) bytes_contains /*sq_contains*/
1692
+ bytes_contains /*sq_contains*/
1688
1693
};
1689
1694
1690
1695
static PyMappingMethods bytes_as_mapping = {
1691
- ( lenfunc ) bytes_length ,
1692
- ( binaryfunc ) bytes_subscript ,
1696
+ bytes_length ,
1697
+ bytes_subscript ,
1693
1698
0 ,
1694
1699
};
1695
1700
1696
1701
static PyBufferProcs bytes_as_buffer = {
1697
- ( getbufferproc ) bytes_buffer_getbuffer ,
1702
+ bytes_buffer_getbuffer ,
1698
1703
NULL ,
1699
1704
};
1700
1705
@@ -3043,11 +3048,11 @@ PyTypeObject PyBytes_Type = {
3043
3048
0 , /* tp_getattr */
3044
3049
0 , /* tp_setattr */
3045
3050
0 , /* tp_as_async */
3046
- ( reprfunc ) bytes_repr , /* tp_repr */
3051
+ bytes_repr , /* tp_repr */
3047
3052
& bytes_as_number , /* tp_as_number */
3048
3053
& bytes_as_sequence , /* tp_as_sequence */
3049
3054
& bytes_as_mapping , /* tp_as_mapping */
3050
- ( hashfunc ) bytes_hash , /* tp_hash */
3055
+ bytes_hash , /* tp_hash */
3051
3056
0 , /* tp_call */
3052
3057
bytes_str , /* tp_str */
3053
3058
PyObject_GenericGetAttr , /* tp_getattro */
0 commit comments