41
41
package com .oracle .graal .python .builtins .objects .cext .capi ;
42
42
43
43
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .SystemError ;
44
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
44
45
import static com .oracle .graal .python .builtins .objects .cext .capi .transitions .ArgDescriptor .CharPtrAsTruffleString ;
45
46
import static com .oracle .graal .python .builtins .objects .cext .capi .transitions .ArgDescriptor .InitResult ;
46
47
import static com .oracle .graal .python .builtins .objects .cext .capi .transitions .ArgDescriptor .InquiryResult ;
63
64
import java .util .Arrays ;
64
65
65
66
import com .oracle .graal .python .PythonLanguage ;
66
- import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
67
67
import com .oracle .graal .python .builtins .objects .PNone ;
68
68
import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
69
69
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .PCallCapiFunction ;
140
140
import com .oracle .truffle .api .dsl .Fallback ;
141
141
import com .oracle .truffle .api .dsl .GenerateUncached ;
142
142
import com .oracle .truffle .api .dsl .ImportStatic ;
143
+ import com .oracle .truffle .api .dsl .NeverDefault ;
143
144
import com .oracle .truffle .api .dsl .Specialization ;
144
145
import com .oracle .truffle .api .dsl .TypeSystemReference ;
145
146
import com .oracle .truffle .api .frame .VirtualFrame ;
@@ -739,13 +740,12 @@ public static MethDirectRoot create(PythonLanguage lang, TruffleString name, PEx
739
740
/**
740
741
* Like {@link com.oracle.graal.python.nodes.call.FunctionInvokeNode} but invokes a C function.
741
742
*/
742
- static final class ExternalFunctionInvokeNode extends PNodeWithContext implements IndirectCallNode {
743
+ public static final class ExternalFunctionInvokeNode extends PNodeWithContext implements IndirectCallNode {
743
744
private final CApiTiming timing ;
744
745
@ Child private CheckFunctionResultNode checkResultNode ;
745
746
@ Child private PForeignToPTypeNode fromForeign = PForeignToPTypeNode .create ();
746
747
@ Child private CExtToJavaNode convertReturnValue ;
747
748
@ Child private InteropLibrary lib ;
748
- @ Child private PRaiseNode raiseNode ;
749
749
@ Child private GetThreadStateNode getThreadStateNode = GetThreadStateNodeGen .create ();
750
750
@ Child private GilNode gilNode = GilNode .create ();
751
751
@@ -810,13 +810,13 @@ public Object execute(VirtualFrame frame, TruffleString name, Object callable, O
810
810
if (convertReturnValue != null ) {
811
811
result = convertReturnValue .execute (result );
812
812
}
813
- return fromNative (result );
813
+ return fromForeign . executeConvert (result );
814
814
} catch (UnsupportedTypeException | UnsupportedMessageException e ) {
815
815
CompilerDirectives .transferToInterpreterAndInvalidate ();
816
- throw ensureRaiseNode (). raise ( PythonBuiltinClassType . TypeError , ErrorMessages .CALLING_NATIVE_FUNC_FAILED , name , e );
816
+ throw PRaiseNode . raiseUncached ( this , TypeError , ErrorMessages .CALLING_NATIVE_FUNC_FAILED , name , e );
817
817
} catch (ArityException e ) {
818
818
CompilerDirectives .transferToInterpreterAndInvalidate ();
819
- throw ensureRaiseNode (). raise ( PythonBuiltinClassType . TypeError , ErrorMessages .CALLING_NATIVE_FUNC_EXPECTED_ARGS , name , e .getExpectedMinArity (), e .getActualArity ());
819
+ throw PRaiseNode . raiseUncached ( this , TypeError , ErrorMessages .CALLING_NATIVE_FUNC_EXPECTED_ARGS , name , e .getExpectedMinArity (), e .getActualArity ());
820
820
} finally {
821
821
CApiTiming .exit (timing );
822
822
/*
@@ -830,23 +830,14 @@ public Object execute(VirtualFrame frame, TruffleString name, Object callable, O
830
830
* Special case after calling a C function: transfer caught exception back to frame
831
831
* to simulate the global state semantics.
832
832
*/
833
- PArguments .setException (frame , threadState .getCaughtException ());
833
+ if (frame != null ) {
834
+ PArguments .setException (frame , threadState .getCaughtException ());
835
+ }
834
836
IndirectCallContext .exit (frame , threadState , state );
835
837
}
836
838
}
837
839
838
- private Object fromNative (Object result ) {
839
- return fromForeign .executeConvert (result );
840
- }
841
-
842
- private PRaiseNode ensureRaiseNode () {
843
- if (raiseNode == null ) {
844
- CompilerDirectives .transferToInterpreterAndInvalidate ();
845
- raiseNode = insert (PRaiseNode .create ());
846
- }
847
- return raiseNode ;
848
- }
849
-
840
+ @ NeverDefault
850
841
public static ExternalFunctionInvokeNode create (PExternalFunctionWrapper provider ) {
851
842
return new ExternalFunctionInvokeNode (provider );
852
843
}
0 commit comments