Skip to content

Commit 969fbc1

Browse files
committed
Move the ToNative conversion in TransformExceptionToNativeNode earlier
1 parent 40030ac commit 969fbc1

File tree

1 file changed

+7
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ static void setCurrentException(Frame frame, Node inliningTarget, PException e,
480480
@Cached GetClassNode getClassNode,
481481
@Cached(inline = false) PythonToNativeNode pythonToNativeNode,
482482
@Cached(inline = false) CStructAccess.WritePointerNode writePointerNode) {
483+
/*
484+
* Run the ToNative conversion early so that nothing interrups the code between setting
485+
* the managed and native states
486+
*/
487+
Object exceptionType = getClassNode.execute(inliningTarget, e.getUnreifiedException());
488+
Object exceptionTypeNative = pythonToNativeNode.execute(exceptionType);
483489
// TODO connect f_back
484490
getCurrentFrameRef.execute(frame, inliningTarget).markAsEscaped();
485491
PythonThreadState threadState = getThreadStateNode.execute(inliningTarget);
@@ -497,12 +503,11 @@ static void setCurrentException(Frame frame, Node inliningTarget, PException e,
497503
*/
498504
Object nativeThreadState = PThreadState.getNativeThreadState(threadState);
499505
if (nativeThreadState != null) {
500-
Object exceptionType = getClassNode.execute(inliningTarget, e.getUnreifiedException());
501506
/*
502507
* Write a borrowed ref to the native mirror because we need to keep that in sync
503508
* anyway.
504509
*/
505-
writePointerNode.write(nativeThreadState, CFields.PyThreadState__curexc_type, pythonToNativeNode.execute(exceptionType));
510+
writePointerNode.write(nativeThreadState, CFields.PyThreadState__curexc_type, exceptionTypeNative);
506511
}
507512
}
508513
}

0 commit comments

Comments
 (0)