Skip to content

Commit cc1af0c

Browse files
committed
Always pass exception state in IndirectCalleeContext
1 parent 0bcfa6b commit cc1af0c

File tree

6 files changed

+12
-38
lines changed

6 files changed

+12
-38
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/ConversionNodeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public boolean isPythonInternal() {
101101
PArguments.setException(arguments, PException.NO_EXCEPTION);
102102
PArguments.setArgument(arguments, 0, arg);
103103
PythonThreadState threadState = pythonContext.getThreadState(language);
104-
Object state = IndirectCalleeContext.enter(threadState, arguments, callTarget);
104+
Object state = IndirectCalleeContext.enter(threadState, arguments);
105105
try {
106106
return CallDispatchers.SimpleIndirectInvokeNode.executeUncached(callTarget, arguments);
107107
} finally {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private void runFile(PythonContext context, TruffleString inputFilePath) {
391391
PArguments.setSpecialArgument(arguments, mainDict);
392392
PArguments.setException(arguments, PException.NO_EXCEPTION);
393393
context.initializeMainModule(inputFilePath);
394-
Object state = ExecutionContext.IndirectCalleeContext.enterIndirect(language, context, arguments, callTarget);
394+
Object state = ExecutionContext.IndirectCalleeContext.enter(context.getThreadState(language), arguments);
395395
try {
396396
callTarget.call(arguments);
397397
} finally {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SortNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private void sortWithoutKey(VirtualFrame frame, Object[] array, int len, boolean
321321
final RootCallTarget callTarget = getComparatorCallTarget(language);
322322
if (frame == null) {
323323
PythonThreadState threadState = PythonContext.get(this).getThreadState(language);
324-
Object state = IndirectCalleeContext.enter(threadState, arguments, callTarget);
324+
Object state = IndirectCalleeContext.enter(threadState, arguments);
325325
try {
326326
callSortWithoutKey(array, len, callTarget, arguments);
327327
} finally {
@@ -422,7 +422,7 @@ private void sortWithKey(VirtualFrame frame, Object[] array, int len, Object key
422422
final RootCallTarget callTarget = getComparatorCallTarget(language);
423423
if (frame == null) {
424424
PythonThreadState threadState = PythonContext.get(this).getThreadState(language);
425-
Object state = IndirectCalleeContext.enter(threadState, arguments, callTarget);
425+
Object state = IndirectCalleeContext.enter(threadState, arguments);
426426
try {
427427
callSortWithKey(pairArray, len, callTarget, arguments);
428428
} finally {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static Object doDirect(VirtualFrame frame, Node inliningTarget, DirectCallNode c
121121
if (profileIsNullFrame.profile(inliningTarget, frame == null)) {
122122
PythonContext context = PythonContext.get(inliningTarget);
123123
PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
124-
Object state = IndirectCalleeContext.enter(threadState, arguments, callTarget);
124+
Object state = IndirectCalleeContext.enter(threadState, arguments);
125125
try {
126126
return callNode.call(arguments);
127127
} finally {
@@ -160,7 +160,7 @@ static Object doDirect(VirtualFrame frame, Node inliningTarget, RootCallTarget c
160160
if (profileIsNullFrame.profile(inliningTarget, frame == null)) {
161161
PythonContext context = PythonContext.get(inliningTarget);
162162
PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
163-
Object state = IndirectCalleeContext.enterIndirect(threadState, arguments, callTarget);
163+
Object state = IndirectCalleeContext.enter(threadState, arguments);
164164
try {
165165
return callNode.call(callTarget, arguments);
166166
} finally {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private Object run(VirtualFrame frame) {
318318
}
319319
// At the top level we don't have a real Python frame at hand, so we go through
320320
// IndirectCalleeContext
321-
Object state = IndirectCalleeContext.enterIndirect(language, pythonContext, arguments, innerCallTarget);
321+
Object state = IndirectCalleeContext.enter(pythonContext.getThreadState(language), arguments);
322322
try {
323323
Object result = innerCallTarget.call(arguments);
324324
if (mainModule != null && result == PNone.NONE && !source.isInteractive()) {

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -722,44 +722,18 @@ private IndirectCalleeState(PFrame.Reference info, AbstractTruffleException curE
722722
* asks for it using {@link PRootNode#getCallerFlags()}.
723723
*/
724724
public abstract static class IndirectCalleeContext {
725-
/**
726-
* Prepare an indirect call from code that doesn't have access to the current Python
727-
* {@link VirtualFrame}, or doesn't have a frame, e.g., foreign code, to a Python function.
728-
* <p>
729-
* Unlike {@link #enter(PythonLanguage, PythonContext, Object[], RootCallTarget)}, this
730-
* method does not assume that the call target argument is a constant.
731-
*/
732-
public static Object enterIndirect(PythonLanguage language, PythonContext context, Object[] pArguments, RootCallTarget callTarget) {
733-
return enter(context.getThreadState(language), pArguments, needsExceptionState(callTarget));
734-
}
735725

736726
/**
737-
* @see #enterIndirect(PythonLanguage, PythonContext, Object[], RootCallTarget)
727+
* @see #enter(PythonThreadState, Object[])
738728
*/
739-
public static Object enterIndirect(PythonThreadState threadState, Object[] pArguments, RootCallTarget callTarget) {
740-
return enter(threadState, pArguments, needsExceptionState(callTarget));
741-
}
742-
743-
/**
744-
* @see #enter(PythonThreadState, Object[], RootCallTarget)
745-
*/
746-
public static Object enter(PythonLanguage language, PythonContext context, Object[] pArguments, RootCallTarget callTarget) {
747-
return enter(context.getThreadState(language), pArguments, needsExceptionState(callTarget));
729+
public static Object enter(PythonLanguage language, PythonContext context, Object[] pArguments) {
730+
return enter(context.getThreadState(language), pArguments);
748731
}
749732

750733
/**
751734
* Prepare a call from a foreign frame to a Python function.
752735
*/
753-
public static Object enter(PythonThreadState threadState, Object[] pArguments, RootCallTarget callTarget) {
754-
return enter(threadState, pArguments, needsExceptionState(callTarget));
755-
}
756-
757-
private static boolean needsExceptionState(RootCallTarget callTarget) {
758-
PRootNode calleeRootNode = (PRootNode) callTarget.getRootNode();
759-
return CallerFlags.needsExceptionState(calleeRootNode.getCallerFlags());
760-
}
761-
762-
private static Object enter(PythonThreadState threadState, Object[] pArguments, boolean needsExceptionState) {
736+
public static Object enter(PythonThreadState threadState, Object[] pArguments) {
763737
// We decided on if and how to materialize PFrame.Reference/PFrame itself at the point
764738
// of transition from code with access to virtual frame to the code without access to it
765739
// (e.g., TruffleBoundary code) in IndirectCallContext
@@ -769,7 +743,7 @@ private static Object enter(PythonThreadState threadState, Object[] pArguments,
769743
// If someone set the exception in the arguments explicitly, we do not override it. This
770744
// is used in top level code, async handlers, etc., where we want to avoid pointless
771745
// stack-walking
772-
if (needsExceptionState && PArguments.getException(pArguments) == null) {
746+
if (PArguments.getException(pArguments) == null) {
773747
AbstractTruffleException curExc = threadState.getCaughtException();
774748
if (curExc != null) {
775749
threadState.setCaughtException(null);

0 commit comments

Comments
 (0)