summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2005-12-18 03:34:22 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2005-12-18 03:34:22 (GMT)
commit8856fb750b3417fc4770ad70cce56b4aad61c225 (patch)
tree76d2a3c73215958c035da7fb01ec21bfab86c1c6
parent84456bdab35ea8a4c75eeaee6f3320c8c4280007 (diff)
downloadcpython-8856fb750b3417fc4770ad70cce56b4aad61c225.zip
cpython-8856fb750b3417fc4770ad70cce56b4aad61c225.tar.gz
cpython-8856fb750b3417fc4770ad70cce56b4aad61c225.tar.bz2
SF Patch #1365916, mmap fails on AMD64
Fix some 64-bit issues due to mismatch format characters w/actual data types
-rw-r--r--Lib/test/test_mmap.py16
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/mmapmodule.c24
3 files changed, 30 insertions, 12 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 0b9cea9..849f170 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -356,6 +356,22 @@ def test_both():
finally:
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'
test_both()
diff --git a/Misc/NEWS b/Misc/NEWS
index d4aaa74..8b79fb6 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -197,6 +197,8 @@ Core and builtins
Extension Modules
-----------------
+- Patch #1365916: fix some unsafe 64-bit mmap methods.
+
- Bug #1290333: Added a workaround for cjkcodecs' _codecs_cn build
problem on AIX.
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 7796ced..dbb3fcd 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -374,7 +374,7 @@ mmap_resize_method(mmap_object *self,
{
unsigned long new_size;
CHECK_VALID(NULL);
- if (!PyArg_ParseTuple (args, "l:resize", &new_size) ||
+ if (!PyArg_ParseTuple (args, "k:resize", &new_size) ||
!is_resizeable(self)) {
return NULL;
#ifdef MS_WINDOWS
@@ -463,10 +463,10 @@ mmap_tell_method(mmap_object *self, PyObject *args)
static PyObject *
mmap_flush_method(mmap_object *self, PyObject *args)
{
- size_t offset = 0;
- size_t size = self->size;
+ unsigned long offset = 0;
+ unsigned long size = self->size;
CHECK_VALID(NULL);
- if (!PyArg_ParseTuple (args, "|ll:flush", &offset, &size)) {
+ if (!PyArg_ParseTuple (args, "|kk:flush", &offset, &size)) {
return NULL;
} else if ((offset + size) > self->size) {
PyErr_SetString (PyExc_ValueError,
@@ -539,7 +539,7 @@ mmap_move_method(mmap_object *self, PyObject *args)
{
unsigned long dest, src, count;
CHECK_VALID(NULL);
- if (!PyArg_ParseTuple (args, "iii:move", &dest, &src, &count) ||
+ if (!PyArg_ParseTuple (args, "kkk:move", &dest, &src, &count) ||
!is_writeable(self)) {
return NULL;
} else {
@@ -863,7 +863,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
PyObject *map_size_obj = NULL;
int map_size;
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",
"flags", "prot",
"access", NULL};
@@ -876,11 +876,11 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
if (map_size < 0)
return NULL;
- if ((access != ACCESS_DEFAULT) &&
+ if ((access != (int)ACCESS_DEFAULT) &&
((flags != MAP_SHARED) || ( prot != (PROT_WRITE | PROT_READ))))
return PyErr_Format(PyExc_ValueError,
"mmap can't specify both access and flags, prot.");
- switch(access) {
+ switch((access_mode)access) {
case ACCESS_READ:
flags = MAP_SHARED;
prot = PROT_READ;
@@ -935,7 +935,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
PyErr_SetFromErrno(mmap_module_error);
return NULL;
}
- m_obj->access = access;
+ m_obj->access = (access_mode)access;
return (PyObject *)m_obj;
}
#endif /* UNIX */
@@ -951,7 +951,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
DWORD dwErr = 0;
int fileno;
HANDLE fh = 0;
- access_mode access = ACCESS_DEFAULT;
+ int access = (access_mode)ACCESS_DEFAULT;
DWORD flProtect, dwDesiredAccess;
static const char *keywords[] = { "fileno", "length",
"tagname",
@@ -963,7 +963,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
return NULL;
}
- switch(access) {
+ switch((access_mode)access) {
case ACCESS_READ:
flProtect = PAGE_READONLY;
dwDesiredAccess = FILE_MAP_READ;
@@ -1048,7 +1048,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
else
m_obj->tagname = NULL;
- m_obj->access = access;
+ m_obj->access = (access_mode)access;
m_obj->map_handle = CreateFileMapping (m_obj->file_handle,
NULL,
flProtect,