summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-17 02:27:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-17 02:27:38 +0000
commit288ceaeec2077d06df3ba46bca97960f76f283e1 (patch)
tree8593a93244c96b098dd6611ee7e4dfe2c7ba9957
parent3ad741f132133bb542a84a01d8e7644fc4b51e4c (diff)
* 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
-rw-r--r--ChangeLog13
-rw-r--r--error.c2
-rw-r--r--eval.c22
-rw-r--r--node.h13
-rw-r--r--numeric.c7
-rw-r--r--parse.y6
-rw-r--r--re.c2
-rw-r--r--ruby.h3
-rw-r--r--string.c13
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 <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>
* 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<<NODE_TYPESHIFT)
+/* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_NEWLINE */
+#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) \
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 nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
#define nd_set_line(n,l) \
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_alen u2.argc
#define nd_next u3.node
diff --git a/numeric.c b/numeric.c
index a222bf3401..abf4cda397 100644
--- a/numeric.c
+++ b/numeric.c
@@ -716,6 +716,7 @@ flo_divmod(x, y)
VALUE x, y;
{
double fy, div, mod;
+ volatile VALUE a, b;
switch (TYPE(y)) {
case T_FIXNUM:
@@ -731,9 +732,9 @@ flo_divmod(x, y)
return rb_num_coerce_bin(x, y);
}
flodivmod(RFLOAT(x)->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 {