Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
starlark: fix tests for 386 (google#283)
Browse files Browse the repository at this point in the history
The recent int change didn't compile on 386. Fixed.
Thanks to user @anyktx for pointing this out.

Also, tests of string * int and tuple * int printed a bad
error message containing an integer overflow. Now fixed.
  • Loading branch information
adonovan authored Jun 19, 2020
1 parent c6daab6 commit 50ca820
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions starlark/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,8 @@ func tupleRepeat(elems Tuple, n Int) (Tuple, error) {
// Inv: i > 0, len > 0
sz := len(elems) * i
if sz < 0 || sz >= maxAlloc { // sz < 0 => overflow
return nil, fmt.Errorf("excessive repeat (%d elements)", sz)
// Don't print sz.
return nil, fmt.Errorf("excessive repeat (%d * %d elements)", len(elems), i)
}
res := make([]Value, sz)
// copy elems into res, doubling each time
Expand All @@ -1053,7 +1054,8 @@ func stringRepeat(s String, n Int) (String, error) {
// Inv: i > 0, len > 0
sz := len(s) * i
if sz < 0 || sz >= maxAlloc { // sz < 0 => overflow
return "", fmt.Errorf("excessive repeat (%d elements)", sz)
// Don't print sz.
return "", fmt.Errorf("excessive repeat (%d * %d elements)", len(s), i)
}
return String(strings.Repeat(string(s), i)), nil
}
Expand Down
2 changes: 1 addition & 1 deletion starlark/int_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type intImpl struct {
// small is defined only if big is nil.
// small is sign-extended to 64 bits for ease of subsequent arithmetic.
func (i Int) get() (small int64, big *big.Int) {
return i.small_, i.big_
return i.impl.small_, i.impl.big_
}

// Precondition: math.MinInt32 <= x && x <= math.MaxInt32
Expand Down
2 changes: 1 addition & 1 deletion starlark/testdata/string.star
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ assert.eq(1 * "abc", "abc")
assert.eq(5 * "abc", "abcabcabcabcabc")
assert.fails(lambda: 1.0 * "abc", "unknown.*float \\* str")
assert.fails(lambda : "abc" * (1000000 * 1000000), "repeat count 1000000000000 too large")
assert.fails(lambda : "abc" * 1000000 * 1000000, "excessive repeat .3000000000000 elements")
assert.fails(lambda : "abc" * 1000000 * 1000000, "excessive repeat \\(3000000 \\* 1000000 elements")

# len
assert.eq(len("Hello, 世界!"), 14)
Expand Down
6 changes: 3 additions & 3 deletions starlark/testdata/tuple.star
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ assert.eq(tuple(), ())
assert.eq(tuple("abc".elems()), ("a", "b", "c"))
assert.eq(tuple(["a", "b", "c"]), ("a", "b", "c"))
assert.eq(tuple([1]), (1,))
assert.fails(lambda : tuple(1), "got int, want iterable")
assert.fails(lambda: tuple(1), "got int, want iterable")

# tuple * int, int * tuple
abc = tuple("abc".elems())
Expand All @@ -48,8 +48,8 @@ assert.eq(0 * abc, ())
assert.eq(-1 * abc, ())
assert.eq(1 * abc, abc)
assert.eq(3 * abc, ("a", "b", "c", "a", "b", "c", "a", "b", "c"))
assert.fails(lambda : abc * (1000000 * 1000000), "repeat count 1000000000000 too large")
assert.fails(lambda : abc * 1000000 * 1000000, "excessive repeat .3000000000000 elements")
assert.fails(lambda: abc * (1000000 * 1000000), "repeat count 1000000000000 too large")
assert.fails(lambda: abc * 1000000 * 1000000, "excessive repeat \\(3000000 \\* 1000000 elements")

# TODO(adonovan): test use of tuple as sequence
# (for loop, comprehension, library functions).

0 comments on commit 50ca820

Please sign in to comment.