|
41 | 41 | // skip GIL
|
42 | 42 | package com.oracle.graal.python.builtins.objects.cext.hpy;
|
43 | 43 |
|
| 44 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError; |
44 | 45 | import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContext.HPyContextSignatureType.DataPtr;
|
45 | 46 | import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContext.HPyContextSignatureType.DataPtrPtr;
|
46 | 47 | import static com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyContext.HPyContextSignatureType.Double;
|
|
82 | 83 |
|
83 | 84 | import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
|
84 | 85 | import com.oracle.truffle.api.strings.TruffleString;
|
| 86 | +import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.HPyRaiseNode; |
| 87 | +import com.oracle.graal.python.builtins.objects.cext.hpy.GraalHPyNodes.HPyTransformExceptionToNativeNode; |
| 88 | +import com.oracle.graal.python.lib.PyObjectGetItem; |
| 89 | +import com.oracle.graal.python.lib.PyObjectSetItem; |
| 90 | +import com.oracle.graal.python.runtime.GilNode.UncachedAcquire; |
85 | 91 | import org.graalvm.nativeimage.ImageInfo;
|
86 | 92 |
|
87 | 93 | import com.oracle.graal.python.PythonLanguage;
|
@@ -1650,6 +1656,8 @@ public enum Counter {
|
1650 | 1656 | UpcallDictNew,
|
1651 | 1657 | UpcallListNew,
|
1652 | 1658 | UpcallTupleFromArray,
|
| 1659 | + UpcallGetItemS, |
| 1660 | + UpcallSetItemS, |
1653 | 1661 | UpcallFieldLoad,
|
1654 | 1662 | UpcallFieldStore,
|
1655 | 1663 | UpcallGlobalLoad,
|
@@ -1736,6 +1744,48 @@ public long ctxAsStruct(long handle) {
|
1736 | 1744 | return (long) HPyGetNativeSpacePointerNodeGen.getUncached().execute(receiver);
|
1737 | 1745 | }
|
1738 | 1746 |
|
| 1747 | + |
| 1748 | + // Note: assumes that receiverHandle is not a boxed primitive value |
| 1749 | + @SuppressWarnings("try") |
| 1750 | + public final int ctxSetItems(long receiverHandle, String name, long valueHandle) { |
| 1751 | + increment(Counter.UpcallSetItemS); |
| 1752 | + Object receiver = getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(receiverHandle)); |
| 1753 | + Object value; |
| 1754 | + if (GraalHPyBoxing.isBoxedHandle(valueHandle)) { |
| 1755 | + value = getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(valueHandle)); |
| 1756 | + } else if (GraalHPyBoxing.isBoxedInt(valueHandle)) { |
| 1757 | + value = GraalHPyBoxing.unboxInt(valueHandle); |
| 1758 | + } else if (GraalHPyBoxing.isBoxedDouble(valueHandle)) { |
| 1759 | + value = GraalHPyBoxing.unboxDouble(valueHandle); |
| 1760 | + } else { |
| 1761 | + HPyRaiseNode.raiseIntUncached(this, -1, SystemError, ErrorMessages.HPY_UNEXPECTED_HPY_NULL); |
| 1762 | + return -1; |
| 1763 | + } |
| 1764 | + try (UncachedAcquire gil = GilNode.uncachedAcquire()) { |
| 1765 | + PyObjectSetItem.getUncached().execute(null, receiver, name, value); |
| 1766 | + return 0; |
| 1767 | + } catch (PException e) { |
| 1768 | + HPyTransformExceptionToNativeNode.executeUncached(this, e); |
| 1769 | + return -1; |
| 1770 | + } |
| 1771 | + } |
| 1772 | + |
| 1773 | + // Note: assumes that receiverHandle is not a boxed primitive value |
| 1774 | + @SuppressWarnings("try") |
| 1775 | + public final long ctxGetItems(long receiverHandle, String name) { |
| 1776 | + increment(Counter.UpcallGetItemS); |
| 1777 | + Object receiver = getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(receiverHandle)); |
| 1778 | + TruffleString tsName = toTruffleStringUncached(name); |
| 1779 | + Object result; |
| 1780 | + try (UncachedAcquire gil = GilNode.uncachedAcquire()) { |
| 1781 | + result = PyObjectGetItem.getUncached().execute(null, receiver, tsName); |
| 1782 | + } catch (PException e) { |
| 1783 | + HPyTransformExceptionToNativeNode.executeUncached(this, e); |
| 1784 | + return 0; |
| 1785 | + } |
| 1786 | + return GraalHPyBoxing.boxHandle(getHPyHandleForObject(result)); |
| 1787 | + } |
| 1788 | + |
1739 | 1789 | public long ctxNew(long typeHandle, long dataOutVar) {
|
1740 | 1790 | increment(Counter.UpcallNew);
|
1741 | 1791 |
|
@@ -2352,7 +2402,7 @@ private static Object[] createMembers(PythonContext context, TruffleString name,
|
2352 | 2402 | createTypeConstant(members, HPyContextMember.H_INDENTATIONERROR, context, PythonBuiltinClassType.IndentationError);
|
2353 | 2403 | createTypeConstant(members, HPyContextMember.H_TABERROR, context, PythonBuiltinClassType.TabError);
|
2354 | 2404 | createTypeConstant(members, HPyContextMember.H_REFERENCEERROR, context, PythonBuiltinClassType.ReferenceError);
|
2355 |
| - createTypeConstant(members, HPyContextMember.H_SYSTEMERROR, context, PythonBuiltinClassType.SystemError); |
| 2405 | + createTypeConstant(members, HPyContextMember.H_SYSTEMERROR, context, SystemError); |
2356 | 2406 | createTypeConstant(members, HPyContextMember.H_SYSTEMEXIT, context, PythonBuiltinClassType.SystemExit);
|
2357 | 2407 | createTypeConstant(members, HPyContextMember.H_TYPEERROR, context, PythonBuiltinClassType.TypeError);
|
2358 | 2408 | createTypeConstant(members, HPyContextMember.H_UNBOUNDLOCALERROR, context, PythonBuiltinClassType.UnboundLocalError);
|
|
0 commit comments