ruby-changes:6443
From: mame <ko1@a...>
Date: Tue, 8 Jul 2008 22:57:29 +0900 (JST)
Subject: [ruby-changes:6443] Ruby:r17959 (trunk): * thread.c (rb_enable_coverages): hide coverage array by setting 0 to
mame 2008-07-08 22:57:06 +0900 (Tue, 08 Jul 2008) New Revision: 17959 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17959 Log: * thread.c (rb_enable_coverages): hide coverage array by setting 0 to klass during measurement. * parse.y (coverage, yycompile0): ditto. * iseq.c (prepare_iseq_build): use rb_hash_lookup instead of rb_hash_aref. * thread.c (rb_coverage_result): restore klass of coverage array and return it. * theaad.c (update_coverage): chcek whether its klass is 0. Modified files: trunk/ChangeLog trunk/iseq.c trunk/parse.y trunk/thread.c Index: ChangeLog =================================================================== --- ChangeLog (revision 17958) +++ ChangeLog (revision 17959) @@ -1,3 +1,18 @@ +Tue Jul 8 22:56:23 2008 Yusuke Endoh <mame@t...> + + * thread.c (rb_enable_coverages): hide coverage array by setting 0 to + klass during measurement. + + * parse.y (coverage, yycompile0): ditto. + + * iseq.c (prepare_iseq_build): use rb_hash_lookup instead of + rb_hash_aref. + + * thread.c (rb_coverage_result): restore klass of coverage array + and return it. + + * theaad.c (update_coverage): chcek whether its klass is 0. + Tue Jul 8 22:28:25 2008 Koichi Sasada <ko1@a...> * lib/debug.rb, lib/profile.rb: fix to use RubyVM. Index: iseq.c =================================================================== --- iseq.c (revision 17958) +++ iseq.c (revision 17959) @@ -197,7 +197,7 @@ extern VALUE rb_vm_get_coverages(void); VALUE coverages = rb_vm_get_coverages(); if (RTEST(coverages)) { - iseq->coverage = rb_hash_aref(coverages, filename); + iseq->coverage = rb_hash_lookup(coverages, filename); if (NIL_P(iseq->coverage)) iseq->coverage = Qfalse; } } Index: thread.c =================================================================== --- thread.c (revision 17958) +++ thread.c (revision 17959) @@ -3535,7 +3535,7 @@ update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass) { VALUE coverage = GET_THREAD()->cfp->iseq->coverage; - if (coverage) { + if (coverage && RBASIC(coverage)->klass == 0) { long line = rb_sourceline() - 1; long count; if (RARRAY_PTR(coverage)[line] == Qnil) { @@ -3548,16 +3548,37 @@ } } +static int +coverage_result_i(st_data_t key, st_data_t val, st_data_t dummy) +{ + VALUE coverage = (VALUE)val; + RBASIC(coverage)->klass = rb_cArray; + rb_ary_freeze(coverage); + return ST_CONTINUE; +} + +static VALUE +rb_coverage_result(VALUE klass) +{ + extern VALUE rb_vm_get_coverages(void); + VALUE coverages = rb_vm_get_coverages(); + st_foreach(RHASH_TBL(coverages), coverage_result_i, 0); + RBASIC(coverages)->klass = rb_cHash; + rb_hash_freeze(coverages); + return coverages; +} + void rb_enable_coverages(void) { VALUE rb_mCoverage; if (!RTEST(GET_VM()->coverages)) { - extern VALUE rb_vm_get_coverages(void); - GET_VM()->coverages = rb_hash_new(); + VALUE coverages = rb_hash_new(); + RBASIC(coverages)->klass = 0; + GET_VM()->coverages = coverages; rb_add_event_hook(update_coverage, RUBY_EVENT_COVERAGE, Qnil); rb_mCoverage = rb_define_module("Coverage"); - rb_define_module_function(rb_mCoverage, "result", rb_vm_get_coverages, 0); + rb_define_module_function(rb_mCoverage, "result", rb_coverage_result, 0); } } Index: parse.y =================================================================== --- parse.y (revision 17958) +++ parse.y (revision 17959) @@ -4674,10 +4674,11 @@ { extern VALUE rb_vm_get_coverages(void); VALUE coverages = rb_vm_get_coverages(); - if (RTEST(coverages)) { + if (RTEST(coverages) && RBASIC(coverages)->klass == 0) { VALUE fname = rb_str_new2(f); VALUE lines = rb_ary_new2(n); int i; + RBASIC(lines)->klass = 0; for (i = 0; i < n; i++) RARRAY_PTR(lines)[i] = Qnil; RARRAY(lines)->len = n; rb_hash_aset(coverages, fname, lines); @@ -4718,9 +4719,6 @@ parser_prepare(parser); n = yyparse((void*)parser); - if (ruby_coverage) { - rb_ary_freeze(ruby_coverage); - } ruby_debug_lines = 0; ruby_coverage = 0; compile_for_eval = 0; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/