From 9b192302ec9449d6374f681c005210c5a62d79ef Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 30 Sep 2009 08:32:43 +0000 Subject: [PATCH] * time.c (rb_time_succ): make Time#succ obsolete since time is not a discrete value. * range.c (discrete_object_p): treat time objects specially to determine discrete values, since time objects have #succ yet are discrete (for now at least). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ range.c | 13 +++++++++++-- time.c | 13 ++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ee8ae5ba2..87cb1842ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -415,6 +415,15 @@ Mon Sep 21 17:12:10 2009 Nobuyoshi Nakada * vm.c (collect_local_variables_in_env): block iseq can be NULL. +Mon Sep 21 10:50:37 2009 Yukihiro Matsumoto + + * time.c (rb_time_succ): make Time#succ obsolete since time is not + a discrete value. + + * range.c (discrete_object_p): treat time objects specially to + determine discrete values, since time objects have #succ yet are + discrete (for now at least). + Mon Sep 21 10:13:22 2009 Nobuyoshi Nakada * cont.c (cont_new, cont_capture, fiber_t_alloc): needs already diff --git a/range.c b/range.c index 1c735d0ed2..ec10bdf907 100644 --- a/range.c +++ b/range.c @@ -308,6 +308,15 @@ step_i(VALUE i, void *arg) extern int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl); +static int +discrete_object_p(obj) +{ + if (rb_obj_is_kind_of(obj, rb_cTime)) return Qfalse; /* until Time#succ removed */ + if (rb_respond_to(obj, id_succ)) return Qtrue; + return Qfalse; +} + + /* * call-seq: * rng.step(n=1) {| obj | block } => rng @@ -416,7 +425,7 @@ range_step(int argc, VALUE *argv, VALUE range) else { VALUE args[2]; - if (!rb_respond_to(b, id_succ)) { + if (!discrete_object_p(b)) { rb_raise(rb_eTypeError, "can't iterate from %s", rb_obj_classname(b)); } @@ -498,7 +507,7 @@ range_each(VALUE range) rb_block_call(tmp, rb_intern("upto"), 2, args, rb_yield, 0); } else { - if (!rb_respond_to(beg, id_succ)) { + if (!discrete_object_p(beg)) { rb_raise(rb_eTypeError, "can't iterate from %s", rb_obj_classname(beg)); } diff --git a/time.c b/time.c index 62b2f5d1cf..775640acb7 100644 --- a/time.c +++ b/time.c @@ -2948,17 +2948,19 @@ time_minus(VALUE time1, VALUE time2) * time.succ => new_time * * Return a new time object, one second later than time. + * Time#succ is obsolete since 1.9.2 for time is not a discrete value. * * t = Time.now #=> 2007-11-19 08:23:57 -0600 * t.succ #=> 2007-11-19 08:23:58 -0600 */ -static VALUE -time_succ(VALUE time) +VALUE +rb_time_succ(VALUE time) { struct time_object *tobj; struct time_object *tobj2; + rb_warn("Time#succ is obsolete; use time + 1"); GetTimeval(time, tobj); time = time_new_timexv(rb_cTime, add(tobj->timexv, INT2FIX(TIME_SCALE))); GetTimeval(time, tobj2); @@ -2966,11 +2968,8 @@ time_succ(VALUE time) return time; } -VALUE -rb_time_succ(VALUE time) -{ - return time_succ(time); -} +#define time_succ rb_time_succ + /* * call-seq: