Skip to content

Commit f099585

Browse files
committed
fix
1 parent fe63c59 commit f099585

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

Objects/bytesobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,8 @@ bytes_length(PyObject *self)
15361536
return Py_SIZE(a);
15371537
}
15381538

1539-
/* This is also used by PyBytes_Concat() and BINARY_OP_EXTEND */
1540-
PyObject *
1539+
/* This is also used by PyBytes_Concat() */
1540+
static PyObject *
15411541
bytes_concat(PyObject *a, PyObject *b)
15421542
{
15431543
Py_buffer va, vb;
@@ -1581,7 +1581,7 @@ bytes_concat(PyObject *a, PyObject *b)
15811581
return result;
15821582
}
15831583

1584-
PyObject *
1584+
static PyObject *
15851585
bytes_repeat(PyObject *self, Py_ssize_t n)
15861586
{
15871587
PyBytesObject *a = _PyBytes_CAST(self);

Objects/dictobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,7 +5041,7 @@ dict___sizeof___impl(PyDictObject *self)
50415041
return PyLong_FromSsize_t(_PyDict_SizeOf(self));
50425042
}
50435043

5044-
PyObject *
5044+
static PyObject *
50455045
dict_or(PyObject *self, PyObject *other)
50465046
{
50475047
if (!PyAnyDict_Check(self) || !PyAnyDict_Check(other)) {
@@ -5081,7 +5081,7 @@ frozendict_or(PyObject *self, PyObject *other)
50815081
}
50825082

50835083

5084-
PyObject *
5084+
static PyObject *
50855085
dict_ior(PyObject *self, PyObject *other)
50865086
{
50875087
if (dict_update_arg(self, other)) {

Objects/tupleobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ _PyTuple_Concat(PyObject *aa, PyObject *bb)
594594
return (PyObject *)np;
595595
}
596596

597-
PyObject *
597+
static PyObject *
598598
tuple_repeat(PyObject *self, Py_ssize_t n)
599599
{
600600
PyTupleObject *a = _PyTuple_CAST(self);

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12494,7 +12494,7 @@ unicode_rstrip_impl(PyObject *self, PyObject *chars)
1249412494
}
1249512495

1249612496

12497-
PyObject*
12497+
static PyObject*
1249812498
unicode_repeat(PyObject *str, Py_ssize_t len)
1249912499
{
1250012500
PyObject *u;

Python/specialize.c

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,13 +2136,6 @@ tuple_tuple_add(PyObject *lhs, PyObject *rhs)
21362136
/* sequence * int helpers: bypass PyNumber_Multiply dispatch overhead
21372137
by calling sq_repeat directly with PyLong_AsSsize_t. */
21382138

2139-
extern PyObject *unicode_repeat(PyObject *str, Py_ssize_t n);
2140-
extern PyObject *bytes_repeat(PyObject *self, Py_ssize_t n);
2141-
extern PyObject *bytes_concat(PyObject *a, PyObject *b);
2142-
extern PyObject *tuple_repeat(PyObject *self, Py_ssize_t n);
2143-
extern PyObject *dict_or(PyObject *self, PyObject *other);
2144-
extern PyObject *dict_ior(PyObject *self, PyObject *other);
2145-
21462139
static inline PyObject *
21472140
seq_int_multiply(PyObject *seq, PyObject *n,
21482141
ssizeargfunc repeat)
@@ -2171,13 +2164,15 @@ int_str_guard(PyObject *lhs, PyObject *rhs)
21712164
static PyObject *
21722165
str_int_multiply(PyObject *lhs, PyObject *rhs)
21732166
{
2174-
return seq_int_multiply(lhs, rhs, unicode_repeat);
2167+
return seq_int_multiply(lhs, rhs,
2168+
PyUnicode_Type.tp_as_sequence->sq_repeat);
21752169
}
21762170

21772171
static PyObject *
21782172
int_str_multiply(PyObject *lhs, PyObject *rhs)
21792173
{
2180-
return seq_int_multiply(rhs, lhs, unicode_repeat);
2174+
return seq_int_multiply(rhs, lhs,
2175+
PyUnicode_Type.tp_as_sequence->sq_repeat);
21812176
}
21822177

21832178
/* bytes-bytes */
@@ -2188,6 +2183,12 @@ bytes_bytes_guard(PyObject *lhs, PyObject *rhs)
21882183
return PyBytes_CheckExact(lhs) && PyBytes_CheckExact(rhs);
21892184
}
21902185

2186+
static PyObject *
2187+
bytes_bytes_add(PyObject *lhs, PyObject *rhs)
2188+
{
2189+
return PyBytes_Type.tp_as_sequence->sq_concat(lhs, rhs);
2190+
}
2191+
21912192
/* bytes-int and int-bytes */
21922193

21932194
static int
@@ -2205,13 +2206,15 @@ int_bytes_guard(PyObject *lhs, PyObject *rhs)
22052206
static PyObject *
22062207
bytes_int_multiply(PyObject *lhs, PyObject *rhs)
22072208
{
2208-
return seq_int_multiply(lhs, rhs, bytes_repeat);
2209+
return seq_int_multiply(lhs, rhs,
2210+
PyBytes_Type.tp_as_sequence->sq_repeat);
22092211
}
22102212

22112213
static PyObject *
22122214
int_bytes_multiply(PyObject *lhs, PyObject *rhs)
22132215
{
2214-
return seq_int_multiply(rhs, lhs, bytes_repeat);
2216+
return seq_int_multiply(rhs, lhs,
2217+
PyBytes_Type.tp_as_sequence->sq_repeat);
22152218
}
22162219

22172220
/* tuple-int and int-tuple */
@@ -2231,13 +2234,15 @@ int_tuple_guard(PyObject *lhs, PyObject *rhs)
22312234
static PyObject *
22322235
tuple_int_multiply(PyObject *lhs, PyObject *rhs)
22332236
{
2234-
return seq_int_multiply(lhs, rhs, tuple_repeat);
2237+
return seq_int_multiply(lhs, rhs,
2238+
PyTuple_Type.tp_as_sequence->sq_repeat);
22352239
}
22362240

22372241
static PyObject *
22382242
int_tuple_multiply(PyObject *lhs, PyObject *rhs)
22392243
{
2240-
return seq_int_multiply(rhs, lhs, tuple_repeat);
2244+
return seq_int_multiply(rhs, lhs,
2245+
PyTuple_Type.tp_as_sequence->sq_repeat);
22412246
}
22422247

22432248
/* dict-dict */
@@ -2248,6 +2253,18 @@ dict_dict_guard(PyObject *lhs, PyObject *rhs)
22482253
return PyDict_CheckExact(lhs) && PyDict_CheckExact(rhs);
22492254
}
22502255

2256+
static PyObject *
2257+
dict_dict_or(PyObject *lhs, PyObject *rhs)
2258+
{
2259+
return PyDict_Type.tp_as_number->nb_or(lhs, rhs);
2260+
}
2261+
2262+
static PyObject *
2263+
dict_dict_ior(PyObject *lhs, PyObject *rhs)
2264+
{
2265+
return PyDict_Type.tp_as_number->nb_inplace_or(lhs, rhs);
2266+
}
2267+
22512268
static int
22522269
compactlongs_guard(PyObject *lhs, PyObject *rhs)
22532270
{
@@ -2373,10 +2390,10 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23732390
{NB_INPLACE_MULTIPLY, str_int_guard, str_int_multiply, &PyUnicode_Type, 0, &PyUnicode_Type, &PyLong_Type},
23742391
{NB_INPLACE_MULTIPLY, int_str_guard, int_str_multiply, &PyUnicode_Type, 0, &PyLong_Type, &PyUnicode_Type},
23752392

2376-
/* bytes + bytes: call bytes_concat directly. bytes_concat may return
2377-
an operand when one side is empty, so result is not always unique. */
2378-
{NB_ADD, bytes_bytes_guard, bytes_concat, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
2379-
{NB_INPLACE_ADD, bytes_bytes_guard, bytes_concat, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
2393+
/* bytes + bytes: bytes_concat may return an operand when one side
2394+
is empty, so result is not always unique. */
2395+
{NB_ADD, bytes_bytes_guard, bytes_bytes_add, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
2396+
{NB_INPLACE_ADD, bytes_bytes_guard, bytes_bytes_add, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
23802397

23812398
/* bytes * int / int * bytes: call bytes_repeat directly.
23822399
bytes_repeat returns the original when n == 1. */
@@ -2392,9 +2409,9 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23922409
{NB_INPLACE_MULTIPLY, tuple_int_guard, tuple_int_multiply, &PyTuple_Type, 0, &PyTuple_Type, &PyLong_Type},
23932410
{NB_INPLACE_MULTIPLY, int_tuple_guard, int_tuple_multiply, &PyTuple_Type, 0, &PyLong_Type, &PyTuple_Type},
23942411

2395-
/* dict | dict: call dict_or directly */
2396-
{NB_OR, dict_dict_guard, dict_or, &PyDict_Type, 1, &PyDict_Type, &PyDict_Type},
2397-
{NB_INPLACE_OR, dict_dict_guard, dict_ior, &PyDict_Type, 0, &PyDict_Type, &PyDict_Type},
2412+
/* dict | dict */
2413+
{NB_OR, dict_dict_guard, dict_dict_or, &PyDict_Type, 1, &PyDict_Type, &PyDict_Type},
2414+
{NB_INPLACE_OR, dict_dict_guard, dict_dict_ior, &PyDict_Type, 0, &PyDict_Type, &PyDict_Type},
23982415
};
23992416

24002417
static int

0 commit comments

Comments
 (0)