Skip to content

Commit 1d5c0ae

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

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

Objects/bytesobject.c

Lines changed: 41 additions & 35 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,16 +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
}
1483+
PyBytesObject *op;
14841484
op = (PyBytesObject *)PyObject_Malloc(PyBytesObject_SIZE + nbytes);
14851485
if (op == NULL) {
14861486
return PyErr_NoMemory();
@@ -1504,8 +1504,9 @@ bytes_contains(PyObject *self, PyObject *arg)
15041504
}
15051505

15061506
static PyObject *
1507-
bytes_item(PyBytesObject *a, Py_ssize_t i)
1507+
bytes_item(PyObject *self, Py_ssize_t i)
15081508
{
1509+
PyBytesObject *a = _PyBytes_CAST(self);
15091510
if (i < 0 || i >= Py_SIZE(a)) {
15101511
PyErr_SetString(PyExc_IndexError, "index out of range");
15111512
return NULL;
@@ -1531,29 +1532,28 @@ bytes_compare_eq(PyBytesObject *a, PyBytesObject *b)
15311532
}
15321533

15331534
static PyObject*
1534-
bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
1535+
bytes_richcompare(PyObject *aa, PyObject *bb, int op)
15351536
{
1536-
int c;
1537-
Py_ssize_t len_a, len_b;
1538-
Py_ssize_t min_len;
1539-
15401537
/* Make sure both arguments are strings. */
1541-
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
1538+
if (!(PyBytes_Check(aa) && PyBytes_Check(bb))) {
15421539
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)) {
15441541
if (PyErr_WarnEx(PyExc_BytesWarning,
15451542
"Comparison between bytes and string", 1))
15461543
return NULL;
15471544
}
1548-
if (PyLong_Check(a) || PyLong_Check(b)) {
1545+
if (PyLong_Check(aa) || PyLong_Check(bb)) {
15491546
if (PyErr_WarnEx(PyExc_BytesWarning,
15501547
"Comparison between bytes and int", 1))
15511548
return NULL;
15521549
}
15531550
}
15541551
Py_RETURN_NOTIMPLEMENTED;
15551552
}
1556-
else if (a == b) {
1553+
1554+
PyBytesObject *a = _PyBytes_CAST(aa);
1555+
PyBytesObject *b = _PyBytes_CAST(bb);
1556+
if (a == b) {
15571557
switch (op) {
15581558
case Py_EQ:
15591559
case Py_LE:
@@ -1575,25 +1575,29 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
15751575
return PyBool_FromLong(eq);
15761576
}
15771577
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;
15811582
if (min_len > 0) {
15821583
c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
15831584
if (c == 0)
15841585
c = memcmp(a->ob_sval, b->ob_sval, min_len);
15851586
}
1586-
else
1587+
else {
15871588
c = 0;
1588-
if (c != 0)
1589+
}
1590+
if (c != 0) {
15891591
Py_RETURN_RICHCOMPARE(c, 0, op);
1592+
}
15901593
Py_RETURN_RICHCOMPARE(len_a, len_b, op);
15911594
}
15921595
}
15931596

15941597
static Py_hash_t
1595-
bytes_hash(PyBytesObject *a)
1598+
bytes_hash(PyObject *self)
15961599
{
1600+
PyBytesObject *a = _PyBytes_CAST(self);
15971601
_Py_COMP_DIAG_PUSH
15981602
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
15991603
if (a->ob_shash == -1) {
@@ -1605,8 +1609,9 @@ _Py_COMP_DIAG_POP
16051609
}
16061610

16071611
static PyObject*
1608-
bytes_subscript(PyBytesObject* self, PyObject* item)
1612+
bytes_subscript(PyObject *op, PyObject* item)
16091613
{
1614+
PyBytesObject *self = _PyBytes_CAST(op);
16101615
if (_PyIndex_Check(item)) {
16111616
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
16121617
if (i == -1 && PyErr_Occurred())
@@ -1670,31 +1675,32 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
16701675
}
16711676

16721677
static int
1673-
bytes_buffer_getbuffer(PyBytesObject *self, Py_buffer *view, int flags)
1678+
bytes_buffer_getbuffer(PyObject *op, Py_buffer *view, int flags)
16741679
{
1680+
PyBytesObject *self = _PyBytes_CAST(op);
16751681
return PyBuffer_FillInfo(view, (PyObject*)self, (void *)self->ob_sval, Py_SIZE(self),
16761682
1, flags);
16771683
}
16781684

16791685
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*/
16841690
0, /*sq_slice*/
16851691
0, /*sq_ass_item*/
16861692
0, /*sq_ass_slice*/
1687-
(objobjproc)bytes_contains /*sq_contains*/
1693+
bytes_contains /*sq_contains*/
16881694
};
16891695

16901696
static PyMappingMethods bytes_as_mapping = {
1691-
(lenfunc)bytes_length,
1692-
(binaryfunc)bytes_subscript,
1697+
bytes_length,
1698+
bytes_subscript,
16931699
0,
16941700
};
16951701

16961702
static PyBufferProcs bytes_as_buffer = {
1697-
(getbufferproc)bytes_buffer_getbuffer,
1703+
bytes_buffer_getbuffer,
16981704
NULL,
16991705
};
17001706

@@ -3043,11 +3049,11 @@ PyTypeObject PyBytes_Type = {
30433049
0, /* tp_getattr */
30443050
0, /* tp_setattr */
30453051
0, /* tp_as_async */
3046-
(reprfunc)bytes_repr, /* tp_repr */
3052+
bytes_repr, /* tp_repr */
30473053
&bytes_as_number, /* tp_as_number */
30483054
&bytes_as_sequence, /* tp_as_sequence */
30493055
&bytes_as_mapping, /* tp_as_mapping */
3050-
(hashfunc)bytes_hash, /* tp_hash */
3056+
bytes_hash, /* tp_hash */
30513057
0, /* tp_call */
30523058
bytes_str, /* tp_str */
30533059
PyObject_GenericGetAttr, /* tp_getattro */

0 commit comments

Comments
 (0)