Commit fd385e70 authored by Tim Peters's avatar Tim Peters

new_mmap_object(), Windows flavor.

On a box where sizeof(size_t) == 4, C doesn't define
what happens when a size_t value is shifted right by
32 bits, and this caused test_mmap to fail on Windows
in a debug build.  So use different code to break
the size apart depending on how large size_t actually
is.

This looks like an illusion, since lots of code in this
module still appears to assume sizes can't be more
than 32 bits (e.g., the internal _GetMapSize() still
returns an int), but at least test_mmap passes again.
parent 0051f5b4
...@@ -980,6 +980,8 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -980,6 +980,8 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
mmap_object *m_obj; mmap_object *m_obj;
PyObject *map_size_obj = NULL; PyObject *map_size_obj = NULL;
int map_size; int map_size;
DWORD size_hi; /* upper 32 bits of m_obj->size */
DWORD size_lo; /* lower 32 bits of m_obj->size */
char *tagname = ""; char *tagname = "";
DWORD dwErr = 0; DWORD dwErr = 0;
int fileno; int fileno;
...@@ -1089,11 +1091,23 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict) ...@@ -1089,11 +1091,23 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
m_obj->tagname = NULL; m_obj->tagname = NULL;
m_obj->access = (access_mode)access; m_obj->access = (access_mode)access;
/* DWORD is a 4-byte int. If we're on a box where size_t consumes
* more then 4 bytes, we need to break it apart. Else (size_t
* consumes 4 bytes), C doesn't define what happens if we shift
* right by 32, so we need different code.
*/
#if SIZEOF_SIZE_T > 4
size_hi = (DWORD)(m_obj->size >> 32);
size_lo = (DWORD)(m_obj->size & 0xFFFFFFFF);
#else
size_hi = 0;
size_lo = (DWORD)m_obj->size;
#endif
m_obj->map_handle = CreateFileMapping (m_obj->file_handle, m_obj->map_handle = CreateFileMapping (m_obj->file_handle,
NULL, NULL,
flProtect, flProtect,
(DWORD)(m_obj->size >> 32), size_hi,
(DWORD)(m_obj->size & 0xFFFFFFFF), size_lo,
m_obj->tagname); m_obj->tagname);
if (m_obj->map_handle != NULL) { if (m_obj->map_handle != NULL) {
m_obj->data = (char *) MapViewOfFile (m_obj->map_handle, m_obj->data = (char *) MapViewOfFile (m_obj->map_handle,
......
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