File tree 2 files changed +7
-26
lines changed
test/test_helpers/stack_busters
2 files changed +7
-26
lines changed Original file line number Diff line number Diff line change @@ -25,32 +25,13 @@ def stack_depth_remaining
25
25
def stack_overflow_threshold
26
26
# Use a frame size that's larger than the expected frame size to ensure
27
27
# that limit is less than the point of overflow
28
- limit = last_good_limit = stack_depth_limit_for_frame_size ( LARGEST_VM_STACK_SIZE * 2 )
29
- last_overflow_limit = nil
30
- # Determine an upper-bound for binary search
28
+ limit = stack_depth_limit_for_frame_size ( LARGEST_VM_STACK_SIZE * 2 )
31
29
loop do
32
30
begin
33
31
unoptimized_factorial ( limit )
34
- last_good_limit = limit
35
32
limit *= 2
36
- rescue SystemStackError
37
- last_overflow_limit = limit
38
- break
39
- end
40
- end
41
-
42
- # Reset for binary search for point of stack overflow
43
- limit = last_good_limit
44
- loop do
45
- return last_overflow_limit if last_overflow_limit == last_good_limit + 1
46
- begin
47
- half_the_distance_to_overflow = ( last_overflow_limit - limit ) / 2
48
- limit += half_the_distance_to_overflow
49
- unoptimized_factorial ( limit )
50
- last_good_limit = limit
51
- rescue SystemStackError
52
- last_overflow_limit = limit
53
- limit = last_good_limit
33
+ rescue SystemStackError => e
34
+ return e . backtrace . length
54
35
end
55
36
end
56
37
end
Original file line number Diff line number Diff line change @@ -14,10 +14,10 @@ def stack_depth_remaining
14
14
15
15
private
16
16
17
- def stack_overflow_threshold ( depth = 1 )
18
- stack_overflow_threshold ( depth + 1 )
19
- rescue SystemStackError
20
- depth
17
+ def stack_overflow_threshold
18
+ stack_overflow_threshold
19
+ rescue SystemStackError => e
20
+ e . backtrace . length
21
21
end
22
22
end
23
23
end
You can’t perform that action at this time.
0 commit comments