Skip to content

Commit 3b18909

Browse files
committed
[GR-47378] Compare bytes as unsigned bytes
PullRequest: graalpython/2870
2 parents 45dfc3d + b6bc780 commit 3b18909

File tree

2 files changed

+5
-2
lines changed
  • graalpython
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes
    • com.oracle.graal.python.test/src/tests

2 files changed

+5
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -184,6 +184,9 @@ def test_setitem():
184184
except TypeError:
185185
pass
186186

187+
def test_unsignedByte():
188+
assert b'\x80' > b'\x00'
189+
assert not b'\x80' < b'\x00'
187190

188191
class BaseGetSlice:
189192
def assertEqualWithType(self, a, b):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ protected boolean doCmp(byte[] selfArray, int selfLength, byte[] otherArray, int
966966
return shortcutLengthResult();
967967
}
968968
for (int i = 0; i < Math.min(selfLength, otherLength); i++) {
969-
compareResult = Byte.compare(selfArray[i], otherArray[i]);
969+
compareResult = Byte.compareUnsigned(selfArray[i], otherArray[i]);
970970
if (compareResult != 0) {
971971
break;
972972
}

0 commit comments

Comments
 (0)