* 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
This commit is contained in:
matz 2001-10-22 06:48:18 +00:00
parent d0129370f0
commit 959d5febcf
7 changed files with 59 additions and 41 deletions

View File

@ -1,3 +1,8 @@
Mon Oct 22 15:21:55 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* class.c (rb_mod_clone): should not copy class name, since clone
should remain anonymous.
Fri Oct 19 23:40:37 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> Fri Oct 19 23:40:37 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* variable.c (remove_trace): should not access already freed area. * variable.c (remove_trace): should not access already freed area.
@ -25,6 +30,14 @@ Wed Oct 17 14:12:50 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* variable.c (rb_gvar_defined): refer the original entry of an alias. * variable.c (rb_gvar_defined): refer the original entry of an alias.
Tue Oct 16 23:29:26 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nobu.nakada@nifty.ne.jp> Tue Oct 16 21:38:15 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* eval.c (rb_f_missing): check stack level with rb_stack_check(). * 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 <nobu.nakada@nifty.ne.jp>
* object.c (rb_mod_initialize): optional block with * object.c (rb_mod_initialize): optional block with
Module.new. [new] (from 2001-10-10) Module.new. [new] (from 2001-10-10)
>>>>>>> 1.591
Tue Oct 16 00:07:06 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> Tue Oct 16 00:07:06 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* parse.y (yylex): disallow alpha-numeric and mbchar for * parse.y (yylex): disallow alpha-numeric and mbchar for
terminator of %string. terminator of %string.
Mond Oct 15 18:00:05 2001 Pit Capitain <pit@capitain.de> Mon Oct 15 18:00:05 2001 Pit Capitain <pit@capitain.de>
* string.c (rb_str_index): wrong increment for non alphanumeric * string.c (rb_str_index): wrong increment for non alphanumeric
string. string.
Mon Oct 15 05:23:02 2001 Koji Arai <JCA02266@nifty.ne.jp>
* sprintf.c (rb_f_sprintf): support "%B".
Wed Oct 10 03:11:47 2001 Yukihiro Matsumoto <matz@ruby-lang.org> Wed Oct 10 03:11:47 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* file.c (rb_stat_clone): should copy internal data too. * file.c (rb_stat_clone): should copy internal data too.

View File

