diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-03 09:12:13 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-03 09:12:13 +0000 |
commit | 74697788d4e93eafabc652657ecb477a39b75507 (patch) | |
tree | ae4d5b2d854a65b2e53f249f41eee2c8ede52b2d | |
parent | e5248cfd79f61f9bb73bd755632aa28d8a1b97f1 (diff) | |
download | ruby-74697788d4e93eafabc652657ecb477a39b75507.tar.gz |
* time.c (time_timespec): raise TypeError for nil and other objects
which has no divmod method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | time.c | 24 |
2 files changed, 20 insertions, 9 deletions
@@ -1,3 +1,8 @@ +Sat May 3 18:10:54 2008 Tanaka Akira <akr@fsij.org> + + * 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@ruby-lang.org> * io.c (internal_read_func, internal_write_func): split from @@ -217,18 +217,24 @@ time_timespec(VALUE num, int interval) 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; |