Commit 8856fb75 authored by Neal Norwitz's avatar Neal Norwitz

SF Patch #1365916, mmap fails on AMD64

Fix some 64-bit issues due to mismatch format characters w/actual data types
parent 84456bda
...@@ -356,6 +356,22 @@ def test_both(): ...@@ -356,6 +356,22 @@ def test_both():
finally: finally:
os.unlink(TESTFN) os.unlink(TESTFN)
# make move works everywhere (64-bit format problem earlier)
f = open(TESTFN, 'w+')
try: # unlink TESTFN no matter what
f.write("ABCDEabcde") # Arbitrary character
f.flush()
mf = mmap.mmap(f.fileno(), 10)
mf.move(5, 0, 5)
verify(mf[:] == "ABCDEABCDE", "Map move should have duplicated front 5")
mf.close()
f.close()
finally:
os.unlink(TESTFN)
print ' Test passed' print ' Test passed'
test_both() test_both()
...@@ -197,6 +197,8 @@ Core and builtins ...@@ -197,6 +197,8 @@ Core and builtins
Extension Modules Extension Modules
----------------- -----------------
- Patch #1365916: fix some unsafe 64-bit mmap methods.
- Bug #1290333: Added a workaround for cjkcodecs' _codecs_cn build - Bug #1290333: Added a workaround for cjkcodecs' _codecs_cn build
problem on AIX. problem on AIX.
......
...@@ -374,7 +374,7 @@ mmap_resize_method(mmap_object *self, ...@@ -374,7 +374,7 @@ mmap_resize_method(mmap_object *self,
{ {
unsigned long new_size; unsigned long new_size;
CHECK_VALID(NULL); CHECK_VALID(NULL);
if (!PyArg_ParseTuple (args, "l:resize", &new_size) || if (!PyArg_ParseTuple (args, "k:resize", &new_size) ||
!is_resizeable(self)) { !is_resizeable(self)) {
return NULL; return NULL;
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
...@@ -463,10 +463,10 @@ mmap_tell_method(mmap_object *self, PyObject *args) ...@@ -463,10 +463,10 @@ mmap_tell_method(mmap_object *self, PyObject *args)
static PyObject * static PyObject *
mmap_flush_method(mmap_object *self, PyObject *args) mmap_flush_method(mmap_object *self, PyObject *args)
{ {
size_t offset = 0; unsigned long offset = 0;
size_t size = self->size; unsigned long size = self->size;
CHECK_VALID(NULL); CHECK_VALID(NULL);
if (!PyArg_ParseTuple (args, "|ll:flush", &offset, &size)) { if (!PyArg_ParseTuple (args, "|kk:flush", &offset, &size)) {
return NULL; return NULL;
} else if ((offset + size) > self->size) { } else if ((offset + size) > self->size) {
PyErr_SetString (PyExc_ValueError, PyErr_SetString (PyExc_ValueError,
...@@ -539,7 +539,7 @@ mmap_move_method(mmap_object *self, PyObject *args) ...@@ -539,7 +539,7 @@ mmap_move_method(mmap_object *self, PyObject *args)
{ {
unsigned long dest, src, count; unsigned long dest, src, count;
CHECK_VALID(NULL); CHECK_VALID(NULL);
if (!PyArg_ParseTuple (args, "iii:move", &dest, &src, &count) || if (!PyArg_ParseTuple (args, "kkk:move", &dest, &src, &count) ||
!is_writeable(self)) { !is_writeable(self)) {
return NULL; return NULL;
} else { } else {
...@@ -863,7 +863,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -863,7 +863,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
PyObject *map_size_obj = NULL; PyObject *map_size_obj = NULL;
int map_size; int map_size;
int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ; int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ;
access_mode access = ACCESS_DEFAULT; int access = (int)ACCESS_DEFAULT;
static const char *keywords[] = {"fileno", "length", static const char *keywords[] = {"fileno", "length",
"flags", "prot", "flags", "prot",
"access", NULL}; "access", NULL};
...@@ -876,11 +876,11 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -876,11 +876,11 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
if (map_size < 0) if (map_size < 0)
return NULL; return NULL;
if ((access != ACCESS_DEFAULT) && if ((access != (int)ACCESS_DEFAULT) &&
((flags != MAP_SHARED) || ( prot != (PROT_WRITE | PROT_READ)))) ((flags != MAP_SHARED) || ( prot != (PROT_WRITE | PROT_READ))))
return PyErr_Format(PyExc_ValueError, return PyErr_Format(PyExc_ValueError,
"mmap can't specify both access and flags, prot."); "mmap can't specify both access and flags, prot.");
switch(access) { switch((access_mode)access) {
case ACCESS_READ: case ACCESS_READ:
flags = MAP_SHARED; flags = MAP_SHARED;
prot = PROT_READ; prot = PROT_READ;
...@@ -935,7 +935,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -935,7 +935,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
PyErr_SetFromErrno(mmap_module_error); PyErr_SetFromErrno(mmap_module_error);
return NULL; return NULL;
} }
m_obj->access = access; m_obj->access = (access_mode)access;
return (PyObject *)m_obj; return (PyObject *)m_obj;
} }
#endif /* UNIX */ #endif /* UNIX */
...@@ -951,7 +951,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -951,7 +951,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
DWORD dwErr = 0; DWORD dwErr = 0;
int fileno; int fileno;
HANDLE fh = 0; HANDLE fh = 0;
access_mode access = ACCESS_DEFAULT; int access = (access_mode)ACCESS_DEFAULT;
DWORD flProtect, dwDesiredAccess; DWORD flProtect, dwDesiredAccess;
static const char *keywords[] = { "fileno", "length", static const char *keywords[] = { "fileno", "length",
"tagname", "tagname",
...@@ -963,7 +963,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -963,7 +963,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
return NULL; return NULL;
} }
switch(access) { switch((access_mode)access) {
case ACCESS_READ: case ACCESS_READ:
flProtect = PAGE_READONLY; flProtect = PAGE_READONLY;
dwDesiredAccess = FILE_MAP_READ; dwDesiredAccess = FILE_MAP_READ;
...@@ -1048,7 +1048,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -1048,7 +1048,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
else else
m_obj->tagname = NULL; m_obj->tagname = NULL;
m_obj->access = access; m_obj->access = (access_mode)access;
m_obj->map_handle = CreateFileMapping (m_obj->file_handle, m_obj->map_handle = CreateFileMapping (m_obj->file_handle,
NULL, NULL,
flProtect, flProtect,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment