[Ironruby-core] Core Review: Time and IO#open fixes

Daniele Alessandri suppakilla at gmail.com
Mon Aug 24 03:01:59 EDT 2009

The int,int,int,int,int,int,object,object,object,object overloads are
there just to skip the (relative) complexity of CreateTime when you
pass 10 arguments to local/utc and all the relevant arguments are
integers, e.g. when you do Time.local(*Time.now.to_a). The last four
arguments are typed as object just because in the MRI you can pass
whatever you want, they are totally ignored anyways. As for the double
variant... well yeah, it might be superfluous and I guess it would be
rarely used, so I will remove it.

By the way the cast double -> int cast is admittedly wrong, that
scenario under the MRI throws a RangeError:

RangeError: float 1e+018 out of range of integer
        from (irb):1:in `local'
        from (irb):1
        from :0

I was going to use RubyOps.ConvertDoubleToFixnum(double) for that one,
but I noticed that when it catches an overflow the message for
RangeError is a little bit different (Fixnum instead of integer) and I
was wondering if this difference was intentional or what. But then, I
blatantly forgot to check it out and ask on the list... :-)

As for Create(object,long,long) I can fix it while I am at it, I just
committed the same change introduced in Create(object,double) but had
not investigated other issues.


On Sun, Aug 23, 2009 at 23:58, Tomas
Matousek<Tomas.Matousek at microsoft.com> wrote:
> What are overloads like this:
> ...(int second, int minute, int hour, int day, int month, int year,  object wday, object yday, object isdst, object zone)
> good for?
> It seems that the parameters typed to object are not used. Also when you cast double to int it might overflow. What should happen if a big integer is passed in?
> This is also suspicious:
> public static DateTime Create(object/*!*/ self, long seconds, long microseconds)
> MRI actually uses a default protocol for Fixnum for the parameters:
> class C
>  def respond_to? name
>    puts name
>    true
>  end
>  def to_int
>   123
>  end
> end
> Time.at(C.new, 1.2)                  #=> to_int
> Time.at(C.new, 1000000000) #=> to_int
> Tomas
> -----Original Message-----
> From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Daniele Alessandri
> Sent: Sunday, August 23, 2009 1:20 PM
> To: ironruby-core at rubyforge.org
> Subject: Re: [Ironruby-core] Core Review: Time and IO#open fixes
> On Sun, Aug 23, 2009 at 15:15, Daniele Alessandri<suppakilla at gmail.com> wrote:
> [...]
>> * http://github.com/nrk/ironruby/commit/48a4a02b5b47d61f2f7a3f3887ea4bf02d63edb4
>> Miscellaneous fixes to Time:
> [...]
> Just noticed the wrong link :-/ Here is the correct one:
> http://github.com/nrk/ironruby/commit/fb55ffcfb7193eba537eb4aba98c3d55871006d6
> --
> Daniele Alessandri
> http://www.clorophilla.net/blog/
> http://twitter.com/JoL1hAHN
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core

Daniele Alessandri

More information about the Ironruby-core mailing list