Skip to content

Commit e09132f

Browse files
Backed out changeset b0087e17cd5e (issue python#26765)
For unknown reasons it perhaps caused a crash on 32-bit Windows (issue #).
1 parent ab8bcb3 commit e09132f

3 files changed

Lines changed: 138 additions & 77 deletions

File tree

Objects/bytearrayobject.c

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,18 @@ bytearray_dealloc(PyByteArrayObject *self)
10971097
#include "stringlib/transmogrify.h"
10981098

10991099

1100+
static PyObject *
1101+
bytearray_find(PyByteArrayObject *self, PyObject *args)
1102+
{
1103+
return _Py_bytes_find(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1104+
}
1105+
1106+
static PyObject *
1107+
bytearray_count(PyByteArrayObject *self, PyObject *args)
1108+
{
1109+
return _Py_bytes_count(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1110+
}
1111+
11001112
/*[clinic input]
11011113
bytearray.clear
11021114
@@ -1126,6 +1138,42 @@ bytearray_copy_impl(PyByteArrayObject *self)
11261138
PyByteArray_GET_SIZE(self));
11271139
}
11281140

1141+
static PyObject *
1142+
bytearray_index(PyByteArrayObject *self, PyObject *args)
1143+
{
1144+
return _Py_bytes_index(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1145+
}
1146+
1147+
static PyObject *
1148+
bytearray_rfind(PyByteArrayObject *self, PyObject *args)
1149+
{
1150+
return _Py_bytes_rfind(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1151+
}
1152+
1153+
static PyObject *
1154+
bytearray_rindex(PyByteArrayObject *self, PyObject *args)
1155+
{
1156+
return _Py_bytes_rindex(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1157+
}
1158+
1159+
static int
1160+
bytearray_contains(PyObject *self, PyObject *arg)
1161+
{
1162+
return _Py_bytes_contains(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), arg);
1163+
}
1164+
1165+
static PyObject *
1166+
bytearray_startswith(PyByteArrayObject *self, PyObject *args)
1167+
{
1168+
return _Py_bytes_startswith(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1169+
}
1170+
1171+
static PyObject *
1172+
bytearray_endswith(PyByteArrayObject *self, PyObject *args)
1173+
{
1174+
return _Py_bytes_endswith(PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), args);
1175+
}
1176+
11291177

11301178
/*[clinic input]
11311179
bytearray.translate
@@ -1281,8 +1329,8 @@ bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
12811329
/*[clinic end generated code: output=d39884c4dc59412a input=aa379d988637c7fb]*/
12821330
{
12831331
return stringlib_replace((PyObject *)self,
1284-
old->buf, old->len,
1285-
new->buf, new->len, count);
1332+
(const char *)old->buf, old->len,
1333+
(const char *)new->buf, new->len, count);
12861334
}
12871335

12881336
/*[clinic input]
@@ -1947,6 +1995,14 @@ PyDoc_STRVAR(hex__doc__,
19471995
Create a string of hexadecimal numbers from a bytearray object.\n\
19481996
Example: bytearray([0xb9, 0x01, 0xef]).hex() -> 'b901ef'.");
19491997

1998+
static PyObject *
1999+
bytearray_hex(PyBytesObject *self)
2000+
{
2001+
char* argbuf = PyByteArray_AS_STRING(self);
2002+
Py_ssize_t arglen = PyByteArray_GET_SIZE(self);
2003+
return _Py_strhex(argbuf, arglen);
2004+
}
2005+
19502006
static PyObject *
19512007
_common_reduce(PyByteArrayObject *self, int proto)
19522008
{
@@ -2035,7 +2091,7 @@ static PySequenceMethods bytearray_as_sequence = {
20352091
0, /* sq_slice */
20362092
(ssizeobjargproc)bytearray_setitem, /* sq_ass_item */
20372093
0, /* sq_ass_slice */
2038-
(objobjproc)stringlib_contains, /* sq_contains */
2094+
(objobjproc)bytearray_contains, /* sq_contains */
20392095
(binaryfunc)bytearray_iconcat, /* sq_inplace_concat */
20402096
(ssizeargfunc)bytearray_irepeat, /* sq_inplace_repeat */
20412097
};
@@ -2063,19 +2119,19 @@ bytearray_methods[] = {
20632119
{"center", (PyCFunction)stringlib_center, METH_VARARGS, _Py_center__doc__},
20642120
BYTEARRAY_CLEAR_METHODDEF
20652121
BYTEARRAY_COPY_METHODDEF
2066-
{"count", (PyCFunction)stringlib_method_count, METH_VARARGS,
2122+
{"count", (PyCFunction)bytearray_count, METH_VARARGS,
20672123
_Py_count__doc__},
20682124
BYTEARRAY_DECODE_METHODDEF
2069-
{"endswith", (PyCFunction)stringlib_endswith, METH_VARARGS,
2125+
{"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS,
20702126
_Py_endswith__doc__},
20712127
{"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS,
20722128
_Py_expandtabs__doc__},
20732129
BYTEARRAY_EXTEND_METHODDEF
2074-
{"find", (PyCFunction)stringlib_method_find, METH_VARARGS,
2130+
{"find", (PyCFunction)bytearray_find, METH_VARARGS,
20752131
_Py_find__doc__},
20762132
BYTEARRAY_FROMHEX_METHODDEF
2077-
{"hex", (PyCFunction)stringlib_hex, METH_NOARGS, hex__doc__},
2078-
{"index", (PyCFunction)stringlib_index, METH_VARARGS, _Py_index__doc__},
2133+
{"hex", (PyCFunction)bytearray_hex, METH_NOARGS, hex__doc__},
2134+
{"index", (PyCFunction)bytearray_index, METH_VARARGS, _Py_index__doc__},
20792135
BYTEARRAY_INSERT_METHODDEF
20802136
{"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS,
20812137
_Py_isalnum__doc__},
@@ -2101,16 +2157,15 @@ bytearray_methods[] = {
21012157
BYTEARRAY_REMOVE_METHODDEF
21022158
BYTEARRAY_REPLACE_METHODDEF
21032159
BYTEARRAY_REVERSE_METHODDEF
2104-
{"rfind", (PyCFunction)stringlib_method_rfind, METH_VARARGS,
2105-
_Py_rfind__doc__},
2106-
{"rindex", (PyCFunction)stringlib_rindex, METH_VARARGS, _Py_rindex__doc__},
2160+
{"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS, _Py_rfind__doc__},
2161+
{"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS, _Py_rindex__doc__},
21072162
{"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, _Py_rjust__doc__},
21082163
BYTEARRAY_RPARTITION_METHODDEF
21092164
BYTEARRAY_RSPLIT_METHODDEF
21102165
BYTEARRAY_RSTRIP_METHODDEF
21112166
BYTEARRAY_SPLIT_METHODDEF
21122167
BYTEARRAY_SPLITLINES_METHODDEF
2113-
{"startswith", (PyCFunction)stringlib_startswith, METH_VARARGS,
2168+
{"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS ,
21142169
_Py_startswith__doc__},
21152170
BYTEARRAY_STRIP_METHODDEF
21162171
{"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,

Objects/bytesobject.c

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,12 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
14851485
return (PyObject *) op;
14861486
}
14871487

1488+
static int
1489+
bytes_contains(PyObject *self, PyObject *arg)
1490+
{
1491+
return _Py_bytes_contains(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), arg);
1492+
}
1493+
14881494
static PyObject *
14891495
bytes_item(PyBytesObject *a, Py_ssize_t i)
14901496
{
@@ -1695,7 +1701,7 @@ static PySequenceMethods bytes_as_sequence = {
16951701
0, /*sq_slice*/
16961702
0, /*sq_ass_item*/
16971703
0, /*sq_ass_slice*/
1698-
(objobjproc)stringlib_contains /*sq_contains*/
1704+
(objobjproc)bytes_contains /*sq_contains*/
16991705
};
17001706

17011707
static PyMappingMethods bytes_as_mapping = {
@@ -1867,6 +1873,32 @@ _PyBytes_Join(PyObject *sep, PyObject *x)
18671873
return bytes_join((PyBytesObject*)sep, x);
18681874
}
18691875

1876+
static PyObject *
1877+
bytes_find(PyBytesObject *self, PyObject *args)
1878+
{
1879+
return _Py_bytes_find(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
1880+
}
1881+
1882+
static PyObject *
1883+
bytes_index(PyBytesObject *self, PyObject *args)
1884+
{
1885+
return _Py_bytes_index(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
1886+
}
1887+
1888+
1889+
static PyObject *
1890+
bytes_rfind(PyBytesObject *self, PyObject *args)
1891+
{
1892+
return _Py_bytes_rfind(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
1893+
}
1894+
1895+
1896+
static PyObject *
1897+
bytes_rindex(PyBytesObject *self, PyObject *args)
1898+
{
1899+
return _Py_bytes_rindex(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
1900+
}
1901+
18701902

18711903
Py_LOCAL_INLINE(PyObject *)
18721904
do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
@@ -2003,6 +2035,13 @@ bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes)
20032035
}
20042036

20052037

2038+
static PyObject *
2039+
bytes_count(PyBytesObject *self, PyObject *args)
2040+
{
2041+
return _Py_bytes_count(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
2042+
}
2043+
2044+
20062045
/*[clinic input]
20072046
bytes.translate
20082047
@@ -2189,6 +2228,19 @@ bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
21892228
/** End DALKE **/
21902229

21912230

2231+
static PyObject *
2232+
bytes_startswith(PyBytesObject *self, PyObject *args)
2233+
{
2234+
return _Py_bytes_startswith(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
2235+
}
2236+
2237+
static PyObject *
2238+
bytes_endswith(PyBytesObject *self, PyObject *args)
2239+
{
2240+
return _Py_bytes_endswith(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
2241+
}
2242+
2243+
21922244
/*[clinic input]
21932245
bytes.decode
21942246
@@ -2342,6 +2394,14 @@ PyDoc_STRVAR(hex__doc__,
23422394
Create a string of hexadecimal numbers from a bytes object.\n\
23432395
Example: b'\\xb9\\x01\\xef'.hex() -> 'b901ef'.");
23442396

2397+
static PyObject *
2398+
bytes_hex(PyBytesObject *self)
2399+
{
2400+
char* argbuf = PyBytes_AS_STRING(self);
2401+
Py_ssize_t arglen = PyBytes_GET_SIZE(self);
2402+
return _Py_strhex(argbuf, arglen);
2403+
}
2404+
23452405
static PyObject *
23462406
bytes_getnewargs(PyBytesObject *v)
23472407
{
@@ -2354,19 +2414,20 @@ bytes_methods[] = {
23542414
{"__getnewargs__", (PyCFunction)bytes_getnewargs, METH_NOARGS},
23552415
{"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
23562416
_Py_capitalize__doc__},
2357-
{"center", (PyCFunction)stringlib_center, METH_VARARGS, _Py_center__doc__},
2358-
{"count", (PyCFunction)stringlib_method_count, METH_VARARGS,
2417+
{"center", (PyCFunction)stringlib_center, METH_VARARGS,
2418+
_Py_center__doc__},
2419+
{"count", (PyCFunction)bytes_count, METH_VARARGS,
23592420
_Py_count__doc__},
23602421
BYTES_DECODE_METHODDEF
2361-
{"endswith", (PyCFunction)stringlib_endswith, METH_VARARGS,
2422+
{"endswith", (PyCFunction)bytes_endswith, METH_VARARGS,
23622423
_Py_endswith__doc__},
23632424
{"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS,
23642425
_Py_expandtabs__doc__},
2365-
{"find", (PyCFunction)stringlib_method_find, METH_VARARGS,
2426+
{"find", (PyCFunction)bytes_find, METH_VARARGS,
23662427
_Py_find__doc__},
23672428
BYTES_FROMHEX_METHODDEF
2368-
{"hex", (PyCFunction)stringlib_hex, METH_NOARGS, hex__doc__},
2369-
{"index", (PyCFunction)stringlib_index, METH_VARARGS, _Py_index__doc__},
2429+
{"hex", (PyCFunction)bytes_hex, METH_NOARGS, hex__doc__},
2430+
{"index", (PyCFunction)bytes_index, METH_VARARGS, _Py_index__doc__},
23702431
{"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS,
23712432
_Py_isalnum__doc__},
23722433
{"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS,
@@ -2388,16 +2449,15 @@ bytes_methods[] = {
23882449
BYTES_MAKETRANS_METHODDEF
23892450
BYTES_PARTITION_METHODDEF
23902451
BYTES_REPLACE_METHODDEF
2391-
{"rfind", (PyCFunction)stringlib_method_rfind, METH_VARARGS,
2392-
_Py_rfind__doc__},
2393-
{"rindex", (PyCFunction)stringlib_rindex, METH_VARARGS, _Py_rindex__doc__},
2452+
{"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, _Py_rfind__doc__},
2453+
{"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, _Py_rindex__doc__},
23942454
{"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, _Py_rjust__doc__},
23952455
BYTES_RPARTITION_METHODDEF
23962456
BYTES_RSPLIT_METHODDEF
23972457
BYTES_RSTRIP_METHODDEF
23982458
BYTES_SPLIT_METHODDEF
23992459
BYTES_SPLITLINES_METHODDEF
2400-
{"startswith", (PyCFunction)stringlib_startswith, METH_VARARGS,
2460+
{"startswith", (PyCFunction)bytes_startswith, METH_VARARGS,
24012461
_Py_startswith__doc__},
24022462
BYTES_STRIP_METHODDEF
24032463
{"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,

Objects/stringlib/transmogrify.h

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,6 @@
22
# error "transmogrify.h only compatible with byte-wise strings"
33
#endif
44

5-
Py_LOCAL(PyObject *)
6-
stringlib_method_find(PyObject *self, PyObject *args)
7-
{
8-
return _Py_bytes_find(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
9-
}
10-
11-
Py_LOCAL(PyObject *)
12-
stringlib_index(PyObject *self, PyObject *args)
13-
{
14-
return _Py_bytes_index(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
15-
}
16-
17-
Py_LOCAL(PyObject *)
18-
stringlib_method_rfind(PyObject *self, PyObject *args)
19-
{
20-
return _Py_bytes_rfind(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
21-
}
22-
23-
Py_LOCAL(PyObject *)
24-
stringlib_rindex(PyObject *self, PyObject *args)
25-
{
26-
return _Py_bytes_rindex(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
27-
}
28-
29-
Py_LOCAL(PyObject *)
30-
stringlib_method_count(PyObject *self, PyObject *args)
31-
{
32-
return _Py_bytes_count(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
33-
}
34-
35-
Py_LOCAL(int)
36-
stringlib_contains(PyObject *self, PyObject *arg)
37-
{
38-
return _Py_bytes_contains(STRINGLIB_STR(self), STRINGLIB_LEN(self), arg);
39-
}
40-
41-
Py_LOCAL(PyObject *)
42-
stringlib_startswith(PyObject *self, PyObject *args)
43-
{
44-
return _Py_bytes_startswith(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
45-
}
46-
47-
Py_LOCAL(PyObject *)
48-
stringlib_endswith(PyObject *self, PyObject *args)
49-
{
50-
return _Py_bytes_endswith(STRINGLIB_STR(self), STRINGLIB_LEN(self), args);
51-
}
52-
53-
Py_LOCAL(PyObject *)
54-
stringlib_hex(PyObject *self)
55-
{
56-
return _Py_strhex(STRINGLIB_STR(self), STRINGLIB_LEN(self));
57-
}
58-
595
/* the more complicated methods. parts of these should be pulled out into the
606
shared code in bytes_methods.c to cut down on duplicate code bloat. */
617

0 commit comments

Comments
 (0)