summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-07-03 10:57:48 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-07-03 10:57:48 (GMT)
commite09132f2c764a9e7df1181b1999d517d949c99e6 (patch)
treee06fd6a797b2f36a23ca18d43e989ca40462243f /Objects/bytesobject.c
parentab8bcb34dc0b66ce2bc905f78a664333ee8f65f9 (diff)
downloadcpython-e09132f2c764a9e7df1181b1999d517d949c99e6.zip
cpython-e09132f2c764a9e7df1181b1999d517d949c99e6.tar.gz
cpython-e09132f2c764a9e7df1181b1999d517d949c99e6.tar.bz2
Backed out changeset b0087e17cd5e (issue #26765)
For unknown reasons it perhaps caused a crash on 32-bit Windows (issue #).
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c82
1 files changed, 71 insertions, 11 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 18ee5aa..8ad2782 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1485,6 +1485,12 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
return (PyObject *) op;
}
+static int
+bytes_contains(PyObject *self, PyObject *arg)
+{
+ return _Py_bytes_contains(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), arg);
+}
+
static PyObject *
bytes_item(PyBytesObject *a, Py_ssize_t i)
{
@@ -1695,7 +1701,7 @@ static PySequenceMethods bytes_as_sequence = {
0, /*sq_slice*/
0, /*sq_ass_item*/
0, /*sq_ass_slice*/
- (objobjproc)stringlib_contains /*sq_contains*/
+ (objobjproc)bytes_contains /*sq_contains*/
};
static PyMappingMethods bytes_as_mapping = {
@@ -1867,6 +1873,32 @@ _PyBytes_Join(PyObject *sep, PyObject *x)
return bytes_join((PyBytesObject*)sep, x);
}
+static PyObject *
+bytes_find(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_find(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
+static PyObject *
+bytes_index(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_index(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
+
+static PyObject *
+bytes_rfind(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_rfind(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
+
+static PyObject *
+bytes_rindex(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_rindex(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
Py_LOCAL_INLINE(PyObject *)
do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
@@ -2003,6 +2035,13 @@ bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes)
}
+static PyObject *
+bytes_count(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_count(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
+
/*[clinic input]
bytes.translate
@@ -2189,6 +2228,19 @@ bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
/** End DALKE **/
+static PyObject *
+bytes_startswith(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_startswith(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
+static PyObject *
+bytes_endswith(PyBytesObject *self, PyObject *args)
+{
+ return _Py_bytes_endswith(PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), args);
+}
+
+
/*[clinic input]
bytes.decode
@@ -2343,6 +2395,14 @@ Create a string of hexadecimal numbers from a bytes object.\n\
Example: b'\\xb9\\x01\\xef'.hex() -> 'b901ef'.");
static PyObject *
+bytes_hex(PyBytesObject *self)
+{
+ char* argbuf = PyBytes_AS_STRING(self);
+ Py_ssize_t arglen = PyBytes_GET_SIZE(self);
+ return _Py_strhex(argbuf, arglen);
+}
+
+static PyObject *
bytes_getnewargs(PyBytesObject *v)
{
return Py_BuildValue("(y#)", v->ob_sval, Py_SIZE(v));
@@ -2354,19 +2414,20 @@ bytes_methods[] = {
{"__getnewargs__", (PyCFunction)bytes_getnewargs, METH_NOARGS},
{"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
_Py_capitalize__doc__},
- {"center", (PyCFunction)stringlib_center, METH_VARARGS, _Py_center__doc__},
- {"count", (PyCFunction)stringlib_method_count, METH_VARARGS,
+ {"center", (PyCFunction)stringlib_center, METH_VARARGS,
+ _Py_center__doc__},
+ {"count", (PyCFunction)bytes_count, METH_VARARGS,
_Py_count__doc__},
BYTES_DECODE_METHODDEF
- {"endswith", (PyCFunction)stringlib_endswith, METH_VARARGS,
+ {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS,
_Py_endswith__doc__},
{"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS,
_Py_expandtabs__doc__},
- {"find", (PyCFunction)stringlib_method_find, METH_VARARGS,
+ {"find", (PyCFunction)bytes_find, METH_VARARGS,
_Py_find__doc__},
BYTES_FROMHEX_METHODDEF
- {"hex", (PyCFunction)stringlib_hex, METH_NOARGS, hex__doc__},
- {"index", (PyCFunction)stringlib_index, METH_VARARGS, _Py_index__doc__},
+ {"hex", (PyCFunction)bytes_hex, METH_NOARGS, hex__doc__},
+ {"index", (PyCFunction)bytes_index, METH_VARARGS, _Py_index__doc__},
{"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS,
_Py_isalnum__doc__},
{"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS,
@@ -2388,16 +2449,15 @@ bytes_methods[] = {
BYTES_MAKETRANS_METHODDEF
BYTES_PARTITION_METHODDEF
BYTES_REPLACE_METHODDEF
- {"rfind", (PyCFunction)stringlib_method_rfind, METH_VARARGS,
- _Py_rfind__doc__},
- {"rindex", (PyCFunction)stringlib_rindex, METH_VARARGS, _Py_rindex__doc__},
+ {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, _Py_rfind__doc__},
+ {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, _Py_rindex__doc__},
{"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, _Py_rjust__doc__},
BYTES_RPARTITION_METHODDEF
BYTES_RSPLIT_METHODDEF
BYTES_RSTRIP_METHODDEF
BYTES_SPLIT_METHODDEF
BYTES_SPLITLINES_METHODDEF
- {"startswith", (PyCFunction)stringlib_startswith, METH_VARARGS,
+ {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS,
_Py_startswith__doc__},
BYTES_STRIP_METHODDEF
{"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS,