]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Whitespace normalization.
authorTim Peters <tim.peters@gmail.com>
Sun, 18 Jan 2004 20:29:55 +0000 (20:29 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 18 Jan 2004 20:29:55 +0000 (20:29 +0000)
34 files changed:
Lib/StringIO.py
Lib/_strptime.py
Lib/distutils/command/build_ext.py
Lib/httplib.py
Lib/random.py
Lib/sre_parse.py
Lib/test/pystone.py
Lib/test/test_applesingle.py
Lib/test/test_codeccallbacks.py
Lib/test/test_codecencodings_cn.py
Lib/test/test_codecencodings_jp.py
Lib/test/test_codecencodings_kr.py
Lib/test/test_codecencodings_tw.py
Lib/test/test_codecmaps_cn.py
Lib/test/test_codecmaps_jp.py
Lib/test/test_codecmaps_kr.py
Lib/test/test_codecmaps_tw.py
Lib/test/test_curses.py
Lib/test/test_descr.py
Lib/test/test_difflib.py
Lib/test/test_marshal.py
Lib/test/test_md5.py
Lib/test/test_multibytecodec.py
Lib/test/test_multibytecodec_support.py
Lib/test/test_os.py
Lib/test/test_re.py
Lib/test/test_set.py
Lib/test/test_sort.py
Lib/test/test_support.py
Lib/test/test_unicode_file.py
Lib/test/test_urllib2.py
Lib/traceback.py
Lib/urllib2.py
Objects/listobject.c

index 6422f76647cff5db08482472bf1a724256021475..4739d1395dd00dd7a096ec134c818db8132f876a 100644 (file)
@@ -142,7 +142,7 @@ class StringIO:
         return lines
 
     def truncate(self, size=None):
-        _complain_ifclosed(self.closed) 
+        _complain_ifclosed(self.closed)
         if size is None:
             size = self.pos
         elif size < 0:
index df04674d027d855bda4509cd6f8e284568f5555b..e93d14682723c64282494b23920fe6d7554b188b 100644 (file)
@@ -365,7 +365,7 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
                     # be able to tell what timezone has daylight savings
                     if time.tzname[0] == time.tzname[1] and \
                        time.daylight:
-                            break
+                        break
                     else:
                         tz = value
                         break
index 0c377681793f02be91084cae0eb46cfb75f07702..7fff422268483327a0de2a5449290fffe3af1a42 100644 (file)
@@ -171,7 +171,8 @@ class build_ext (Command):
             # Append the source distribution include and library directories,
             # this allows distutils on windows to work in the source tree
             self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
-            self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))
+            self.library_dirs.append(os.path.join(sys.exec_prefix, 'PC', 'VC6'))
+            #self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))
 
         # OS/2 (EMX) doesn't support Debug vs Release builds, but has the 
         # import libraries in its "Config" subdirectory
index 0dfea33285bdb2f3c362891028e84af628a5f27e..a23caf5651c689d73994d7b1df659491d18b827f 100644 (file)
@@ -610,7 +610,7 @@ class HTTPConnection:
         if self.__response and self.__response.isclosed():
             self.__response = None
 
-       
+
         # in certain cases, we cannot issue another request on this connection.
         # this occurs when:
         #   1) we are in the process of sending a request.   (_CS_REQ_STARTED)
@@ -731,7 +731,7 @@ class HTTPConnection:
         # If headers already contains a host header, then define the
         # optional skip_host argument to putrequest().  The check is
         # harder because field names are case insensitive.
-        if 'host' in [k.lower() for k in headers]:                
+        if 'host' in [k.lower() for k in headers]:
             self.putrequest(method, url, skip_host=1)
         else:
             self.putrequest(method, url)
index 1f279bb8782700f8690ee2e9ad88a85f72aca636..a2415ae6bd989e43f4b7d8b99bfe107f14f873f9 100644 (file)
@@ -177,7 +177,7 @@ class Random(_random.Random):
             # compatibility).
 
             if width >= maxwidth:
-                    return int(istart + self._randbelow(width))
+                return int(istart + self._randbelow(width))
             return int(istart + int(self.random()*width))
         if step == 1:
             raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width)
