Permalink
Browse files

Improved handling of __pyclasspath__ when searching for pyc-files due…

… to oversized methods or functions.
  • Loading branch information...
Stewori committed Apr 21, 2017
1 parent 06dc53c commit 343740e5a34afd90f4953ba0eab18ccf863da860
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/org/python/compiler/Module.java
@@ -28,10 +28,12 @@
import org.python.antlr.ast.Str;
import org.python.antlr.ast.Suite;
import org.python.antlr.base.mod;
+import org.python.core.ClasspathPyImporter;
import org.python.core.CodeBootstrap;
import org.python.core.CodeFlag;
import org.python.core.CodeLoader;
import org.python.core.CompilerFlags;
+import org.python.core.imp;
import org.python.core.Py;
import org.python.core.PyCode;
import org.python.core.PyBytecode;
@@ -729,6 +731,14 @@ private static PyBytecode loadPyBytecode(String filename, boolean try_cpython)
"\npython -m py_compile "+filename+"\nand try again.";
String pyc_filename = filename+"c";
+ if (pyc_filename.startsWith(ClasspathPyImporter.PYCLASSPATH_PREFIX)) {
+ ClassLoader cld = Py.getSystemState().getClassLoader();
+ if (cld == null) {
+ cld = imp.getParentClassLoader();
+ }
+ pyc_filename = cld.getResource(pyc_filename.replace(
+ ClasspathPyImporter.PYCLASSPATH_PREFIX, "")).getPath();
+ }
File pyc_file = new File(pyc_filename);
if (pyc_file.exists()) {
PyFile f = new PyFile(pyc_filename, "rb", 4096);

0 comments on commit 343740e

Please sign in to comment.