summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-13 08:19:09 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-13 08:19:09 +0000
commitd8c75ddad376abf83a4d6dd9d4c8eb1736db497c (patch)
tree12ebace8954f29cfbc70bc55800cfa1e01dcc5b0
parenta59c599209a11d4ab0dc0d7626ab3d5ca43a78c2 (diff)
* time.c (time_new_internal): avoid loop to calculate negative
div, mod. * time.c (time_cmp): should handle Bignums. * array.c (rb_ary_pop): should ELTS_SHARED flag check before REALLOC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--array.c4
-rw-r--r--ext/gdbm/gdbm.c12
-rw-r--r--time.c41
-rw-r--r--version.h4
5 files changed, 51 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index d1fc61e1cc..d83526be32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Thu Dec 13 09:52:59 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * time.c (time_new_internal): avoid loop to calculate negative
+ div, mod.
+
+ * time.c (time_cmp): should handle Bignums.
+
+Tue Dec 11 17:39:16 2001 K.Kosako <kosako@sofnec.co.jp>
+
+ * array.c (rb_ary_pop): should ELTS_SHARED flag check before
+ REALLOC.
+
Tue Dec 11 12:45:28 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c (rb_str_match_m): should convert an argument into
diff --git a/array.c b/array.c
index c9b66eb2ed..b58f484fc0 100644
--- a/array.c
+++ b/array.c
@@ -336,7 +336,9 @@ rb_ary_pop(ary)
{
rb_ary_modify_check(ary);
if (RARRAY(ary)->len == 0) return Qnil;
- if (RARRAY(ary)->len * 10 < RARRAY(ary)->aux.capa && RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
+ if (!FL_TEST(ary, ELTS_SHARED) &&
+ RARRAY(ary)->len * 10 < RARRAY(ary)->aux.capa &&
+ RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
RARRAY(ary)->aux.capa = RARRAY(ary)->len * 2;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
}
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 0fa13a5e67..eddeb11f8e 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -159,13 +159,13 @@ rb_gdbm_fetch(dbm, key)
datum key;
{
datum val;
- VALUE str = rb_obj_alloc(rb_cString);
+ VALUE str;
val = gdbm_fetch(dbm, key);
if (val.dptr == 0)
return Qnil;
- RSTRING(str)->ptr = 0;
+ str = rb_obj_alloc(rb_cString);
RSTRING(str)->len = val.dsize;
RSTRING(str)->aux.capa = val.dsize;
RSTRING(str)->ptr = REALLOC_N(val.dptr,char,val.dsize+1);
@@ -206,13 +206,13 @@ rb_gdbm_firstkey(dbm)
GDBM_FILE dbm;
{
datum key;
- VALUE str = rb_obj_alloc(rb_cString);
+ VALUE str;
key = gdbm_firstkey(dbm);
if (key.dptr == 0)
return Qnil;
- RSTRING(str)->ptr = 0;
+ str = rb_obj_alloc(rb_cString);
RSTRING(str)->len = key.dsize;
RSTRING(str)->aux.capa = key.dsize;
RSTRING(str)->ptr = REALLOC_N(key.dptr,char,key.dsize+1);
@@ -228,7 +228,7 @@ rb_gdbm_nextkey(dbm, keystr)
VALUE keystr;
{
datum key, key2;
- VALUE str = rb_obj_alloc(rb_cString);
+ VALUE str;
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
@@ -236,7 +236,7 @@ rb_gdbm_nextkey(dbm, keystr)
if (key2.dptr == 0)
return Qnil;
- RSTRING(str)->ptr = 0;
+ str = rb_obj_alloc(rb_cString);
RSTRING(str)->len = key2.dsize;
RSTRING(str)->aux.capa = key2.dsize;
RSTRING(str)->ptr = REALLOC_N(key2.dptr,char,key2.dsize+1);
diff --git a/time.c b/time.c
index 655a49f1fe..bffb985afd 100644
--- a/time.c
+++ b/time.c
@@ -60,6 +60,9 @@ time_s_now(klass)
return obj;
}
+#define NDIV(x,y) (-(-((x)+1)/(y))-1)
+#define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
+
static VALUE
time_new_internal(klass, sec, usec)
VALUE klass;
@@ -68,13 +71,13 @@ time_new_internal(klass, sec, usec)
VALUE obj;
struct time_object *tobj;
- if (usec >= 1000000) { /* usec overflow */
+ if (usec >= 1000000) { /* usec positive overflow */
sec += usec / 1000000;
usec %= 1000000;
}
- while (usec < 0) { /* usec underflow */
- sec--;
- usec += 1000000;
+ if (usec < 0) { /* usec negative overflow */
+ sec += NDIV(usec,1000000); /* negative div */
+ usec = NMOD(usec,1000000); /* negative mod */
}
#ifndef NEGATIVE_TIME_T
if (sec < 0 || (sec == 0 && usec < 0))
@@ -642,6 +645,14 @@ time_cmp(time1, time2)
if (tobj1->tv.tv_sec > tobj2->tv.tv_sec) return INT2FIX(1);
return INT2FIX(-1);
}
+ if (TYPE(time2) == T_BIGNUM) {
+ double a = (double)tobj1->tv.tv_sec+(double)tobj1->tv.tv_usec/1e6;
+ double b = rb_big2dbl(time2);
+
+ if (a == b) return INT2FIX(0);
+ if (a > b) return INT2FIX(1);
+ if (a < b) return INT2FIX(-1);
+ }
i = NUM2LONG(time2);
if (tobj1->tv.tv_sec == i) {
if (tobj1->tv.tv_usec == 0)
@@ -856,12 +867,15 @@ time_plus(time1, time2)
}
f = NUM2DBL(time2);
sec = (time_t)f;
+ if (f != (double)sec) {
+ rb_raise(rb_eRangeError, "time + %f out of Time range", f);
+ }
usec = tobj->tv.tv_usec + (time_t)((f - (double)sec)*1e6);
sec = tobj->tv.tv_sec + sec;
#ifdef NEGATIVE_TIME_T
- if ((tobj->tv.tv_sec > 0 && f > 0 && sec < 0) ||
- (tobj->tv.tv_sec < 0 && f < 0 && sec > 0)) {
+ if ((tobj->tv.tv_sec >= 0 && f >= 0 && sec < 0) ||
+ (tobj->tv.tv_sec <= 0 && f <= 0 && sec > 0)) {
rb_raise(rb_eRangeError, "time + %f out of Time range", f);
}
#endif
@@ -891,15 +905,16 @@ time_minus(time1, time2)
return rb_float_new(f);
}
- else {
- f = NUM2DBL(time2);
- sec = (time_t)f;
- usec = tobj->tv.tv_usec - (time_t)((f - (double)sec)*1e6);
- sec = tobj->tv.tv_sec - sec;
+ f = NUM2DBL(time2);
+ sec = (time_t)f;
+ if (f != (double)sec) {
+ rb_raise(rb_eRangeError, "time - %f out of Time range", f);
}
+ usec = tobj->tv.tv_usec - (time_t)((f - (double)sec)*1e6);
+ sec = tobj->tv.tv_sec - sec;
#ifdef NEGATIVE_TIME_T
- if ((tobj->tv.tv_sec < 0 && f > 0 && sec > 0) ||
- (tobj->tv.tv_sec > 0 && f < 0 && sec < 0)) {
+ if ((tobj->tv.tv_sec <= 0 && f >= 0 && sec > 0) ||
+ (tobj->tv.tv_sec >= 0 && f <= 0 && sec < 0)) {
rb_raise(rb_eRangeError, "time - %f out of Time range", f);
}
#endif
diff --git a/version.h b/version.h
index fb712da798..1826f8efce 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
-#define RUBY_RELEASE_DATE "2001-12-10"
+#define RUBY_RELEASE_DATE "2001-12-13"
#define RUBY_VERSION_CODE 172
-#define RUBY_RELEASE_CODE 20011210
+#define RUBY_RELEASE_CODE 20011213