Skip to content

Commit babaeba

Browse files
authored
Merge pull request RustPython#1952 from RustPython/coolreader18/32bit-support
32 bit support
2 parents 5f34c61 + 2fc90e1 commit babaeba

15 files changed

+171
-234
lines changed

Lib/test/seq_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def test_repeat(self):
321321
self.assertEqual(self.type2test(s)*(-4), self.type2test([]))
322322
self.assertEqual(id(s), id(s*1))
323323

324+
@unittest.skip("TODO: RUSTPYTHON")
324325
def test_bigrepeat(self):
325326
if sys.maxsize <= 2147483647:
326327
x = self.type2test([0])

Lib/test/string_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ def test_expandtabs(self):
352352

353353
self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
354354
# This test is only valid when sizeof(int) == sizeof(void*) == 4.
355-
if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4:
355+
# XXX RUSTPYTHON TODO: expandtabs overflow checks
356+
if sys.maxsize < (1 << 32) and struct.calcsize('P') == 4 and False:
356357
self.checkraises(OverflowError,
357358
'\ta\n\tb', 'expandtabs', sys.maxsize)
358359

@@ -672,6 +673,7 @@ def test_replace(self):
672673
self.checkraises(TypeError, 'hello', 'replace', 42, 'h')
673674
self.checkraises(TypeError, 'hello', 'replace', 'h', 42)
674675

676+
@unittest.skip("TODO: RUSTPYTHON")
675677
@unittest.skipIf(sys.maxsize > (1 << 32) or struct.calcsize('P') != 4,
676678
'only applies to 32-bit platforms')
677679
def test_replace_overflow(self):

Lib/test/test_bytes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ def test_copy(self):
5454
self.assertEqual(a, b)
5555
self.assertEqual(type(a), type(b))
5656

57-
# TODO: RUSTPYTHON
58-
@unittest.expectedFailure
5957
def test_empty_sequence(self):
6058
b = self.type2test()
6159
self.assertEqual(len(b), 0)

Lib/test/test_list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_basic(self):
2020
self.assertEqual(list(x for x in range(10) if x % 2),
2121
[1, 3, 5, 7, 9])
2222

23-
if sys.maxsize == 0x7fffffff:
23+
# XXX RUSTPYTHON TODO: catch ooms
24+
if sys.maxsize == 0x7fffffff and False:
2425
# This test can currently only work on 32-bit machines.
2526
# XXX If/when PySequence_Length() returns a ssize_t, it should be
2627
# XXX re-enabled.

Lib/test/test_memoryview.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def check_getitem_with_type(self, tp):
4747
m = None
4848
self.assertEqual(sys.getrefcount(b), oldrefcount)
4949

50-
# TODO: RUSTPYTHON
51-
@unittest.expectedFailure
5250
def test_getitem(self):
5351
for tp in self._types:
5452
self.check_getitem_with_type(tp)

Lib/test/test_unicode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def __str__(self): return self.sval
471471
self.checkraises(TypeError, ' ', 'join', [1, 2, 3])
472472
self.checkraises(TypeError, ' ', 'join', ['1', '2', 3])
473473

474+
@unittest.skip("TODO: RUSTPYTHON, oom handling")
474475
@unittest.skipIf(sys.maxsize > 2**32,
475476
'needs too much memory on a 64-bit platform')
476477
def test_join_overflow(self):
@@ -2357,6 +2358,7 @@ def test_printable_repr(self):
23572358
# This test only affects 32-bit platforms because expandtabs can only take
23582359
# an int as the max value, not a 64-bit C long. If expandtabs is changed
23592360
# to take a 64-bit long, this test should apply to all platforms.
2361+
@unittest.skip("TODO: RUSTPYTHON, oom handling")
23602362
@unittest.skipIf(sys.maxsize > (1 << 32) or struct.calcsize('P') != 4,
23612363
'only applies to 32-bit platforms')
23622364
def test_expandtabs_overflows_gracefully(self):

tests/snippets/index_overflow.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
def expect_cannot_fit_index_error(s, index):
55
try:
66
s[index]
7-
except IndexError:
8-
pass
9-
# TODO: Replace current except block with commented
10-
# after solving https://github.com/RustPython/RustPython/issues/322
11-
# except IndexError as error:
12-
# assert str(error) == "cannot fit 'int' into an index-sized integer"
7+
except IndexError as error:
8+
assert str(error) == "cannot fit 'int' into an index-sized integer"
139
else:
1410
assert False
1511

vm/src/obj/objbytearray.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::objbyteinner::{
1212
};
1313
use super::objint::PyIntRef;
1414
use super::objiter;
15-
use super::objslice::PySliceRef;
15+
use super::objsequence::SequenceIndex;
1616
use super::objstr::{PyString, PyStringRef};
1717
use super::objtype::PyClassRef;
1818
use super::pystr::{self, PyCommonString};
@@ -172,22 +172,17 @@ impl PyByteArray {
172172
}
173173

