diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-13 17:52:16 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-13 17:52:16 (GMT) |
commit | 5136ac0ca21a05691978df8d0650f902c8ca3463 (patch) | |
tree | 4b5569dad3f1b36f115c673602dde6ff49eae5e0 /Lib/py_compile.py | |
parent | 1f918c1480a1566b774391bbc4ddf1d4153965a1 (diff) | |
download | cpython-5136ac0ca21a05691978df8d0650f902c8ca3463.zip cpython-5136ac0ca21a05691978df8d0650f902c8ca3463.tar.gz cpython-5136ac0ca21a05691978df8d0650f902c8ca3463.tar.bz2 |
Issue #13645: pyc files now contain the size of the corresponding source
code, to avoid timestamp collisions (especially on filesystems with a low
timestamp resolution) when checking for freshness of the bytecode.
Diffstat (limited to 'Lib/py_compile.py')
-rw-r--r-- | Lib/py_compile.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 5adb70a..62d69ad 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -110,9 +110,11 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1): """ with tokenize.open(file) as f: try: - timestamp = int(os.fstat(f.fileno()).st_mtime) + st = os.fstat(f.fileno()) except AttributeError: - timestamp = int(os.stat(file).st_mtime) + st = os.stat(file) + timestamp = int(st.st_mtime) + size = st.st_size & 0xFFFFFFFF codestring = f.read() try: codeobject = builtins.compile(codestring, dfile or file, 'exec', @@ -139,6 +141,7 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1): with open(cfile, 'wb') as fc: fc.write(b'\0\0\0\0') wr_long(fc, timestamp) + wr_long(fc, size) marshal.dump(codeobject, fc) fc.flush() fc.seek(0, 0) |