summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-31 13:48:41 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-31 13:48:41 (GMT)
commit06b8b027112a491af996d8be25ee79959f8c18dc (patch)
treeb9c0836a86b64eba20815eb74f48dcc4cf38443e /Objects/bytesobject.c
parent674e9389e9fdadd622829f4833367ac3b38475b5 (diff)
downloadcpython-06b8b027112a491af996d8be25ee79959f8c18dc.zip
cpython-06b8b027112a491af996d8be25ee79959f8c18dc.tar.gz
cpython-06b8b027112a491af996d8be25ee79959f8c18dc.tar.bz2
Per Georg's suggestion, get rid of str.decode() (which always raises an
exception) and change bytes.find() to use _getbuffer(), so b"".find("") will raise TypeError instead of SystemError.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index ec37928..930b761 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1067,32 +1067,25 @@ Py_LOCAL_INLINE(Py_ssize_t)
bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
{
PyObject *subobj;
- const char *sub;
- Py_ssize_t sub_len;
+ PyBuffer subbuf;
Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
+ Py_ssize_t res;
if (!PyArg_ParseTuple(args, "O|O&O&:find/rfind/index/rindex", &subobj,
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
return -2;
- if (PyBytes_Check(subobj)) {
- sub = PyBytes_AS_STRING(subobj);
- sub_len = PyBytes_GET_SIZE(subobj);
- }
- /* XXX --> use the modern buffer interface */
- else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len)) {
- /* XXX - the "expected a character buffer object" is pretty
- confusing for a non-expert. remap to something else ? */
+ if (_getbuffer(subobj, &subbuf) < 0)
return -2;
- }
-
if (dir > 0)
- return stringlib_find_slice(
+ res = stringlib_find_slice(
PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
- sub, sub_len, start, end);
+ subbuf.buf, subbuf.len, start, end);
else
- return stringlib_rfind_slice(
+ res = stringlib_rfind_slice(
PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self),
- sub, sub_len, start, end);
+ subbuf.buf, subbuf.len, start, end);
+ PyObject_ReleaseBuffer(subobj, &subbuf);
+ return res;
}