[Python-checkins] cpython (merge 3.2 -> default): 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/2b62348a1c03
changeset:   74612:2b62348a1c03
parent:      74607:585d3664da89
parent:      74611:c79d0a7ac79d
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Wed Jan 25 18:06:07 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
@@ -133,7 +133,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
@@ -317,7 +317,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
@@ -1343,9 +1343,9 @@
     PyMarshal_WriteLongToFile(0L, fp, Py_MARSHAL_VERSION);
     PyMarshal_WriteObjectToFile((PyObject *)co, fp, Py_MARSHAL_VERSION);
     fflush(fp);
-    /* Now write the true mtime and size */
+    /* Now write the true mtime and size (as 32-bit fields) */
     fseek(fp, 4L, 0);
-    assert(mtime < LONG_MAX);
+    assert(mtime <= 0xFFFFFFFF);
     PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
     PyMarshal_WriteLongToFile(size, fp, Py_MARSHAL_VERSION);
     if (fflush(fp) != 0 || ferror(fp)) {
@@ -1476,14 +1476,14 @@
                      pathname);
         goto error;
     }
-#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;
+    }
     if (PyUnicode_READY(pathname) < 0)
         return NULL;
     cpathname = make_compiled_pathname(pathname, !Py_OptimizeFlag);

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


More information about the Python-checkins mailing list