From: <pj...@us...> - 2009-06-06 07:06:32
|
Revision: 6457 http://jython.svn.sourceforge.net/jython/?rev=6457&view=rev Author: pjenvey Date: 2009-06-06 07:06:19 +0000 (Sat, 06 Jun 2009) Log Message: ----------- o fix recompiling due to stale byte code not tagging an mtime on the new code o change importer isAcceptableBytecode -> getSourceMtime to fix zipimporter to check mtime against the actual bytecode's tagged mtime Modified Paths: -------------- trunk/jython/src/org/python/core/ClasspathPyImporter.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/core/util/importer.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/src/org/python/core/ClasspathPyImporter.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporter.java 2009-06-06 05:45:22 UTC (rev 6456) +++ trunk/jython/src/org/python/core/ClasspathPyImporter.java 2009-06-06 07:06:19 UTC (rev 6457) @@ -1,3 +1,4 @@ +/* Copyright (c) Jython Developers */ package org.python.core; import java.io.IOException; @@ -63,8 +64,9 @@ } @Override - protected boolean isAcceptableBytecode(String searchPath, String entry) { - return true; + protected long getSourceMtime(String path) { + // Can't determine this easily + return -1; } @Override Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-06-06 05:45:22 UTC (rev 6456) +++ trunk/jython/src/org/python/core/imp.java 2009-06-06 07:06:19 UTC (rev 6457) @@ -474,10 +474,12 @@ boolean pkg = false; try { - pkg = dir.isDirectory() && caseok(dir, name) && (sourceFile.isFile() - || compiledFile.isFile()); + pkg = dir.isDirectory() && caseok(dir, name) + && (sourceFile.isFile() || compiledFile.isFile()); } catch (SecurityException e) { + // ok } + if (!pkg) { Py.writeDebug(IMPORT_LOG, "trying source " + dir.getPath()); sourceName = name + ".py"; @@ -506,7 +508,7 @@ } } return createFromSource(modName, makeStream(sourceFile), displaySourceName, - compiledFile.getPath()); + compiledFile.getPath(), pyTime); } return createFromSource(modName, makeStream(sourceFile), displaySourceName, compiledFile.getPath(), pyTime); @@ -519,6 +521,7 @@ displayCompiledName); } } catch (SecurityException e) { + // ok } return null; } Modified: trunk/jython/src/org/python/core/util/importer.java =================================================================== --- trunk/jython/src/org/python/core/util/importer.java 2009-06-06 05:45:22 UTC (rev 6456) +++ trunk/jython/src/org/python/core/util/importer.java 2009-06-06 07:06:19 UTC (rev 6457) @@ -1,3 +1,4 @@ +/* Copyright (c) Jython Developers */ package org.python.core.util; import java.io.IOException; @@ -127,7 +128,14 @@ public abstract void close(); } - protected abstract boolean isAcceptableBytecode(String searchPath, T entry); + /** + * Given a path to a compiled file in the archive, return the modification time of the + * matching .py file. + * + * @param path to the compiled file + * @return long mtime of the .py, or -1 if no source is available + */ + protected abstract long getSourceMtime(String path); /** * Return module information for the module with the fully qualified name. @@ -181,9 +189,9 @@ boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); - - if (isbytecode && !isAcceptableBytecode(searchPath, tocEntry)) { - continue; + long mtime = -1; + if (isbytecode) { + mtime = getSourceMtime(searchPath); } Bundle bundle = makeBundle(searchPath, tocEntry); @@ -191,10 +199,14 @@ try { if (isbytecode) { try { - codeBytes = imp.readCode(fullname, bundle.inputStream, true); + codeBytes = imp.readCode(fullname, bundle.inputStream, true, mtime); } catch (IOException ioe) { throw Py.ImportError(ioe.getMessage() + "[path=" + fullSearchPath + "]"); } + if (codeBytes == null) { + // bad magic number or non-matching mtime in byte code, try next + continue; + } } else { codeBytes = imp.compileSource(fullname, bundle.inputStream, fullSearchPath); } Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-06-06 05:45:22 UTC (rev 6456) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-06-06 07:06:19 UTC (rev 6457) @@ -12,6 +12,7 @@ import org.python.core.ArgParser; import org.python.core.Py; import org.python.core.PyDictionary; +import org.python.core.PyException; import org.python.core.PyInteger; import org.python.core.PyLong; import org.python.core.PyObject; @@ -299,31 +300,27 @@ } } - /** - * Determine if the byte code at path with the specified toc entry has a modification time - * greater than its accompanying source code's. - * - * @param path a String path to the byte code - * @param tocEntry the byte code's PyObject toc entry - * @return boolean whether or not the byte code is older - */ @Override - protected boolean isAcceptableBytecode(String path, PyObject tocEntry) { + protected long getSourceMtime(String path) { String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); if (sourceTocEntry == null) { - return true;// If there is no source, assume the bytecode is ok + return -1; } + + int time; + int date; try { - long bytecodeTime = dosTimeToEpoch(tocEntry.__finditem__(5).asInt(0), - tocEntry.__finditem__(6).asInt(0)); - long sourceTime = dosTimeToEpoch(sourceTocEntry.__finditem__(5).asInt(0), - sourceTocEntry.__finditem__(6).asInt(0)); - return bytecodeTime < sourceTime; + time = sourceTocEntry.__finditem__(5).asInt(); + date = sourceTocEntry.__finditem__(6).asInt(); + } catch (PyException pye) { + if (!pye.match(Py.TypeError)) { + throw pye; + } + time = -1; + date = -1; } - catch (PyObject.ConversionException ce) { - return false; - } + return dosTimeToEpoch(time, date); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |