Skip to content

Commit 2203667

Browse files
committed
[GR-46265] Foreign strings don't correctly compare for equality to Python ones
PullRequest: graalpython/3099
2 parents d368dd4 + 554fbed commit 2203667

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignObjectBuiltins.java

+18
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,24 @@ Object doComparison(VirtualFrame frame, @SuppressWarnings("unused") Object left,
649649
return comparisonNode.executeObject(frame, PNone.NONE, right);
650650
}
651651

652+
@Specialization(guards = "lib.isString(left)")
653+
Object doComparisonString(VirtualFrame frame, @SuppressWarnings("unused") Object left, Object right,
654+
@Shared @CachedLibrary(limit = "3") InteropLibrary lib,
655+
@Shared @Cached GilNode gil,
656+
@Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
657+
TruffleString leftString;
658+
gil.release(true);
659+
try {
660+
leftString = switchEncodingNode.execute(lib.asTruffleString(left), TS_ENCODING);
661+
} catch (UnsupportedMessageException e) {
662+
CompilerDirectives.transferToInterpreterAndInvalidate();
663+
throw new IllegalStateException("object does not unpack to string for comparison as it claims to");
664+
} finally {
665+
gil.acquire();
666+
}
667+
return comparisonNode.executeObject(frame, leftString, right);
668+
}
669+
652670
@SuppressWarnings("unused")
653671
@Fallback
654672
public static PNotImplemented doGeneric(Object left, Object right) {

0 commit comments

Comments
 (0)