Index: Modules/mmapmodule.c =================================================================== --- Modules/mmapmodule.c (revision 73839) +++ Modules/mmapmodule.c (working copy) @@ -323,20 +323,33 @@ static int is_writeable(mmap_object *self) { - if (self->access != ACCESS_READ) - return 1; - PyErr_Format(PyExc_TypeError, "mmap can't modify a readonly memory map."); - return 0; + if (self->access == ACCESS_READ) { + PyErr_Format(PyExc_TypeError, "mmap can't modify a readonly memory map"); + return 0; + } + return 1; } static int is_resizeable(mmap_object *self) { - if ((self->access == ACCESS_WRITE) || (self->access == ACCESS_DEFAULT)) - return 1; - PyErr_Format(PyExc_TypeError, - "mmap can't resize a readonly or copy-on-write memory map."); - return 0; + if ((self->access != ACCESS_WRITE) && (self->access != ACCESS_DEFAULT)) { + PyErr_Format(PyExc_TypeError, + "mmap can't resize a readonly or copy-on-write memory map"); + return 0; + } +#if defined(MS_WINDOWS) + if (self->file_handle == INVALID_HANDLE_VALUE) { + PyErr_Format(PyExc_TypeError, "mmap can't resize an anonymous memory map"); + return 0; + } +#elif defined(UNIX) + if (self->fd == -1) { + PyErr_Format(PyExc_TypeError, "mmap can't resize an anonymous memory map"); + return 0; + } +#endif + return 1; }