Skip to content

Commit d39d920

Browse files
committed
Fix: ctx_Tuple_FromArray did not correctly read array elements
1 parent 6fa6a5d commit d39d920

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import java.nio.charset.StandardCharsets;
6262
import java.util.WeakHashMap;
6363

64+
import com.oracle.truffle.api.interop.UnknownIdentifierException;
6465
import org.graalvm.collections.Pair;
6566

6667
import com.oracle.graal.python.PythonLanguage;
@@ -1651,13 +1652,20 @@ Object execute(Object[] arguments,
16511652
Object[] elements = new Object[n];
16521653
try {
16531654
for (int i = 0; i < elements.length; i++) {
1654-
elements[i] = asPythonObjectNode.execute(nativeContext, lib.readArrayElement(typedArrayPtr, i));
1655+
// This will read an element of a 'HPy arr[]' and the returned value will be
1656+
// an HPy "structure". So, we also need to read element "_i" to get the
1657+
// internal handle value.
1658+
Object hpyStructPtr = lib.readArrayElement(typedArrayPtr, i);
1659+
elements[i] = asPythonObjectNode.execute(nativeContext, lib.readMember(hpyStructPtr, GraalHPyHandle.I));
16551660
}
16561661
} catch (UnsupportedMessageException e) {
16571662
throw CompilerDirectives.shouldNotReachHere(e);
16581663
} catch (InvalidArrayIndexException e) {
16591664
CompilerDirectives.transferToInterpreterAndInvalidate();
16601665
throw raiseNode.raise(SystemError, "Cannot access index %d although array should have size %d ", e.getInvalidIndex(), n);
1666+
} catch (UnknownIdentifierException e) {
1667+
CompilerDirectives.transferToInterpreterAndInvalidate();
1668+
throw raiseNode.raise(SystemError, "Cannot read handle value");
16611669
}
16621670

16631671
return asHandleNode.execute(nativeContext, factory.createTuple(elements));

0 commit comments

Comments
 (0)