Skip to content

Commit 90e02bc

Browse files
committed
fix issues with ob_digits and ob_size for PyLong
1 parent 9f6a182 commit 90e02bc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,7 +3168,7 @@ static long doLong(@SuppressWarnings("unused") long object,
31683168
int size = 0;
31693169
while (t != 0) {
31703170
++size;
3171-
t >>= context.getCApiContext().getPyLongBitsInDigit();
3171+
t >>>= context.getCApiContext().getPyLongBitsInDigit();
31723172
}
31733173
return size * sign;
31743174
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,17 @@ final Object readArrayElement(long index,
146146
if (delegate instanceof Integer || delegate instanceof Long) {
147147
long val;
148148
if (delegate instanceof Integer) {
149-
val = PInt.abs(((Integer) delegate).longValue());
149+
val = PInt.abs((int) delegate);
150150
} else {
151-
val = PInt.abs((Long) delegate);
151+
long l = (long) delegate;
152+
if (l == Long.MIN_VALUE) {
153+
// this is valid since we treat the long as unsigned afterwards
154+
val = Long.MAX_VALUE + 1;
155+
} else {
156+
val = PInt.abs(l);
157+
}
152158
}
153-
return (val >> (longShift * index)) & longMask;
159+
return (val >>> (longShift * index)) & longMask;
154160
} else {
155161
byte[] bytes = PInt.toByteArray(((PInt) delegate).abs());
156162
// the cast to int is safe since the length check already succeeded

0 commit comments

Comments
 (0)