[Python-Dev] test_mmap failing?

Tim Peters tim.one@home.com
Wed, 9 May 2001 22:54:45 -0400


I checked in a change to mmapmodule.c earlier today, to close a patch
complaining about unused vrbl warnings.

Here's the changed routine before ("value" is unused):

mmap_read_byte_method(mmap_object *self,
                      PyObject *args)
{
        char value;
        char *where;
        CHECK_VALID(NULL);
        if (!PyArg_ParseTuple(args, ":read_byte"))
                return NULL;
        if (self->pos < self->size) {
                where = self->data + self->pos;
                value = (char) *(where);
                self->pos += 1;
                return Py_BuildValue("c", (char) *(where));
        } else {
               PyErr_SetString (PyExc_ValueError, "read byte out of
                                                   range");
                return NULL;
        }
}

and after:

mmap_read_byte_method(mmap_object *self,
                      PyObject *args)
{
        CHECK_VALID(NULL);
        if (!PyArg_ParseTuple(args, ":read_byte"))
                return NULL;
        if (self->pos < self->size) {
                char value = self->data[self->pos];
                self->pos += 1;
                return Py_BuildValue("c", value);
        } else {
                PyErr_SetString (PyExc_ValueError, "read byte out of
                                                    range");
                return NULL;
        }
}

I'll be damned if I can see any semantic difference, and test_mmap worked
fine on Windows after the change.  But Fred reported:

"""
the fix introduced breakage on Linux (kernel 2.2.17):

cj42289-a(.../python/linux-beowolf); ./python
../Lib/test/regrtest.py -v test_mmap
test_mmap
test_mmap
test test_mmap crashed -- exceptions.IOError: [Errno 22]
Invalid argument
Traceback (most recent call last):
  File "../Lib/test/regrtest.py", line 246, in runtest
    __import__(test, globals(), locals(), [])
  File "../Lib/test/test_mmap.py", line 124, in ?
    test_both()
  File "../Lib/test/test_mmap.py", line 14, in
test_both
    f.write('\0'* PAGESIZE)
IOError: [Errno 22] Invalid argument
1 test failed: test_mmap
"""

However, at the point that's failing, test_mmap hasn't even *created* an
mmap'ed file yet, let alone tried to read from it.  The only thing test_mmap
did so far is (the first comment is bogus -- that's the builtin Python open()
function):

    # Create an mmap'ed file   # THIS IS A BOGUS COMMENT
    f = open('foo', 'w+')

    # Write 2 pages worth of data to the file
    f.write('\0'* PAGESIZE)    # THIS IS THE LINE IT'S DYING ON

But having suffered too many "impossible problems" the last 36 hours, my
confidence is shot <0.93 wink>.  Is test_mmap failing for anyone else under
current CVS?  Fred, are you *sure* it fails for you -- if so, does the
problem actually go away if you revert mmapmodule.c?

looking-for-sense-in-all-the-wrong-places-ly y'rs  - tim