* 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
This commit is contained in:
matz 2004-11-17 02:27:38 +00:00
Родитель 3ad741f132
Коммит 288ceaeec2
9 изменённых файлов: 49 добавлений и 32 удалений

Просмотреть файл

@ -1,3 +1,16 @@
Wed Nov 17 09:38:18 2004 Johan Holmberg <holmberg@iar.se>
* 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 <matz@ruby-lang.org>
* 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 <mneumann@ruby-lang.org> Tue Nov 16 21:22:47 2004 Michael Neumann <mneumann@ruby-lang.org>
* lib/xmlrpc/server.rb (CGIServer): fixed bug when client sends * lib/xmlrpc/server.rb (CGIServer): fixed bug when client sends

Просмотреть файл

@ -1208,7 +1208,7 @@ void
rb_error_frozen(what) rb_error_frozen(what)
const char *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 void

22
eval.c
Просмотреть файл

@ -2651,7 +2651,7 @@ rb_eval(self, n)
if (!node) RETURN(Qnil); if (!node) RETURN(Qnil);
ruby_current_node = node; 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, call_trace_func("line", node, self,
ruby_frame->last_func, ruby_frame->last_func,
ruby_frame->last_class); ruby_frame->last_class);
@ -4513,6 +4513,7 @@ proc_jump_error(state, result)
localjump_error(mesg, result, state); localjump_error(mesg, result, state);
} }
NORETURN(static void return_jump(VALUE));
static void static void
return_jump(retval) return_jump(retval)
VALUE retval; VALUE retval;
@ -4526,14 +4527,15 @@ return_jump(retval)
yield = Qtrue; yield = Qtrue;
tt = tt->prev; tt = tt->prev;
} }
if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) { if ((tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) ||
tt->dst = (VALUE)ruby_frame->uniq; (tt->tag == PROT_LAMBDA && !yield))
tt->retval = retval; {
JUMP_TAG(TAG_RETURN);
}
if (tt->tag == PROT_LAMBDA && !yield) {
tt->dst = (VALUE)tt->frame->uniq; tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval; 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); JUMP_TAG(TAG_RETURN);
} }
if (tt->tag == PROT_THREAD) { 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); call_trace_func("call", b2, recv, id, klass);
} }
result = rb_eval(recv, body); result = rb_eval(recv, body);
if (trace_func) {
call_trace_func("return", body, recv, id, klass);
}
} }
else if (state == TAG_RETURN && TAG_DST()) { else if (state == TAG_RETURN && TAG_DST()) {
result = prot_tag->retval; result = prot_tag->retval;
@ -5660,9 +5665,6 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
POP_CLASS(); POP_CLASS();
POP_SCOPE(); POP_SCOPE();
ruby_cref = saved_cref; ruby_cref = saved_cref;
if (trace_func) {
call_trace_func("return", ruby_frame->prev->node, recv, id, klass);
}
switch (state) { switch (state) {
case 0: case 0:
break; break;

13
node.h
Просмотреть файл

@ -156,21 +156,22 @@ typedef struct RNode {
#define RNODE(obj) (R_CAST(RNode)(obj)) #define RNODE(obj) (R_CAST(RNode)(obj))
#define NODE_TYPESHIFT 7 /* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_NEWLINE */
#define NODE_TYPEMASK (0xff<<NODE_TYPESHIFT) #define NODE_NEWLINE (1<<7)
#define nd_type(n) ((int)(((RNODE(n))->flags>>NODE_TYPESHIFT)&0x7f)) #define NODE_TYPESHIFT 8
#define NODE_TYPEMASK (0x7f<<NODE_TYPESHIFT)
#define nd_type(n) ((int) (((RNODE(n))->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
#define nd_set_type(n,t) \ #define nd_set_type(n,t) \
RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|(((t)<<NODE_TYPESHIFT)&NODE_TYPEMASK)) RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|(((t)<<NODE_TYPESHIFT)&NODE_TYPEMASK))
#define NODE_LSHIFT (NODE_TYPESHIFT+8) #define NODE_LSHIFT (NODE_TYPESHIFT+7)
#define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1) #define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
#define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK)) #define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
#define nd_set_line(n,l) \ #define nd_set_line(n,l) \
RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT)) RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
#define NODE_NEWLINE FL_USER7
#define nd_head u1.node #define nd_head u1.node
#define nd_alen u2.argc #define nd_alen u2.argc
#define nd_next u3.node #define nd_next u3.node

Просмотреть файл

@ -716,6 +716,7 @@ flo_divmod(x, y)
VALUE x, y; VALUE x, y;
{ {
double fy, div, mod; double fy, div, mod;
volatile VALUE a, b;
switch (TYPE(y)) { switch (TYPE(y)) {
case T_FIXNUM: case T_FIXNUM:
@ -731,9 +732,9 @@ flo_divmod(x, y)
return rb_num_coerce_bin(x, y); return rb_num_coerce_bin(x, y);
} }
flodivmod(RFLOAT(x)->value, fy, &div, &mod); flodivmod(RFLOAT(x)->value, fy, &div, &mod);
x = rb_float_new(div); a = rb_float_new(div);
y = rb_float_new(mod); b = rb_float_new(mod);
return rb_assoc_new(x, y); return rb_assoc_new(a, b);
} }
/* /*

Просмотреть файл

@ -3599,7 +3599,7 @@ string_content : tSTRING_CONTENT
COND_LEXPOP(); COND_LEXPOP();
CMDARG_LEXPOP(); CMDARG_LEXPOP();
/*%%%*/ /*%%%*/
FL_UNSET($3, NODE_NEWLINE); $3->flags &= ~NODE_NEWLINE;
$$ = new_evstr($3); $$ = new_evstr($3);
/*% /*%
$$ = dispatch1(string_embexpr, $3); $$ = dispatch1(string_embexpr, $3);
@ -6507,7 +6507,9 @@ static NODE*
newline_node(node) newline_node(node)
NODE *node; NODE *node;
{ {
FL_SET(node, NODE_NEWLINE); if (node) {
node->flags |= NODE_NEWLINE;
}
return node; return node;
} }

2
re.c
Просмотреть файл

@ -1760,7 +1760,7 @@ rb_reg_initialize_m(argc, argv, self)
s = StringValuePtr(argv[0]); s = StringValuePtr(argv[0]);
len = RSTRING(argv[0])->len; len = RSTRING(argv[0])->len;
} }
rb_reg_initialize(self, s, len, flags, Qtrue); rb_reg_initialize(self, s, len, flags, Qfalse);
return self; return self;
} }

3
ruby.h
Просмотреть файл

@ -425,7 +425,8 @@ struct RBignum {
#define RFILE(obj) (R_CAST(RFile)(obj)) #define RFILE(obj) (R_CAST(RFile)(obj))
#define FL_SINGLETON FL_USER0 #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_FINALIZE (1<<7)
#define FL_TAINT (1<<8) #define FL_TAINT (1<<8)
#define FL_EXIVAR (1<<9) #define FL_EXIVAR (1<<9)

Просмотреть файл

@ -788,8 +788,8 @@ VALUE
rb_str_append(str, str2) rb_str_append(str, str2)
VALUE str, str2; VALUE str, str2;
{ {
rb_str_modify(str);
StringValue(str2); StringValue(str2);
rb_str_modify(str);
if (RSTRING(str2)->len > 0) { if (RSTRING(str2)->len > 0) {
if (FL_TEST(str, STR_ASSOC)) { if (FL_TEST(str, STR_ASSOC)) {
long len = RSTRING(str)->len+RSTRING(str2)->len; long len = RSTRING(str)->len+RSTRING(str2)->len;
@ -1643,6 +1643,7 @@ rb_str_splice(str, beg, len, val)
} }
StringValue(val); StringValue(val);
rb_str_modify(str);
if (len < RSTRING(val)->len) { if (len < RSTRING(val)->len) {
/* expand string */ /* expand string */
RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(val)->len - len + 1); 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; long beg, len;
VALUE val; VALUE val;
{ {
rb_str_modify(str);
rb_str_splice(str, beg, len, val); rb_str_splice(str, beg, len, val);
} }
@ -1706,7 +1706,6 @@ rb_str_subpat_set(str, re, nth, val)
} }
end = RMATCH(match)->END(nth); end = RMATCH(match)->END(nth);
len = end - start; len = end - start;
rb_str_modify(str);
rb_str_splice(str, start, len, val); rb_str_splice(str, start, len, val);
} }
@ -1731,6 +1730,7 @@ rb_str_aset(str, indx, val)
idx += RSTRING(str)->len; idx += RSTRING(str)->len;
} }
if (FIXNUM_P(val)) { if (FIXNUM_P(val)) {
rb_str_modify(str);
if (RSTRING(str)->len == idx) { if (RSTRING(str)->len == idx) {
RSTRING(str)->len += 1; RSTRING(str)->len += 1;
RESIZE_CAPA(str, RSTRING(str)->len); RESIZE_CAPA(str, RSTRING(str)->len);
@ -1799,7 +1799,6 @@ rb_str_aset_m(argc, argv, str)
VALUE *argv; VALUE *argv;
VALUE str; VALUE str;
{ {
rb_str_modify(str);
if (argc == 3) { if (argc == 3) {
if (TYPE(argv[0]) == T_REGEXP) { if (TYPE(argv[0]) == T_REGEXP) {
rb_str_subpat_set(str, argv[0], NUM2INT(argv[1]), argv[2]); 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); long pos = NUM2LONG(idx);
rb_str_modify(str);
if (pos == -1) { if (pos == -1) {
pos = RSTRING(str)->len; pos = RSTRING(str)->len;
} }
@ -2092,7 +2090,7 @@ str_gsub(argc, argv, str, bang)
rb_match_busy(match); rb_match_busy(match);
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match))); val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
str_mod_check(str, sp, slen); str_mod_check(str, sp, slen);
str_frozen_check(str); if (bang) str_frozen_check(str);
if (val == dest) { /* paranoid chack [ruby-dev:24827] */ if (val == dest) { /* paranoid chack [ruby-dev:24827] */
rb_raise(rb_eRuntimeError, "block should not cheat"); rb_raise(rb_eRuntimeError, "block should not cheat");
} }
@ -3897,8 +3895,8 @@ rb_str_chomp_bang(argc, argv, str)
rs = rb_rs; rs = rb_rs;
if (rs == rb_default_rs) { if (rs == rb_default_rs) {
smart_chomp: smart_chomp:
rb_str_modify(str);
if (RSTRING(str)->ptr[len-1] == '\n') { if (RSTRING(str)->ptr[len-1] == '\n') {
rb_str_modify(str);
RSTRING(str)->len--; RSTRING(str)->len--;
if (RSTRING(str)->len > 0 && if (RSTRING(str)->len > 0 &&
RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') { 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') { else if (RSTRING(str)->ptr[len-1] == '\r') {
rb_str_modify(str);
RSTRING(str)->len--; RSTRING(str)->len--;
} }
else { else {