@ -66,7 +66,13 @@ rb_mod_clone(module)
RCLASS(clone)->super = RCLASS(module)->super; RCLASS(clone)->super = RCLASS(module)->super;
if (RCLASS(module)->iv_tbl) { if (RCLASS(module)->iv_tbl) {
ID id;
RCLASS(clone)->iv_tbl = st_copy(RCLASS(module)->iv_tbl); 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) { if (RCLASS(module)->m_tbl) {
RCLASS(clone)->m_tbl = st_init_numtable(); RCLASS(clone)->m_tbl = st_init_numtable();

36
eval.c
View File

@ -99,7 +99,7 @@ struct timeval {
VALUE rb_cProc; VALUE rb_cProc;
static VALUE rb_cBinding; 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 VALUE rb_f_binding _((VALUE));
static void rb_f_END _((void)); static void rb_f_END _((void));
static VALUE rb_f_block_given_p _((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)) { if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
rb_raise(rb_eSecurityError, "Insecure: can't undef"); 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); rb_frozen_class_p(klass);
if (id == __id__ || id == __send__) { if (id == __id__ || id == __send__ || id == init) {
rb_warn("undefining `%s' may cause serious problem", rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
rb_id2name(id));
} }
body = search_method(ruby_class, id, &origin); body = search_method(ruby_class, id, &origin);
if (!body || !body->nd_body) { if (!body || !body->nd_body) {
@ -2010,12 +2012,13 @@ call_trace_func(event, file, line, self, id, klass)
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)"); srcfile = rb_str_new2(ruby_sourcefile?ruby_sourcefile:"(ruby)");
proc_call(trace_func, rb_ary_new3(6, rb_str_new2(event), proc_invoke(trace_func, rb_ary_new3(6, rb_str_new2(event),
srcfile, srcfile,
INT2FIX(ruby_sourceline), INT2FIX(ruby_sourceline),
id?ID2SYM(id):Qnil, id?ID2SYM(id):Qnil,
self?rb_f_binding(self):Qnil, self?rb_f_binding(self):Qnil,
klass)); klass),
Qtrue, 0);
} }
POP_TMPTAG(); /* do not propagate retval */ POP_TMPTAG(); /* do not propagate retval */
POP_FRAME(); POP_FRAME();
@ -4467,7 +4470,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
break; break;
case NODE_BMETHOD: 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; break;
case NODE_SCOPE: case NODE_SCOPE:
@ -5928,7 +5931,7 @@ call_end_proc(data)
ruby_frame->self = ruby_frame->prev->self; ruby_frame->self = ruby_frame->prev->self;
ruby_frame->last_func = 0; ruby_frame->last_func = 0;
ruby_frame->last_class = 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_FRAME();
POP_ITER(); POP_ITER();
} }
@ -6407,9 +6410,10 @@ blk_orphan(data)
} }
static VALUE static VALUE
proc_invoke(proc, args, pcall) proc_invoke(proc, args, pcall, self)
VALUE proc, args; /* OK */ VALUE proc, args; /* OK */
int pcall; int pcall;
VALUE self;
{ {
struct BLOCK * volatile old_block; struct BLOCK * volatile old_block;
struct BLOCK _block; struct BLOCK _block;
@ -6447,7 +6451,7 @@ proc_invoke(proc, args, pcall)
state = EXEC_TAG(); state = EXEC_TAG();
if (state == 0) { if (state == 0) {
proc_set_safe_level(proc); 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(); POP_TAG();
@ -6484,14 +6488,14 @@ static VALUE
proc_call(proc, args) proc_call(proc, args)
VALUE proc, args; /* OK */ VALUE proc, args; /* OK */
{ {
return proc_invoke(proc, args, Qtrue); return proc_invoke(proc, args, Qtrue, 0);
} }
static VALUE static VALUE
proc_yield(proc, args) proc_yield(proc, args)
VALUE proc, args; /* OK */ VALUE proc, args; /* OK */
{ {
return proc_invoke(proc, args, Qfalse); return proc_invoke(proc, args, Qfalse, 0);
} }
static VALUE static VALUE

View File

@ -28,7 +28,6 @@
# Complex::conjugate # Complex::conjugate
# Complex::<=> # Complex::<=>
# Complex::== # Complex::==
# Complex::to_i
# Complex::to_f # Complex::to_f
# Complex::to_r # Complex::to_r
# Complex::to_s # Complex::to_s
@ -243,18 +242,6 @@ class Complex < Numeric
end end
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 def denominator
@real.denominator.lcm(@image.denominator) @real.denominator.lcm(@image.denominator)
end end

View File

@ -247,7 +247,7 @@ w_uclass(obj, klass, arg)
VALUE obj, klass; VALUE obj, klass;
struct dump_arg *arg; struct dump_arg *arg;
{ {
if (rb_class_real(CLASS_OF(obj)) != klass) { if (rb_obj_class(obj) != klass) {
w_byte(TYPE_UCLASS, arg); w_byte(TYPE_UCLASS, arg);
w_unique(rb_class2name(CLASS_OF(obj)), arg); w_unique(rb_class2name(CLASS_OF(obj)), arg);
} }
@ -799,20 +799,17 @@ r_object(arg)
case TYPE_UCLASS: case TYPE_UCLASS:
{ {
VALUE c = rb_path2class(r_unique(arg)); VALUE c = rb_path2class(r_unique(arg));
VALUE tmp;
v = r_object(arg); v = r_object(arg);
if (rb_special_const_p(v) || if (rb_special_const_p(v) || TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS) {
TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS || TYPE(v) == T_MODULE || format_error:
!RTEST(rb_funcall(c, '<', 1, RBASIC(v)->klass))) {
rb_raise(rb_eArgError, "dump format error (user class)"); rb_raise(rb_eArgError, "dump format error (user class)");
} }
#if 0 if (TYPE(v) == T_MODULE || !RTEST(rb_funcall(c, '<', 1, RBASIC(v)->klass))) {
tmp = rb_obj_alloc(c); VALUE tmp = rb_obj_alloc(c);
if (TYPE(v) != TYPE(tmp)) {
rb_raise(rb_eArgError, "dump format error (user class)"); if (TYPE(v) != TYPE(tmp)) goto format_error;
} }
#endif
RBASIC(v)->klass = c; RBASIC(v)->klass = c;
return v; return v;
} }

View File

@ -1192,6 +1192,9 @@ $x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)]
$y = Marshal.dump($x) $y = Marshal.dump($x)
test_ok($x == Marshal.load($y)) test_ok($x == Marshal.load($y))
StrClone=String.clone;
test_ok(Marshal.load(Marshal.dump(StrClone.new("abc"))).type == StrClone)
test_check "pack" test_check "pack"
$format = "c2x5CCxsdils_l_a6"; $format = "c2x5CCxsdils_l_a6";

View File

@ -352,6 +352,7 @@ rb_f_sprintf(argc, argv)
case 'x': case 'x':
case 'X': case 'X':
case 'b': case 'b':
case 'B':
case 'u': case 'u':
{ {
volatile VALUE val = GETARG(); volatile VALUE val = GETARG();
@ -371,6 +372,7 @@ rb_f_sprintf(argc, argv)
case 'x': case 'x':
case 'X': case 'X':
case 'b': case 'b':
case 'B':
case 'u': case 'u':
default: default:
if (flags&(FPLUS|FSPACE)) sign = 1; 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 == 'X') prefix = "0X"; else if (*p == 'X') prefix = "0X";
else if (*p == 'b') prefix = "0b"; else if (*p == 'b') prefix = "0b";
else if (*p == 'B') prefix = "0B";
if (prefix) { if (prefix) {
width -= strlen(prefix); width -= strlen(prefix);
} }
@ -410,7 +413,7 @@ rb_f_sprintf(argc, argv)
if (*p == 'u' || *p == 'd' || *p == 'i') base = 10; if (*p == 'u' || *p == 'd' || *p == 'i') base = 10;
else if (*p == 'x' || *p == 'X') base = 16; else if (*p == 'x' || *p == 'X') base = 16;
else if (*p == 'o') base = 8; else if (*p == 'o') base = 8;
else if (*p == 'b') base = 2; else if (*p == 'b' || *p == 'B') base = 2;
if (!bignum) { if (!bignum) {
if (base == 2) { if (base == 2) {
val = rb_int2big(v); val = rb_int2big(v);