[#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

Re: possible bug in method dictionary

From: nobu.nokada@...
Date: 2004-11-12 11:23:39 UTC
List: ruby-core #3717
Hi,

At Fri, 12 Nov 2004 17:50:52 +0900,
Ryan Davis wrote in [ruby-core:03716]:
> 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.

It silently redefines and discards old one.

$ cat factorial.c
#include <stdio.h>
#include <ruby.h>

static long
factorial(int max)
{
    int i=max, result=1;
    while (i >= 2) { result *= i--; }
    return result;
}

static VALUE
factorial_m(VALUE self, VALUE maxv)
{
    int max = NUM2INT(maxv);
    long result = factorial(max);
    printf("factorial(%d) = %ld\n", max, result);
    return LONG2NUM(result);
}

void
Init_factorial(void)
{
    VALUE t = rb_const_get(rb_cObject, rb_intern("MyTest"));
    rb_define_method(t, "factorial", factorial_m, 1);
}

$ cat t.rb
class MyTest
  def factorial(n)
    f = 1
    n.downto(2) { |x| f *= x }
    f
  end
end
t = MyTest.new
p t.factorial(10)
require 'factorial.so'
p t.factorial(10)

$ ruby t.rb
3628800
factorial(10) = 3628800
3628800

-- 
Nobu Nakada

In This Thread