Skip to content

Commit 99fc72d

Browse files
committed
Remove ImportCAPISymbolNode
1 parent e4c5e6f commit 99fc72d

File tree

6 files changed

+24
-52
lines changed

6 files changed

+24
-52
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ private static Object[] getSymbolCache(Node caller) {
446446
return PythonContext.get(caller).getCApiContext().nativeSymbolCache;
447447
}
448448

449-
static Object getNativeSymbol(Node caller, NativeCAPISymbol symbol) {
449+
public static Object getNativeSymbol(Node caller, NativeCAPISymbol symbol) {
450450
Object[] nativeSymbolCache = getSymbolCache(caller);
451451
Object result = nativeSymbolCache[symbol.ordinal()];
452452
if (result == null) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,11 @@ Object callNativeConstructor(Object object, Object arg,
231231
@Bind("this") Node inliningTarget,
232232
@Cached PythonToNativeNode toSulongNode,
233233
@Cached NativeToPythonNode toJavaNode,
234-
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
235-
@Cached ImportCAPISymbolNode importCAPISymbolNode) {
234+
@CachedLibrary(limit = "1") InteropLibrary interopLibrary) {
236235
assert TypeNodes.NeedsNativeAllocationNode.executeUncached(object);
237236
try {
238-
CApiContext cApiContext = PythonContext.get(inliningTarget).getCApiContext();
239-
Object result = interopLibrary.execute(importCAPISymbolNode.execute(inliningTarget, cApiContext, getFunction()), toSulongNode.execute(object), arg);
237+
Object callable = CApiContext.getNativeSymbol(inliningTarget, getFunction());
238+
Object result = interopLibrary.execute(callable, toSulongNode.execute(object), arg);
240239
return toJavaNode.execute(result);
241240
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
242241
throw shouldNotReachHere("C subtype_new function failed", e);
@@ -583,9 +582,9 @@ public abstract static class PointerCompareNode extends Node {
583582

584583
public abstract boolean execute(Node inliningTarget, ComparisonOp op, Object a, Object b);
585584

586-
private static boolean executeCFunction(Node inliningTarget, int op, Object a, Object b, InteropLibrary interopLibrary, ImportCAPISymbolNode importCAPISymbolNode) {
585+
private static boolean executeCFunction(Node inliningTarget, int op, Object a, Object b, InteropLibrary interopLibrary) {
587586
try {
588-
Object sym = importCAPISymbolNode.execute(inliningTarget, FUN_PTR_COMPARE);
587+
Object sym = CApiContext.getNativeSymbol(inliningTarget, FUN_PTR_COMPARE);
589588
return (int) interopLibrary.execute(sym, a, b, op) != 0;
590589
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
591590
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -602,26 +601,23 @@ static boolean doEqNe(ComparisonOp op, PythonAbstractNativeObject a, PythonAbstr
602601

603602
@Specialization
604603
static boolean doPythonNativeObject(Node inliningTarget, ComparisonOp op, PythonNativeObject a, PythonNativeObject b,
605-
@Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary,
606-
@Shared @Cached ImportCAPISymbolNode importCAPISymbolNode) {
604+
@Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary) {
607605
CompilerAsserts.partialEvaluationConstant(op);
608-
return executeCFunction(inliningTarget, op.opCode, a.getPtr(), b.getPtr(), interopLibrary, importCAPISymbolNode);
606+
return executeCFunction(inliningTarget, op.opCode, a.getPtr(), b.getPtr(), interopLibrary);
609607
}
610608

611609
@Specialization
612610
static boolean doPythonNativeObjectLong(Node inliningTarget, ComparisonOp op, PythonNativeObject a, long b,
613-
@Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary,
614-
@Shared @Cached ImportCAPISymbolNode importCAPISymbolNode) {
611+
@Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary) {
615612
CompilerAsserts.partialEvaluationConstant(op);
616-
return executeCFunction(inliningTarget, op.opCode, a.getPtr(), b, interopLibrary, importCAPISymbolNode);
613+
return executeCFunction(inliningTarget, op.opCode, a.getPtr(), b, interopLibrary);
617614
}
618615

619616
@Specialization
620617
static boolean doNativeVoidPtrLong(Node inliningTarget, ComparisonOp op, PythonNativeVoidPtr a, long b,
621-
@Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary,
622-
@Shared @Cached ImportCAPISymbolNode importCAPISymbolNode) {
618+
@Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary) {
623619
CompilerAsserts.partialEvaluationConstant(op);
624-
return executeCFunction(inliningTarget, op.opCode, a.getPointerObject(), b, interopLibrary, importCAPISymbolNode);
620+
return executeCFunction(inliningTarget, op.opCode, a.getPointerObject(), b, interopLibrary);
625621
}
626622
}
627623

@@ -822,22 +818,19 @@ public final Object call(NativeCAPISymbol symbol, Object... args) {
822818
protected abstract Object execute(NativeCAPISymbol symbol, Object[] args);
823819

824820
@Specialization
825-
static Object doWithoutContext(NativeCAPISymbol name, Object[] args,
821+
static Object doWithoutContext(NativeCAPISymbol symbol, Object[] args,
826822
@Bind("this") Node inliningTarget,
827-
@Cached ImportCAPISymbolNode importCAPISymbolNode,
828823
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
829824
@Cached EnsureTruffleStringNode ensureTruffleStringNode) {
830825
try {
831826
PythonContext pythonContext = PythonContext.get(inliningTarget);
832-
CApiContext cApiContext;
833827
if (!pythonContext.hasCApiContext()) {
834828
CompilerDirectives.transferToInterpreterAndInvalidate();
835-
cApiContext = CApiContext.ensureCapiWasLoaded();
836-
} else {
837-
cApiContext = pythonContext.getCApiContext();
829+
CApiContext.ensureCapiWasLoaded();
838830
}
839831
// TODO review EnsureTruffleStringNode with GR-37896
840-
return ensureTruffleStringNode.execute(inliningTarget, interopLibrary.execute(importCAPISymbolNode.execute(inliningTarget, cApiContext, name), args));
832+
Object callable = CApiContext.getNativeSymbol(inliningTarget, symbol);
833+
return ensureTruffleStringNode.execute(inliningTarget, interopLibrary.execute(callable, args));
841834
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
842835
// consider these exceptions to be fatal internal errors
843836
throw shouldNotReachHere(e);
@@ -2020,21 +2013,4 @@ public static Object resolveClosurePointer(PythonContext context, Object callabl
20202013
return null;
20212014
}
20222015
}
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
2036-
static Object doGeneric(Node inliningTarget, @SuppressWarnings("unused") CApiContext nativeContext, NativeCAPISymbol symbol) {
2037-
return CApiContext.getNativeSymbol(inliningTarget, symbol);
2038-
}
2039-
}
20402016
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceDelItemNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
import com.oracle.graal.python.builtins.objects.PNone;
4747
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
48-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
48+
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
4949
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
5050
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
5151
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
@@ -110,9 +110,8 @@ static Object doGenericManaged(VirtualFrame frame, Object object, int index,
110110
static Object doNative(VirtualFrame frame, PythonAbstractNativeObject object, int index,
111111
@Bind("this") Node inliningTarget,
112112
@Cached CApiTransitions.PythonToNativeNode toNativeNode,
113-
@Cached CExtNodes.ImportCAPISymbolNode importCAPISymbolNode,
114113
@Cached ExternalFunctionNodes.ExternalFunctionInvokeNode invokeNode) {
115-
Object executable = importCAPISymbolNode.execute(inliningTarget, SYMBOL);
114+
Object executable = CApiContext.getNativeSymbol(inliningTarget, SYMBOL);
116115
return invokeNode.execute(frame, DELITEM, C_API_TIMING, SYMBOL.getTsName(), executable, new Object[]{toNativeNode.execute(object), index});
117116
}
118117
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceGetItemNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
import com.oracle.graal.python.builtins.objects.PNone;
4747
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
48-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
48+
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
4949
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
5050
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
5151
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
@@ -110,9 +110,8 @@ static Object doGenericManaged(VirtualFrame frame, Object object, int index,
110110
static Object doNative(VirtualFrame frame, PythonAbstractNativeObject object, int index,
111111
@Bind("this") Node inliningTarget,
112112
@Cached CApiTransitions.PythonToNativeNode toNativeNode,
113-
@Cached CExtNodes.ImportCAPISymbolNode importCAPISymbolNode,
114113
@Cached ExternalFunctionNodes.ExternalFunctionInvokeNode invokeNode) {
115-
Object executable = importCAPISymbolNode.execute(inliningTarget, SYMBOL);
114+
Object executable = CApiContext.getNativeSymbol(inliningTarget, SYMBOL);
116115
return invokeNode.execute(frame, GETITEM, C_API_TIMING, SYMBOL.getTsName(), executable, new Object[]{toNativeNode.execute(object), index});
117116
}
118117
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSetItemNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
import com.oracle.graal.python.builtins.objects.PNone;
4747
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
48-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
48+
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
4949
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
5050
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
5151
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
@@ -110,9 +110,8 @@ static Object doGenericManaged(VirtualFrame frame, Object object, int index, Obj
110110
static Object doNative(VirtualFrame frame, PythonAbstractNativeObject object, int index, Object value,
111111
@Bind("this") Node inliningTarget,
112112
@Cached CApiTransitions.PythonToNativeNode toNativeNode,
113-
@Cached CExtNodes.ImportCAPISymbolNode importCAPISymbolNode,
114113
@Cached ExternalFunctionNodes.ExternalFunctionInvokeNode invokeNode) {
115-
Object executable = importCAPISymbolNode.execute(inliningTarget, SYMBOL);
114+
Object executable = CApiContext.getNativeSymbol(inliningTarget, SYMBOL);
116115
return invokeNode.execute(frame, SETITEM, C_API_TIMING, SYMBOL.getTsName(), executable, new Object[]{toNativeNode.execute(object), index, toNativeNode.execute(value)});
117116
}
118117
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
import com.oracle.graal.python.builtins.objects.PNone;
4747
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
48-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
48+
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
4949
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
5050
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
5151
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
@@ -125,9 +125,8 @@ static long doGenericManaged(VirtualFrame frame, Object object,
125125
static long doNative(VirtualFrame frame, PythonAbstractNativeObject object,
126126
@Bind("this") Node inliningTarget,
127127
@Cached CApiTransitions.PythonToNativeNode toNativeNode,
128-
@Cached CExtNodes.ImportCAPISymbolNode importCAPISymbolNode,
129128
@Cached ExternalFunctionNodes.ExternalFunctionInvokeNode invokeNode) {
130-
Object executable = importCAPISymbolNode.execute(inliningTarget, SYMBOL);
129+
Object executable = CApiContext.getNativeSymbol(inliningTarget, SYMBOL);
131130
Object size = invokeNode.execute(frame, LENFUNC, C_API_TIMING, SYMBOL.getTsName(), executable, new Object[]{toNativeNode.execute(object)});
132131
assert PGuards.isInteger(size);
133132
return (long) size;

0 commit comments

Comments
 (0)