Skip to content

Commit 288ceae

Browse files
author
matz
committed
* 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
1 parent 3ad741f commit 288ceae

File tree

9 files changed

+49
-32
lines changed

9 files changed

+49
-32
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Wed Nov 17 09:38:18 2004 Johan Holmberg <holmberg@iar.se>
2+
3+
* re.c (rb_reg_initialize_m): should raise exception instead of
4+
compile error. [ruby-core:03755]
5+
6+
Wed Nov 17 03:42:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
7+
8+
* string.c (rb_str_splice): move rb_str_modify() after
9+
StringValue(), which may alter the receiver. [ruby-dev:24878]
10+
11+
* error.c (rb_error_frozen): now raise RuntimeError instead of
12+
TypeError.
13+
114
Tue Nov 16 21:22:47 2004 Michael Neumann <mneumann@ruby-lang.org>
215

316
* lib/xmlrpc/server.rb (CGIServer): fixed bug when client sends

error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ void
12081208
rb_error_frozen(what)
12091209
const char *what;
12101210
{
1211-
rb_raise(rb_eTypeError, "can't modify frozen %s", what);
1211+
rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
12121212
}
12131213

12141214
void

eval.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,7 @@ rb_eval(self, n)
26512651
if (!node) RETURN(Qnil);
26522652

