summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-13 09:21:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-13 09:21:18 +0000
commitcf5d04f663e9e7a61da4dda66e78097aefe66919 (patch)
tree431e5afae10458ab9e139683d74724bd713b0ed8
parent510c93caacad0911261f3adeed73b43fc5fca57f (diff)
* hash.c (rb_hash_replace): should copy ifnone.
* hash.c (rb_hash_dup): should preserve HASH_PROC_DEFAULT and HASH_DELETED flags. * hash.c (rb_hash_shift): shift from empty hash should not return its default proc. * hash.c (rb_hash_default_proc): new method. [new] * array.c (rb_ary_aref): no need for Bignum check. * array.c (rb_ary_aset): explicit Bignum check removd. * numeric.c (fix_aref): normalize bignum before bit-op. * bignum.c (rb_big_rand): max may be Bignum zero. * bignum.c (rb_cstr_to_inum): should normalize bignums, to avoid returning fixable bignum value. * bignum.c (rb_uint2big): there should be no zero sized bignum. * ext/extmk.rb.in: extmake() that works properly for both tkutil (tk/tkutil.so) and digest/sha1. * hash.c (rb_hash_equal): should check HASH_PROC_DEFAULT too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog36
-rw-r--r--array.c21
-rw-r--r--bignum.c7
-rw-r--r--ext/extmk.rb.in17
-rw-r--r--ext/pty/lib/expect.rb4
-rw-r--r--hash.c47
-rw-r--r--numeric.c26
-rw-r--r--random.c1
-rw-r--r--version.h4
9 files changed, 122 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 66904c073e..166851629f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,43 @@
+Tue Aug 13 15:32:14 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * hash.c (rb_hash_replace): should copy ifnone.
+
+ * hash.c (rb_hash_dup): should preserve HASH_PROC_DEFAULT and
+ HASH_DELETED flags.
+
+ * hash.c (rb_hash_shift): shift from empty hash should not return
+ its default proc.
+
+ * hash.c (rb_hash_default_proc): new method. [new]
+
+Tue Aug 13 00:37:11 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * array.c (rb_ary_aref): no need for Bignum check.
+
+ * array.c (rb_ary_aset): explicit Bignum check removd.
+
+ * numeric.c (fix_aref): normalize bignum before bit-op.
+
+ * bignum.c (rb_big_rand): max may be Bignum zero.
+
+ * bignum.c (rb_cstr_to_inum): should normalize bignums, to avoid
+ returning fixable bignum value.
+
+ * bignum.c (rb_uint2big): there should be no zero sized bignum.
+
+Mon Aug 12 23:45:28 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * ext/extmk.rb.in: extmake() that works properly for both tkutil
+ (tk/tkutil.so) and digest/sha1.
+
Mon Aug 12 22:29:35 2002 Akinori MUSHA <knu@iDaemons.org>
* ruby.c (set_arg0): Correct the position of #endif.
+Mon Aug 12 17:25:06 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * hash.c (rb_hash_equal): should check HASH_PROC_DEFAULT too.
+
Mon Aug 12 16:15:37 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* bignum.c (rb_big_cmp): raise for NaN. (ruby-bugs-ja:PR#284).
diff --git a/array.c b/array.c
index b505775626..4d9de4bd60 100644
--- a/array.c
+++ b/array.c
@@ -298,16 +298,21 @@ rb_ary_store(ary, idx, val)
}
if (idx >= RARRAY(ary)->aux.capa) {
- long capa_inc = RARRAY(ary)->aux.capa / 2;
- if (capa_inc < ARY_DEFAULT_SIZE) {
- capa_inc = ARY_DEFAULT_SIZE;
+ long new_capa = RARRAY(ary)->aux.capa / 2;
+
+ if (new_capa < ARY_DEFAULT_SIZE) {
+ new_capa = ARY_DEFAULT_SIZE;
}
- RARRAY(ary)->aux.capa = idx + capa_inc;
+ new_capa += idx;
+ if (new_capa > new_capa * (long)sizeof(VALUE)) {
+ rb_raise(rb_eArgError, "index too big");
+ }
+ RARRAY(ary)->aux.capa = new_capa;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
}
if (idx > RARRAY(ary)->len) {
rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len,
- idx-RARRAY(ary)->len + 1);
+ idx-RARRAY(ary)->len + 1);
}
if (idx >= RARRAY(ary)->len) {
@@ -502,9 +507,6 @@ rb_ary_aref(argc, argv, ary)
if (FIXNUM_P(arg)) {
return rb_ary_entry(ary, FIX2LONG(arg));
}
- if (TYPE(arg) == T_BIGNUM) {
- rb_raise(rb_eIndexError, "index too big");
- }
/* check if idx is Range */
switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
case Qfalse:
@@ -706,9 +708,6 @@ rb_ary_aset(argc, argv, ary)
offset = FIX2LONG(argv[0]);
goto fixnum;
}
- if (TYPE(argv[0]) == T_BIGNUM) {
- rb_raise(rb_eIndexError, "index too big");
- }
if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
/* check if idx is Range */
rb_ary_update(ary, beg, len, argv[1]);
diff --git a/bignum.c b/bignum.c
index ad1b2ca1c4..622fd5e1af 100644
--- a/bignum.c
+++ b/bignum.c
@@ -142,7 +142,7 @@ rb_uint2big(n)
}
i = DIGSPERLONG;
- while (i-- && !digits[i]) ;
+ while (--i && !digits[i]) ;
RBIGNUM(big)->len = i+1;
return big;
}
@@ -398,7 +398,7 @@ rb_cstr_to_inum(str, base, badcheck)
else {
VALUE big = rb_uint2big(val);
RBIGNUM(big)->sign = sign;
- return big;
+ return bignorm(big);
}
}
bigparse:
@@ -1685,6 +1685,9 @@ rb_big_rand(max, rand_buf)
long len;
len = RBIGNUM(max)->len;
+ if (len == 0 && BDIGITS(max)[0] == 0) {
+ return rb_float_new(rand_buf[0]);
+ }
v = bignew(len,1);
while (len--) {
BDIGITS(v)[len] = ((BDIGIT)~0) * rand_buf[len];
diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in
index a8bcafa0bf..a2f1a2cbf6 100644
--- a/ext/extmk.rb.in
+++ b/ext/extmk.rb.in
@@ -693,7 +693,7 @@ def extmake(target)
unless $install or $clean
if $static_ext.size > 0 ||
!File.exist?("./Makefile") ||
- older("./Makefile", "#{$top_srcdir}/ext/@setup@") ||
+ older("./Makefile", $setup) ||
older("./Makefile", "#{$topdir}/ext/extmk.rb") ||
older("./Makefile", "#{$top_srcdir}/ext/#{target}/makefile.rb") ||
older("./Makefile", "#{$top_srcdir}/ext/#{target}/extconf.rb")
@@ -708,10 +708,9 @@ def extmake(target)
end
end
end
- $static = $target if $static
if File.exist?("./Makefile")
if $static
- $extlist.push [$static, File.basename($target)]
+ $extlist.push [$static, $target, File.basename($target)]
end
if $install
if /bccwin32/ =~ RUBY_PLATFORM
@@ -731,6 +730,7 @@ def extmake(target)
end
if $static
$extlibs ||= ""
+ $extlibs += " " + $DLDFLAGS if $DLDFLAGS
$extlibs += " " + $LDFLAGS unless $LDFLAGS == ""
$extlibs += " " + $libs unless $libs == ""
$extlibs += " " + $LOCAL_LIBS unless $LOCAL_LIBS == ""
@@ -761,6 +761,7 @@ for setup in ["@setup@", "#{$top_srcdir}/ext/@setup@"]
target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM
$static_ext[target] = true
end
+ $setup = setup
f.close
break
end
@@ -797,13 +798,13 @@ miniruby = "miniruby@EXEEXT@"
$extobjs = "" unless $extobjs
if $extlist.size > 0
- for s,t in $extlist
- f = format("%s/%s.%s", s, t, $LIBEXT)
+ for s,t,i in $extlist
+ f = format("%s/%s.%s", s, i, $LIBEXT)
if File.exist?(f)
$extinit += format("\
\tInit_%s();\n\
\trb_provide(\"%s\");\n\
-", t, s)
+", i, t)
$extobjs += "ext/"
$extobjs += f
$extobjs += " "
@@ -812,7 +813,7 @@ if $extlist.size > 0
end
end
- if older("extinit.c", "#{$top_srcdir}/ext/@setup@")
+ if older("extinit.c", $setup) || older("extinit.c", "#{$topdir}/ext/extmk.rb")
f = open("extinit.c", "w")
f.printf "void Init_ext() {\n"
f.printf $extinit
@@ -827,7 +828,7 @@ if $extlist.size > 0
Dir.chdir ".."
- if older(ruby, "#{$top_srcdir}/ext/@setup@") or older(ruby, miniruby)
+ if older(ruby, $setup) or older(ruby, miniruby)
rm_f ruby
end
diff --git a/ext/pty/lib/expect.rb b/ext/pty/lib/expect.rb
index 5b5619e6b2..aa9ab895d3 100644
--- a/ext/pty/lib/expect.rb
+++ b/ext/pty/lib/expect.rb
@@ -20,8 +20,8 @@ class IO
STDOUT.print c
STDOUT.flush
end
- if buf =~ e_pat then
- result = [buf,$1,$2,$3,$4,$5,$6,$7,$8,$9]
+ if mat=e_pat.match(buf) then
+ result = [buf,*mat.to_a[1..-1]]
break
end
end
diff --git a/hash.c b/hash.c
index 98bf3427f0..dc7483b771 100644
--- a/hash.c
+++ b/hash.c
@@ -260,6 +260,21 @@ rb_hash_clone(hash)
}
static VALUE
+rb_hash_dup(hash)
+ VALUE hash;
+{
+ VALUE dup = rb_obj_dup(hash);
+
+ if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
+ FL_SET(dup, HASH_PROC_DEFAULT);
+ }
+ if (FL_TEST(hash, HASH_DELETED)) {
+ FL_SET(dup, HASH_DELETED);
+ }
+ return dup;
+}
+
+static VALUE
to_hash(hash)
VALUE hash;
{
@@ -353,6 +368,18 @@ rb_hash_set_default(hash, ifnone)
return ifnone;
}
+static VALUE
+rb_hash_default_proc(hash)
+ VALUE hash;
+{
+ VALUE key;
+
+ if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
+ return RHASH(hash)->ifnone;
+ }
+ return Qnil;
+}
+
static int
index_i(key, value, args)
VALUE key, value;
@@ -448,8 +475,15 @@ rb_hash_shift(hash)
var.stop = 0;
st_foreach(RHASH(hash)->tbl, shift_i, &var);
- if (var.stop == 0) return RHASH(hash)->ifnone;
- return rb_assoc_new(var.key, var.val);
+ if (var.stop) {
+ return rb_assoc_new(var.key, var.val);
+ }
+ else if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
+ return rb_funcall(RHASH(hash)->ifnone, id_yield, 2, hash, Qnil);
+ }
+ else {
+ return RHASH(hash)->ifnone;
+ }
}
static int
@@ -573,6 +607,10 @@ rb_hash_replace(hash, hash2)
hash2 = to_hash(hash2);
rb_hash_clear(hash);
st_foreach(RHASH(hash2)->tbl, replace_i, hash);
+ RHASH(hash)->ifnone = RHASH(hash2)->ifnone;
+ if (FL_TEST(hash2, HASH_PROC_DEFAULT)) {
+ FL_SET(hash, HASH_PROC_DEFAULT);
+ }
return hash;
}
@@ -854,7 +892,8 @@ rb_hash_equal(hash1, hash2)
if (TYPE(hash2) != T_HASH) return Qfalse;
if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries)
return Qfalse;
- if (!rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone))
+ if (!(rb_equal(RHASH(hash1)->ifnone, RHASH(hash2)->ifnone) &&
+ FL_TEST(hash1, HASH_PROC_DEFAULT) == FL_TEST(hash2, HASH_PROC_DEFAULT)))
return Qfalse;
data.tbl = RHASH(hash2)->tbl;
@@ -1576,6 +1615,7 @@ Init_Hash()
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
rb_define_method(rb_cHash,"clone", rb_hash_clone, 0);
+ rb_define_method(rb_cHash,"dup", rb_hash_dup, 0);
rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
@@ -1590,6 +1630,7 @@ Init_Hash()
rb_define_method(rb_cHash,"store", rb_hash_aset, 2);
rb_define_method(rb_cHash,"default", rb_hash_default, -1);
rb_define_method(rb_cHash,"default=", rb_hash_set_default, 1);
+ rb_define_method(rb_cHash,"default_proc", rb_hash_default_proc, 0);
rb_define_method(rb_cHash,"index", rb_hash_index, 1);
rb_define_method(rb_cHash,"indexes", rb_hash_indexes, -1);
rb_define_method(rb_cHash,"indices", rb_hash_indexes, -1);
diff --git a/numeric.c b/numeric.c
index f485987467..a62f53f748 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1464,24 +1464,26 @@ fix_aref(fix, idx)
VALUE fix, idx;
{
long val = FIX2LONG(fix);
+ long i;
if (TYPE(idx) == T_BIGNUM) {
- if (!RBIGNUM(idx)->sign || val >= 0)
- return INT2FIX(0);
- return INT2FIX(1);
+ idx = rb_big_norm(idx);
+ if (!FIXNUM_P(idx)) {
+ if (!RBIGNUM(idx)->sign || val >= 0)
+ return INT2FIX(0);
+ return INT2FIX(1);
+ }
}
- else {
- int i = NUM2INT(idx);
+ i = NUM2LONG(idx);
- if (i < 0) return INT2FIX(0);
- if (sizeof(VALUE)*CHAR_BIT-1 < i) {
- if (val < 0) return INT2FIX(1);
- return INT2FIX(0);
- }
- if (val & (1L<<i))
- return INT2FIX(1);
+ if (i < 0) return INT2FIX(0);
+ if (sizeof(VALUE)*CHAR_BIT-1 < i) {
+ if (val < 0) return INT2FIX(1);
return INT2FIX(0);
}
+ if (val & (1L<<i))
+ return INT2FIX(1);
+ return INT2FIX(0);
}
static VALUE
diff --git a/random.c b/random.c
index b00675d771..f9487ae480 100644
--- a/random.c
+++ b/random.c
@@ -224,7 +224,6 @@ rb_f_rand(argc, argv, obj)
}
vmax = rb_dbl2big(RFLOAT(vmax)->value);
/* fall through */
- case T_BIGNUM:
{
long len = RBIGNUM(vmax)->len;
double *buf = ALLOCA_N(double, len);
diff --git a/version.h b/version.h
index 3bb7a00b6b..629a64f32a 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
-#define RUBY_RELEASE_DATE "2002-08-12"
+#define RUBY_RELEASE_DATE "2002-08-13"
#define RUBY_VERSION_CODE 172
-#define RUBY_RELEASE_CODE 20020812
+#define RUBY_RELEASE_CODE 20020813