Port import fixes from 2.7.

This commit is contained in:
Antoine Pitrou 2012-01-25 18:01:45 +01:00
parent dd21f68963
commit 33d15f7c85
3 changed files with 12 additions and 12 deletions

View File

@ -138,7 +138,7 @@ class SimpleTest(unittest.TestCase):
with open(source, 'w') as f: with open(source, 'w') as f:
f.write("x = 5") f.write("x = 5")
try: try:
os.utime(source, (2 ** 33, 2 ** 33)) os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
except OverflowError: except OverflowError:
self.skipTest("cannot set modification time to large integer") self.skipTest("cannot set modification time to large integer")
except OSError as e: except OSError as e:

View File

@ -321,7 +321,7 @@ class ImportTests(unittest.TestCase):
with open(source, 'w') as f: with open(source, 'w') as f:
pass pass
try: try:
os.utime(source, (2 ** 33, 2 ** 33)) os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
except OverflowError: except OverflowError:
self.skipTest("cannot set modification time to large integer") self.skipTest("cannot set modification time to large integer")
except OSError as e: except OSError as e:

View File

@ -1226,9 +1226,9 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
(void) unlink(cpathname); (void) unlink(cpathname);
return; return;
} }
/* Now write the true mtime */ /* Now write the true mtime (as a 32-bit field) */
fseek(fp, 4L, 0); fseek(fp, 4L, 0);
assert(mtime < LONG_MAX); assert(mtime <= 0xFFFFFFFF);
PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION); PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
fflush(fp); fflush(fp);
fclose(fp); fclose(fp);
@ -1302,14 +1302,14 @@ load_source_module(char *name, char *pathname, FILE *fp)
pathname); pathname);
return NULL; return NULL;
} }
#if SIZEOF_TIME_T > 4 if (sizeof st.st_mtime > 4) {
/* Python's .pyc timestamp handling presumes that the timestamp fits /* Python's .pyc timestamp handling presumes that the timestamp fits
in 4 bytes. Since the code only does an equality comparison, in 4 bytes. Since the code only does an equality comparison,
ordering is not important and we can safely ignore the higher bits ordering is not important and we can safely ignore the higher bits
(collisions are extremely unlikely). (collisions are extremely unlikely).
*/ */
st.st_mtime &= 0xFFFFFFFF; st.st_mtime &= 0xFFFFFFFF;
#endif }
cpathname = make_compiled_pathname( cpathname = make_compiled_pathname(
pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag); pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag);
if (cpathname != NULL && if (cpathname != NULL &&