103
103
import com .oracle .graal .python .builtins .objects .cext .common .CArrayWrappers .CStringWrapper ;
104
104
import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .CheckFunctionResultNode ;
105
105
import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .EnsureTruffleStringNode ;
106
- import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .ImportCExtSymbolNode ;
107
106
import com .oracle .graal .python .builtins .objects .cext .common .CExtContext ;
108
107
import com .oracle .graal .python .builtins .objects .cext .common .CExtContext .ModuleSpec ;
109
108
import com .oracle .graal .python .builtins .objects .cext .common .GetNextVaArgNode ;
@@ -233,7 +232,7 @@ Object callNativeConstructor(Object object, Object arg,
233
232
@ Cached PythonToNativeNode toSulongNode ,
234
233
@ Cached NativeToPythonNode toJavaNode ,
235
234
@ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary ,
236
- @ Cached ImportCExtSymbolNode importCAPISymbolNode ) {
235
+ @ Cached ImportCAPISymbolNode importCAPISymbolNode ) {
237
236
assert TypeNodes .NeedsNativeAllocationNode .executeUncached (object );
238
237
try {
239
238
CApiContext cApiContext = PythonContext .get (inliningTarget ).getCApiContext ();
@@ -584,7 +583,7 @@ public abstract static class PointerCompareNode extends Node {
584
583
585
584
public abstract boolean execute (Node inliningTarget , ComparisonOp op , Object a , Object b );
586
585
587
- private static boolean executeCFunction (Node inliningTarget , int op , Object a , Object b , InteropLibrary interopLibrary , ImportCExtSymbolNode importCAPISymbolNode ) {
586
+ private static boolean executeCFunction (Node inliningTarget , int op , Object a , Object b , InteropLibrary interopLibrary , ImportCAPISymbolNode importCAPISymbolNode ) {
588
587
try {
589
588
Object sym = importCAPISymbolNode .execute (inliningTarget , FUN_PTR_COMPARE );
590
589
return (int ) interopLibrary .execute (sym , a , b , op ) != 0 ;
@@ -604,23 +603,23 @@ static boolean doEqNe(ComparisonOp op, PythonAbstractNativeObject a, PythonAbstr
604
603
@ Specialization
605
604
static boolean doPythonNativeObject (Node inliningTarget , ComparisonOp op , PythonNativeObject a , PythonNativeObject b ,
606
605
@ Shared @ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary ,
607
- @ Shared @ Cached ImportCExtSymbolNode importCAPISymbolNode ) {
606
+ @ Shared @ Cached ImportCAPISymbolNode importCAPISymbolNode ) {
608
607
CompilerAsserts .partialEvaluationConstant (op );
609
608
return executeCFunction (inliningTarget , op .opCode , a .getPtr (), b .getPtr (), interopLibrary , importCAPISymbolNode );
610
609
}
611
610
612
611
@ Specialization
613
612
static boolean doPythonNativeObjectLong (Node inliningTarget , ComparisonOp op , PythonNativeObject a , long b ,
614
613
@ Shared @ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary ,
615
- @ Shared @ Cached ImportCExtSymbolNode importCAPISymbolNode ) {
614
+ @ Shared @ Cached ImportCAPISymbolNode importCAPISymbolNode ) {
616
615
CompilerAsserts .partialEvaluationConstant (op );
617
616
return executeCFunction (inliningTarget , op .opCode , a .getPtr (), b , interopLibrary , importCAPISymbolNode );
618
617
}
619
618
620
619
@ Specialization
621
620
static boolean doNativeVoidPtrLong (Node inliningTarget , ComparisonOp op , PythonNativeVoidPtr a , long b ,
622
621
@ Shared @ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary ,
623
- @ Shared @ Cached ImportCExtSymbolNode importCAPISymbolNode ) {
622
+ @ Shared @ Cached ImportCAPISymbolNode importCAPISymbolNode ) {
624
623
CompilerAsserts .partialEvaluationConstant (op );
625
624
return executeCFunction (inliningTarget , op .opCode , a .getPointerObject (), b , interopLibrary , importCAPISymbolNode );
626
625
}
@@ -825,7 +824,7 @@ public final Object call(NativeCAPISymbol symbol, Object... args) {
825
824
@ Specialization
826
825
static Object doWithoutContext (NativeCAPISymbol name , Object [] args ,
827
826
@ Bind ("this" ) Node inliningTarget ,
828
- @ Cached ImportCExtSymbolNode importCExtSymbolNode ,
827
+ @ Cached ImportCAPISymbolNode importCAPISymbolNode ,
829
828
@ CachedLibrary (limit = "1" ) InteropLibrary interopLibrary ,
830
829
@ Cached EnsureTruffleStringNode ensureTruffleStringNode ) {
831
830
try {
@@ -838,7 +837,7 @@ static Object doWithoutContext(NativeCAPISymbol name, Object[] args,
838
837
cApiContext = pythonContext .getCApiContext ();
839
838
}
840
839
// TODO review EnsureTruffleStringNode with GR-37896
841
- return ensureTruffleStringNode .execute (inliningTarget , interopLibrary .execute (importCExtSymbolNode .execute (inliningTarget , cApiContext , name ), args ));
840
+ return ensureTruffleStringNode .execute (inliningTarget , interopLibrary .execute (importCAPISymbolNode .execute (inliningTarget , cApiContext , name ), args ));
842
841
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e ) {
843
842
// consider these exceptions to be fatal internal errors
844
843
throw shouldNotReachHere (e );
@@ -2021,4 +2020,28 @@ public static Object resolveClosurePointer(PythonContext context, Object callabl
2021
2020
return null ;
2022
2021
}
2023
2022
}
2023
+
2024
+ @ GenerateUncached
2025
+ @ GenerateInline
2026
+ @ GenerateCached (false )
2027
+ public abstract static class ImportCAPISymbolNode extends PNodeWithContext {
2028
+
2029
+ public final Object execute (Node inliningTarget , NativeCAPISymbol symbol ) {
2030
+ return execute (inliningTarget , PythonContext .get (inliningTarget ).getCApiContext (), symbol );
2031
+ }
2032
+
2033
+ public abstract Object execute (Node inliningTarget , CApiContext nativeContext , NativeCAPISymbol symbol );
2034
+
2035
+ @ Specialization (guards = {"isSingleContext()" , "cachedSymbol == symbol" }, limit = "1" )
2036
+ static Object doCached (@ SuppressWarnings ("unused" ) Node inliningTarget , @ SuppressWarnings ("unused" ) CApiContext nativeContext , @ SuppressWarnings ("unused" ) NativeCAPISymbol symbol ,
2037
+ @ Cached ("symbol" ) @ SuppressWarnings ("unused" ) NativeCAPISymbol cachedSymbol ,
2038
+ @ Cached (value = "nativeContext.getNativeSymbol(symbol)" , weak = true ) Object llvmSymbol ) {
2039
+ return llvmSymbol ;
2040
+ }
2041
+
2042
+ @ Specialization (replaces = "doCached" )
2043
+ static Object doGeneric (CApiContext nativeContext , NativeCAPISymbol symbol ) {
2044
+ return nativeContext .getNativeSymbol (symbol );
2045
+ }
2046
+ }
2024
2047
}
0 commit comments