Skip to content

Commit e791027

Browse files
committed
Improve Python frame asserts message
1 parent ccd8435 commit e791027

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public final class PArguments {
6565
private static final int INDEX_CURRENT_EXCEPTION = 5;
6666
public static final int USER_ARGUMENTS_OFFSET = 6;
6767

68+
public static boolean assertIsPythonFrame(Frame frame) {
69+
assert frame != null;
70+
Object[] frameArgs = frame.getArguments();
71+
assert frameArgs.length >= USER_ARGUMENTS_OFFSET : frameArgs.length;
72+
assert frameArgs[INDEX_CURRENT_FRAME_INFO] instanceof PFrame.Reference : frameArgs[INDEX_CURRENT_FRAME_INFO];
73+
return true;
74+
}
75+
6876
public static boolean isPythonFrame(Frame frame) {
6977
return frame != null && isPythonFrame(frame.getArguments());
7078
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadFrameNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ public StackWalkResult visitFrame(FrameInstance frameInstance) {
440440
if (!selector.skip(pRootNode)) {
441441
if (i == level) {
442442
Frame frame = ReadFrameNode.getFrame(frameInstance, frameAccess);
443-
assert PArguments.isPythonFrame(frame);
443+
assert PArguments.assertIsPythonFrame(frame);
444444
IndirectCallData.setCallerFlagsOnIndirectCallData(callNode, callerFlags);
445445
if (prevRootNode instanceof PRootNode prevPRootNode && prevPRootNode.setsUpCalleeContext()) {
446446
// Update the flags in the callee

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -181,7 +181,7 @@ protected static void prepareCall(VirtualFrame frame, Object[] callArguments, in
181181
@Bind Node inliningTarget,
182182
@Cached PassCallerFrameNode passCallerFrame,
183183
@Cached PassExceptionStateNode passExceptionState) {
184-
assert PArguments.isPythonFrame(frame) || inliningTarget.getRootNode() instanceof TopLevelExceptionHandler : "calling from non-Python or non-top-level frame";
184+
assert inliningTarget.getRootNode() instanceof TopLevelExceptionHandler || PArguments.assertIsPythonFrame(frame) : "calling from non-Python or non-top-level frame";
185185
passCallerFrame.execute(frame, inliningTarget, callArguments, callerFlags);
186186
passExceptionState.execute(frame, inliningTarget, callArguments, CallerFlags.needsExceptionState(callerFlags));
187187
}

0 commit comments

Comments
 (0)