diff --git a/ChangeLog b/ChangeLog index 97c63c9b6a5bea..299a035fe40172 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,24 @@ +Wed Sep 22 09:04:41 2004 Yukihiro Matsumoto + + * parse.y: remove global variables ruby_eval_tree and + ruby_eval_tree_begin. + + * array.c (rb_ary_collect_bang): element size might change during + comparison. [ruby-dev:24300] + + * array.c (rb_ary_reject_bang): ditto. [ruby-dev:24300] + + * array.c (rb_ary_eql): ditto. [ruby-dev:24300] + Wed Sep 22 00:11:12 2004 Dave Thomas * process.c: Add documentation for fork() +Tue Sep 21 18:29:49 2004 Yukihiro Matsumoto + + * array.c (rb_ary_uniq_bang): element size might change during + comparison. [ruby-dev:24298] + Mon Sep 20 17:46:51 2004 Minero Aoki * ext/ripper/lib/ripper/tokenizer.rb: fix typo. diff --git a/array.c b/array.c index 8e6385d588bd26..6045bbea0e1a85 100644 --- a/array.c +++ b/array.c @@ -1828,7 +1828,7 @@ rb_ary_collect_bang(ary) rb_ary_modify(ary); for (i = 0; i < RARRAY(ary)->len; i++) { - RARRAY(ary)->ptr[i] = rb_yield(RARRAY(ary)->ptr[i]); + rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i])); } return ary; } @@ -2089,14 +2089,16 @@ rb_ary_reject_bang(ary) rb_ary_modify(ary); for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) { - if (RTEST(rb_yield(RARRAY(ary)->ptr[i1]))) continue; + VALUE v = RARRAY(ary)->ptr[i1]; + if (RTEST(rb_yield(v))) continue; if (i1 != i2) { - RARRAY(ary)->ptr[i2] = RARRAY(ary)->ptr[i1]; + rb_ary_store(ary, i2, v); } i2++; } if (RARRAY(ary)->len == i2) return Qnil; - RARRAY(ary)->len = i2; + if (i2 < RARRAY(ary)->len) + RARRAY(ary)->len = i2; return ary; } @@ -2603,7 +2605,7 @@ rb_ary_eql(ary1, ary2) if (TYPE(ary2) != T_ARRAY) return Qfalse; if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse; for (i=0; ilen; i++) { - if (!rb_eql(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i])) + if (!rb_eql(rb_ary_elt(ary1, i), rb_ary_elt(ary2, i))) return Qfalse; } return Qtrue; @@ -2694,7 +2696,7 @@ rb_ary_cmp(ary1, ary2) len = RARRAY(ary2)->len; } for (i=0; iptr[i], id_cmp, 1, RARRAY(ary2)->ptr[i]); + VALUE v = rb_funcall(rb_ary_elt(ary1, i), id_cmp, 1, rb_ary_elt(ary2, i)); if (v != INT2FIX(0)) { return v; } @@ -2842,7 +2844,7 @@ rb_ary_uniq_bang(ary) VALUE ary; { VALUE hash; - VALUE *p, *q, *end; + long i, j; rb_ary_modify(ary); @@ -2851,16 +2853,13 @@ rb_ary_uniq_bang(ary) if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) { return Qnil; } - p = q = RARRAY(ary)->ptr; - end = p + RARRAY(ary)->len; - while (p < end) { - VALUE v = *p; + for (i=j=0; ilen; i++) { + VALUE v = rb_ary_elt(ary, i); if (st_delete(RHASH(hash)->tbl, (st_data_t*)&v, 0)) { - *q++ = *p; + rb_ary_store(ary, j++, v); } - p++; } - RARRAY(ary)->len = (q - RARRAY(ary)->ptr); + RARRAY(ary)->len = j; return ary; } diff --git a/eval.c b/eval.c index 6ab9f5e6aaf86c..eddf931e76a473 100644 --- a/eval.c +++ b/eval.c @@ -645,8 +645,6 @@ rb_attr(klass, id, read, write, ex) extern int ruby_in_compile; VALUE ruby_errinfo = Qnil; -extern NODE *ruby_eval_tree_begin; -extern NODE *ruby_eval_tree; extern int ruby_nerrs; static VALUE rb_eLocalJumpError; @@ -949,6 +947,7 @@ static struct tag *prot_tag; #define TAG_RAISE 0x6 #define TAG_THROW 0x7 #define TAG_FATAL 0x8 +#define TAG_CONT 0x9 #define TAG_MASK 0xf VALUE ruby_class; @@ -1278,13 +1277,11 @@ eval_node(self, node) VALUE self; NODE *node; { - NODE *beg_tree = ruby_eval_tree_begin; - - ruby_eval_tree_begin = 0; - if (beg_tree) { - rb_eval(self, beg_tree); + if (!node) return Qnil; + if (nd_type(node) == NODE_PRELUDE) { + rb_eval(self, node->nd_head); + node = node->nd_body; } - if (!node) return Qnil; return rb_eval(self, node); } @@ -1443,6 +1440,8 @@ ruby_cleanup(ex) return ex; } +extern NODE *ruby_eval_tree; + int ruby_exec() { @@ -7508,9 +7507,6 @@ Init_eval() __send__ = rb_intern("__send__"); rb_global_variable((VALUE*)&top_scope); - rb_global_variable((VALUE*)&ruby_eval_tree_begin); - - rb_global_variable((VALUE*)&ruby_eval_tree); rb_global_variable((VALUE*)&ruby_dyna_vars); rb_define_virtual_variable("$@", errat_getter, errat_setter); diff --git a/hash.c b/hash.c index 89d5461e735939..27955f45295436 100644 --- a/hash.c +++ b/hash.c @@ -133,7 +133,7 @@ rb_hash_foreach_iter(key, value, arg) status = (*arg->func)(key, value, arg->arg); if (RHASH(arg->hash)->tbl != tbl || RHASH(arg->hash)->tbl->bins != bins) { - rb_raise(rb_eIndexError, "rehash occurred during iteration"); + rb_raise(rb_eArgError, "rehash occurred during iteration"); } if (RHASH(arg->hash)->iter_lev == 0) { rb_raise(rb_eArgError, "block re-entered"); diff --git a/intern.h b/intern.h index 063e442dd29791..8bd5a722fce85a 100644 --- a/intern.h +++ b/intern.h @@ -326,8 +326,6 @@ double rb_str_to_dbl _((VALUE, int)); RUBY_EXTERN int ruby_sourceline; RUBY_EXTERN char *ruby_sourcefile; ID rb_id_attrset _((ID)); -void rb_parser_append_print _((void)); -void rb_parser_while_loop _((int, int)); int ruby_parser_stack_on_heap _((void)); void rb_gc_mark_parser _((void)); int rb_is_const_id _((ID)); diff --git a/node.h b/node.h index 3795a91b2d04f8..00ecedcd2247c7 100644 --- a/node.h +++ b/node.h @@ -124,6 +124,7 @@ enum node_type { NODE_IFUNC, NODE_DSYM, NODE_ATTRASGN, + NODE_PRELUDE, NODE_LAST }; @@ -337,6 +338,7 @@ typedef struct RNode { #define NEW_POSTEXE() NEW_NODE(NODE_POSTEXE,0,0,0) #define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b) #define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a) +#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0) #define NOEX_PUBLIC 0 #define NOEX_NOSUPER 1 diff --git a/parse.y b/parse.y index 828e55d063f691..8c7f5bd92bea6c 100644 --- a/parse.y +++ b/parse.y @@ -49,9 +49,6 @@ ((id)&ID_SCOPE_MASK) == ID_CLASS)) #ifndef RIPPER -NODE *ruby_eval_tree_begin = 0; -NODE *ruby_eval_tree = 0; - char *ruby_sourcefile; /* current source file */ int ruby_sourceline; /* current line no. */ #endif @@ -116,6 +113,10 @@ struct parser_params { union tmpyystype *parser_yylval; /* YYSTYPE not defined yet */ VALUE eofp; +#ifndef RIPPER + NODE *parser_eval_tree_begin; + NODE *parser_eval_tree; +#endif NODE *parser_lex_strterm; enum lex_state_e parser_lex_state; stack_type parser_cond_stack; @@ -158,6 +159,8 @@ static int parser_yyerror _((struct parser_params*, const char*)); #define YYLEX_PARAM parser_v #define parser ((struct parser_params*)parser_v) +#define ruby_eval_tree (parser->parser_eval_tree) +#define ruby_eval_tree_begin (parser->parser_eval_tree_begin) #define lex_strterm (parser->parser_lex_strterm) #define lex_state (parser->parser_lex_state) #define cond_stack (parser->parser_cond_stack) @@ -4332,23 +4335,12 @@ yycompile(parser, f, line) } } - ruby__end__seen = 0; - ruby_eval_tree = 0; - heredoc_end = 0; - lex_strterm = 0; ruby_current_node = 0; ruby_sourcefile = rb_source_filename(f); n = yyparse((void*)parser); ruby_debug_lines = 0; compile_for_eval = 0; ruby_in_compile = 0; - cond_stack = 0; - cmdarg_stack = 0; - command_start = 1; - class_nest = 0; - in_single = 0; - in_def = 0; - cur_mid = 0; vp = ruby_dyna_vars; ruby_dyna_vars = vars; @@ -4358,6 +4350,13 @@ yycompile(parser, f, line) vp = vp->next; rb_gc_force_recycle((VALUE)tmp); } + if (ruby_eval_tree_begin) { + return NEW_PRELUDE(ruby_eval_tree_begin, ruby_eval_tree); + } + else { + return ruby_eval_tree; + } + if (n == 0) node = ruby_eval_tree; else ruby_eval_tree_begin = 0; return node; @@ -7750,32 +7749,31 @@ rb_gc_mark_parser() rb_gc_mark(ruby_debug_lines); } -void -rb_parser_append_print() +NODE* +rb_parser_append_print(node) + NODE *node; { - ruby_eval_tree = - block_append(ruby_eval_tree, - NEW_FCALL(rb_intern("print"), - NEW_ARRAY(NEW_GVAR(rb_intern("$_"))))); + return block_append(node, + NEW_FCALL(rb_intern("print"), + NEW_ARRAY(NEW_GVAR(rb_intern("$_"))))); } -void -rb_parser_while_loop(chop, split) +NODE * +rb_parser_while_loop(node, chop, split) + NODE *node; int chop, split; { if (split) { - ruby_eval_tree = - block_append(NEW_GASGN(rb_intern("$F"), - NEW_CALL(NEW_GVAR(rb_intern("$_")), - rb_intern("split"), 0)), - ruby_eval_tree); + node = block_append(NEW_GASGN(rb_intern("$F"), + NEW_CALL(NEW_GVAR(rb_intern("$_")), + rb_intern("split"), 0)), + node); } if (chop) { - ruby_eval_tree = - block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")), - rb_intern("chop!"), 0), ruby_eval_tree); + node = block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")), + rb_intern("chop!"), 0), node); } - ruby_eval_tree = NEW_OPT_N(ruby_eval_tree); + return NEW_OPT_N(node); } static struct { @@ -8100,6 +8098,10 @@ parser_initialize(parser) parser->toplevel_p = Qtrue; parser->parsing_thread = Qnil; +#ifndef RIPPER + parser->parser_eval_tree_begin = 0; + parser->parser_eval_tree = 0; +#endif parser->parser_lex_strterm = 0; parser->parser_cond_stack = 0; parser->parser_cmdarg_stack = 0; @@ -8124,7 +8126,7 @@ parser_initialize(parser) } static void -ripper_mark(ptr) +parser_mark(ptr) void *ptr; { struct parser_params *p = (struct parser_params*)ptr; @@ -8138,11 +8140,14 @@ ripper_mark(ptr) #ifdef RIPPER rb_gc_mark(p->parser_ruby_sourcefile); rb_gc_mark(p->delayed); +#else + rb_gc_mark((VALUE)p->parser_eval_tree_begin) ; + rb_gc_mark((VALUE)p->parser_eval_tree) ; #endif } static void -ripper_free(ptr) +parser_free(ptr) void *ptr; { struct parser_params *p = (struct parser_params*)ptr; @@ -8161,7 +8166,7 @@ parser_new() p = ALLOC_N(struct parser_params, 1); MEMZERO(p, struct parser_params, 1); - p->value = Data_Wrap_Struct(rb_cData, ripper_mark, ripper_free, p); + p->value = Data_Wrap_Struct(rb_cData, parser_mark, parser_free, p); parser_initialize(p); return p; } @@ -8458,7 +8463,7 @@ ripper_s_allocate(klass) p = ALLOC_N(struct parser_params, 1); MEMZERO(p, struct parser_params, 1); - self = Data_Wrap_Struct(klass, ripper_mark, ripper_free, p); + self = Data_Wrap_Struct(klass, parser_mark, parser_free, p); p->value = self; return self; } diff --git a/ruby.c b/ruby.c index 52faf02f7674c3..4ce5cb863a4723 100644 --- a/ruby.c +++ b/ruby.c @@ -347,12 +347,11 @@ require_libraries() struct req_list *tmp; save[0] = ruby_eval_tree; - save[1] = ruby_eval_tree_begin; - save[2] = NEW_BEGIN(0); - ruby_eval_tree = ruby_eval_tree_begin = 0; + save[1] = NEW_BEGIN(0); + ruby_eval_tree = 0; ruby_current_node = 0; Init_ext(); /* should be called here for some reason :-( */ - ruby_current_node = save[2]; + ruby_current_node = save[1]; ruby_set_current_source(); req_list_last = 0; while (list) { @@ -362,13 +361,12 @@ require_libraries() free(list->name); free(list); list = tmp; - ruby_current_node = save[2]; + ruby_current_node = save[1]; ruby_set_current_source(); } req_list_head.next = 0; ruby_eval_tree = save[0]; - ruby_eval_tree_begin = save[1]; - rb_gc_force_recycle((VALUE)save[2]); + rb_gc_force_recycle((VALUE)save[1]); ruby_current_node = 0; } @@ -430,6 +428,8 @@ moreswitches(s) return s; } +NODE *ruby_eval_tree; + static void proc_options(argc, argv) int argc; @@ -779,7 +779,7 @@ proc_options(argc, argv) ruby_sourcefile = rb_source_filename(argv0); if (e_script) { require_libraries(); - rb_compile_string(script, e_script, 1); + ruby_eval_tree = rb_compile_string(script, e_script, 1); } else if (strlen(script) == 1 && script[0] == '-') { load_stdin(); @@ -909,7 +909,7 @@ load_file(fname, script) require_libraries(); /* Why here? unnatural */ if (NIL_P(c)) return; } - rb_compile_file(fname, f, line_start); + ruby_eval_tree = rb_compile_file(fname, f, line_start); if (script && ruby__end__seen) { rb_define_global_const("DATA", f); } @@ -1122,6 +1122,9 @@ ruby_set_argv(argc, argv) } } +NODE *rb_parser_append_print _((NODE*)); +NODE *rb_parser_while_loop _((NODE*, int, int)); + void ruby_process_options(argc, argv) int argc; @@ -1141,9 +1144,9 @@ ruby_process_options(argc, argv) exit(0); } if (do_print) { - rb_parser_append_print(); + ruby_eval_tree = rb_parser_append_print(ruby_eval_tree); } if (do_loop) { - rb_parser_while_loop(do_line, do_split); + ruby_eval_tree = rb_parser_while_loop(ruby_eval_tree, do_line, do_split); } }