index fe5d143482fbf31092cea3524fd87dd7e5f66966..9482bf81b0a67a3fe6ed2e2d06e01ffc73675f0b 100644 (file)
@@ -365,9 +365,9 @@ def _parse_sub(source, state, nested=1):
     return subpattern
 
 def _parse_sub_cond(source, state, condgroup):
-    item_yes = _parse(source, state) 
+    item_yes = _parse(source, state)
     if source.match("|"):
-        item_no = _parse(source, state) 
+        item_no = _parse(source, state)
         if source.match("|"):
             raise error, "conditional backref with more than two branches"
     else:
index 168c399d026c4d86fb8e151b386ab74003d5de04..0a25981eb68cbd6d8d3be1cce126175f835234c4 100755 (executable)
@@ -264,4 +264,3 @@ if __name__ == '__main__':
     else:
         loops = LOOPS
     main(loops)
-
index eeb01c5d35673ce80fb8bb14c90abdf038d85370..2a2d60ad32e33704dbefe1c5eba39c74a62705d8 100644 (file)
@@ -55,7 +55,7 @@ class TestApplesingle(unittest.TestCase):
         applesingle.decode(test_support.TESTFN, TESTFN2)
         self.compareData(False, dataforkdata)
         self.compareData(True, resourceforkdata)
-        
+
     def test_applesingle_resonly(self):
         try:
             os.unlink(TESTFN2)
index 289e838b5887559eb814ab4029dd1bd5b9d39934..ac561cc219074653c27b8adf45bf61b0209cac09 100644 (file)
@@ -697,7 +697,7 @@ class CodecCallbackTest(unittest.TestCase):
             ord(">"): u"&gt;",
             ord('"'): u"&quot;",
         }
-        
+
         for n in (1, 10, 100, 1000):
             text = u'abc<def>ghi'*n
             text.translate(charmap)
index 3960c9cf67e5b1887b140265fd5796dc7f92f0fc..269e00ae487423e1ed7e314001abef6067de3bc3 100644 (file)
@@ -27,8 +27,8 @@ class Test_GBK(test_multibytecodec_support.TestBase, unittest.TestCase):
     tstring = test_multibytecodec_support.load_teststring('gbk')
     codectests = (
         # invalid bytes
-        ("abc\x80\x80\xc1\xc4", "strict",  None),  
-        ("abc\xc8", "strict",  None),  
+        ("abc\x80\x80\xc1\xc4", "strict",  None),
+        ("abc\xc8", "strict",  None),
         ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),
         ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
         ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\u804a"),
@@ -58,4 +58,3 @@ def test_main():
 
 if __name__ == "__main__":
     test_main()
-
index 264b6b991f2f5bb1bac109a0a030111aa0b4e22d..f5745116e7fedc1dbffbf749ce67e327ef9a75ff 100644 (file)
@@ -131,4 +131,3 @@ def test_main():
 
 if __name__ == "__main__":
     test_main()
-
index 17615ba8f3dae0de17e679ea813f807a287dca69..449237d3b114cca3430820cefa6a0358e50cc633 100644 (file)
@@ -54,4 +54,3 @@ def test_main():
 
 if __name__ == "__main__":
     test_main()
-
index 3e2fa8b9bf4bab0b053f386619afdbcaf63c0d49..897f060605089c9f6679ed6dcf0e2d477f42d15f 100644 (file)
@@ -28,4 +28,3 @@ def test_main():
 
 if __name__ == "__main__":
     test_main()
-
index 919c81bd0385a38981de582fb63ba61864a134d9..337ac912ea051998dc31aa4f92b9d8b36e9dd230 100644 (file)
@@ -31,4 +31,3 @@ def test_main():
 test_multibytecodec_support.register_skip_expected(TestGB2312Map, TestGBKMap)
 if __name__ == "__main__":
     test_main()
-
index ef491781c547794f34a43c6a651657d5d6f570ab..9519da2e5e17504ca44d8adb337e8e52667ee702 100644 (file)
@@ -87,4 +87,3 @@ test_multibytecodec_support.register_skip_expected(TestCP932Map,
     TestSJISX0213Map)
 if __name__ == "__main__":
     test_main()
-
index 910396ed7e1928e27efb12e4ea46e78737ce0800..9a71939158a7ae7c23028c9c4ab696d012f13191 100644 (file)
@@ -48,4 +48,3 @@ test_multibytecodec_support.register_skip_expected(TestCP949Map,
     TestEUCKRMap, TestJOHABMap)
 if __name__ == "__main__":
     test_main()
