[bug:trunk] prime and timeout

e$B$?$^$K!“e(Brubyspec e$B$,0J2<$N$h$&$K<:GT$9$k$3$H$,$”$j$^$9!#e(B

http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20091008T160610.log.txt.gz
:

| 53)
| Prime#each when an instance created via Prime.new infinitely iterates the given block passing a prime FAILED
| Expected Timeout::Error
| but got SpecExpectationNotMetError (Expected false to be true)
| /home/akr/chkbuild/tmp/build/ruby-trunk/20091008T160610/rubyspec/library/prime/each_spec.rb:41:in block (2 levels) in <top (required)>' | /home/akr/chkbuild/tmp/build/ruby-trunk/20091008T160610/rubyspec/library/prime/each_spec.rb:17:in <top (required)>’

e$B5-O?$rD4$Y$k$H:#G/$Oe(B 15e$B2s$[$I<:GT$7$F$$$^$9!#e(B

% zgrep ‘Prime#each infinitely iterates the given block passing a prime
FAILED’ 2009log
20090501T201000.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090817T235403.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090820T061900.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090820T225200.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090822T121606.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090825T035002.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090906T105301.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090911T115004.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090918T210300.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090919T041101.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090923T213200.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090929T153305.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090930T023500.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20090930T090400.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED
20091008T160610.log.txt.gz:Prime#each infinitely iterates the given
block passing a prime FAILED

e$B$F$-$H$&$KD4$Y$F$$k$H!“$I$&$be(B prime e$B$,e(B timeout
e$B$GCfCG$5$l$ke(B
e$B$H!”$=$l0J9
$KJQ$Je(B (e$BAG?t$G$J$$e(B)
e$BCM$,@8@.$5$l$k$3$H$,$"$k$h$&e(B
e$B$G$9!#e(B

% ./ruby -rtimeout -rprime -ve ’
e = Prime.instance
begin
timeout(0.01) {
e.each {|v| p v if (2…Math.sqrt(v)).any?{|n| v%n == 0 } }
}
rescue Timeout::Error
retry
end

ruby 1.9.2dev (2009-10-11 trunk 25297) [i686-linux]
1369
1369
1517
1591
1369
1517
1517
1369

e$B$3$N%9%/%j%W%H$Oe(B Prime.instance.each e$B$,AG?t$G$J$$CM$r@8@.$7e(B
e$B$?$H$-$K$=$NCM$rI=<($7$^$9!#$?$H$($P!“e(B1369 e$B$Oe(B 37*37
e$B$J$N$GAGe(B
e$B?t$G$O$”$j$^$;$s!#e(B

e$B%?%$%%s%0$,4X78$9$k$h$&$J$N$G!"2?$bI=<($5$l$J$+$C$?$iCfCG$7e(B
e$B$F7+$jJV$7;n$7$F$
$F$/$@$5$$!#e(B

e$B$^$!!"e(Btimeout e$B$N$d$j$+$?$,4b$J$N$b3N$+$G$9$,!"1F6A$,8e$r$R$/e(B
prime e$B$N$D$/$j$b$h$m$7$/$J$$$s$8$c$J$$$G$7$g$&$+!#e(B

In article [email protected],
Tanaka A. [email protected] writes:

e$B$F$-$H$&$KD4$Y$F$$k$H!“$I$&$be(B prime e$B$,e(B timeout e$B$GCfCG$5$l$ke(B
e$B$H!”$=$l0J9
$KJQ$Je(B (e$BAG?t$G$J$$e(B) e$BCM$,@8@.$5$l$k$3$H$,$"$k$h$&e(B
e$B$G$9!#e(B

e$B%?%$%%s%0$,4X78$9$k$h$&$J$N$G!"2?$bI=<($5$l$J$+$C$?$iCfCG$7e(B
e$B$F7+$jJV$7;n$7$F$
$F$/$@$5$$!#e(B

Timeout::Error e$B$O$I$3$G$$3$C$F$b$$+$7$/$J$$$o$1$G$9$,!"0Je(B
e$B2<$N$h$&$Ke(B prime.rb e$B$NFCDj$N>l=j$Ge(B Timeout::Error
e$B$rH/@8$5$;e(B
e$B$k$h$&$K$9$k$H!"3N<B$K:F8=$7$^$9!#e(B

% svn diff lib/prime.rb
Index: lib/prime.rb

— lib/prime.rb (revision 25297)
+++ lib/prime.rb (working copy)
@@ -436,6 +436,7 @@
lbound = orig_len32
ubound = new_len
32
@table.fill(0xFFFF, orig_len…new_len)

  •  raise Timeout::Error
     (3..Integer(Math.sqrt(ubound))).step(2) do |p|
      i, j = p.divmod(32)
      next if @table[i][j.div(2)].zero?
    

% ./ruby -Ilib -rtimeout -rprime -ve ’
e = Prime.instance
begin
e.each {|v| }
rescue Timeout::Error
end
p e.each {|v| break v if (2…Math.sqrt(v)).any?{|n| v%n == 0 } }

ruby 1.9.2dev (2009-10-11 trunk 25297) [i686-linux]
259

e$B$3$3$Ge(B 259 e$B$Oe(B 7*37 e$B$J$N$G!“AG?t$G$O$”$j$^$;$s!#e(B