]> granicus.if.org Git - python/commitdiff
Port import fixes from 2.7.
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 25 Jan 2012 17:01:45 +0000 (18:01 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 25 Jan 2012 17:01:45 +0000 (18:01 +0100)
Lib/importlib/test/source/test_file_loader.py
Lib/test/test_import.py
Python/import.c

index 912e6c3b51b4211f03e0c298678e4f0cea2ea20d..c7a7d8fbcae2d371c166f7a050c8e50844d6a3f6 100644 (file)
@@ -138,7 +138,7 @@ class SimpleTest(unittest.TestCase):
             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:
index 311063505e9ed29b0f90c0bfac81614a1ee4041d..48443ea58010ce8adc7d59a976f798046b0ad281 100644 (file)
@@ -321,7 +321,7 @@ class ImportTests(unittest.TestCase):
             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:
index 40b8d0a55835dd75cbf5ac8e790c1aa5ef179c9e..beda7f97d274b2f426cf19d3d0e7921ea352c173 100644 (file)
@@ -1226,9 +1226,9 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
         (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 @@ load_source_module(char *name, char *pathname, FILE *fp)
                      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 &&