-
index 9b28fef939abb6eb4a57abdec01ee6460d399c01..2f416605c735fe0b2c528c6cfb2f5a3c14b87e1b 100644 (file)
@@ -36,4 +36,3 @@ def test_main():
 test_multibytecodec_support.register_skip_expected(TestBIG5Map, TestCP950Map)
 if __name__ == "__main__":
     test_main()
-
index 10ebe09243e25e96154bdb9597b9f55a5bb843f2..2065ef24a1a728c45816d1d7355d4b5bff6700d8 100644 (file)
@@ -204,7 +204,7 @@ def unit_tests():
                          ]:
         if ascii.unctrl(ch) != expected:
             print 'curses.unctrl fails on character', repr(ch)
-            
+
 
 
 def main(stdscr):
@@ -215,7 +215,7 @@ def main(stdscr):
     finally:
         curses.resetty()
 
-    
+
 if __name__ == '__main__':
     curses.wrapper(main)
     unit_tests()
index e001562f971e2da79474153e77d3464160237fca..d0500e6c168f45f592f67a385432ede3f1906511 100644 (file)
@@ -3966,7 +3966,7 @@ def vicious_descriptor_nonsense():
     # this makes a crash more likely:
     import gc; gc.collect()
     vereq(hasattr(c, 'attr'), False)
-    
+
 
 def test_main():
     weakref_segfault() # Must be first, somehow
index 3879967ddb860fa780d0041379d64132aabcb634..17037547f673180366740c0ffc5d057148cbb1ad 100644 (file)
@@ -15,4 +15,3 @@ class TestSFbugs(unittest.TestCase):
 Doctests = doctest.DocTestSuite(difflib)
 
 test_support.run_unittest(TestSFbugs, Doctests)
-
index ad45c2919f61fc88b6d9f24af25d261c8a1ac1a5..f971d11f8f7abac5e131b76ddd6540c87b940db4 100644 (file)
@@ -55,7 +55,7 @@ class IntTestCase(unittest.TestCase):
             new = marshal.load(file(test_support.TESTFN, "rb"))
             self.assertEqual(b, new)
             self.assertEqual(type(b), type(new))
-            
+
 class FloatTestCase(unittest.TestCase):
     def test_floats(self):
         # Test a few floats
@@ -122,7 +122,7 @@ class StringTestCase(unittest.TestCase):
             marshal.load(file(test_support.TESTFN, "rb"))
             self.assertEqual(s, new)
         os.unlink(test_support.TESTFN)
-            
+
 class ExceptionTestCase(unittest.TestCase):
     def test_exceptions(self):
         new = marshal.loads(marshal.dumps(StopIteration))
@@ -151,7 +151,7 @@ class ContainerTestCase(unittest.TestCase):
         marshal.load(file(test_support.TESTFN, "rb"))
         self.assertEqual(self.d, new)
         os.unlink(test_support.TESTFN)
-        
+
     def test_list(self):
         lst = self.d.items()
         new = marshal.loads(marshal.dumps(lst))
@@ -169,7 +169,7 @@ class ContainerTestCase(unittest.TestCase):
         marshal.load(file(test_support.TESTFN, "rb"))
         self.assertEqual(t, new)
         os.unlink(test_support.TESTFN)
-        
+
 class BugsTestCase(unittest.TestCase):
     def test_bug_5888452(self):
         # Simple-minded check for SF 588452: Debug build crashes
index bd0fb2eff5fc9497c52b1e2b55b04fe4335f81e7..1f08568508b7e537911fb323c595e3bcc6ea045e 100644 (file)
@@ -26,9 +26,9 @@ class MD5_Test(unittest.TestCase):
         eq('abc', '900150983cd24fb0d6963f7d28e17f72')
         eq('message digest', 'f96b697d7cb7938d525a2f31aaf161d0')
         eq('abcdefghijklmnopqrstuvwxyz', 'c3fcd3d76192e4007dfb496cca67e13b')
-        eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 
+        eq('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
            'd174ab98d277d9f5a5611c2c9f419d9f')
-        eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890', 
+        eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890',
            '57edf4a22be3c955ac49da2e2107b67a')
 
     def test_hexdigest(self):
index f686b702dad755ea669d88850cea7119a8941234..c77898bbb32c8376cfb4788d564b56b0f4d65cc5 100644 (file)
@@ -76,4 +76,3 @@ def test_main():
 
 if __name__ == "__main__":
     test_main()
-
index 6185243fc763282d2963b4f3eedd4276f52b5e15..77033cd422770aa620114eb661d9caaabc309861 100644 (file)
@@ -230,4 +230,3 @@ def register_skip_expected(*cases):
             break
     else:
         sys.modules[case.__module__].skip_expected = False
-
index 221571abad39485472de03f6375eb1893c786853..db8d99e1e20bd3806effc8753e364bc7863940fe 100644 (file)
@@ -319,10 +319,10 @@ class MakedirTests (unittest.TestCase):
         path = os.path.join(base, 'dir1', os.curdir, 'dir2', 'dir3', 'dir4',
                             'dir5', 'dir6')
         os.makedirs(path)
-        
 
-    
-        
+
+
+
     def tearDown(self):
         path = os.path.join(test_support.TESTFN, 'dir1', 'dir2', 'dir3',
                             'dir4', 'dir5', 'dir6')
index d2e2753122e5c0a8e79401e03d58511e211efd66..6ceab6de3bca467bcdb114a9b51c0d238b4e6457 100644 (file)
@@ -405,7 +405,7 @@ class ReTests(unittest.TestCase):
                          20003)
         self.assertEqual(re.match('.*?cd', 20000*'abc'+'de').end(0), 60001)
         # non-simple '*?' still used to hit the recursion limit, before the
-        # non-recursive scheme was implemented. 
+        # non-recursive scheme was implemented.
         self.assertEqual(re.search('(a|b)*?c', 10000*'ab'+'cd').end(0), 20001)
 
     def test_bug_612074(self):
index 2104ee90e1eea74da71e4f17f4b1de2014c24e59..3b108a1ebd80e0fa448bb2b2c88f784f492fa1c5 100644 (file)
@@ -179,7 +179,7 @@ class TestJointOps(unittest.TestCase):
             def __init__(self, value):
                 self.value = value
             def __hash__(self):
-                    return self.value
+                return self.value
             def __deepcopy__(self, memo=None):
                 return Tracer(self.value + 1)
         t = Tracer(10)
index dedc41c793ef814095814d9021217c17e12b96b8..5d670a8d7599f7902b9010d4264bdaf895bdc04f 100644 (file)
@@ -270,5 +270,3 @@ def test_main(verbose=None):
 
 if __name__ == "__main__":
     test_main(verbose=True)
-
-
index 6a0b0d8ebfe4718fe6b62d4d9d8f19259dcaf31d..485e9e09f6aa4f330af19ad01720f79a61f8da6f 100644 (file)
@@ -141,7 +141,7 @@ else:
         # which have special Unicode support in posixmodule.
         if (not hasattr(sys, "getwindowsversion") or
                 sys.getwindowsversion()[3] < 2): #  0=win32s or 1=9x/ME
-           TESTFN_UNICODE_UNENCODEABLE = None
+            TESTFN_UNICODE_UNENCODEABLE = None
         else:
             # Japanese characters (I think - from bug 846133)
             TESTFN_UNICODE_UNENCODEABLE = u"@test-\u5171\u6709\u3055\u308c\u308b"
index fbca88b221a067053b28afc418b562022caf8f3a..46a99f2fbf006fd94da5e4caa4efc03cd3f5d29d 100644 (file)
@@ -20,7 +20,7 @@ def remove_if_exists(filename):
 class TestUnicodeFiles(unittest.TestCase):
     # The 'do_' functions are the actual tests.  They generally assume the
     # file already exists etc.
-    
+
     # Do all the tests we can given only a single filename.  The file should
     # exist.
     def _do_single(self, filename):
@@ -39,7 +39,7 @@ class TestUnicodeFiles(unittest.TestCase):
         # basename should appear in listdir.
         path, base = os.path.split(os.path.abspath(filename))
         self.failUnless(base in os.listdir(path))
-    
+
     # Do as many "equivalancy' tests as we can - ie, check that although we
     # have different types for the filename, they refer to the same file.
     def _do_equivilent(self, filename1, filename2):
