-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mmap.flush does not check for errors on windows #46375
Comments
mmap.flush returns the result of the call to FlushViewOfFile as an Here's the current version of that function: static PyObject *
mmap_flush_method(mmap_object *self, PyObject *args)
{
Py_ssize_t offset = 0;
Py_ssize_t size = self->size;
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, "|nn:flush", &offset, &size))
return NULL;
if ((size_t)(offset + size) > self->size) {
PyErr_SetString(PyExc_ValueError, "flush values out of range");
return NULL;
}
#ifdef MS_WINDOWS
return PyInt_FromLong((long) FlushViewOfFile(self->data+offset, size));
#elif defined(UNIX)
/* XXX semantics of return value? */
/* XXX flags for msync? */
if (-1 == msync(self->data + offset, size, MS_SYNC)) {
PyErr_SetFromErrno(mmap_module_error);
return NULL;
}
return PyInt_FromLong(0);
#else
PyErr_SetString(PyExc_ValueError, "flush not supported on this system");
return NULL;
#endif
} |
attached is a patch. I hope it is ok to change the semantics a bit.
Now, flush returns None or raises an Exception. |
now this insanity is even documented with svn revision 62359 |
Perhaps it would be better if the patch came with unit tests. I agree PS : I have no power to commit or even accept a patch :) |
I thought about this too, but I don't know of a way to provoke an error. One could currently pass in a negative value for size (this isn't caught m.flush(500, -500) gives an 'error: [Errno 22] Invalid argument' on linux. but then you don't want to rely on another bug for testing purposes. |
This issue seems to be reproduced in following way.
> import mmap
|
I think we should be properly handling errors. If people agree I'll provide a new patch to cover code and doc changes, but I've no idea how to provide any form of unit test for the change. |
If we break compatibility in any case, what if return None instead of 0? The function always returning 0 looks strange. The function always returning None is common. |
I agree. We should definitely document it as a change, but I don't think there's anything useful you can do in the case of a flush failing anyway, so it seems unlikely that anyone could depend on the return value. Returning None for success and exception on error sounds like a good change. Technically this is no longer returning zero, as previously documented, so if anyone wants to get *really* pedantic, we're not returning the "failed" result for success ;) |
Thanks for the suggestions and for the reviews! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: