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

Skip to content

Commit 9e719b6

Browse files
committed
Merged revisions 88460,88464,88466,88486,88511,88652 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r88460 | antoine.pitrou | 2011-02-21 19:03:13 +0100 (lun., 21 févr. 2011) | 4 lines Issue #10276: Fix the results of zlib.crc32() and zlib.adler32() on buffers larger than 4GB. Patch by Nadeem Vawda. ........ r88464 | antoine.pitrou | 2011-02-21 20:05:08 +0100 (lun., 21 févr. 2011) | 3 lines Fix issues on 32-bit systems introduced by r88460 ........ r88466 | antoine.pitrou | 2011-02-21 20:28:40 +0100 (lun., 21 févr. 2011) | 3 lines Fix compile error under MSVC introduced by r88460. ........ r88486 | antoine.pitrou | 2011-02-22 00:41:12 +0100 (mar., 22 févr. 2011) | 5 lines Issue #4681: Allow mmap() to work on file sizes and offsets larger than 4GB, even on 32-bit builds. Initial patch by Ross Lagerwall, adapted for 32-bit Windows. ........ r88511 | antoine.pitrou | 2011-02-22 22:42:56 +0100 (mar., 22 févr. 2011) | 4 lines Issue #11277: finally fix Snow Leopard crash following r88460. (probably an OS-related issue with mmap) ........ r88652 | antoine.pitrou | 2011-02-26 16:58:05 +0100 (sam., 26 févr. 2011) | 4 lines Issue #9931: Fix hangs in GUI tests under Windows in certain conditions. Patch by Hirokazu Yamamoto. ........
1 parent 6c04569 commit 9e719b6

6 files changed

Lines changed: 210 additions & 54 deletions

File tree

Lib/test/support.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,36 @@ def forget(modname):
198198
# is exited) but there is a .pyo file.
199199
unlink(os.path.join(dirname, modname + '.pyo'))
200200

