Skip to content

Commit ee923bf

Browse files
committed
Implement ReferenceLibrary for PrimitiveNativeWrapper.
1 parent c277dc8 commit ee923bf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
import com.oracle.truffle.api.dsl.Cached.Exclusive;
146146
import com.oracle.truffle.api.dsl.Cached.Shared;
147147
import com.oracle.truffle.api.dsl.CachedContext;
148+
import com.oracle.truffle.api.dsl.Fallback;
148149
import com.oracle.truffle.api.dsl.GenerateUncached;
149150
import com.oracle.truffle.api.dsl.ImportStatic;
150151
import com.oracle.truffle.api.dsl.Specialization;
@@ -164,6 +165,7 @@
164165
import com.oracle.truffle.api.profiles.ConditionProfile;
165166
import com.oracle.truffle.api.profiles.ValueProfile;
166167
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
168+
import com.oracle.truffle.llvm.spi.ReferenceLibrary;
167169

168170
@ExportLibrary(InteropLibrary.class)
169171
@ExportLibrary(NativeTypeLibrary.class)
@@ -1281,6 +1283,7 @@ public boolean isMemberModifiable(String member) {
12811283
}
12821284
}
12831285

1286+
@ExportLibrary(ReferenceLibrary.class)
12841287
public static final class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
12851288

12861289
public static final byte PRIMITIVE_STATE_BOOL = 1 << 0;
@@ -1400,6 +1403,24 @@ public static PrimitiveNativeWrapper createDouble(double val) {
14001403
protected boolean isMemberReadable(String member) {
14011404
return member.equals(DynamicObjectNativeWrapper.GP_OBJECT) || NativeMemberNames.isValid(member);
14021405
}
1406+
1407+
@ExportMessage
1408+
static class IsSame {
1409+
1410+
@Specialization
1411+
static boolean doPrimitiveWrapper(PrimitiveNativeWrapper receiver, PrimitiveNativeWrapper other) {
1412+
// This basically emulates singletons for boxed values. However, we need to do so to
1413+
// preserve the invariant that storing an object into a list and getting it out (in
1414+
// the same critical region) returns the same object.
1415+
return other.state == receiver.state && other.value == receiver.value && (other.dvalue == receiver.dvalue || Double.isNaN(receiver.dvalue) && Double.isNaN(other.dvalue));
1416+
}
1417+
1418+
@Fallback
1419+
@SuppressWarnings("unused")
1420+
static boolean doGeneric(PrimitiveNativeWrapper receiver, Object other) {
1421+
return false;
1422+
}
1423+
}
14031424
}
14041425

14051426
@ExportMessage

0 commit comments

Comments
 (0)