From 288ceaeec2077d06df3ba46bca97960f76f283e1 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 17 Nov 2004 02:27:38 +0000 Subject: * re.c (rb_reg_initialize_m): should raise exception instead of compile error. [ruby-core:03755] * string.c (rb_str_splice): move rb_str_modify() after StringValue(), which may alter the receiver. [ruby-dev:24878] * error.c (rb_error_frozen): now raise RuntimeError instead of TypeError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ error.c | 2 +- eval.c | 22 ++++++++++++---------- node.h | 13 +++++++------ numeric.c | 7 ++++--- parse.y | 6 ++++-- re.c | 2 +- ruby.h | 3 ++- string.c | 13 +++++-------- 9 files changed, 49 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89017b624d..77950acc86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Wed Nov 17 09:38:18 2004 Johan Holmberg + + * re.c (rb_reg_initialize_m): should raise exception instead of + compile error. [ruby-core:03755] + +Wed Nov 17 03:42:45 2004 Yukihiro Matsumoto + + * string.c (rb_str_splice): move rb_str_modify() after + StringValue(), which may alter the receiver. [ruby-dev:24878] + + * error.c (rb_error_frozen): now raise RuntimeError instead of + TypeError. + Tue Nov 16 21:22:47 2004 Michael Neumann * lib/xmlrpc/server.rb (CGIServer): fixed bug when client sends diff --git a/error.c b/error.c index ebc431107b..0d16ec3cb1 100644 --- a/error.c +++ b/error.c @@ -1208,7 +1208,7 @@ void rb_error_frozen(what) const char *what; { - rb_raise(rb_eTypeError, "can't modify frozen %s", what); + rb_raise(rb_eRuntimeError, "can't modify frozen %s", what); } void diff --git a/eval.c b/eval.c index dfb77c952e..55ab01e4b8 100644 --- a/eval.c +++ b/eval.c @@ -2651,7 +2651,7 @@ rb_eval(self, n) if (!node) RETURN(Qnil); ruby_current_node = node; - if (trace_func && FL_TEST(node, NODE_NEWLINE)) { + if (trace_func && (node->flags & NODE_NEWLINE)) { call_trace_func("line", node, self, ruby_frame->last_func, ruby_frame->last_class); @@ -4513,6 +4513,7 @@ proc_jump_error(state, result) localjump_error(mesg, result, state); } +NORETURN(static void return_jump(VALUE)); static void return_jump(retval) VALUE retval; @@ -4526,14 +4527,15 @@ return_jump(retval) yield = Qtrue; tt = tt->prev; } - if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) { - tt->dst = (VALUE)ruby_frame->uniq; - tt->retval = retval; - JUMP_TAG(TAG_RETURN); - } - if (tt->tag == PROT_LAMBDA && !yield) { + if ((tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) || + (tt->tag == PROT_LAMBDA && !yield)) + { tt->dst = (VALUE)tt->frame->uniq; tt->retval = retval; + if (trace_func) { + struct FRAME *f = tt->frame; + call_trace_func("return", f->node, f->self, f->last_func, f->last_class); + } JUMP_TAG(TAG_RETURN); } if (tt->tag == PROT_THREAD) { @@ -5650,6 +5652,9 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) call_trace_func("call", b2, recv, id, klass); } result = rb_eval(recv, body); + if (trace_func) { + call_trace_func("return", body, recv, id, klass); + } } else if (state == TAG_RETURN && TAG_DST()) { result = prot_tag->retval; @@ -5660,9 +5665,6 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper) POP_CLASS(); POP_SCOPE(); ruby_cref = saved_cref; - if (trace_func) { - call_trace_func("return", ruby_frame->prev->node, recv, id, klass); - } switch (state) { case 0: break; diff --git a/node.h b/node.h index df822462e5..6c8acb59b0 100644 --- a/node.h +++ b/node.h @@ -156,21 +156,22 @@ typedef struct RNode { #define RNODE(obj) (R_CAST(RNode)(obj)) -#define NODE_TYPESHIFT 7 -#define NODE_TYPEMASK (0xff<flags>>NODE_TYPESHIFT)&0x7f)) +#define NODE_TYPESHIFT 8 +#define NODE_TYPEMASK (0x7f<flags & NODE_TYPEMASK)>>NODE_TYPESHIFT)) #define nd_set_type(n,t) \ RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|(((t)<flags>>NODE_LSHIFT)&NODE_LMASK)) #define nd_set_line(n,l) \ RNODE(n)->flags=((RNODE(n)->flags&~(-1<value, fy, &div, &mod); - x = rb_float_new(div); - y = rb_float_new(mod); - return rb_assoc_new(x, y); + a = rb_float_new(div); + b = rb_float_new(mod); + return rb_assoc_new(a, b); } /* diff --git a/parse.y b/parse.y index 051bee456f..a19cc38603 100644 --- a/parse.y +++ b/parse.y @@ -3599,7 +3599,7 @@ string_content : tSTRING_CONTENT COND_LEXPOP(); CMDARG_LEXPOP(); /*%%%*/ - FL_UNSET($3, NODE_NEWLINE); + $3->flags &= ~NODE_NEWLINE; $$ = new_evstr($3); /*% $$ = dispatch1(string_embexpr, $3); @@ -6507,7 +6507,9 @@ static NODE* newline_node(node) NODE *node; { - FL_SET(node, NODE_NEWLINE); + if (node) { + node->flags |= NODE_NEWLINE; + } return node; } diff --git a/re.c b/re.c index 59b80a9b04..661848c8d2 100644 --- a/re.c +++ b/re.c @@ -1760,7 +1760,7 @@ rb_reg_initialize_m(argc, argv, self) s = StringValuePtr(argv[0]); len = RSTRING(argv[0])->len; } - rb_reg_initialize(self, s, len, flags, Qtrue); + rb_reg_initialize(self, s, len, flags, Qfalse); return self; } diff --git a/ruby.h b/ruby.h index 383afe9333..ed3c3a1591 100644 --- a/ruby.h +++ b/ruby.h @@ -425,7 +425,8 @@ struct RBignum { #define RFILE(obj) (R_CAST(RFile)(obj)) #define FL_SINGLETON FL_USER0 -#define FL_MARK (1<<6) +#define FL_MARK (1<<5) +#define FL_RESERVED (1<<6) /* will be used in the future GC */ #define FL_FINALIZE (1<<7) #define FL_TAINT (1<<8) #define FL_EXIVAR (1<<9) diff --git a/string.c b/string.c index 7648e446aa..f388d24db6 100644 --- a/string.c +++ b/string.c @@ -788,8 +788,8 @@ VALUE rb_str_append(str, str2) VALUE str, str2; { - rb_str_modify(str); StringValue(str2); + rb_str_modify(str); if (RSTRING(str2)->len > 0) { if (FL_TEST(str, STR_ASSOC)) { long len = RSTRING(str)->len+RSTRING(str2)->len; @@ -1643,6 +1643,7 @@ rb_str_splice(str, beg, len, val) } StringValue(val); + rb_str_modify(str); if (len < RSTRING(val)->len) { /* expand string */ RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(val)->len - len + 1); @@ -1672,7 +1673,6 @@ rb_str_update(str, beg, len, val) long beg, len; VALUE val; { - rb_str_modify(str); rb_str_splice(str, beg, len, val); } @@ -1706,7 +1706,6 @@ rb_str_subpat_set(str, re, nth, val) } end = RMATCH(match)->END(nth); len = end - start; - rb_str_modify(str); rb_str_splice(str, start, len, val); } @@ -1731,6 +1730,7 @@ rb_str_aset(str, indx, val) idx += RSTRING(str)->len; } if (FIXNUM_P(val)) { + rb_str_modify(str); if (RSTRING(str)->len == idx) { RSTRING(str)->len += 1; RESIZE_CAPA(str, RSTRING(str)->len); @@ -1799,7 +1799,6 @@ rb_str_aset_m(argc, argv, str) VALUE *argv; VALUE str; { - rb_str_modify(str); if (argc == 3) { if (TYPE(argv[0]) == T_REGEXP) { rb_str_subpat_set(str, argv[0], NUM2INT(argv[1]), argv[2]); @@ -1838,7 +1837,6 @@ rb_str_insert(str, idx, str2) { long pos = NUM2LONG(idx); - rb_str_modify(str); if (pos == -1) { pos = RSTRING(str)->len; } @@ -2092,7 +2090,7 @@ str_gsub(argc, argv, str, bang) rb_match_busy(match); val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); str_mod_check(str, sp, slen); - str_frozen_check(str); + if (bang) str_frozen_check(str); if (val == dest) { /* paranoid chack [ruby-dev:24827] */ rb_raise(rb_eRuntimeError, "block should not cheat"); } @@ -3897,8 +3895,8 @@ rb_str_chomp_bang(argc, argv, str) rs = rb_rs; if (rs == rb_default_rs) { smart_chomp: + rb_str_modify(str); if (RSTRING(str)->ptr[len-1] == '\n') { - rb_str_modify(str); RSTRING(str)->len--; if (RSTRING(str)->len > 0 && RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') { @@ -3906,7 +3904,6 @@ rb_str_chomp_bang(argc, argv, str) } } else if (RSTRING(str)->ptr[len-1] == '\r') { - rb_str_modify(str); RSTRING(str)->len--; } else { -- cgit v1.2.3