26532653
ruby_current_node = node;
2654-
if (trace_func && FL_TEST(node, NODE_NEWLINE)) {
2654+
if (trace_func && (node->flags & NODE_NEWLINE)) {
26552655
call_trace_func("line", node, self,
26562656
ruby_frame->last_func,
26572657
ruby_frame->last_class);
@@ -4513,6 +4513,7 @@ proc_jump_error(state, result)
45134513
localjump_error(mesg, result, state);
45144514
}
45154515

4516+
NORETURN(static void return_jump(VALUE));
45164517
static void
45174518
return_jump(retval)
45184519
VALUE retval;
@@ -4526,14 +4527,15 @@ return_jump(retval)
45264527
yield = Qtrue;
45274528
tt = tt->prev;
45284529
}
4529-
if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) {
4530-
tt->dst = (VALUE)ruby_frame->uniq;
4531-
tt->retval = retval;
4532-
JUMP_TAG(TAG_RETURN);
4533-
}
4534-
if (tt->tag == PROT_LAMBDA && !yield) {
4530+
if ((tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) ||
4531+
(tt->tag == PROT_LAMBDA && !yield))
4532+
{
45354533
tt->dst = (VALUE)tt->frame->uniq;
45364534
tt->retval = retval;
4535+
if (trace_func) {
4536+
struct FRAME *f = tt->frame;
4537+
call_trace_func("return", f->node, f->self, f->last_func, f->last_class);
4538+
}
45374539
JUMP_TAG(TAG_RETURN);
45384540
}
45394541
if (tt->tag == PROT_THREAD) {
@@ -5650,6 +5652,9 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
56505652
call_trace_func("call", b2, recv, id, klass);
56515653
}
56525654
result = rb_eval(recv, body);
5655+
if (trace_func) {
5656+
call_trace_func("return", body, recv, id, klass);
5657+
}
56535658
}
56545659
else if (state == TAG_RETURN && TAG_DST()) {
56555660
result = prot_tag->retval;
@@ -5660,9 +5665,6 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
56605665
POP_CLASS();
56615666
POP_SCOPE();
56625667
ruby_cref = saved_cref;
5663-
if (trace_func) {
5664-
call_trace_func("return", ruby_frame->prev->node, recv, id, klass);
5665-
}
56665668
switch (state) {
56675669
case 0:
56685670
break;

node.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,22 @@ typedef struct RNode {
156156

157157
#define RNODE(obj) (R_CAST(RNode)(obj))
158158

159-
#define NODE_TYPESHIFT 7
160-
#define NODE_TYPEMASK (0xff<<NODE_TYPESHIFT)
159+
/* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_NEWLINE */
160+
#define NODE_NEWLINE (1<<7)
161161

162-
#define nd_type(n) ((int)(((RNODE(n))->flags>>NODE_TYPESHIFT)&0x7f))
162+
#define NODE_TYPESHIFT 8
163+
#define NODE_TYPEMASK (0x7f<<NODE_TYPESHIFT)
164+
165+
#define nd_type(n) ((int) (((RNODE(n))->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
163166
#define nd_set_type(n,t) \
164167
RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|(((t)<<NODE_TYPESHIFT)&NODE_TYPEMASK))
165168

166-
#define NODE_LSHIFT (NODE_TYPESHIFT+8)
169+
#define NODE_LSHIFT (NODE_TYPESHIFT+7)
167170
#define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
168171
#define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
169172
#define nd_set_line(n,l) \
170173
RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
171174

172-
#define NODE_NEWLINE FL_USER7
173-
174175
#define nd_head u1.node
175176
#define nd_alen u2.argc
176177
#define nd_next u3.node

numeric.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ flo_divmod(x, y)
716716
VALUE x, y;
717717
{
718718
double fy, div, mod;
719+
volatile VALUE a, b;
719720

720721
switch (TYPE(y)) {
721722
case T_FIXNUM:
@@ -731,9 +732,9 @@ flo_divmod(x, y)
731732
return rb_num_coerce_bin(x, y);
732733
}
733734
flodivmod(RFLOAT(x)->value, fy, &div, &mod);
734-
x = rb_float_new(div);
735-
y = rb_float_new(mod);
736-
return rb_assoc_new(x, y);
735+
a = rb_float_new(div);
736+
b = rb_float_new(mod);
737+
return rb_assoc_new(a, b);
737738
}
738739

739740
/*

parse.y

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,7 +3599,7 @@ string_content : tSTRING_CONTENT
35993599
COND_LEXPOP();
36003600
CMDARG_LEXPOP();
36013601
/*%%%*/
3602-
FL_UNSET($3, NODE_NEWLINE);
3602+
$3->flags &= ~NODE_NEWLINE;
36033603
$$ = new_evstr($3);
36043604
/*%
36053605
$$ = dispatch1(string_embexpr, $3);
@@ -6507,7 +6507,9 @@ static NODE*
65076507
newline_node(node)
65086508
NODE *node;
65096509
{
6510-
FL_SET(node, NODE_NEWLINE);
6510+
if (node) {
6511+
node->flags |= NODE_NEWLINE;
6512+
}
65116513
return node;
65126514
}
65136515

re.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ rb_reg_initialize_m(argc, argv, self)
17601760
s = StringValuePtr(argv[0]);
17611761
len = RSTRING(argv[0])->len;
17621762
}
1763-
rb_reg_initialize(self, s, len, flags, Qtrue);
1763+
rb_reg_initialize(self, s, len, flags, Qfalse);
17641764
return self;
17651765
}
17661766

ruby.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ struct RBignum {
425425
#define RFILE(obj) (R_CAST(RFile)(obj))
426426

427427
#define FL_SINGLETON FL_USER0
428-
#define FL_MARK (1<<6)
428+
#define FL_MARK (1<<5)
429+
#define FL_RESERVED (1<<6) /* will be used in the future GC */
429430
#define FL_FINALIZE (1<<7)
430431
#define FL_TAINT (1<<8)
431432
#define FL_EXIVAR (1<<9)

string.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ VALUE
788788
rb_str_append(str, str2)
789789
VALUE str, str2;
790790
{
791-
rb_str_modify(str);
792791
StringValue(str2);
792+
rb_str_modify(str);
793793
if (RSTRING(str2)->len > 0) {
794794
if (FL_TEST(str, STR_ASSOC)) {
795795
long len = RSTRING(str)->len+RSTRING(str2)->len;
@@ -1643,6 +1643,7 @@ rb_str_splice(str, beg, len, val)
16431643
}
16441644

16451645
StringValue(val);
1646+
rb_str_modify(str);
16461647
if (len < RSTRING(val)->len) {
16471648
/* expand string */
16481649
RESIZE_CAPA(str, RSTRING(str)->len + RSTRING(val)->len - len + 1);
@@ -1672,7 +1673,6 @@ rb_str_update(str, beg, len, val)
16721673
long beg, len;
16731674
VALUE val;
16741675
{
1675-
rb_str_modify(str);
16761676
rb_str_splice(str, beg, len, val);
16771677
}
16781678

@@ -1706,7 +1706,6 @@ rb_str_subpat_set(str, re, nth, val)
17061706
}
17071707
end = RMATCH(match)->END(nth);
17081708
len = end - start;
1709-
rb_str_modify(str);
17101709
rb_str_splice(str, start, len, val);
17111710
}
17121711

@@ -1731,6 +1730,7 @@ rb_str_aset(str, indx, val)
17311730
idx += RSTRING(str)->len;
17321731
}
17331732
if (FIXNUM_P(val)) {
1733+
rb_str_modify(str);
17341734
if (RSTRING(str)->len == idx) {
17351735
RSTRING(str)->len += 1;
17361736
RESIZE_CAPA(str, RSTRING(str)->len);
@@ -1799,7 +1799,6 @@ rb_str_aset_m(argc, argv, str)
17991799
VALUE *argv;
18001800
VALUE str;
18011801
{
1802-
rb_str_modify(str);
18031802
if (argc == 3) {
18041803
if (TYPE(argv[0]) == T_REGEXP) {
18051804
rb_str_subpat_set(str, argv[0], NUM2INT(argv[1]), argv[2]);
@@ -1838,7 +1837,6 @@ rb_str_insert(str, idx, str2)
18381837
{
18391838
long pos = NUM2LONG(idx);
18401839

1841-
rb_str_modify(str);
18421840
if (pos == -1) {
18431841
pos = RSTRING(str)->len;
18441842
}
@@ -2092,7 +2090,7 @@ str_gsub(argc, argv, str, bang)
20922090
rb_match_busy(match);
20932091
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
20942092
str_mod_check(str, sp, slen);
2095-
str_frozen_check(str);
2093+
if (bang) str_frozen_check(str);
20962094
if (val == dest) { /* paranoid chack [ruby-dev:24827] */
20972095
rb_raise(rb_eRuntimeError, "block should not cheat");
20982096
}
@@ -3897,16 +3895,15 @@ rb_str_chomp_bang(argc, argv, str)
38973895
rs = rb_rs;
38983896
if (rs == rb_default_rs) {
38993897
smart_chomp:
3898+
rb_str_modify(str);
39003899
if (RSTRING(str)->ptr[len-1] == '\n') {
3901-
rb_str_modify(str);
39023900
RSTRING(str)->len--;
39033901
if (RSTRING(str)->len > 0 &&
39043902
RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') {
39053903
RSTRING(str)->len--;
39063904
}
39073905
}
39083906
else if (RSTRING(str)->ptr[len-1] == '\r') {
3909-
rb_str_modify(str);
39103907
RSTRING(str)->len--;
39113908
}
39123909
else {

0 commit comments

Comments
 (0)