@@ -124,7 +124,7 @@ class TestUnicodeFiles(unittest.TestCase):
             self._do_single(filename)
         finally:
             os.unlink(filename)
-    
+
     def _test_equivalent(self, filename1, filename2):
         remove_if_exists(filename1)
         self.failUnless(not os.path.exists(filename2))
index 6438b4ee278d7ca92264c9e0a187640f39bd9bdd..87de229768564766db291bb97cfc85b70ea49912 100644 (file)
@@ -269,6 +269,14 @@ class OpenerDirectorTests(unittest.TestCase):
                              isinstance(args[1], MockResponse))
 
 
+def sanepathname2url(path):
+    import urllib
+    urlpath = urllib.pathname2url(path)
+    if os.name == "nt" and urlpath.startswith("///"):
+        urlpath = urlpath[2:]
+    # XXX don't ask me about the mac...
+    return urlpath
+
 class HandlerTests(unittest.TestCase):
 
     def test_ftp(self):
@@ -323,19 +331,17 @@ class HandlerTests(unittest.TestCase):
         h = urllib2.FileHandler()
         o = h.parent = MockOpener()
 
-        #from test_support import TESTFN
-        TESTFN = "test.txt"
+        TESTFN = test_support.TESTFN
+        urlpath = sanepathname2url(os.path.abspath(TESTFN))
         towrite = "hello, world\n"
         for url in [
-            "file://localhost%s/%s" % (os.getcwd(), TESTFN),
-            "file://%s/%s" % (os.getcwd(), TESTFN),
-            "file://%s%s/%s" % (socket.gethostbyname('localhost'),
-                                os.getcwd(), TESTFN),
-            "file://%s%s/%s" % (socket.gethostbyname(socket.gethostname()),
-                                os.getcwd(), TESTFN),
-            # XXX Windows / Mac format(s), ... ?
+            "file://localhost%s" % urlpath,
+            "file://%s" % urlpath,
+            "file://%s%s" % (socket.gethostbyname('localhost'), urlpath),
+            "file://%s%s" % (socket.gethostbyname(socket.gethostname()),
+                             urlpath),
             ]:
-            f = open(TESTFN, "w")
+            f = open(TESTFN, "wb")
             try:
                 try:
                     f.write(towrite)
@@ -345,25 +351,21 @@ class HandlerTests(unittest.TestCase):
                 r = h.file_open(Request(url))
                 try:
                     data = r.read()
-                    read_time = time.time()
                     headers = r.info()
                     newurl = r.geturl()
                 finally:
                     r.close()
+                stats = os.stat(TESTFN)
+                modified = rfc822.formatdate(stats.st_mtime)
             finally:
                 os.remove(TESTFN)
             self.assertEqual(data, towrite)
             self.assertEqual(headers["Content-type"], "text/plain")
             self.assertEqual(headers["Content-length"], "13")
-            # Fudge Last-modified string comparison by one second to
-            # prevent spurious failure on crossing a second boundary while
-            # executing this test.
-            unfudged = rfc822.formatdate(read_time)
-            fudged = rfc822.formatdate(read_time-1)
-            self.assert_(headers["Last-modified"] in [unfudged, fudged])
+            self.assertEqual(headers["Last-modified"], modified)
 
         for url in [
-            "file://localhost:80%s/%s" % (os.getcwd(), TESTFN),
+            "file://localhost:80%s" % urlpath,
 # XXXX bug: these fail with socket.gaierror, should be URLError
 ##             "file://%s:80%s/%s" % (socket.gethostbyname('localhost'),
 ##                                    os.getcwd(), TESTFN),
@@ -371,7 +373,7 @@ class HandlerTests(unittest.TestCase):
 ##             (os.getcwd(), TESTFN),
             ]:
             try:
-                f = open(TESTFN, "w")
+                f = open(TESTFN, "wb")
                 try:
                     f.write(towrite)
                 finally:
index d99009bf28ebac80bbb10470477a4e42d131e2a0..cf78648c5339787bfafdf7b53f062dc6cc189bae 100644 (file)
@@ -219,7 +219,7 @@ def format_exc(limit=None):
         return ''.join(format_exception(etype, value, tb, limit))
     finally:
         etype = value = tb = None
