Skip to content

Commit f40791f

Browse files
committed
fix native argument passing
1 parent 1fb2b56 commit f40791f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ public void finalizeContext() {
26252625
private long nativeArgumentsStack = 0;
26262626
private int nativeArgumentStackPos = 0;
26272627

2628-
public final long createNativeArguments(Object[] delegate) {
2628+
public final long createNativeArguments(Object[] delegate, InteropLibrary delegateLib) {
26292629
if (nativeArgumentsStack == 0) {
26302630
CompilerDirectives.transferToInterpreterAndInvalidate();
26312631
nativeArgumentsStack = unsafe.allocateMemory(NATIVE_ARGUMENT_STACK_SIZE);
@@ -2639,7 +2639,13 @@ public final long createNativeArguments(Object[] delegate) {
26392639
nativeArgumentsStack += arraySize;
26402640

26412641
for (int i = 0; i < delegate.length; i++) {
2642-
unsafe.putLong(arrayPtr + i * SIZEOF_LONG, ((GraalHPyHandle) delegate[i]).getId(this, ConditionProfile.getUncached()));
2642+
Object element = delegate[i];
2643+
delegateLib.toNative(element);
2644+
try {
2645+
unsafe.putLong(arrayPtr + i * SIZEOF_LONG, delegateLib.asPointer(element));
2646+
} catch (UnsupportedMessageException ex) {
2647+
throw CompilerDirectives.shouldNotReachHere(ex);
2648+
}
26432649
}
26442650
return arrayPtr;
26452651
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyArrayWrappers.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
5555
import com.oracle.truffle.api.interop.TruffleObject;
5656
import com.oracle.truffle.api.interop.UnsupportedMessageException;
57+
import com.oracle.truffle.api.library.CachedLibrary;
5758
import com.oracle.truffle.api.library.ExportLibrary;
5859
import com.oracle.truffle.api.library.ExportMessage;
5960
import com.oracle.truffle.api.nodes.ExplodeLoop;
@@ -173,6 +174,7 @@ long asPointer() throws UnsupportedMessageException {
173174
@ExportMessage
174175
void toNative(
175176
@Cached.Exclusive @Cached InvalidateNativeObjectsAllManagedNode invalidateNode,
177+
@CachedLibrary(limit = "1") InteropLibrary delegateLib,
176178
@Shared("asHandleNode") @Cached HPyAsHandleNode asHandleNode) {
177179
invalidateNode.execute();
178180
if (!isPointer()) {
@@ -182,7 +184,7 @@ void toNative(
182184
delegate[i] = asHandleNode.execute(hpyContext, element);
183185
}
184186
}
185-
setNativePointer(hpyContext.createNativeArguments(delegate));
187+
setNativePointer(hpyContext.createNativeArguments(delegate, delegateLib));
186188
}
187189
}
188190

0 commit comments

Comments
 (0)