103103import com .oracle .graal .python .builtins .objects .cext .PythonNativeVoidPtr ;
104104import com .oracle .graal .python .builtins .objects .cext .capi .CApiContext ;
105105import com .oracle .graal .python .builtins .objects .cext .capi .CApiContext .AllocInfo ;
106+ import com .oracle .graal .python .builtins .objects .cext .capi .CApiContext .LLVMType ;
106107import com .oracle .graal .python .builtins .objects .cext .capi .CApiGuards ;
107108import com .oracle .graal .python .builtins .objects .cext .capi .CArrayWrappers .CStringWrapper ;
108109import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes ;
120121import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .FastCallArgsToSulongNode ;
121122import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .FastCallWithKeywordsArgsToSulongNode ;
122123import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .FromCharPointerNode ;
124+ import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .GetLLVMType ;
123125import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .GetNativeNullNode ;
124126import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .MayRaiseErrorResult ;
125127import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .MayRaiseNode ;
278280import com .oracle .truffle .api .dsl .Specialization ;
279281import com .oracle .truffle .api .dsl .TypeSystemReference ;
280282import com .oracle .truffle .api .frame .VirtualFrame ;
283+ import com .oracle .truffle .api .interop .ArityException ;
281284import com .oracle .truffle .api .interop .InteropException ;
282285import com .oracle .truffle .api .interop .InteropLibrary ;
283286import com .oracle .truffle .api .interop .InvalidArrayIndexException ;
284287import com .oracle .truffle .api .interop .TruffleObject ;
288+ import com .oracle .truffle .api .interop .UnknownIdentifierException ;
285289import com .oracle .truffle .api .interop .UnsupportedMessageException ;
290+ import com .oracle .truffle .api .interop .UnsupportedTypeException ;
286291import com .oracle .truffle .api .library .CachedLibrary ;
287292import com .oracle .truffle .api .nodes .ControlFlowException ;
288293import com .oracle .truffle .api .nodes .Node ;
@@ -3307,13 +3312,15 @@ static Object doFunction(VirtualFrame frame, Object callableObj, Object vaList,
33073312 @ Shared ("argLib" ) @ CachedLibrary (limit = "2" ) InteropLibrary argLib ,
33083313 @ CachedLibrary (limit = "1" ) PythonObjectLibrary callableLib ,
33093314 @ Cached AsPythonObjectNode asPythonObjectNode ,
3315+ @ Cached CExtNodes .ToJavaNode toJavaNode ,
3316+ @ Cached GetLLVMType getLLVMType ,
33103317 @ Cached ToNewRefNode toNewRefNode ,
33113318 @ Cached GetNativeNullNode getNativeNullNode ,
33123319 @ Cached CExtNodes .ToSulongNode nullToSulongNode ,
33133320 @ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ) {
33143321 try {
33153322 Object callable = asPythonObjectNode .execute (callableObj );
3316- return toNewRefNode .execute (callFunction (frame , callable , vaList , argsArrayLib , argLib , callableLib , asPythonObjectNode ));
3323+ return toNewRefNode .execute (callFunction (frame , callable , vaList , argsArrayLib , argLib , callableLib , toJavaNode , getLLVMType ));
33173324 } catch (PException e ) {
33183325 // transformExceptionToNativeNode acts as a branch profile
33193326 transformExceptionToNativeNode .execute (frame , e );
@@ -3325,7 +3332,8 @@ static Object callFunction(VirtualFrame frame, Object callable, Object vaList,
33253332 InteropLibrary argsArrayLib ,
33263333 InteropLibrary argLib ,
33273334 PythonObjectLibrary callableLib ,
3328- AsPythonObjectNode asPythonObjectNode ) {
3335+ CExtNodes .ToJavaNode toJavaNode ,
3336+ GetLLVMType getLLVMType ) {
33293337 if (argsArrayLib .hasArrayElements (vaList )) {
33303338 try {
33313339 /*
@@ -3339,15 +3347,16 @@ static Object callFunction(VirtualFrame frame, Object callable, Object vaList,
33393347 long arraySize = argsArrayLib .getArraySize (vaList );
33403348 Object [] args = new Object [PInt .intValueExact (arraySize ) - 1 ];
33413349 int filled = 0 ;
3350+ Object llvmPyObjectPtrType = getLLVMType .execute (LLVMType .PyObject_ptr_t );
33423351 for (int i = 0 ; i < args .length ; i ++) {
33433352 try {
3344- Object object = argsArrayLib .readArrayElement (vaList , i );
3353+ Object object = argsArrayLib .invokeMember (vaList , "get" , i , llvmPyObjectPtrType );
33453354 if (argLib .isNull (object )) {
33463355 break ;
33473356 }
3348- args [i ] = asPythonObjectNode .execute (object );
3357+ args [i ] = toJavaNode .execute (object );
33493358 filled ++;
3350- } catch (InvalidArrayIndexException e ) {
3359+ } catch (ArityException | UnknownIdentifierException | UnsupportedTypeException e ) {
33513360 throw CompilerDirectives .shouldNotReachHere ();
33523361 }
33533362 }
@@ -3377,6 +3386,8 @@ static Object doMethod(VirtualFrame frame, Object receiverObj, Object methodName
33773386 @ Shared ("argLib" ) @ CachedLibrary (limit = "2" ) InteropLibrary argLib ,
33783387 @ Cached GetAnyAttributeNode getAnyAttributeNode ,
33793388 @ Cached AsPythonObjectNode asPythonObjectNode ,
3389+ @ Cached CExtNodes .ToJavaNode toJavaNode ,
3390+ @ Cached GetLLVMType getLLVMType ,
33803391 @ Cached ToNewRefNode toNewRefNode ,
33813392 @ Cached GetNativeNullNode getNativeNullNode ,
33823393 @ Cached CExtNodes .ToSulongNode nullToSulongNode ,
@@ -3386,7 +3397,7 @@ static Object doMethod(VirtualFrame frame, Object receiverObj, Object methodName
33863397 Object receiver = asPythonObjectNode .execute (receiverObj );
33873398 Object methodName = asPythonObjectNode .execute (methodNameObj );
33883399 Object method = getAnyAttributeNode .executeObject (frame , receiver , methodName );
3389- return toNewRefNode .execute (PyObjectCallFunctionObjArgsNode .callFunction (frame , method , vaList , argsArrayLib , argLib , methodLib , asPythonObjectNode ));
3400+ return toNewRefNode .execute (PyObjectCallFunctionObjArgsNode .callFunction (frame , method , vaList , argsArrayLib , argLib , methodLib , toJavaNode , getLLVMType ));
33903401 } catch (PException e ) {
33913402 // transformExceptionToNativeNode acts as a branch profile
33923403 transformExceptionToNativeNode .execute (frame , e );
@@ -3434,6 +3445,7 @@ abstract static class PyObjectFastCallDictNode extends PythonTernaryBuiltinNode
34343445 @ Specialization (limit = "1" )
34353446 static Object doGeneric (VirtualFrame frame , Object callableObj , Object argsArray , Object kwargsObj ,
34363447 @ CachedLibrary ("argsArray" ) InteropLibrary argsArrayLib ,
3448+ @ Cached CExtNodes .ToJavaNode toJavaNode ,
34373449 @ Cached AsPythonObjectNode asPythonObjectNode ,
34383450 @ Cached CastKwargsNode castKwargsNode ,
34393451 @ Cached CallNode callNode ,
@@ -3449,7 +3461,7 @@ static Object doGeneric(VirtualFrame frame, Object callableObj, Object argsArray
34493461 Object [] args = new Object [PInt .intValueExact (arraySize )];
34503462 for (int i = 0 ; i < args .length ; i ++) {
34513463 try {
3452- args [i ] = asPythonObjectNode .execute (argsArrayLib .readArrayElement (argsArray , i ));
3464+ args [i ] = toJavaNode .execute (argsArrayLib .readArrayElement (argsArray , i ));
34533465 } catch (InvalidArrayIndexException e ) {
34543466 throw CompilerDirectives .shouldNotReachHere ();
34553467 }
@@ -3487,9 +3499,9 @@ static Object[] doNull(VirtualFrame frame, Object argsObj,
34873499 @ Specialization (guards = "!lib.isNull(argsObj)" )
34883500 static Object [] doNotNull (VirtualFrame frame , Object argsObj ,
34893501 @ Cached ExecutePositionalStarargsNode expandArgsNode ,
3490- @ Cached AsPythonObjectNode argsToJavaNode ,
3502+ @ Cached AsPythonObjectNode asPythonObjectNode ,
34913503 @ Shared ("lib" ) @ CachedLibrary (limit = "3" ) @ SuppressWarnings ("unused" ) InteropLibrary lib ) {
3492- return expandArgsNode .executeWith (frame , argsToJavaNode .execute (argsObj ));
3504+ return expandArgsNode .executeWith (frame , asPythonObjectNode .execute (argsObj ));
34933505 }
34943506 }
34953507
0 commit comments