Permalink
Browse files

* parse.y (rb_parser_append_print): should handle prelude.

  [llama@u01.gate0]

* parse.y (rb_parser_while_loop): ditto.

* array.c (rb_ary_subseq): original object might be modified after
  sharing data creation.  [ruby-dev:24327]

* array.c (rb_ary_replace): ditto.

* array.c (ary_make_shared): freeze shared array. [ruby-dev:24325]

* struct.c (struct_members): always check struct size and size of
  members list in the class.  [ruby-dev:24320]

* string.c (rb_str_sub_bang): check if string is not modified
  during iteration.  [ruby-dev:24315]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 0c9d768 commit c0a998d027eac8e9dc6d85b4b56c5e5bc87024a0 matz committed Sep 24, 2004
Showing with 196 additions and 155 deletions.
  1. +20 −0 ChangeLog
  2. +27 −15 array.c
  3. +0 −4 eval.c
  4. +30 −13 ext/tk/tkutil.c
  5. +1 −15 gc.c
  6. +1 −1 intern.h
  7. +26 −22 parse.y
  8. +33 −20 re.c
  9. +0 −5 ruby.c
  10. +5 −0 string.c
  11. +53 −60 struct.c
View
@@ -1,3 +1,20 @@
+Fri Sep 24 08:29:45 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (rb_parser_append_print): should handle prelude.
+ [llama@u01.gate0]
+
+ * parse.y (rb_parser_while_loop): ditto.
+
+ * array.c (rb_ary_subseq): original object might be modified after
+ sharing data creation. [ruby-dev:24327]
+
+ * array.c (rb_ary_replace): ditto.
+
+ * array.c (ary_make_shared): freeze shared array. [ruby-dev:24325]
+
+ * struct.c (struct_members): always check struct size and size of
+ members list in the class. [ruby-dev:24320]
+
Thu Sep 23 19:48:14 2004 Minero Aoki <aamine@loveruby.net>
* ext/ripper/Makefile.dev: removed.
@@ -16,6 +33,9 @@ Thu Sep 23 19:48:14 2004 Minero Aoki <aamine@loveruby.net>
Thu Sep 23 09:29:14 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * string.c (rb_str_sub_bang): check if string is not modified
+ during iteration. [ruby-dev:24315]
+
* hash.c (rb_hash_rehash): replace st_foreach() by its deep
checking counterpart. [ruby-dev:24310]
View
42 array.c
@@ -237,7 +237,7 @@ rb_values_new2(n, elts)
return val;
}
-static void
+static VALUE
ary_make_shared(ary)
VALUE ary;
{
@@ -250,6 +250,11 @@ ary_make_shared(ary)
shared->aux.capa = RARRAY(ary)->aux.capa;
RARRAY(ary)->aux.shared = (VALUE)shared;
FL_SET(ary, ELTS_SHARED);
+ OBJ_FREEZE(shared);
+ return (VALUE)shared;
+ }
+ else {
+ return RARRAY(ary)->aux.shared;
}
}
@@ -744,7 +749,8 @@ rb_ary_subseq(ary, beg, len)
VALUE ary;
long beg, len;
{
- VALUE klass, ary2;
+ VALUE klass, ary2, shared;
+ VALUE *ptr;
if (beg > RARRAY(ary)->len) return Qnil;
if (beg < 0 || len < 0) return Qnil;
@@ -757,11 +763,12 @@ rb_ary_subseq(ary, beg, len)
klass = rb_obj_class(ary);
if (len == 0) return ary_new(klass, 0);
- ary_make_shared(ary);
+ shared = ary_make_shared(ary);
+ ptr = RARRAY(ary)->ptr;
ary2 = ary_alloc(klass);
- RARRAY(ary2)->ptr = RARRAY(ary)->ptr + beg;
+ RARRAY(ary2)->ptr = ptr + beg;
RARRAY(ary2)->len = len;
- RARRAY(ary2)->aux.shared = RARRAY(ary)->aux.shared;
+ RARRAY(ary2)->aux.shared = shared;
FL_SET(ary2, ELTS_SHARED);
return ary2;
@@ -1675,7 +1682,6 @@ sort_1(a, b, data)
VALUE retval = rb_yield_values(2, *a, *b);
int n;
- ary_sort_check(data);
n = rb_cmpint(retval, *a, *b);
ary_sort_check(data);
return n;
@@ -1700,7 +1706,6 @@ sort_2(ap, bp, data)
}
retval = rb_funcall(a, id_cmp, 1, b);
- ary_sort_check(data);
n = rb_cmpint(retval, a, b);
ary_sort_check(data);
@@ -2263,15 +2268,17 @@ static VALUE
rb_ary_replace(copy, orig)
VALUE copy, orig;
{
+ VALUE shared;
+
rb_ary_modify(copy);
orig = to_ary(orig);
if (copy == orig) return copy;
- ary_make_shared(orig);
+ shared = ary_make_shared(orig);
if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
free(RARRAY(copy)->ptr);
- RARRAY(copy)->ptr = RARRAY(orig)->ptr;
- RARRAY(copy)->len = RARRAY(orig)->len;
- RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
+ RARRAY(copy)->ptr = RARRAY(shared)->ptr;
+ RARRAY(copy)->len = RARRAY(shared)->len;
+ RARRAY(copy)->aux.shared = shared;
FL_SET(copy, ELTS_SHARED);
return copy;
@@ -2987,8 +2994,11 @@ flatten(ary, idx, ary2, memo)
rb_ary_push(memo, id);
rb_ary_update(ary, idx, 1, ary2);
while (i < lim) {
- if (TYPE(RARRAY(ary)->ptr[i]) == T_ARRAY) {
- n = flatten(ary, i, RARRAY(ary)->ptr[i], memo);
+ VALUE tmp;
+
+ tmp = rb_check_array_type(RARRAY(ary)->ptr[i]);
+ if (!NIL_P(tmp)) {
+ n = flatten(ary, i, tmp, memo);
i += n; lim += n;
}
i++;
@@ -3023,12 +3033,14 @@ rb_ary_flatten_bang(ary)
rb_ary_modify(ary);
while (i<RARRAY(ary)->len) {
VALUE ary2 = RARRAY(ary)->ptr[i];
+ VALUE tmp;
- if (TYPE(ary2) == T_ARRAY) {
+ tmp = rb_check_array_type(ary2);
+ if (!NIL_P(tmp)) {
if (NIL_P(memo)) {
memo = rb_ary_new();
}
- i += flatten(ary, i, ary2, memo);
+ i += flatten(ary, i, tmp, memo);
mod = 1;
}
i++;
View
4 eval.c
@@ -642,8 +642,6 @@ rb_attr(klass, id, read, write, ex)
}
}
-extern int ruby_in_compile;
-
VALUE ruby_errinfo = Qnil;
extern int ruby_nerrs;
@@ -2451,7 +2449,6 @@ call_trace_func(event, node, self, id, klass)
if (!trace_func) return;
if (tracing) return;
- if (ruby_in_compile) return;
if (id == ID_ALLOCATOR) return;
if (!(node_save = ruby_current_node)) {
@@ -10379,7 +10376,6 @@ rb_thread_wait_fd(fd)
int fd;
{
if (rb_thread_critical) return;
- if (ruby_in_compile) return;
if (curr_thread == curr_thread->next) return;
if (curr_thread->status == THREAD_TO_KILL) return;
View
@@ -197,15 +197,26 @@ fromUTF8_toDefaultEnc(str, self)
}
+static void
+hash_check(err)
+ int err;
+{
+ if (err) {
+ rb_raise(rb_eRuntimeError, "hash modified");
+ }
+}
+
static int
-to_strkey(key, value, hash)
+to_strkey(key, value, hash, err)
VALUE key;
VALUE value;
VALUE hash;
+ int err;
{
+ hash_check(err);
if (key == Qundef) return ST_CONTINUE;
rb_hash_aset(hash, rb_funcall(key, ID_to_s, 0, 0), value);
- return ST_CONTINUE;
+ return ST_CHECK;
}
static VALUE
@@ -216,9 +227,7 @@ tk_symbolkey2str(self, keys)
volatile VALUE new_keys = rb_hash_new();
if NIL_P(keys) return new_keys;
- if (TYPE(keys) != T_HASH) {
- rb_raise(rb_eArgError, "Hash is expected");
- }
+ keys = rb_convert_type(keys, T_HASH, "Hash", "to_hash");
st_foreach(RHASH(keys)->tbl, to_strkey, new_keys);
return new_keys;
}
@@ -437,12 +446,16 @@ assoc2kv_enc(assoc, ary, self)
}
static int
-push_kv(key, val, args)
+push_kv(key, val, args, err)
VALUE key;
VALUE val;
VALUE args;
+ int err;
{
- volatile VALUE ary = RARRAY(args)->ptr[0];
+ volatile VALUE ary;
+
+ hash_check(err);
+ ary = RARRAY(args)->ptr[0];
if (key == Qundef) return ST_CONTINUE;
#if 0
@@ -451,12 +464,12 @@ push_kv(key, val, args)
#endif
RARRAY(ary)->ptr[RARRAY(ary)->len++] = key2keyname(key);
- if (val == TK_None) return ST_CONTINUE;
+ if (val == TK_None) return ST_CHECK;
RARRAY(ary)->ptr[RARRAY(ary)->len++]
= get_eval_string_core(val, Qnil, RARRAY(args)->ptr[1]);
- return ST_CONTINUE;
+ return ST_CHECK;
}
static VALUE
@@ -483,12 +496,16 @@ hash2kv(hash, ary, self)
}
static int
-push_kv_enc(key, val, args)
+push_kv_enc(key, val, args, err)
VALUE key;
VALUE val;
VALUE args;
+ int err;
{
- volatile VALUE ary = RARRAY(args)->ptr[0];
+ volatile VALUE ary;
+
+ hash_check(err);
+ ary = RARRAY(args)->ptr[0];
if (key == Qundef) return ST_CONTINUE;
#if 0
@@ -500,12 +517,12 @@ push_kv_enc(key, val, args)
#endif
RARRAY(ary)->ptr[RARRAY(ary)->len++] = key2keyname(key);
- if (val == TK_None) return ST_CONTINUE;
+ if (val == TK_None) return ST_CHECK;
RARRAY(ary)->ptr[RARRAY(ary)->len++]
= get_eval_string_core(val, Qtrue, RARRAY(args)->ptr[1]);
- return ST_CONTINUE;
+ return ST_CHECK;
}
static VALUE
View
16 gc.c
@@ -178,7 +178,6 @@ ruby_xfree(x)
RUBY_CRITICAL(free(x));
}
-extern int ruby_in_compile;
static int dont_gc;
static int during_gc;
static int need_call_final = 0;
@@ -1001,19 +1000,6 @@ gc_sweep()
int i, j;
unsigned long live = 0;
- if (ruby_in_compile && ruby_parser_stack_on_heap()) {
- /* should not reclaim nodes during compilation
- if yacc's semantic stack is not allocated on machine stack */
- for (i = 0; i < heaps_used; i++) {
- p = heaps[i].slot; pend = p + heaps[i].limit;
- while (p < pend) {
- if (!(p->as.basic.flags&FL_MARK) && BUILTIN_TYPE(p) == T_NODE)
- gc_mark((VALUE)p, 0);
- p++;
- }
- }
- }
-
mark_source_filename(ruby_sourcefile);
st_foreach(source_filenames, sweep_source_filename, 0);
@@ -1080,7 +1066,7 @@ gc_sweep()
if (final_list) {
RVALUE *tmp;
- if (rb_prohibit_interrupt || ruby_in_compile) {
+ if (rb_prohibit_interrupt) {
deferred_final_list = final_list;
return;
}
View
@@ -326,7 +326,6 @@ double rb_str_to_dbl _((VALUE, int));
RUBY_EXTERN int ruby_sourceline;
RUBY_EXTERN char *ruby_sourcefile;
ID rb_id_attrset _((ID));
-int ruby_parser_stack_on_heap _((void));
void rb_gc_mark_parser _((void));
int rb_is_const_id _((ID));
int rb_is_instance_id _((ID));
@@ -370,6 +369,7 @@ VALUE rb_reg_match_pre _((VALUE));
VALUE rb_reg_match_post _((VALUE));
VALUE rb_reg_match_last _((VALUE));
VALUE rb_reg_new _((const char*, long, int));
+VALUE rb_reg_compile _((const char*, long, int));
VALUE rb_reg_match _((VALUE, VALUE));
VALUE rb_reg_match2 _((VALUE));
int rb_reg_options _((VALUE));
Oops, something went wrong.

0 comments on commit c0a998d

Please sign in to comment.