SF patch# 1752647 by Joe Gregorio.

Fixes to make test_mmap.py pass unit tests.
Moves the interface from being string based to being bytes based.
This commit is contained in:
Guido van Rossum 2007-07-16 19:29:02 +00:00
parent 88079f472e
commit b358a2c423
2 changed files with 49 additions and 47 deletions

View file

@ -206,7 +206,7 @@ mmap_read_line_method(mmap_object *self,
else
++eol; /* we're interested in the position after the
newline. */
result = PyString_FromStringAndSize(start, (eol - start));
result = PyBytes_FromStringAndSize(start, (eol - start));
self->pos += (eol - start);
return result;
}
@ -659,7 +659,7 @@ mmap_item(mmap_object *self, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return NULL;
}
return PyString_FromStringAndSize(self->data + i, 1);
return PyBytes_FromStringAndSize(self->data + i, 1);
}
static PyObject *
@ -677,7 +677,7 @@ mmap_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh)
else if ((size_t)ihigh > self->size)
ihigh = self->size;
return PyString_FromStringAndSize(self->data + ilow, ihigh-ilow);
return PyBytes_FromStringAndSize(self->data + ilow, ihigh-ilow);
}
static PyObject *
@ -720,19 +720,19 @@ mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v
"mmap object doesn't support slice deletion");
return -1;
}
if (! (PyString_Check(v)) ) {
if (! (PyBytes_Check(v)) ) {
PyErr_SetString(PyExc_IndexError,
"mmap slice assignment must be a string");
"mmap slice assignment must be bytes");
return -1;
}
if (PyString_Size(v) != (ihigh - ilow)) {
if (PyBytes_Size(v) != (ihigh - ilow)) {
PyErr_SetString(PyExc_IndexError,
"mmap slice assignment is wrong size");
return -1;
}
if (!is_writeable(self))
return -1;
buf = PyString_AsString(v);
buf = PyBytes_AsString(v);
memcpy(self->data + ilow, buf, ihigh-ilow);
return 0;
}
@ -752,14 +752,14 @@ mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
"mmap object doesn't support item deletion");
return -1;
}
if (! (PyString_Check(v) && PyString_Size(v)==1) ) {
if (! (PyBytes_Check(v) && PyBytes_Size(v)==1) ) {
PyErr_SetString(PyExc_IndexError,
"mmap assignment must be single-character string");
return -1;
}
if (!is_writeable(self))
return -1;
buf = PyString_AsString(v);
buf = PyBytes_AsString(v);
self->data[i] = buf[0];
return 0;
}