[#3726] Fixnum#clone and Float#clone raise different exceptions — "David A. Black" <dblack@...>

Hi --

15 messages 2004/11/12
[#3749] Re: Fixnum#clone and Float#clone raise different exceptions — "David A. Black" <dblack@...> 2004/11/16

Hi --

[#3751] Re: Fixnum#clone and Float#clone raise different exceptions — Yukihiro Matsumoto <matz@...> 2004/11/16

Hi,

[#3752] Re: Fixnum#clone and Float#clone raise different exceptions — "David A. Black" <dblack@...> 2004/11/16

Hi --

[#3785] The latest 1.8.2 cvs prints parse error when starting extension compiling — Yukihiro Matsumoto <matz@...>

Hi,

13 messages 2004/11/23
[#3787] Re: The latest 1.8.2 cvs prints parse error when starting extension compiling — Johan Holmberg <holmberg@...> 2004/11/23

possible bug in method dictionary

From: Ryan Davis <ryand@...>
Date: 2004-11-12 08:50:52 UTC
List: ruby-core #3716
NOTE: to repro this bug as written, you must have RubyInline 3.1.0 
installed.

I think I found a possible bug in the method dictionary or cache. Then 
again, this might be considered a feature for all I know. It really 
depends on the intended behavior.

If a pure ruby method exists and a C extension is loaded in that tries 
to replace said method with a C based method, it silently fails (I 
think). I've worked around this problem with:

       @mod.class_eval "alias :#{meth}_slow :#{meth}"
       @mod.class_eval "remove_method :#{meth}"

I can only currently demonstrate the bug by benchmarking. If you run 
the code below normally (fast) vs with -d (slow) you can see the 
differences in time.

&make clean; ruby -v bug.rb ; ruby -v -d bug.rb
rm -rf *~ doc ~/.ruby_inline
ruby 1.8.2 (2004-08-22) [powerpc-darwin7.5.0]
n = 50000
            user     system      total        real
ruby:  0.640000   0.000000   0.640000 (  0.729796)
c:     0.080000   0.000000   0.080000 (  0.113721)
ruby 1.8.2 (2004-08-22) [powerpc-darwin7.5.0]
RubyInline v 3.1.0
/Users/ryan/.ruby_inline/Mod_MyTest.bundle is up to date
n = 50000
            user     system      total        real
ruby:  0.540000   0.000000   0.540000 (  0.596802)
c:     0.560000   0.000000   0.560000 (  0.611343)

-----

#!/usr/local/bin/ruby -I. -w

require 'benchmark'
require 'inline'

class MyTest

   def factorial_slow(n)
     f = 1
     n.downto(2) { |x| f *= x }
     f
   end

   def factorial(n)
     f = 1
     n.downto(2) { |x| f *= x }
     f
   end if $DEBUG

   inline do |builder|
     builder.c "
     long factorial(int max) {
       int i=max, result=1;
       while (i >= 2) { result *= i--; }
       return result;
     }"
   end
end

t = MyTest.new
n = ARGV.empty? ? 50000 : ARGV.shift.to_i
puts "n = #{n}"
Benchmark.bm(5) do |x|
   x.report("ruby:")   { for i in 1..n; t.factorial_slow(5); end }
   x.report("c:")      { for i in 1..n; t.factorial(5); end }
end


In This Thread

Prev Next