summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog23
-rw-r--r--array.c54
-rw-r--r--doc/NEWS8
-rw-r--r--eval.c5
-rw-r--r--ext/pty/pty.c2
-rw-r--r--ext/tk/lib/tk.rb5
-rw-r--r--ext/tk/lib/tkfont.rb4
-rw-r--r--ext/tk/lib/tktext.rb16
-rw-r--r--hash.c4
-rw-r--r--lib/singleton.rb3
-rw-r--r--object.c6
-rw-r--r--parse.y2
-rw-r--r--string.c2
-rw-r--r--version.h4
14 files changed, 110 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index ee4a66f..1d3a3d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+Mon Jan 28 13:29:41 2002 K.Kosako <kosako@sofnec.co.jp>
+
+ * eval.c (is_defined): defined?(Foo::Baz) should check constants
+ only, no methods.
+
+ * eval.c (is_defined): should not dump core on defined?(a::b)
+ where a is not a class nor a module.
+
+Mon Jan 28 02:50:12 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * object.c (Init_Object): remove dup and clone from TrueClass,
+ FalseClass, and NilClass.
+
+ * array.c (rb_ary_fill): Array#fill takes block to get the value to
+ fill.
+
+Sat Jan 26 20:05:18 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_to_i): to_i(0) auto-detects base radix.
+
+ * array.c (rb_ary_initialize): fill by the block evaluation value
+ if block is given.
+
Fri Jan 25 17:48:43 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* configure.in (solaris): add '-shared' only for GNU ld.
diff --git a/array.c b/array.c
index f4ec707..f2ff470 100644
--- a/array.c
+++ b/array.c
@@ -228,12 +228,18 @@ rb_ary_initialize(argc, argv, ary)
rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
RARRAY(ary)->len = 0;
+ if (rb_block_given_p()) {
+ rb_warning("given block not used");
+ }
return ary;
}
- if (argc == 1 && !FIXNUM_P(size) && rb_respond_to(size, rb_intern("to_ary"))) {
- rb_ary_replace(ary, rb_convert_type(size, T_ARRAY, "Array", "to_ary"));
- return ary;
+ if (argc == 1 && !FIXNUM_P(size)) {
+ val = rb_check_convert_type(size, T_ARRAY, "Array", "to_ary");
+ if (!NIL_P(val)) {
+ rb_ary_replace(ary, val);
+ return ary;
+ }
}
len = NUM2LONG(size);
@@ -247,8 +253,21 @@ rb_ary_initialize(argc, argv, ary)
RARRAY(ary)->aux.capa = len;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
}
- memfill(RARRAY(ary)->ptr, len, val);
- RARRAY(ary)->len = len;
+ if (rb_block_given_p()) {
+ long i;
+
+ if (argc > 1) {
+ rb_raise(rb_eArgError, "wrong number of arguments");
+ }
+ for (i=0; i<len; i++) {
+ RARRAY(ary)->ptr[i] = rb_yield(INT2NUM(i));
+ RARRAY(ary)->len = i+1;
+ }
+ }
+ else {
+ memfill(RARRAY(ary)->ptr, len, val);
+ RARRAY(ary)->len = len;
+ }
return ary;
}
@@ -1343,6 +1362,7 @@ static VALUE
rb_ary_replace(ary, ary2)
VALUE ary, ary2;
{
+ if (ary == ary2) return ary;
ary2 = to_ary(ary2);
rb_ary_update(ary, 0, RARRAY(ary)->len, ary2);
return ary;
@@ -1370,12 +1390,20 @@ rb_ary_fill(argc, argv, ary)
VALUE item, arg1, arg2;
long beg, end, len;
VALUE *p, *pend;
+ int block_p;
- rb_scan_args(argc, argv, "12", &item, &arg1, &arg2);
+ if (rb_block_given_p()) {
+ block_p = Qtrue;
+ rb_scan_args(argc, argv, "02", &arg1, &arg2);
+ argc += 1; /* hackish */
+ }
+ else {
+ rb_scan_args(argc, argv, "12", &item, &arg1, &arg2);
+ }
switch (argc) {
case 1:
beg = 0;
- len = RARRAY(ary)->len - beg;
+ len = RARRAY(ary)->len;
break;
case 2:
if (rb_range_beg_len(arg1, &beg, &len, RARRAY(ary)->len, 1)) {
@@ -1405,8 +1433,16 @@ rb_ary_fill(argc, argv, ary)
}
p = RARRAY(ary)->ptr + beg; pend = p + len;
- while (p < pend) {
- *p++ = item;
+ if (block_p) {
+ while (p < pend) {
+ *p++ = rb_yield(INT2NUM(beg));
+ beg++;
+ }
+ }
+ else {
+ while (p < pend) {
+ *p++ = item;
+ }
}
return ary;
}
diff --git a/doc/NEWS b/doc/NEWS
index b633d7c..b611e7c 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -1,3 +1,11 @@
+: Array#fill
+
+ takes block to get the values to fill.
+
+: Array#new
+
+ takes block to get the values to fill.
+
: Array#fetch
takes block to get the default value.
diff --git a/eval.c b/eval.c
index cd0e719..576b98b 100644
--- a/eval.c
+++ b/eval.c
@@ -1934,8 +1934,9 @@ is_defined(self, node, buf)
case T_MODULE:
if (rb_const_defined_at(val, node->nd_mid))
return "constant";
+ break;
default:
- if (rb_method_boundp(val, node->nd_mid, 1)) {
+ if (rb_method_boundp(CLASS_OF(val), node->nd_mid, 1)) {
return "method";
}
}
@@ -2937,7 +2938,7 @@ rb_eval(self, n)
default:
return rb_funcall(klass, node->nd_mid, 0, 0);
}
- result = rb_const_get_at(klass, node->nd_mid);
+ result = rb_const_get(klass, node->nd_mid);
}
break;
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index def44b6..b7c69fe 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -433,7 +433,7 @@ pty_getpty(argc, argv, self)
rfptr->f = fdopen(info.fd, "r");
rfptr->path = strdup(SlaveName);
- wfptr->mode = rb_io_mode_flags("w");
+ wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
wfptr->f = fdopen(dup(info.fd), "w");
wfptr->path = strdup(SlaveName);
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 26b3dca..066864a 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -93,7 +93,6 @@ module TkComm
brace -= 1 if c == ?}
break if brace == 0
}
- p str[0,i]
if str[0, i] == ' '
list.push ' '
else
@@ -1318,7 +1317,7 @@ class TkVariable
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
idx = -1
newopts = ''
- @trace_var.each_with_index{|i,e|
+ @trace_var.each_with_index{|e,i|
if idx < 0 && e[0] == opts && e[1] == cmd
idx = i
next
@@ -1352,7 +1351,7 @@ class TkVariable
return unless @trace_elem[elem].kind_of? Array
opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
idx = -1
- @trace_elem[elem].each_with_index{|i,e|
+ @trace_elem[elem].each_with_index{|e,i|
if idx < 0 && e[0] == opts && e[1] == cmd
idx = i
next
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index c44b215..c1e45cb 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -173,8 +173,8 @@ class TkFont
TkFont.new(nil, nil).call_font_configure(path, *(args + [{}]))
else
begin
- compound = Hash[*list(tk_call('font', 'configure',
- fnt))].collect{|key,value|
+ compound = Hash[*tk_split_simplelist(tk_call('font', 'configure',
+ fnt))].collect{|key,value|
[key[1..-1], value]
}.assoc('compound')[1]
rescue
diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb
index 6ec738e..f7d9361 100644
--- a/ext/tk/lib/tktext.rb
+++ b/ext/tk/lib/tktext.rb
@@ -813,12 +813,20 @@ class TkTextMark<TkObject
tk_call @t.path, 'mark', 'gravity', @id, direction
end
- def next(index)
- @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index))
+ def next(index = nil)
+ if index
+ @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index))
+ else
+ @t.tagid2obj(tk_call(@t.path, 'mark', 'next', @id))
+ end
end
- def previous(index)
- @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index))
+ def previous(index = nil)
+ if index
+ @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index))
+ else
+ @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', @id))
+ end
end
end
diff --git a/hash.c b/hash.c
index 0f91bc6..8234db2 100644
--- a/hash.c
+++ b/hash.c
@@ -201,8 +201,8 @@ rb_hash_initialize(argc, argv, hash)
rb_hash_modify(hash);
if (rb_block_given_p()) {
- if (argc > 1) {
- rb_raise(rb_eArgError, "wrong number of arguments", argc);
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number of arguments");
}
RHASH(hash)->ifnone = rb_f_lambda();
FL_SET(hash, HASH_PROC_DEFAULT);
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 404eaf7..5a9b271 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -30,7 +30,7 @@
# that the Singleton pattern is properly inherited.
#
# In addition Klass is provided with the class methods
-# * Klass.instance() - returning ``the instance''
+# * Klass.instance() - returning ``the instance''
# * Klass._load(str) - returning ``the instance''
# * Klass._wait() - a hook method putting a second (or n-th)
# thread calling Klass.instance on a waiting loop if the first call
@@ -43,6 +43,7 @@
# _dump(depth) and _load(str) method allows the (partial) resurrection
# of a previous state of ``the instance'' - see third example.
#
+
module Singleton
def Singleton.included (klass)
# should this be checked?
diff --git a/object.c b/object.c
index 2c4440c..e2ecbd3 100644
--- a/object.c
+++ b/object.c
@@ -1239,6 +1239,8 @@ Init_Object()
rb_define_method(rb_cNilClass, "&", false_and, 1);
rb_define_method(rb_cNilClass, "|", false_or, 1);
rb_define_method(rb_cNilClass, "^", false_xor, 1);
+ rb_undef_method(rb_cNilClass, "clone");
+ rb_undef_method(rb_cNilClass, "dup");
rb_define_method(rb_cNilClass, "nil?", rb_true, 0);
rb_undef_method(CLASS_OF(rb_cNilClass), "allocate");
@@ -1314,6 +1316,8 @@ Init_Object()
rb_define_method(rb_cTrueClass, "^", true_xor, 1);
rb_undef_method(CLASS_OF(rb_cTrueClass), "allocate");
rb_undef_method(CLASS_OF(rb_cTrueClass), "new");
+ rb_undef_method(rb_cTrueClass, "clone");
+ rb_undef_method(rb_cTrueClass, "dup");
rb_define_global_const("TRUE", Qtrue);
rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
@@ -1323,6 +1327,8 @@ Init_Object()
rb_define_method(rb_cFalseClass, "^", false_xor, 1);
rb_undef_method(CLASS_OF(rb_cFalseClass), "allocate");
rb_undef_method(CLASS_OF(rb_cFalseClass), "new");
+ rb_undef_method(rb_cFalseClass, "clone");
+ rb_undef_method(rb_cFalseClass, "dup");
rb_define_global_const("FALSE", Qfalse);
eq = rb_intern("==");
diff --git a/parse.y b/parse.y
index 07f3642..0296f63 100644
--- a/parse.y
+++ b/parse.y
@@ -1142,7 +1142,7 @@ call_args2 : arg ',' args opt_block_arg
{
value_expr($1);
value_expr($6);
- $$ = list_append(list_concat($1,$3), NEW_HASH($5));
+ $$ = list_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5));
$$ = arg_blk_pass($$, $6);
}
| arg ',' assocs ',' tSTAR arg opt_block_arg
diff --git a/string.c b/string.c
index b36314c..87411a5 100644
--- a/string.c
+++ b/string.c
@@ -1761,7 +1761,7 @@ rb_str_to_i(argc, argv, str)
else base = NUM2INT(b);
switch (base) {
- case 2: case 8: case 10: case 16:
+ case 0: case 2: case 8: case 10: case 16:
break;
default:
rb_raise(rb_eArgError, "illegal radix %d", base);
diff --git a/version.h b/version.h
index 354c571..c52dd9a 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
-#define RUBY_RELEASE_DATE "2002-01-25"
+#define RUBY_RELEASE_DATE "2002-01-28"
#define RUBY_VERSION_CODE 172
-#define RUBY_RELEASE_CODE 20020125
+#define RUBY_RELEASE_CODE 20020128