Skip to content

Commit 967ee0b

Browse files
author
Adam Hrbac
committed
Ensure a python erorr gets raised if assignment to f_trace_lines is incorrect
1 parent fec0c36 commit 967ee0b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
4444
import com.oracle.graal.python.builtins.objects.object.PythonObject;
4545
import com.oracle.graal.python.builtins.objects.str.StringUtils.SimpleTruffleStringFormatNode;
46+
import com.oracle.graal.python.nodes.ErrorMessages;
47+
import com.oracle.graal.python.nodes.PRaiseNode;
4648
import com.oracle.graal.python.nodes.PRootNode;
4749
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
4850
import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode;
@@ -51,6 +53,8 @@
5153
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5254
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5355
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
56+
import com.oracle.graal.python.nodes.util.CannotCastException;
57+
import com.oracle.graal.python.nodes.util.CastToJavaBooleanNode;
5458
import com.oracle.truffle.api.CompilerDirectives;
5559
import com.oracle.truffle.api.RootCallTarget;
5660
import com.oracle.truffle.api.dsl.Cached;
@@ -179,11 +183,14 @@ static boolean doGet(PFrame self, @SuppressWarnings("unused") PNone v) {
179183
}
180184

181185
@Specialization(guards = "!isNoValue(v)")
182-
static Object doSet(PFrame self, boolean v) {
183-
self.setTraceLine(v);
186+
static Object doSet(PFrame self, Object v, @Cached PRaiseNode raise, @Cached CastToJavaBooleanNode cast) {
187+
try {
188+
self.setTraceLine(cast.execute(v));
189+
} catch (CannotCastException e) {
190+
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.ATTRIBUTE_VALUE_MUST_BE_BOOL);
191+
}
184192
return PNone.NONE;
185193
}
186-
187194
}
188195

189196
@Builtin(name = "f_code", minNumOfPositionalArgs = 1, isGetter = true)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,4 +1450,5 @@ public abstract class ErrorMessages {
14501450
public static final TruffleString HPY_DEBUG_MODE_NOT_AVAILABLE = tsLiteral("HPy debug mode is not available");
14511451

14521452
public static final TruffleString SETTRACE_NOT_IMPLEMENTED = tsLiteral("sys.settrace is only implemented for the bytecode interpreter.");
1453+
public static final TruffleString ATTRIBUTE_VALUE_MUST_BE_BOOL = tsLiteral("attribute value type must be bool");
14531454
}

0 commit comments

Comments
 (0)