Skip to content

Commit 6ae8eb1

Browse files
committed
gh-111178: Fix function signatures in bytesobject.c
1 parent 91e64be commit 6ae8eb1

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

Objects/bytesobject.c

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,8 +1405,9 @@ bytes_str(PyObject *op)
14051405
}
14061406

14071407
static Py_ssize_t
1408-
bytes_length(PyBytesObject *a)
1408+
bytes_length(PyObject *self)
14091409
{
1410+
PyBytesObject *a = _PyBytes_CAST(self);
14101411
return Py_SIZE(a);
14111412
}
14121413

@@ -1456,11 +1457,9 @@ bytes_concat(PyObject *a, PyObject *b)
14561457
}
14571458

14581459
static PyObject *
1459-
bytes_repeat(PyBytesObject *a, Py_ssize_t n)
1460+
bytes_repeat(PyObject *self, Py_ssize_t n)
14601461
{
1461-
Py_ssize_t size;
1462-
PyBytesObject *op;
1463-
size_t nbytes;
1462+
PyBytesObject *a = _PyBytes_CAST(self);
14641463
if (n < 0)
14651464
n = 0;
14661465
/* watch out for overflows: the size can overflow int,
@@ -1471,17 +1470,17 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
14711470
"repeated bytes are too long");
14721471
return NULL;
14731472
}
1474-
size = Py_SIZE(a) * n;
1473+
Py_ssize_t size = Py_SIZE(a) * n;
14751474
if (size == Py_SIZE(a) && PyBytes_CheckExact(a)) {
14761475
return Py_NewRef(a);
14771476
}
1478-
nbytes = (size_t)size;
1477+
size_t nbytes = (size_t)size;
14791478
if (nbytes + PyBytesObject_SIZE <= nbytes) {
14801479
PyErr_SetString(PyExc_OverflowError,
14811480
"repeated bytes are too long");
14821481
return NULL;
14831482
}
1484-
op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + nbytes);
1483+
PyBytesObject *op = PyObject_Malloc(PyBytesObject_SIZE + nbytes);
14851484
if (op == NULL) {
14861485
return PyErr_NoMemory();
14871486
}
@@ -1504,8 +1503,9 @@ bytes_contains(PyObject *self, PyObject *arg)
15041503
}
15051504

15061505
static PyObject *
1507-
bytes_item(PyBytesObject *a, Py_ssize_t i)
1506+
bytes_item(PyObject *self, Py_ssize_t i)
15081507
{
1508+
PyBytesObject *a = _PyBytes_CAST(self);
15091509
if (i < 0 || i >= Py_SIZE(a)) {
15101510
PyErr_SetString(PyExc_IndexError, "index out of range");
15111511
return NULL;
@@ -1531,29 +1531,28 @@ bytes_compare_eq(PyBytesObject *a, PyBytesObject *b)
15311531
}
15321532

15331533
static PyObject*
1534-
bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
1534+
bytes_richcompare(PyObject *aa, PyObject *bb, int op)
15351535
{
1536-
int c;
1537-
Py_ssize_t len_a, len_b;
1538-
Py_ssize_t min_len;
1539-
15401536
/* Make sure both arguments are strings. */
1541-
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
1537+
if (!(PyBytes_Check(aa) && PyBytes_Check(bb))) {
15421538
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)) {
15441540
if (PyErr_WarnEx(PyExc_BytesWarning,
15451541
"Comparison between bytes and string", 1))
15461542
return NULL;
15471543
}
1548-
if (PyLong_Check(a) || PyLong_Check(b)) {
1544+
if (PyLong_Check(aa) || PyLong_Check(bb)) {
15491545
if (PyErr_WarnEx(PyExc_BytesWarning,
15501546
"Comparison between bytes and int", 1))
15511547
return NULL;
15521548
}
15531549
}
15541550
Py_RETURN_NOTIMPLEMENTED;
15551551
}
1556-
else if (a == b) {
1552+
1553+
PyBytesObject *a = _PyBytes_CAST(aa);
1554+
PyBytesObject *b = _PyBytes_CAST(bb);
1555+
if (a == b) {
15571556
switch (op) {
15581557
case Py_EQ:
15591558
case Py_LE:
@@ -1575,25 +1574,29 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
15751574
return PyBool_FromLong(eq);
15761575
}
15771576
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;
15811581
if (min_len > 0) {
15821582
c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
15831583
if (c == 0)
15841584
c = memcmp(a->ob_sval, b->ob_sval, min_len);
15851585
}
1586-
else
1586+
else {
15871587
c = 0;
1588-
if (c != 0)
1588+
}
1589+
if (c != 0) {
15891590
Py_RETURN_RICHCOMPARE(c, 0, op);
1591+
}
15901592
Py_RETURN_RICHCOMPARE(len_a, len_b, op);
15911593
}
15921594
}
15931595

