[Python-checkins] cpython (3.2): Port import fixes from 2.7.

antoine.pitrou python-checkins at python.org
Wed Jan 25 18:09:22 CET 2012


http://hg.python.org/cpython/rev/c79d0a7ac79d
changeset:   74611:c79d0a7ac79d
branch:      3.2
parent:      74603:37ac757a9145
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Wed Jan 25 18:01:45 2012 +0100
summary:
  Port import fixes from 2.7.

files:
  Lib/importlib/test/source/test_file_loader.py |   2 +-
  Lib/test/test_import.py                       |   2 +-
  Python/import.c                               |  20 +++++-----
  3 files changed, 12 insertions(+), 12 deletions(-)


diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py
--- a/Lib/importlib/test/source/test_file_loader.py
+++ b/Lib/importlib/test/source/test_file_loader.py
@@ -138,7 +138,7 @@
             with open(source, 'w') as f:
                 f.write("x = 5")
             try:
-                os.utime(source, (2 ** 33, 2 ** 33))
+                os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
             except OverflowError:
                 self.skipTest("cannot set modification time to large integer")
             except OSError as e:
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -321,7 +321,7 @@
             with open(source, 'w') as f:
                 pass
             try:
-                os.utime(source, (2 ** 33, 2 ** 33))
+                os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
             except OverflowError:
                 self.skipTest("cannot set modification time to large integer")
             except OSError as e:
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1226,9 +1226,9 @@
         (void) unlink(cpathname);
         return;
     }
-    /* Now write the true mtime */
+    /* Now write the true mtime (as a 32-bit field) */
     fseek(fp, 4L, 0);
-    assert(mtime < LONG_MAX);
+    assert(mtime <= 0xFFFFFFFF);
     PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
     fflush(fp);
     fclose(fp);
@@ -1302,14 +1302,14 @@
                      pathname);
         return NULL;
     }
-#if SIZEOF_TIME_T > 4
-    /* Python's .pyc timestamp handling presumes that the timestamp fits
-       in 4 bytes. Since the code only does an equality comparison,
-       ordering is not important and we can safely ignore the higher bits
-       (collisions are extremely unlikely).
-     */
-    st.st_mtime &= 0xFFFFFFFF;
-#endif
+    if (sizeof st.st_mtime > 4) {
+        /* Python's .pyc timestamp handling presumes that the timestamp fits
+           in 4 bytes. Since the code only does an equality comparison,
+           ordering is not important and we can safely ignore the higher bits
+           (collisions are extremely unlikely).
+         */
+        st.st_mtime &= 0xFFFFFFFF;
+    }
     cpathname = make_compiled_pathname(
         pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag);
     if (cpathname != NULL &&

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list