ruby-changes:4783
From: ko1@a...
Date: Sat, 3 May 2008 18:12:31 +0900 (JST)
Subject: [ruby-changes:4783] akr - Ruby:r16277 (trunk): * time.c (time_timespec): raise TypeError for nil and other objects
akr 2008-05-03 18:12:13 +0900 (Sat, 03 May 2008)
New Revision: 16277
Modified files:
trunk/ChangeLog
trunk/time.c
Log:
* time.c (time_timespec): raise TypeError for nil and other objects
which has no divmod method.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/time.c?r1=16277&r2=16276&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16277&r2=16276&diff_format=u
Index: time.c
===================================================================
--- time.c (revision 16276)
+++ time.c (revision 16277)
@@ -217,18 +217,24 @@
break;
default:
- ary = rb_check_array_type(rb_funcall(num, id_divmod, 1, INT2FIX(1)));
- if (NIL_P(ary)) {
+ if (rb_respond_to(num, id_divmod)) {
+ ary = rb_check_array_type(rb_funcall(num, id_divmod, 1, INT2FIX(1)));
+ if (NIL_P(ary)) {
+ goto typeerror;
+ }
+ i = rb_ary_entry(ary, 0);
+ f = rb_ary_entry(ary, 1);
+ t.tv_sec = NUM2LONG(i);
+ if (interval && t.tv_sec < 0)
+ rb_raise(rb_eArgError, "%s must be positive", tstr);
+ f = rb_funcall(f, id_mul, 1, INT2FIX(1000000000));
+ t.tv_nsec = NUM2LONG(f);
+ }
+ else {
+typeerror:
rb_raise(rb_eTypeError, "can't convert %s into %s",
rb_obj_classname(num), tstr);
}
- i = rb_ary_entry(ary, 0);
- f = rb_ary_entry(ary, 1);
- t.tv_sec = NUM2LONG(i);
- if (interval && t.tv_sec < 0)
- rb_raise(rb_eArgError, "%s must be positive", tstr);
- f = rb_funcall(f, id_mul, 1, INT2FIX(1000000000));
- t.tv_nsec = NUM2LONG(f);
break;
}
return t;
Index: ChangeLog
===================================================================
--- ChangeLog (revision 16276)
+++ ChangeLog (revision 16277)
@@ -1,3 +1,8 @@
+Sat May 3 18:10:54 2008 Tanaka Akira <akr@f...>
+
+ * time.c (time_timespec): raise TypeError for nil and other objects
+ which has no divmod method.
+
Fri May 2 23:59:26 2008 Nobuyoshi Nakada <nobu@r...>
* io.c (internal_read_func, internal_write_func): split from
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/