File tree Expand file tree Collapse file tree
test/test_helpers/stack_busters Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,32 +25,13 @@ def stack_depth_remaining
2525 def stack_overflow_threshold
2626 # Use a frame size that's larger than the expected frame size to ensure
2727 # 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 )
3129 loop do
3230 begin
3331 unoptimized_factorial ( limit )
34- last_good_limit = limit
3532 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
5435 end
5536 end
5637 end
Original file line number Diff line number Diff line change @@ -14,10 +14,10 @@ def stack_depth_remaining
1414
1515 private
1616
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
2121 end
2222 end
2323 end
You can’t perform that action at this time.
0 commit comments