From 959d5febcf0cdd2f4d81a1bb91bcd8d9fee83f2f Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 22 Oct 2001 06:48:18 +0000 Subject: [PATCH] * class.c (rb_mod_clone): should not copy class name, since clone should remain anonymous. * eval.c (rb_call0): self in a block given to define_method now be switched to the receiver of the method. * eval.c (proc_invoke): added new parameter to allow self switching. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 20 +++++++++++++++++++- class.c | 6 ++++++ eval.c | 36 ++++++++++++++++++++---------------- lib/complex.rb | 13 ------------- marshal.c | 17 +++++++---------- sample/test.rb | 3 +++ sprintf.c | 5 ++++- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index e463a4505a..8b57c65f2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Oct 22 15:21:55 2001 Yukihiro Matsumoto + + * class.c (rb_mod_clone): should not copy class name, since clone + should remain anonymous. + Fri Oct 19 23:40:37 2001 Nobuyoshi Nakada * variable.c (remove_trace): should not access already freed area. @@ -25,6 +30,14 @@ Wed Oct 17 14:12:50 2001 Nobuyoshi Nakada * variable.c (rb_gvar_defined): refer the original entry of an alias. +Tue Oct 16 23:29:26 2001 Yukihiro Matsumoto + + * eval.c (rb_call0): self in a block given to define_method now be + switched to the receiver of the method. + + * eval.c (proc_invoke): added new parameter to allow self + switching. + Tue Oct 16 21:38:15 2001 Nobuyoshi Nakada * eval.c (rb_f_missing): check stack level with rb_stack_check(). @@ -38,16 +51,21 @@ Tue Oct 16 13:18:47 2001 Nobuyoshi Nakada * object.c (rb_mod_initialize): optional block with Module.new. [new] (from 2001-10-10) +>>>>>>> 1.591 Tue Oct 16 00:07:06 2001 Nobuyoshi Nakada * parse.y (yylex): disallow alpha-numeric and mbchar for terminator of %string. -Mond Oct 15 18:00:05 2001 Pit Capitain +Mon Oct 15 18:00:05 2001 Pit Capitain * string.c (rb_str_index): wrong increment for non alphanumeric string. +Mon Oct 15 05:23:02 2001 Koji Arai + + * sprintf.c (rb_f_sprintf): support "%B". + Wed Oct 10 03:11:47 2001 Yukihiro Matsumoto * file.c (rb_stat_clone): should copy internal data too. diff --git a/class.c b/class.c index a7911e8b96..4701054383 100644 --- a/class.c +++ b/class.c @@ -66,7 +66,13 @@ rb_mod_clone(module) RCLASS(clone)->super = RCLASS(module)->super; if (RCLASS(module)->iv_tbl) { + ID id; + RCLASS(clone)->iv_tbl = st_copy(RCLASS(module)->iv_tbl); + id = rb_intern("__classpath__"); + st_delete(RCLASS(clone)->iv_tbl, &id, 0); + id = rb_intern("__classid__"); + st_delete(RCLASS(clone)->iv_tbl, &id, 0); } if (RCLASS(module)->m_tbl) { RCLASS(clone)->m_tbl = st_init_numtable(); diff --git a/eval.c b/eval.c index bc3a4b1a37..943b2e3dba 100644 --- a/eval.c +++ b/eval.c @@ -99,7 +99,7 @@ struct timeval { VALUE rb_cProc; static VALUE rb_cBinding; -static VALUE proc_call _((VALUE,VALUE)); +static VALUE proc_invoke _((VALUE,VALUE,int,VALUE)); static VALUE rb_f_binding _((VALUE)); static void rb_f_END _((void)); static VALUE rb_f_block_given_p _((void)); @@ -1546,11 +1546,13 @@ rb_undef(klass, id) } if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) { rb_raise(rb_eSecurityError, "Insecure: can't undef"); + if (id == __id__ || id == __send__ || id == init) { + rb_name_error(id, "undefining `%s' prohibited", rb_id2name(id)); + } } rb_frozen_class_p(klass); - if (id == __id__ || id == __send__) { - rb_warn("undefining `%s' may cause serious problem", - rb_id2name(id)); + if (id == __id__ || id == __send__ || id == init) { + rb_warn("undefining `%s' may cause serious problem", rb_id2name(id)); } body = search_method(ruby_class, id, &origin); if (!body || !body->nd_body) { @@ -2010,12 +2012,13 @@ call_trace_func(event, file, line, self, id, klass) PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)"); - proc_call(trace_func, rb_ary_new3(6, rb_str_new2(event), - srcfile, - INT2FIX(ruby_sourceline), - id?ID2SYM(id):Qnil, - self?rb_f_binding(self):Qnil, - klass)); + proc_invoke(trace_func, rb_ary_new3(6, rb_str_new2(event), + srcfile, + INT2FIX(ruby_sourceline), + id?ID2SYM(id):Qnil, + self?rb_f_binding(self):Qnil, + klass), + Qtrue, 0); } POP_TMPTAG(); /* do not propagate retval */ POP_FRAME(); @@ -4467,7 +4470,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper) break; case NODE_BMETHOD: - result = proc_call(body->nd_cval, rb_ary_new4(argc, argv)); + result = proc_invoke(body->nd_cval, rb_ary_new4(argc, argv), Qtrue, recv); break; case NODE_SCOPE: @@ -5928,7 +5931,7 @@ call_end_proc(data) ruby_frame->self = ruby_frame->prev->self; ruby_frame->last_func = 0; ruby_frame->last_class = 0; - proc_call(data, rb_ary_new2(0)); + proc_invoke(data, rb_ary_new2(0), Qfalse, 0); POP_FRAME(); POP_ITER(); } @@ -6407,9 +6410,10 @@ blk_orphan(data) } static VALUE -proc_invoke(proc, args, pcall) +proc_invoke(proc, args, pcall, self) VALUE proc, args; /* OK */ int pcall; + VALUE self; { struct BLOCK * volatile old_block; struct BLOCK _block; @@ -6447,7 +6451,7 @@ proc_invoke(proc, args, pcall) state = EXEC_TAG(); if (state == 0) { proc_set_safe_level(proc); - result = rb_yield_0(args, 0, 0, pcall); + result = rb_yield_0(args, self, self?self:ruby_block->self, pcall); } POP_TAG(); @@ -6484,14 +6488,14 @@ static VALUE proc_call(proc, args) VALUE proc, args; /* OK */ { - return proc_invoke(proc, args, Qtrue); + return proc_invoke(proc, args, Qtrue, 0); } static VALUE proc_yield(proc, args) VALUE proc, args; /* OK */ { - return proc_invoke(proc, args, Qfalse); + return proc_invoke(proc, args, Qfalse, 0); } static VALUE diff --git a/lib/complex.rb b/lib/complex.rb index f0a363f9cb..77d8859a6a 100644 --- a/lib/complex.rb +++ b/lib/complex.rb @@ -28,7 +28,6 @@ # Complex::conjugate # Complex::<=> # Complex::== -# Complex::to_i # Complex::to_f # Complex::to_r # Complex::to_s @@ -243,18 +242,6 @@ class Complex < Numeric end end - def to_i - Complex(@real.to_i, @image.to_i) - end - - def to_f - Complex(@real.to_f, @image.to_f) - end - - def to_r - Complex(@real.to_r, @image.to_r) - end - def denominator @real.denominator.lcm(@image.denominator) end diff --git a/marshal.c b/marshal.c index bbc953ddda..6d0b2bc414 100644 --- a/marshal.c +++ b/marshal.c @@ -247,7 +247,7 @@ w_uclass(obj, klass, arg) VALUE obj, klass; struct dump_arg *arg; { - if (rb_class_real(CLASS_OF(obj)) != klass) { + if (rb_obj_class(obj) != klass) { w_byte(TYPE_UCLASS, arg); w_unique(rb_class2name(CLASS_OF(obj)), arg); } @@ -799,20 +799,17 @@ r_object(arg) case TYPE_UCLASS: { VALUE c = rb_path2class(r_unique(arg)); - VALUE tmp; v = r_object(arg); - if (rb_special_const_p(v) || - TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS || TYPE(v) == T_MODULE || - !RTEST(rb_funcall(c, '<', 1, RBASIC(v)->klass))) { + if (rb_special_const_p(v) || TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS) { + format_error: rb_raise(rb_eArgError, "dump format error (user class)"); } -#if 0 - tmp = rb_obj_alloc(c); - if (TYPE(v) != TYPE(tmp)) { - rb_raise(rb_eArgError, "dump format error (user class)"); + if (TYPE(v) == T_MODULE || !RTEST(rb_funcall(c, '<', 1, RBASIC(v)->klass))) { + VALUE tmp = rb_obj_alloc(c); + + if (TYPE(v) != TYPE(tmp)) goto format_error; } -#endif RBASIC(v)->klass = c; return v; } diff --git a/sample/test.rb b/sample/test.rb index 6c352fa083..104ff2900d 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -1192,6 +1192,9 @@ $x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)] $y = Marshal.dump($x) test_ok($x == Marshal.load($y)) +StrClone=String.clone; +test_ok(Marshal.load(Marshal.dump(StrClone.new("abc"))).type == StrClone) + test_check "pack" $format = "c2x5CCxsdils_l_a6"; diff --git a/sprintf.c b/sprintf.c index d3acb56274..fe53d6b27c 100644 --- a/sprintf.c +++ b/sprintf.c @@ -352,6 +352,7 @@ rb_f_sprintf(argc, argv) case 'x': case 'X': case 'b': + case 'B': case 'u': { volatile VALUE val = GETARG(); @@ -371,6 +372,7 @@ rb_f_sprintf(argc, argv) case 'x': case 'X': case 'b': + case 'B': case 'u': default: if (flags&(FPLUS|FSPACE)) sign = 1; @@ -381,6 +383,7 @@ rb_f_sprintf(argc, argv) else if (*p == 'x') prefix = "0x"; else if (*p == 'X') prefix = "0X"; else if (*p == 'b') prefix = "0b"; + else if (*p == 'B') prefix = "0B"; if (prefix) { width -= strlen(prefix); } @@ -410,7 +413,7 @@ rb_f_sprintf(argc, argv) if (*p == 'u' || *p == 'd' || *p == 'i') base = 10; else if (*p == 'x' || *p == 'X') base = 16; else if (*p == 'o') base = 8; - else if (*p == 'b') base = 2; + else if (*p == 'b' || *p == 'B') base = 2; if (!bignum) { if (base == 2) { val = rb_int2big(v);