174174
#[pymethod(name = "__getitem__")]
175-
fn getitem(&self, needle: Either<i32, PySliceRef>, vm: &VirtualMachine) -> PyResult {
175+
fn getitem(&self, needle: SequenceIndex, vm: &VirtualMachine) -> PyResult {
176176
self.borrow_value().getitem(needle, vm)
177177
}
178178

179179
#[pymethod(name = "__setitem__")]
180-
fn setitem(
181-
&self,
182-
needle: Either<i32, PySliceRef>,
183-
value: PyObjectRef,
184-
vm: &VirtualMachine,
185-
) -> PyResult {
180+
fn setitem(&self, needle: SequenceIndex, value: PyObjectRef, vm: &VirtualMachine) -> PyResult {
186181
self.borrow_value_mut().setitem(needle, value, vm)
187182
}
188183

189184
#[pymethod(name = "__delitem__")]
190-
fn delitem(&self, needle: Either<i32, PySliceRef>, vm: &VirtualMachine) -> PyResult<()> {
185+
fn delitem(&self, needle: SequenceIndex, vm: &VirtualMachine) -> PyResult<()> {
191186
self.borrow_value_mut().delitem(needle, vm)
192187
}
193188

vm/src/obj/objbyteinner.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::objint::{self, PyInt, PyIntRef};
1010
use super::objlist::PyList;
1111
use super::objmemory::PyMemoryView;
1212
use super::objnone::PyNoneRef;
13-
use super::objsequence::PySliceableSequence;
13+
use super::objsequence::{PySliceableSequence, SequenceIndex};
1414
use super::objslice::PySliceRef;
1515
use super::objstr::{self, PyString, PyStringRef};
1616
use super::pystr::{self, PyCommonString, PyCommonStringWrapper};
@@ -327,22 +327,22 @@ impl PyByteInner {
327327
})
328328
}
329329

330-
pub fn getitem(&self, needle: Either<i32, PySliceRef>, vm: &VirtualMachine) -> PyResult {
330+
pub fn getitem(&self, needle: SequenceIndex, vm: &VirtualMachine) -> PyResult {
331331
match needle {
332-
Either::A(int) => {
332+
SequenceIndex::Int(int) => {
333333
if let Some(idx) = self.elements.get_pos(int) {
334334
Ok(vm.new_int(self.elements[idx]))
335335
} else {
336336
Err(vm.new_index_error("index out of range".to_owned()))
337337
}
338338
}
339-
Either::B(slice) => Ok(vm
340-
.ctx
341-
.new_bytes(self.elements.get_slice_items(vm, slice.as_object())?)),
339+
SequenceIndex::Slice(slice) => {
340+
Ok(vm.ctx.new_bytes(self.elements.get_slice_items(vm, &slice)?))
341+
}
342342
}
343343
}
344344

345-
fn setindex(&mut self, int: i32, object: PyObjectRef, vm: &VirtualMachine) -> PyResult {
345+
fn setindex(&mut self, int: isize, object: PyObjectRef, vm: &VirtualMachine) -> PyResult {
346346
if let Some(idx) = self.elements.get_pos(int) {
347347
let result = match_class!(match object {
348348
i @ PyInt => {
@@ -392,38 +392,32 @@ impl PyByteInner {
392392
range.end = range.start;
393393
}
394394
self.elements.splice(range, items);
395-
Ok(vm
396-
.ctx
397-
.new_bytes(self.elements.get_slice_items(vm, slice.as_object())?))
395+
Ok(vm.ctx.new_bytes(self.elements.get_slice_items(vm, &slice)?))
398396
}
399397

400398
pub fn setitem(
401399
&mut self,
402-
needle: Either<i32, PySliceRef>,
400+
needle: SequenceIndex,
403401
object: PyObjectRef,
404402
vm: &VirtualMachine,
405403
) -> PyResult {
406404
match needle {
407-
Either::A(int) => self.setindex(int, object, vm),
408-
Either::B(slice) => self.setslice(slice, object, vm),
405+
SequenceIndex::Int(int) => self.setindex(int, object, vm),
406+
SequenceIndex::Slice(slice) => self.setslice(slice, object, vm),
409407
}
410408
}
411409

412-
pub fn delitem(
413-
&mut self,
414-
needle: Either<i32, PySliceRef>,
415-
vm: &VirtualMachine,
416-
) -> PyResult<()> {
410+
pub fn delitem(&mut self, needle: SequenceIndex, vm: &VirtualMachine) -> PyResult<()> {
417411
match needle {
418-
Either::A(int) => {
412+
SequenceIndex::Int(int) => {
419413
if let Some(idx) = self.elements.get_pos(int) {
420414
self.elements.remove(idx);
421415
Ok(())
422416
} else {
423417
Err(vm.new_index_error("index out of range".to_owned()))
424418
}
425419
}
426-
Either::B(slice) => self.delslice(slice, vm),
420+
SequenceIndex::Slice(slice) => self.delslice(slice, vm),
427421
}
428422
}
429423

vm/src/obj/objbytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::objbyteinner::{
1010
};
1111
use super::objint::PyIntRef;
1212
use super::objiter;
13-
use super::objslice::PySliceRef;
13+
use super::objsequence::SequenceIndex;
1414
use super::objstr::{PyString, PyStringRef};
1515
use super::objtype::PyClassRef;
1616
use super::pystr::{self, PyCommonString};
@@ -172,7 +172,7 @@ impl PyBytes {
172172
}
173173

174174
#[pymethod(name = "__getitem__")]
175-
fn getitem(&self, needle: Either<i32, PySliceRef>, vm: &VirtualMachine) -> PyResult {
175+
fn getitem(&self, needle: SequenceIndex, vm: &VirtualMachine) -> PyResult {
176176
self.inner.getitem(needle, vm)
177177
}
178178

0 commit comments

Comments
 (0)