Skip to content

Commit c00f325

Browse files
committed
implement equals for PrimitiveNativeWrappers so that pointer comparisons between Python primitives work in sandboxed
1 parent 7a95398 commit c00f325

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ public boolean isMemberModifiable(String member) {
11771177
}
11781178
}
11791179

1180-
public static class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
1180+
public static final class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
11811181

11821182
public static final byte PRIMITIVE_STATE_BOOL = 1 << 0;
11831183
public static final byte PRIMITIVE_STATE_BYTE = 1 << 1;
@@ -1260,6 +1260,16 @@ public void setMaterializedObject(Object materializedPrimitive) {
12601260
setDelegate(materializedPrimitive);
12611261
}
12621262

1263+
@Override
1264+
public boolean equals(Object obj) {
1265+
return obj instanceof PrimitiveNativeWrapper && ((PrimitiveNativeWrapper)obj).state == state && ((PrimitiveNativeWrapper)obj).value == value && ((PrimitiveNativeWrapper)obj).dvalue == dvalue;
1266+
}
1267+
1268+
@Override
1269+
public int hashCode() {
1270+
return (int) (value ^ Double.doubleToRawLongBits(dvalue) ^ state);
1271+
}
1272+
12631273
public static PrimitiveNativeWrapper createBool(boolean val) {
12641274
return new PrimitiveNativeWrapper(PRIMITIVE_STATE_BOOL, PInt.intValue(val));
12651275
}

0 commit comments

Comments
 (0)