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