201+
# On some platforms, should not run gui test even if it is allowed
202+
# in `use_resources'.
203+
if sys.platform.startswith('win'):
204+
import ctypes
205+
import ctypes.wintypes
206+
def _is_gui_available():
207+
UOI_FLAGS = 1
208+
WSF_VISIBLE = 0x0001
209+
class USEROBJECTFLAGS(ctypes.Structure):
210+
_fields_ = [("fInherit", ctypes.wintypes.BOOL),
211+
("fReserved", ctypes.wintypes.BOOL),
212+
("dwFlags", ctypes.wintypes.DWORD)]
213+
dll = ctypes.windll.user32
214+
h = dll.GetProcessWindowStation()
215+
if not h:
216+
raise ctypes.WinError()
217+
uof = USEROBJECTFLAGS()
218+
needed = ctypes.wintypes.DWORD()
219+
res = dll.GetUserObjectInformationW(h,
220+
UOI_FLAGS,
221+
ctypes.byref(uof),
222+
ctypes.sizeof(uof),
223+
ctypes.byref(needed))
224+
if not res:
225+
raise ctypes.WinError()
226+
return bool(uof.dwFlags & WSF_VISIBLE)
227+
else:
228+
def _is_gui_available():
229+
return True
230+
201231
def is_resource_enabled(resource):
202232
"""Test whether a resource is enabled. Known resources are set by
203233
regrtest.py."""
@@ -208,6 +238,8 @@ def requires(resource, msg=None):
208238
209239
If the caller's module is __main__ then automatically return True. The
210240
possibility of False being returned occurs when regrtest.py is executing."""
241+
if resource == 'gui' and not _is_gui_available():
242+
raise unittest.SkipTest("Cannot use the 'gui' resource")
211243
# see if the caller's module is __main__ - if so, treat as if
212244
# the resource was set
213245
if sys._getframe(1).f_globals.get("__name__") == "__main__":
@@ -869,6 +901,8 @@ def _id(obj):
869901
return obj
870902

871903
def requires_resource(resource):
904+
if resource == 'gui' and not _is_gui_available():
905+
return unittest.skip("resource 'gui' is not available")
872906
if is_resource_enabled(resource):
873907
return _id
874908
else:

Lib/test/test_mmap.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from test.support import TESTFN, run_unittest, import_module
1+
from test.support import TESTFN, run_unittest, import_module, unlink, requires
22
import unittest
3-
import os, re, itertools, socket
3+
import os, re, itertools, socket, sys
44

55
# Skip test if we can't import mmap.
66
mmap = import_module('mmap')
@@ -636,8 +636,63 @@ def test_invalid_descriptor(self):
636636
finally:
637637
s.close()
638638

639+
640+
class LargeMmapTests(unittest.TestCase):
641+
642+
def setUp(self):
643+
unlink(TESTFN)
644+
645+
def tearDown(self):
646+
unlink(TESTFN)
647+
648+
def _working_largefile(self):
649+
# Only run if the current filesystem supports large files.
650+
f = open(TESTFN, 'wb', buffering=0)
651+
try:
652+
f.seek(0x80000001)
653+
f.write(b'x')
654+
f.flush()
655+
except (IOError, OverflowError):
656+
raise unittest.SkipTest("filesystem does not have largefile support")
657+
finally:
658+
f.close()
659+
unlink(TESTFN)
660+
661+
def test_large_offset(self):
662+
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
663+
requires('largefile',
664+
'test requires %s bytes and a long time to run' % str(0x180000000))
665+
self._working_largefile()
666+
with open(TESTFN, 'wb') as f:
667+
f.seek(0x14FFFFFFF)
668+
f.write(b" ")
669+
670+
with open(TESTFN, 'rb') as f:
671+
m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ)
672+
try:
673+
self.assertEqual(m[0xFFFFFFF], 32)
674+
finally:
675+
m.close()
676+
677+
def test_large_filesize(self):
678+
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
679+
requires('largefile',
680+
'test requires %s bytes and a long time to run' % str(0x180000000))
681+
self._working_largefile()
682+
with open(TESTFN, 'wb') as f:
683+
f.seek(0x17FFFFFFF)
684+
f.write(b" ")
685+
686+
with open(TESTFN, 'rb') as f:
687+
m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
688+
try:
689+
self.assertEqual(m.size(), 0x180000000)
690+
finally:
691+
m.close()
692+
693+
639694
def test_main():
640-
run_unittest(MmapTests)
695+
run_unittest(MmapTests, LargeMmapTests)
641696

642697
if __name__ == '__main__':
643698
test_main()

Lib/test/test_zlib.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
from test import support
33
import binascii
44
import random
5-
from test.support import precisionbigmemtest, _1G
5+
import sys
6+
from test.support import precisionbigmemtest, _1G, _4G
67

78
zlib = support.import_module('zlib')
89

10+
try:
11+
import mmap
12+
except ImportError:
13+
mmap = None
14+
915

1016
class ChecksumTestCase(unittest.TestCase):
1117
# checksum test cases
@@ -57,6 +63,28 @@ def test_same_as_binascii_crc32(self):
5763
self.assertEqual(binascii.crc32(b'spam'), zlib.crc32(b'spam'))
5864

5965

66+
# Issue #10276 - check that inputs >=4GB are handled correctly.
67+
class ChecksumBigBufferTestCase(unittest.TestCase):
68+
69+
def setUp(self):
70+
with open(support.TESTFN, "wb+") as f:
71+
f.seek(_4G)
72+
f.write(b"asdf")
73+
with open(support.TESTFN, "rb") as f:
74+
self.mapping = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
75+
76+
def tearDown(self):
77+
self.mapping.close()
78+
support.unlink(support.TESTFN)
79+
80+
@unittest.skipUnless(mmap, "mmap() is not available.")
81+
@unittest.skipUnless(sys.maxsize > _4G, "Can't run on a 32-bit system.")
82+
@unittest.skipUnless(support.is_resource_enabled("largefile"),
83+
"May use lots of disk space.")
84+
def test_big_buffer(self):
85+
self.assertEqual(zlib.crc32(self.mapping), 3058686908)
86+
self.assertEqual(zlib.adler32(self.mapping), 82837919)
87+
6088

6189
class ExceptionTestCase(unittest.TestCase):
6290
# make sure we generate some expected errors
@@ -567,6 +595,7 @@ def choose_lines(source, number, seed=None, generator=random):
567595
def test_main():
568596
support.run_unittest(
569597
ChecksumTestCase,
598+
ChecksumBigBufferTestCase,
570599
ExceptionTestCase,
571600
CompressTestCase,
572601
CompressObjectTestCase

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ Core and Builtins
3737
Library
3838
-------
3939

40+
- Issue #10276: Fix the results of zlib.crc32() and zlib.adler32() on buffers
41+
larger than 4GB. Patch by Nadeem Vawda.
42+
43+
- Issue #4681: Allow mmap() to work on file sizes and offsets larger than
44+
4GB, even on 32-bit builds. Initial patch by Ross Lagerwall, adapted for
45+
32-bit Windows.
46+
4047
- email.header.Header was incorrectly encoding folding white space when
4148
rfc2047-encoding header values with embedded newlines, leaving them
4249
without folding whitespace. It now uses the continuation_ws, as it

0 commit comments

Comments
 (0)