-    
+
 
 def print_last(limit=None, file=None):
     """This is a shorthand for 'print_exception(sys.last_type,
index 923b4e4467694135d32b882f0cb5f73b3856988e..43e9c7d25aa8b1ecf5df2e6b88e3bafee6e203a4 100644 (file)
@@ -426,11 +426,11 @@ class BaseHandler:
 
     def add_parent(self, parent):
         self.parent = parent
-        
+
     def close(self):
         # Only exists for backwards compatibility
         pass
-        
+
     def __lt__(self, other):
         if not hasattr(other, "handler_order"):
             # Try to preserve the old behavior of having custom classes
@@ -770,7 +770,7 @@ class AbstractDigestAuthHandler:
             # prompting for the information. Crap. This isn't great
             # but it's better than the current 'repeat until recursion
             # depth exceeded' approach <wink>
-            raise HTTPError(req.get_full_url(), 401, "digest auth failed", 
+            raise HTTPError(req.get_full_url(), 401, "digest auth failed",
                             headers, None)
         else:
             self.retried += 1
@@ -845,7 +845,7 @@ class AbstractDigestAuthHandler:
         else:
             # XXX handle auth-int.
             pass
-    
+
         # XXX should the partial digests be encoded too?
 
         base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
@@ -887,7 +887,7 @@ class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
 
     def http_error_401(self, req, fp, code, msg, headers):
         host = urlparse.urlparse(req.get_full_url())[1]
-        retry = self.http_error_auth_reqed('www-authenticate', 
+        retry = self.http_error_auth_reqed('www-authenticate',
                                            host, req, headers)
         self.reset_retry_count()
         return retry
@@ -899,7 +899,7 @@ class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
 
     def http_error_407(self, req, fp, code, msg, headers):
         host = req.get_host()
-        retry = self.http_error_auth_reqed('proxy-authenticate', 
+        retry = self.http_error_auth_reqed('proxy-authenticate',
                                            host, req, headers)
         self.reset_retry_count()
         return retry
@@ -964,7 +964,7 @@ class AbstractHTTPHandler(BaseHandler):
             raise URLError(err)
 
         # Pick apart the HTTPResponse object to get the various pieces
-        # of the 
+        # of the
         resp = addinfourl(r.fp, r.msg, req.get_full_url())
         resp.code = r.status
         resp.msg = r.reason
index 3397fbbf93d13818738b0449c52d51b43a35ea7c..a18f3d76c99790ef781e65c4b498291b70598daf 100644 (file)
@@ -57,13 +57,15 @@ PyList_New(int size)
 {
        PyListObject *op;
        size_t nbytes;
+       int allocated_size = roundupsize(size);
+
        if (size < 0) {
                PyErr_BadInternalCall();
                return NULL;
        }
-       nbytes = size * sizeof(PyObject *);
+       nbytes = allocated_size * sizeof(PyObject *);
        /* Check for overflow */
-       if (nbytes / sizeof(PyObject *) != (size_t)size) {
+       if (nbytes / sizeof(PyObject *) != (size_t)allocated_size) {
                return PyErr_NoMemory();
        }
        op = PyObject_GC_New(PyListObject, &PyList_Type);
@@ -78,7 +80,7 @@ PyList_New(int size)
                if (op->ob_item == NULL) {
                        return PyErr_NoMemory();
                }
-               memset(op->ob_item, 0, sizeof(*op->ob_item) * size);
+               memset(op->ob_item, 0, sizeof(*op->ob_item) * allocated_size);
        }
        op->ob_size = size;
        _PyObject_GC_TRACK(op);
@@ -154,7 +156,8 @@ ins1(PyListObject *self, int where, PyObject *v)
                return -1;
        }
        items = self->ob_item;
-       NRESIZE(items, PyObject *, self->ob_size+1);
+       if (roundupsize(self->ob_size) - 1 == self->ob_size || items == NULL)
+               NRESIZE(items, PyObject *, self->ob_size+1);
        if (items == NULL) {
                PyErr_NoMemory();
                return -1;
@@ -1878,7 +1881,8 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
        saved_ob_size = self->ob_size;
        saved_ob_item = self->ob_item;
        self->ob_size = 0;
-       self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, 0);
+/*     self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, 0); */
+       self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, roundupsize(0));
 
        if (keyfunc != NULL) {
                for (i=0 ; i < saved_ob_size ; i++) {