mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
bpo-2122: Make mmap.flush() behave same on all platforms (GH-8692)
Previously, its behavior was platform-dependent and there was no error checking under Windows.
This commit is contained in:
parent
28853a249b
commit
e7d4b2f205
5 changed files with 36 additions and 13 deletions
|
|
@ -569,18 +569,21 @@ mmap_flush_method(mmap_object *self, PyObject *args)
|
|||
}
|
||||
|
||||
if (self->access == ACCESS_READ || self->access == ACCESS_COPY)
|
||||
return PyLong_FromLong(0);
|
||||
Py_RETURN_NONE;
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
return PyLong_FromLong((long) FlushViewOfFile(self->data+offset, size));
|
||||
if (!FlushViewOfFile(self->data+offset, size)) {
|
||||
PyErr_SetFromWindowsErr(GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
#elif defined(UNIX)
|
||||
/* XXX semantics of return value? */
|
||||
/* XXX flags for msync? */
|
||||
if (-1 == msync(self->data + offset, size, MS_SYNC)) {
|
||||
PyErr_SetFromErrno(PyExc_OSError);
|
||||
return NULL;
|
||||
}
|
||||
return PyLong_FromLong(0);
|
||||
Py_RETURN_NONE;
|
||||
#else
|
||||
PyErr_SetString(PyExc_ValueError, "flush not supported on this system");
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue