Skip to content

Commit 4186078

Browse files
committed
Fix: incorrect PrimitiveNativeWrapper.isIdenticalOrUndefined
1 parent e322120 commit 4186078

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,14 +2137,22 @@ int identityHashCode() {
21372137
@ExportMessage
21382138
TriState isIdenticalOrUndefined(Object obj) {
21392139
if (obj instanceof PrimitiveNativeWrapper) {
2140-
// This basically emulates singletons for boxed values. However, we need to do
2141-
// so to
2142-
// preserve the invariant that storing an object into a list and getting it out
2143-
// (in
2144-
// the same critical region) returns the same object.
2140+
/*
2141+
* This basically emulates singletons for boxed values. However, we need to do so to
2142+
* preserve the invariant that storing an object into a list and getting it out (in
2143+
* the same critical region) returns the same object.
2144+
*/
21452145
PrimitiveNativeWrapper other = (PrimitiveNativeWrapper) obj;
2146-
return TriState.valueOf(other.state == state && other.value == value &&
2147-
(other.dvalue == dvalue || Double.isNaN(dvalue) && Double.isNaN(other.dvalue)));
2146+
if (other.state == state && other.value == value && (other.dvalue == dvalue || Double.isNaN(dvalue) && Double.isNaN(other.dvalue))) {
2147+
/*
2148+
* n.b.: in the equals, we also require the native pointer to be the same. The
2149+
* reason for this is to avoid native pointer sharing. Handles are shared if the
2150+
* objects are equal but in this case we must not share because otherwise we
2151+
* would mess up the reference counts.
2152+
*/
2153+
return TriState.valueOf(GetNativePointer.getGenericPtr(this) == GetNativePointer.getGenericPtr(other));
2154+
}
2155+
return TriState.FALSE;
21482156
} else {
21492157
return TriState.UNDEFINED;
21502158
}

0 commit comments

Comments
 (0)