ptl_import recompiles ptl files

Patrik Simons <[email protected]> Thu, 1 Aug 2013 16:05:44 +0300
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
Since stat.st_mtime is a float in linux, _load_pyc will almost always
recompile the ptl files.

Here's a patch to make the logic follow compile.c in python.

-- 
Patrik


--- ptl_import.py.orig	2013-07-15 14:08:19.040156973 +0300
+++ ptl_import.py	2013-08-01 15:28:02.582041857 +0300
@@ -42,7 +42,7 @@
         s = os.stat(filename)
     except OSError:
         return None
-    return s.st_mtime
+    return int(s.st_mtime) & 0xffffffff
 
 def _load_pyc(name, filename, pyc_filename):
     try:
@@ -52,7 +52,7 @@
     if fp.read(4) == imp.get_magic():
         mtime = struct.unpack('<I', fp.read(4))[0]
         ptl_mtime = _timestamp(filename)
-        if ptl_mtime is not None and mtime >= ptl_mtime:
+        if ptl_mtime is not None and mtime == ptl_mtime:
             code = marshal.load(fp)
             return _exec_module_code(code, name, filename)
     return None