Skip to content

Commit 9155b87

Browse files
committed
[GR-38445] Evaluate if PCallCapiFunction and PCallCExtFunction could be merged into one Node.
PullRequest: graalpython/2780
2 parents 28ed0b1 + c44d368 commit 9155b87

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
import com.oracle.truffle.api.dsl.GenerateUncached;
112112
import com.oracle.truffle.api.dsl.ImportStatic;
113113
import com.oracle.truffle.api.dsl.Specialization;
114-
import com.oracle.truffle.api.interop.ArityException;
115114
import com.oracle.truffle.api.interop.InteropException;
116115
import com.oracle.truffle.api.interop.InteropLibrary;
117116
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
@@ -212,32 +211,6 @@ protected Object importCAPISymbolUncached(CExtContext nativeContext, NativeCExtS
212211
}
213212
}
214213

215-
@GenerateUncached
216-
public abstract static class PCallCExtFunction extends PNodeWithContext {
217-
218-
public final Object call(CExtContext nativeContext, NativeCExtSymbol symbol, Object... args) {
219-
return execute(nativeContext, symbol, args);
220-
}
221-
222-
protected abstract Object execute(CExtContext nativeContext, NativeCExtSymbol symbol, Object[] args);
223-
224-
@Specialization
225-
static Object doIt(CExtContext nativeContext, NativeCExtSymbol symbol, Object[] args,
226-
@CachedLibrary(limit = "1") InteropLibrary interopLibrary,
227-
@Cached ImportCExtSymbolNode importCExtSymbolNode,
228-
@Cached EnsureTruffleStringNode ensureTruffleStringNode,
229-
@Cached PRaiseNode raiseNode) {
230-
try {
231-
// TODO review EnsureTruffleString with GR-37896
232-
return ensureTruffleStringNode.execute(interopLibrary.execute(importCExtSymbolNode.execute(nativeContext, symbol), args));
233-
} catch (UnsupportedTypeException | ArityException e) {
234-
throw raiseNode.raise(PythonBuiltinClassType.TypeError, e);
235-
} catch (UnsupportedMessageException e) {
236-
throw raiseNode.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAPI_SYM_NOT_CALLABLE, symbol.getTsName());
237-
}
238-
}
239-
}
240-
241214
@GenerateUncached
242215
public abstract static class EnsureTruffleStringNode extends Node {
243216
public abstract Object execute(Object obj);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
import com.oracle.graal.python.builtins.objects.cext.PythonNativeVoidPtr;
6060
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsCharPointerNode;
6161
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsNativeComplexNode;
62+
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
6263
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PRaiseNativeNode;
6364
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ToSulongNode;
6465
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodesFactory.TransformExceptionToNativeNodeGen;
6566
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
6667
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.NativeToPythonNode;
6768
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.AsNativeDoubleNode;
6869
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.AsNativePrimitiveNode;
69-
import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.PCallCExtFunction;
7070
import com.oracle.graal.python.builtins.objects.cext.common.CExtParseArgumentsNodeFactory.ConvertSingleArgNodeGen;
7171
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageLen;
7272
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
@@ -619,7 +619,7 @@ abstract static class ConvertArgNode extends Node {
619619
@Specialization(guards = "c == FORMAT_LOWER_Y")
620620
void doBufferR(@SuppressWarnings("unused") int c, int la, Object arg, Object varargs,
621621
@Cached GetNextVaArgNode getVaArgNode,
622-
@Cached PCallCExtFunction callGetBufferRwNode,
622+
@Cached PCallCapiFunction callGetBufferRwNode,
623623
@Shared("writeOutVarNode") @Cached WriteNextVaArgNode writeOutVarNode,
624624
@Cached ToSulongNode argToSulongNode,
625625
@Shared("raiseNode") @Cached PRaiseNativeNode raiseNode) throws InteropException {
@@ -712,7 +712,7 @@ static void doObject(@SuppressWarnings("unused") int c, int la, Object arg, Obje
712712
@Specialization(guards = "c == FORMAT_LOWER_W")
713713
void doBufferRW(@SuppressWarnings("unused") int c, int la, Object arg, Object varargs,
714714
@Cached GetNextVaArgNode getVaArgNode,
715-
@Cached PCallCExtFunction callGetBufferRwNode,
715+
@Cached PCallCapiFunction callGetBufferRwNode,
716716
@Cached ToSulongNode toNativeNode,
717717
@Shared("raiseNode") @Cached PRaiseNativeNode raiseNode) throws InteropException, ParseArgumentsException {
718718
if (la != '*') {
@@ -723,7 +723,7 @@ void doBufferRW(@SuppressWarnings("unused") int c, int la, Object arg, Object va
723723
getbuffer(callGetBufferRwNode, raiseNode, arg, toNativeNode, pybufferPtr, false);
724724
}
725725

726-
private void getbuffer(PCallCExtFunction callGetBufferRwNode, PRaiseNativeNode raiseNode, Object arg, CExtToNativeNode toSulongNode, Object pybufferPtr, boolean readOnly)
726+
private void getbuffer(PCallCapiFunction callGetBufferRwNode, PRaiseNativeNode raiseNode, Object arg, CExtToNativeNode toSulongNode, Object pybufferPtr, boolean readOnly)
727727
throws ParseArgumentsException {
728728
NativeCAPISymbol funSymbol = readOnly ? FUN_GET_BUFFER_R : FUN_GET_BUFFER_RW;
729729
Object rc = callGetBufferRwNode.call(PythonContext.get(this).getCApiContext(), funSymbol, toSulongNode.execute(arg), pybufferPtr);
@@ -745,7 +745,7 @@ private static ParseArgumentsException converterr(PRaiseNativeNode raiseNode, Tr
745745
throw raise(raiseNode, TypeError, ErrorMessages.MUST_BE_S_NOT_P, msg, arg);
746746
}
747747

748-
private int convertbuffer(PCallCExtFunction callConvertbuffer, PRaiseNativeNode raiseNode, Object arg, CExtToNativeNode toSulong, Object voidPtr) {
748+
private int convertbuffer(PCallCapiFunction callConvertbuffer, PRaiseNativeNode raiseNode, Object arg, CExtToNativeNode toSulong, Object voidPtr) {
749749
Object rc = callConvertbuffer.call(PythonContext.get(this).getCApiContext(), FUN_CONVERTBUFFER, toSulong.execute(arg), voidPtr);
750750
if (!(rc instanceof Number)) {
751751
throw CompilerDirectives.shouldNotReachHere("wrong result of internal function");
@@ -912,7 +912,7 @@ Object doGeneric(ParserState state, Object kwds, Object kwdnames, boolean keywor
912912
@Shared("getItemNode") @Cached PyTuple_GetItem getItemNode,
913913
@CachedLibrary(limit = "1") InteropLibrary kwdnamesLib,
914914
@Cached PyDict_GetItem getDictItemNode,
915-
@Cached PCallCExtFunction callCStringToString,
915+
@Cached PCallCapiFunction callCStringToString,
916916
@Shared("raiseNode") @Cached PRaiseNativeNode raiseNode) throws InteropException {
917917

918918
Object out = null;

0 commit comments

Comments
 (0)