Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33d15f7

Browse files
committed
Port import fixes from 2.7.
1 parent dd21f68 commit 33d15f7

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

Lib/importlib/test/source/test_file_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_timestamp_overflow(self):
138138
with open(source, 'w') as f:
139139
f.write("x = 5")
140140
try:
141-
os.utime(source, (2 ** 33, 2 ** 33))
141+
os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
142142
except OverflowError:
143143
self.skipTest("cannot set modification time to large integer")
144144
except OSError as e:

Lib/test/test_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test_timestamp_overflow(self):
321321
with open(source, 'w') as f:
322322
pass
323323
try:
324-
os.utime(source, (2 ** 33, 2 ** 33))
324+
os.utime(source, (2 ** 33 - 5, 2 ** 33 - 5))
325325
except OverflowError:
326326
self.skipTest("cannot set modification time to large integer")
327327
except OSError as e:

Python/import.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,9 +1226,9 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
12261226
(void) unlink(cpathname);
12271227
return;
12281228
}
1229-
/* Now write the true mtime */
1229+
/* Now write the true mtime (as a 32-bit field) */
12301230
fseek(fp, 4L, 0);
1231-
assert(mtime < LONG_MAX);
1231+
assert(mtime <= 0xFFFFFFFF);
12321232
PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);
12331233
fflush(fp);
12341234
fclose(fp);
@@ -1302,14 +1302,14 @@ load_source_module(char *name, char *pathname, FILE *fp)
13021302
pathname);
13031303
return NULL;
13041304
}
1305-
#if SIZEOF_TIME_T > 4
1306-
/* Python's .pyc timestamp handling presumes that the timestamp fits
1307-
in 4 bytes. Since the code only does an equality comparison,
1308-
ordering is not important and we can safely ignore the higher bits
1309-
(collisions are extremely unlikely).
1310-
*/
1311-
st.st_mtime &= 0xFFFFFFFF;
1312-
#endif
1305+
if (sizeof st.st_mtime > 4) {
1306+
/* Python's .pyc timestamp handling presumes that the timestamp fits
1307+
in 4 bytes. Since the code only does an equality comparison,
1308+
ordering is not important and we can safely ignore the higher bits
1309+
(collisions are extremely unlikely).
1310+
*/
1311+
st.st_mtime &= 0xFFFFFFFF;
1312+
}
13131313
cpathname = make_compiled_pathname(
13141314
pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag);
13151315
if (cpathname != NULL &&

0 commit comments

Comments
 (0)