diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-13 16:06:26 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-13 16:06:26 +0000 |
commit | 7023a64d802487c2fa0c2de574d6093d2fe0be25 (patch) | |
tree | 8e995558778d8a5d12018ca8d4530031a0a3bf52 /ext | |
parent | 8dddc12ad7a13220d83af86a836812172f3ee906 (diff) | |
download | ruby-7023a64d802487c2fa0c2de574d6093d2fe0be25.tar.gz |
* ext/coverage/coverage.c: make it restartable. [ruby-core:36539]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/coverage/coverage.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c index 29ac7090f3..3a26aaab11 100644 --- a/ext/coverage/coverage.c +++ b/ext/coverage/coverage.c @@ -11,6 +11,8 @@ #include "ruby.h" #include "vm_core.h" +static VALUE rb_coverages = Qundef; + /* * call-seq: * Coverage.start => nil @@ -21,19 +23,25 @@ static VALUE rb_coverage_start(VALUE klass) { if (!RTEST(rb_get_coverages())) { - VALUE coverages = rb_hash_new(); - RBASIC(coverages)->klass = 0; - rb_set_coverages(coverages); + if (rb_coverages == Qundef) { + rb_coverages = rb_hash_new(); + RBASIC(rb_coverages)->klass = 0; + } + rb_set_coverages(rb_coverages); } return Qnil; } static int -coverage_result_i(st_data_t key, st_data_t val, st_data_t dummy) +coverage_result_i(st_data_t key, st_data_t val, st_data_t h) { + VALUE path = (VALUE)key; VALUE coverage = (VALUE)val; - RBASIC(coverage)->klass = rb_cArray; + VALUE coverages = (VALUE)h; + coverage = rb_ary_dup(coverage); + rb_ary_clear((VALUE)val); rb_ary_freeze(coverage); + rb_hash_aset(coverages, path, coverage); return ST_CONTINUE; } @@ -48,14 +56,14 @@ static VALUE rb_coverage_result(VALUE klass) { VALUE coverages = rb_get_coverages(); + VALUE ncoverages = rb_hash_new(); if (!RTEST(coverages)) { rb_raise(rb_eRuntimeError, "coverage measurement is not enabled"); } - RBASIC(coverages)->klass = rb_cHash; - st_foreach(RHASH_TBL(coverages), coverage_result_i, 0); - rb_hash_freeze(coverages); + st_foreach(RHASH_TBL(coverages), coverage_result_i, ncoverages); + rb_hash_freeze(ncoverages); rb_reset_coverages(); - return coverages; + return ncoverages; } /* Coverage provides coverage measurement feature for Ruby. |