summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-27 07:52:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-02-27 07:52:11 +0000
commit64fb417473889de0f03bee0f178293ce70623a92 (patch)
tree1a927def82e6c8c5e14ba34e41aa72f617cf16d6 /time.c
parentdf2d69b49ab1c8b42dd6c18fb63df26aec95f364 (diff)
* time.c (time_timeval): negative time interval shoule not be
allowed. * eval.c (proc_call): ignore block to `call' always, despite of being orphan or not. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/time.c b/time.c
index 8da0daf..1b18859 100644
--- a/time.c
+++ b/time.c
@@ -106,39 +106,37 @@ time_timeval(time, interval)
int interval;
{
struct timeval t;
+ char *tstr = interval ? "time interval" : "time";
+
+#ifndef NEGATIVE_TIME_T
+ interval = 1;
+#endif
switch (TYPE(time)) {
case T_FIXNUM:
t.tv_sec = FIX2LONG(time);
-#ifndef NEGATIVE_TIME_T
- if (t.tv_sec < 0)
- rb_raise(rb_eArgError, "time must be positive");
-#endif
+ if (interval && t.tv_sec < 0)
+ rb_raise(rb_eArgError, "%s must be positive", tstr);
t.tv_usec = 0;
break;
case T_FLOAT:
-#ifndef NEGATIVE_TIME_T
- if (RFLOAT(time)->value < 0.0)
- rb_raise(rb_eArgError, "time must be positive");
-#endif
+ if (interval && RFLOAT(time)->value < 0.0)
+ rb_raise(rb_eArgError, "%s must be positive", tstr);
t.tv_sec = (time_t)RFLOAT(time)->value;
t.tv_usec = (time_t)((RFLOAT(time)->value - (double)t.tv_sec)*1e6);
break;
case T_BIGNUM:
t.tv_sec = NUM2LONG(time);
-#ifndef NEGATIVE_TIME_T
- if (t.tv_sec < 0)
- rb_raise(rb_eArgError, "time must be positive");
-#endif
+ if (interval && t.tv_sec < 0)
+ rb_raise(rb_eArgError, "%s must be positive", tstr);
t.tv_usec = 0;
break;
default:
- rb_raise(rb_eTypeError, "can't convert %s into Time%s",
- rb_class2name(CLASS_OF(time)),
- interval ? " interval" : "");
+ rb_raise(rb_eTypeError, "can't convert %s into %s",
+ rb_class2name(CLASS_OF(time)), tstr);
break;
}
return t;