Skip to content

Commit 85a26a0

Browse files
timfelcosminbasca
authored andcommitted
make sure we enforce freevars in code for now
1 parent ad2dce5 commit 85a26a0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
import com.oracle.graal.python.builtins.objects.function.PArguments;
5050
import com.oracle.graal.python.builtins.objects.function.PFunction;
5151
import com.oracle.graal.python.builtins.objects.function.Signature;
52-
import com.oracle.graal.python.builtins.objects.str.PString;
5352
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
5453
import com.oracle.graal.python.nodes.IndirectCallNode;
5554
import com.oracle.graal.python.nodes.ModuleRootNode;
5655
import com.oracle.graal.python.nodes.PNodeWithContext;
5756
import com.oracle.graal.python.nodes.PRaiseNode;
5857
import com.oracle.graal.python.nodes.PRootNode;
5958
import com.oracle.graal.python.nodes.call.InvokeNode;
59+
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
6060
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
6161
import com.oracle.graal.python.runtime.PythonContext;
6262
import com.oracle.graal.python.runtime.PythonCore;
@@ -197,6 +197,12 @@ private static String createFuncdef(byte[] codestring, Object[] freevars, String
197197
String outernme = "_____" + System.nanoTime();
198198
StringBuilder sb = new StringBuilder();
199199
sb.append("def ").append(outernme).append("():\n");
200+
for (Object f : freevars) {
201+
String freevar = CastToJavaStringNode.getUncached().execute(f);
202+
if (freevar != null) {
203+
sb.append(" ").append(freevar).append(" = None\n");
204+
}
205+
}
200206
if (isLambda) {
201207
sb.append(" ").append("return ").append(codeStr);
202208
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaStringNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ static String doUnsupported(@SuppressWarnings("unused") Object x) {
108108
static boolean isMaterialized(PString x) {
109109
return x.getCharSequence() instanceof String;
110110
}
111+
112+
public static CastToJavaStringNode getUncached() {
113+
return CastToJavaStringNodeGen.getUncached();
114+
}
111115
}

0 commit comments

Comments
 (0)