Skip to content

Commit dd2597a

Browse files
committed
gracefully support using the WarnNode without a frame
1 parent f262e4b commit dd2597a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import com.oracle.truffle.api.nodes.UnexpectedResultException;
106106
import com.oracle.truffle.api.object.DynamicObjectLibrary;
107107
import com.oracle.truffle.api.object.HiddenKey;
108+
import com.oracle.truffle.api.profiles.BranchProfile;
108109

109110
@CoreFunctions(defineModule = "_warnings")
110111
public class WarningsModuleBuiltins extends PythonBuiltins {
@@ -942,12 +943,18 @@ public final void warn(Frame frame, Object category, String message) {
942943
protected abstract void execute(Frame frame, Object source, Object category, String format, int stackLevel, Object... formatArgs);
943944

944945
private static final class WarnNodeCached extends WarnNode {
946+
@CompilationFinal BranchProfile noFrame = BranchProfile.create();
945947
@CompilationFinal ContextReference<PythonContext> ctxRef;
946948
@Child PythonObjectLibrary lib;
947949
@Child WarningsModuleNode moduleFunctionsNode;
948950

949951
@Override
950952
protected void execute(Frame frame, Object source, Object category, String format, int stackLevel, Object... formatArgs) {
953+
if (frame == null) {
954+
noFrame.enter();
955+
UNCACHED.execute(null, source, category, format, stackLevel, formatArgs);
956+
return;
957+
}
951958
assert frame instanceof VirtualFrame;
952959
if (ctxRef == null) {
953960
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1006,7 +1013,6 @@ protected void execute(Frame frame, Object source, Object category, String forma
10061013
}
10071014
lib.callObject(warn, null, message, category, stackLevel, source);
10081015
}
1009-
10101016
}
10111017
}
10121018
}

0 commit comments

Comments
 (0)