[Python-checkins] commit of r41748 - in python/trunk: Lib/test/test_mmap.py Misc/NEWS Modules/mmapmodule.c

Neal Norwitz nnorwitz at gmail.com
Sun Dec 18 04:38:07 CET 2005


I forgot to add that this should be backported.

On 12/17/05, neal.norwitz <python-checkins at python.org> wrote:
> Author: neal.norwitz
> Date: Sun Dec 18 04:34:22 2005
> New Revision: 41748
>
> Modified:
>    python/trunk/Lib/test/test_mmap.py
>    python/trunk/Misc/NEWS
>    python/trunk/Modules/mmapmodule.c
> Log:
> SF Patch #1365916, mmap fails on AMD64
>
> Fix some 64-bit issues due to mismatch format characters w/actual data types
>
>
>
> Modified: python/trunk/Lib/test/test_mmap.py
> ==============================================================================
> --- python/trunk/Lib/test/test_mmap.py  (original)
> +++ python/trunk/Lib/test/test_mmap.py  Sun Dec 18 04:34:22 2005
> @@ -356,6 +356,22 @@
>          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()
>
> Modified: python/trunk/Misc/NEWS
> ==============================================================================
> --- python/trunk/Misc/NEWS      (original)
> +++ python/trunk/Misc/NEWS      Sun Dec 18 04:34:22 2005
> @@ -197,6 +197,8 @@
>  Extension Modules
>  -----------------
>
> +- Patch #1365916: fix some unsafe 64-bit mmap methods.
> +
>  - Bug #1290333: Added a workaround for cjkcodecs' _codecs_cn build
>    problem on AIX.
>
>
> Modified: python/trunk/Modules/mmapmodule.c
> ==============================================================================
> --- python/trunk/Modules/mmapmodule.c   (original)
> +++ python/trunk/Modules/mmapmodule.c   Sun Dec 18 04:34:22 2005
> @@ -374,7 +374,7 @@
>  {
>         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 @@
>  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 @@
>  {
>         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 @@
>         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 @@
>         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 @@
>                 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 @@
>         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 @@
>                 return NULL;
>         }
>
> -       switch(access) {
> +       switch((access_mode)access) {
>         case ACCESS_READ:
>                 flProtect = PAGE_READONLY;
>                 dwDesiredAccess = FILE_MAP_READ;
> @@ -1048,7 +1048,7 @@
>         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,
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>


More information about the Python-checkins mailing list