15941596
static Py_hash_t
1595-
bytes_hash(PyBytesObject *a)
1597+
bytes_hash(PyObject *self)
15961598
{
1599+
PyBytesObject *a = _PyBytes_CAST(self);
15971600
_Py_COMP_DIAG_PUSH
15981601
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
15991602
if (a->ob_shash == -1) {
@@ -1605,8 +1608,9 @@ _Py_COMP_DIAG_POP
16051608
}
16061609

16071610
static PyObject*
1608-
bytes_subscript(PyBytesObject* self, PyObject* item)
1611+
bytes_subscript(PyObject *op, PyObject* item)
16091612
{
1613+
PyBytesObject *self = _PyBytes_CAST(op);
16101614
if (_PyIndex_Check(item)) {
16111615
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
16121616
if (i == -1 && PyErr_Occurred())
@@ -1670,31 +1674,32 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
16701674
}
16711675

16721676
static int
1673-
bytes_buffer_getbuffer(PyBytesObject *self, Py_buffer *view, int flags)
1677+
bytes_buffer_getbuffer(PyObject *op, Py_buffer *view, int flags)
16741678
{
1679+
PyBytesObject *self = _PyBytes_CAST(op);
16751680
return PyBuffer_FillInfo(view, (PyObject*)self, (void *)self->ob_sval, Py_SIZE(self),
16761681
1, flags);
16771682
}
16781683

16791684
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*/
16841689
0, /*sq_slice*/
16851690
0, /*sq_ass_item*/
16861691
0, /*sq_ass_slice*/
1687-
(objobjproc)bytes_contains /*sq_contains*/
1692+
bytes_contains /*sq_contains*/
16881693
};
16891694

16901695
static PyMappingMethods bytes_as_mapping = {
1691-
(lenfunc)bytes_length,
1692-
(binaryfunc)bytes_subscript,
1696+
bytes_length,
1697+
bytes_subscript,
16931698
0,
16941699
};
16951700

16961701
static PyBufferProcs bytes_as_buffer = {
1697-
(getbufferproc)bytes_buffer_getbuffer,
1702+
bytes_buffer_getbuffer,
16981703
NULL,
16991704
};
17001705

@@ -3043,11 +3048,11 @@ PyTypeObject PyBytes_Type = {
30433048
0, /* tp_getattr */
30443049
0, /* tp_setattr */
30453050
0, /* tp_as_async */
3046-
(reprfunc)bytes_repr, /* tp_repr */
3051+
bytes_repr, /* tp_repr */
30473052
&bytes_as_number, /* tp_as_number */
30483053
&bytes_as_sequence, /* tp_as_sequence */
30493054
&bytes_as_mapping, /* tp_as_mapping */
3050-
(hashfunc)bytes_hash, /* tp_hash */
3055+
bytes_hash, /* tp_hash */
30513056
0, /* tp_call */
30523057
bytes_str, /* tp_str */
30533058
PyObject_GenericGetAttr, /* tp_getattro */

0 commit comments

Comments
 (0)