mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
a59c599209
commit
d8c75ddad3
5 changed files with 51 additions and 22 deletions
12
ChangeLog
12
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
|
||||
|
|
4
array.c
4
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
41
time.c
41
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue