diff options
author | Georg Brandl <georg@python.org> | 2008-01-19 20:08:23 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-01-19 20:08:23 (GMT) |
commit | fceab5a385f121029bfa7e855f7fd1aca1eb8c3f (patch) | |
tree | 91d552ec2d068287efc8b8f3769cd6865c3c0620 /Modules/mmapmodule.c | |
parent | 2336bddd5dba559db950e8b5fa73257fc62d1fc3 (diff) | |
download | cpython-fceab5a385f121029bfa7e855f7fd1aca1eb8c3f.zip cpython-fceab5a385f121029bfa7e855f7fd1aca1eb8c3f.tar.gz cpython-fceab5a385f121029bfa7e855f7fd1aca1eb8c3f.tar.bz2 |
Merged revisions 60080-60089,60091-60093 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60080 | andrew.kuchling | 2008-01-19 17:26:13 +0100 (Sat, 19 Jan 2008) | 2 lines
Patch #742598 from Michael Pomraning: add .timeout attribute to SocketServer that will call
.handle_timeout() method when no requests are received within the timeout period.
........
r60081 | andrew.kuchling | 2008-01-19 17:34:09 +0100 (Sat, 19 Jan 2008) | 1 line
Add item
........
r60082 | christian.heimes | 2008-01-19 17:39:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Disabled test_xmlrpc:test_404. It's causing lots of false alarms.
I also disabled a test in test_ssl which requires network access to svn.python.org. This fixes a bug Skip has reported a while ago.
........
r60083 | georg.brandl | 2008-01-19 18:38:53 +0100 (Sat, 19 Jan 2008) | 2 lines
Clarify thread.join() docs. #1873.
........
r60084 | georg.brandl | 2008-01-19 19:02:46 +0100 (Sat, 19 Jan 2008) | 2 lines
#1782: don't leak in error case in PyModule_AddXxxConstant. Patch by Hrvoje Nik?\197?\161i?\196?\135.
........
r60085 | andrew.kuchling | 2008-01-19 19:08:52 +0100 (Sat, 19 Jan 2008) | 1 line
Sort two names into position
........
r60086 | andrew.kuchling | 2008-01-19 19:18:41 +0100 (Sat, 19 Jan 2008) | 2 lines
Patch #976880: add mmap .rfind() method, and 'end' paramter to .find().
Contributed by John Lenton.
........
r60087 | facundo.batista | 2008-01-19 19:38:19 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix #1693149. Now you can pass several modules separated by
coma to trace.py in the same --ignore-module option.
Thanks Raghuram Devarakonda.
........
r60088 | facundo.batista | 2008-01-19 19:45:46 +0100 (Sat, 19 Jan 2008) | 3 lines
Comment in NEWS regarding the change in trace.py.
........
r60089 | skip.montanaro | 2008-01-19 19:47:24 +0100 (Sat, 19 Jan 2008) | 2 lines
missing from r60088 checkin.
........
r60091 | andrew.kuchling | 2008-01-19 20:14:05 +0100 (Sat, 19 Jan 2008) | 1 line
Add item
........
r60092 | georg.brandl | 2008-01-19 20:27:05 +0100 (Sat, 19 Jan 2008) | 4 lines
Fix #1679: "0x" was taken as a valid integer literal.
Fixes the tokenizer, tokenize.py and int() to reject this.
Patches by Malte Helmert.
........
r60093 | georg.brandl | 2008-01-19 20:48:19 +0100 (Sat, 19 Jan 2008) | 3 lines
Fix #1146: TextWrap vs words 1-character shorter than the width.
Patch by Quentin Gallet-Gilles.
........
Diffstat (limited to 'Modules/mmapmodule.c')
-rw-r--r-- | Modules/mmapmodule.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 8302767..ab9eedc 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -254,19 +254,22 @@ mmap_read_method(mmap_object *self, } static PyObject * -mmap_find_method(mmap_object *self, - PyObject *args) +mmap_gfind(mmap_object *self, + PyObject *args, + int reverse) { Py_ssize_t start = self->pos; + Py_ssize_t end = self->size; char *needle; Py_ssize_t len; CHECK_VALID(NULL); - if (!PyArg_ParseTuple(args, "s#|n:find", &needle, &len, &start)) { + if (!PyArg_ParseTuple(args, reverse ? "s#|nn:rfind" : "s#|nn:find", + &needle, &len, &start, &end)) { return NULL; } else { char *p; - char *e = self->data + self->size; + char sign = reverse ? -1 : 1; if (start < 0) start += self->size; @@ -275,7 +278,18 @@ mmap_find_method(mmap_object *self, else if ((size_t)start > self->size) start = self->size; - for (p = self->data + start; p + len <= e; ++p) { + if (end < 0) + end += self->size; + if (end < 0) + end = 0; + else if ((size_t)end > self->size) + end = self->size; + + start += (Py_ssize_t)self->data; + end += (Py_ssize_t)self->data; + + for (p = (char *)(reverse ? end - len : start); + p >= (char *)start && p + len <= (char *)end; p+=sign) { Py_ssize_t i; for (i = 0; i < len && needle[i] == p[i]; ++i) /* nothing */; @@ -287,6 +301,20 @@ mmap_find_method(mmap_object *self, } } +static PyObject * +mmap_find_method(mmap_object *self, + PyObject *args) +{ + return mmap_gfind(self, args, 0); +} + +static PyObject * +mmap_rfind_method(mmap_object *self, + PyObject *args) +{ + return mmap_gfind(self, args, 1); +} + static int is_writable(mmap_object *self) { @@ -604,6 +632,7 @@ mmap_move_method(mmap_object *self, PyObject *args) static struct PyMethodDef mmap_object_methods[] = { {"close", (PyCFunction) mmap_close_method, METH_NOARGS}, {"find", (PyCFunction) mmap_find_method, METH_VARARGS}, + {"rfind", (PyCFunction) mmap_rfind_method, METH_VARARGS}, {"flush", (PyCFunction) mmap_flush_method, METH_VARARGS}, {"move", (PyCFunction) mmap_move_method, METH_VARARGS}, {"read", (PyCFunction) mmap_read_method, METH_VARARGS}, |