|
90 | 90 | import com.oracle.truffle.api.dsl.NodeFactory;
|
91 | 91 | import com.oracle.truffle.api.dsl.Specialization;
|
92 | 92 | import com.oracle.truffle.api.dsl.TypeSystemReference;
|
| 93 | +import com.oracle.truffle.api.interop.ForeignAccess; |
| 94 | +import com.oracle.truffle.api.interop.Message; |
| 95 | +import com.oracle.truffle.api.interop.UnsupportedMessageException; |
| 96 | +import com.oracle.truffle.api.nodes.Node; |
93 | 97 | import com.oracle.truffle.api.profiles.BranchProfile;
|
94 | 98 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
95 | 99 |
|
@@ -1485,6 +1489,41 @@ boolean doDN(PythonNativeObject x, double y,
|
1485 | 1489 | return fromNativeNode.execute(x) < y;
|
1486 | 1490 | }
|
1487 | 1491 |
|
| 1492 | + protected static Node createAsPointerNode() { |
| 1493 | + return Message.AS_POINTER.createNode(); |
| 1494 | + } |
| 1495 | + |
| 1496 | + protected static Node createIsPointerNode() { |
| 1497 | + return Message.IS_POINTER.createNode(); |
| 1498 | + } |
| 1499 | + |
| 1500 | + protected static Node createIsNullNode() { |
| 1501 | + return Message.IS_NULL.createNode(); |
| 1502 | + } |
| 1503 | + |
| 1504 | + @Specialization |
| 1505 | + boolean doVoidPtr(PythonNativeVoidPtr x, long y, |
| 1506 | + @Cached("createIsPointerNode()") Node isPointerNode, |
| 1507 | + @Cached("createAsPointerNode()") Node asPointerNode, |
| 1508 | + @Cached("createIsNullNode()") Node isNullNode) { |
| 1509 | + boolean isPointer = ForeignAccess.sendIsPointer(isPointerNode, x.object); |
| 1510 | + if (isPointer) { |
| 1511 | + try { |
| 1512 | + return ForeignAccess.sendAsPointer(asPointerNode, x.object) < y; |
| 1513 | + } catch (UnsupportedMessageException e) { |
| 1514 | + CompilerDirectives.transferToInterpreter(); |
| 1515 | + throw new IllegalStateException("a void ptr should be a ptr"); |
| 1516 | + } |
| 1517 | + } else if (ForeignAccess.sendIsNull(isNullNode, x.object)) { |
| 1518 | + return 0 < y; |
| 1519 | + } else if (y <= 0) { |
| 1520 | + return false; |
| 1521 | + } else { |
| 1522 | + CompilerDirectives.transferToInterpreter(); |
| 1523 | + throw new IllegalStateException("cannot compare a wrapped void ptr that has no native allocation against arbitrary integers"); |
| 1524 | + } |
| 1525 | + } |
| 1526 | + |
1488 | 1527 | @SuppressWarnings("unused")
|
1489 | 1528 | @Fallback
|
1490 | 1529 | PNotImplemented doGeneric(Object a, Object b) {
|
|
0 commit comments