|
83 | 83 | import java.util.concurrent.atomic.AtomicReference; |
84 | 84 | import java.util.logging.Level; |
85 | 85 |
|
| 86 | +import com.oracle.graal.python.lib.PyObjectGetAttr; |
86 | 87 | import org.graalvm.nativeimage.ImageInfo; |
87 | 88 |
|
88 | 89 | import com.oracle.graal.python.PythonLanguage; |
@@ -1723,7 +1724,8 @@ public enum Counter { |
1723 | 1724 | UpcallGlobalStore, |
1724 | 1725 | UpcallType, |
1725 | 1726 | UpcallTypeGetName, |
1726 | | - UpcallContextVarGet; |
| 1727 | + UpcallContextVarGet, |
| 1728 | + UpcallGetAttrS; |
1727 | 1729 |
|
1728 | 1730 | @CompilationFinal(dimensions = 1) private static final Counter[] VALUES = values(); |
1729 | 1731 | } |
@@ -1811,17 +1813,11 @@ public long ctxAsStruct(long handle) { |
1811 | 1813 |
|
1812 | 1814 | // Note: assumes that receiverHandle is not a boxed primitive value |
1813 | 1815 | @SuppressWarnings("try") |
1814 | | - public final int ctxSetItems(long receiverHandle, String name, long valueHandle) { |
| 1816 | + public int ctxSetItems(long receiverHandle, String name, long valueHandle) { |
1815 | 1817 | increment(Counter.UpcallSetItemS); |
1816 | 1818 | Object receiver = getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(receiverHandle)); |
1817 | | - Object value; |
1818 | | - if (GraalHPyBoxing.isBoxedHandle(valueHandle)) { |
1819 | | - value = getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(valueHandle)); |
1820 | | - } else if (GraalHPyBoxing.isBoxedInt(valueHandle)) { |
1821 | | - value = GraalHPyBoxing.unboxInt(valueHandle); |
1822 | | - } else if (GraalHPyBoxing.isBoxedDouble(valueHandle)) { |
1823 | | - value = GraalHPyBoxing.unboxDouble(valueHandle); |
1824 | | - } else { |
| 1819 | + Object value = bitsAsPythonObject(valueHandle); |
| 1820 | + if (value == GraalHPyHandle.NULL_HANDLE_DELEGATE) { |
1825 | 1821 | HPyRaiseNode.raiseIntUncached(this, -1, SystemError, ErrorMessages.HPY_UNEXPECTED_HPY_NULL); |
1826 | 1822 | return -1; |
1827 | 1823 | } |
@@ -2449,6 +2445,32 @@ public long ctxCapsuleGet(long capsuleBits, int key, long namePtr) { |
2449 | 2445 | } |
2450 | 2446 | } |
2451 | 2447 |
|
| 2448 | + public long ctxGetAttrs(long receiverHandle, String name) { |
| 2449 | + increment(Counter.UpcallGetAttrS); |
| 2450 | + Object receiver = bitsAsPythonObject(receiverHandle); |
| 2451 | + TruffleString tsName = toTruffleStringUncached(name); |
| 2452 | + Object result; |
| 2453 | + try { |
| 2454 | + result = PyObjectGetAttr.getUncached().execute(null, receiver, tsName); |
| 2455 | + } catch (PException e) { |
| 2456 | + HPyTransformExceptionToNativeNode.executeUncached(this, e); |
| 2457 | + return 0; |
| 2458 | + } |
| 2459 | + return GraalHPyBoxing.boxHandle(getHPyHandleForObject(result)); |
| 2460 | + } |
| 2461 | + |
| 2462 | + private Object bitsAsPythonObject(long bits) { |
| 2463 | + if (GraalHPyBoxing.isBoxedNullHandle(bits)) { |
| 2464 | + return GraalHPyHandle.NULL_HANDLE_DELEGATE; |
| 2465 | + } else if (GraalHPyBoxing.isBoxedInt(bits)) { |
| 2466 | + return GraalHPyBoxing.unboxInt(bits); |
| 2467 | + } else if (GraalHPyBoxing.isBoxedDouble(bits)) { |
| 2468 | + return GraalHPyBoxing.unboxDouble(bits); |
| 2469 | + } |
| 2470 | + assert GraalHPyBoxing.isBoxedHandle(bits); |
| 2471 | + return getObjectForHPyHandle(GraalHPyBoxing.unboxHandle(bits)); |
| 2472 | + } |
| 2473 | + |
2452 | 2474 | @ExportMessage |
2453 | 2475 | @SuppressWarnings("static-method") |
2454 | 2476 | boolean hasMembers() { |
|
0 commit comments