Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e564e7f

Browse files
committed
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.
1 parent dde1765 commit e564e7f

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Modules/mmapmodule.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,8 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
980980
mmap_object *m_obj;
981981
PyObject *map_size_obj = NULL;
982982
int map_size;
983+
DWORD size_hi; /* upper 32 bits of m_obj->size */
984+
DWORD size_lo; /* lower 32 bits of m_obj->size */
983985
char *tagname = "";
984986
DWORD dwErr = 0;
985987
int fileno;
@@ -1089,11 +1091,23 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
10891091
m_obj->tagname = NULL;
10901092

10911093
m_obj->access = (access_mode)access;
1094+
/* DWORD is a 4-byte int. If we're on a box where size_t consumes
1095+
* more then 4 bytes, we need to break it apart. Else (size_t
1096+
* consumes 4 bytes), C doesn't define what happens if we shift
1097+
* right by 32, so we need different code.
1098+
*/
1099+
#if SIZEOF_SIZE_T > 4
1100+
size_hi = (DWORD)(m_obj->size >> 32);
1101+
size_lo = (DWORD)(m_obj->size & 0xFFFFFFFF);
1102+
#else
1103+
size_hi = 0;
1104+
size_lo = (DWORD)m_obj->size;
1105+
#endif
10921106
m_obj->map_handle = CreateFileMapping (m_obj->file_handle,
10931107
NULL,
10941108
flProtect,
1095-
(DWORD)(m_obj->size >> 32),
1096-
(DWORD)(m_obj->size & 0xFFFFFFFF),
1109+
size_hi,
1110+
size_lo,
10971111
m_obj->tagname);
10981112
if (m_obj->map_handle != NULL) {
10991113
m_obj->data = (char *) MapViewOfFile (m_obj->map_handle,

0 commit comments

Comments
 (0)