From 5136ac0ca21a05691978df8d0650f902c8ca3463 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 13 Jan 2012 18:52:16 +0100 Subject: 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. --- Lib/py_compile.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Lib/py_compile.py') diff --git a/Lib/py_compile.py b/Lib/py_compile.py index 5adb70a2939..62d69ad4482 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) -- cgit v1.2.3