diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-08 15:13:22 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-08 15:13:22 +0000 |
commit | 91c07a5ac67bc7dad114a84697f3abc32ed78318 (patch) | |
tree | 3a4428340bf02ec6500a8c79866b744ad0a31f9c | |
parent | 485754369101514e6230f4cd0a68922016f29b0e (diff) | |
download | ruby-91c07a5ac67bc7dad114a84697f3abc32ed78318.tar.gz |
* thread.c (rb_set_coverages, rb_reset_coverages): enable and disable
coverage measurement.
* thread.c (rb_get_coverages): rename and move from vm.c.
* vm.c (rb_vm_get_coverages): ditto.
* iseq.c (prepare_iseq_build): ditto.
* thread.c (clear_coverage): ditto.
* parse.y (coverage): ditto.
* ext/coverage/coverage.c: use above functions, add new method
Coverage.start and fix rdoc .
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | ext/coverage/coverage.c | 65 | ||||
-rw-r--r-- | iseq.c | 4 | ||||
-rw-r--r-- | parse.y | 4 | ||||
-rw-r--r-- | thread.c | 39 | ||||
-rw-r--r-- | vm.c | 6 |
6 files changed, 94 insertions, 42 deletions
@@ -1,3 +1,21 @@ +Wed Jul 9 00:12:31 2008 Yusuke Endoh <mame@tsg.ne.jp> + + * thread.c (rb_set_coverages, rb_reset_coverages): enable and disable + coverage measurement. + + * thread.c (rb_get_coverages): rename and move from vm.c. + + * vm.c (rb_vm_get_coverages): ditto. + + * iseq.c (prepare_iseq_build): ditto. + + * thread.c (clear_coverage): ditto. + + * parse.y (coverage): ditto. + + * ext/coverage/coverage.c: use above functions, add new method + Coverage.start and fix rdoc . + Tue Jul 8 23:02:35 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c (find_default_source): bug fix when diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c index b40b28bc21..3c6746f7aa 100644 --- a/ext/coverage/coverage.c +++ b/ext/coverage/coverage.c @@ -10,15 +10,67 @@ #include "ruby.h" -extern void rb_enable_coverages(void); +static VALUE rb_mCoverage; + +extern VALUE rb_get_coverages(void); +extern void rb_set_coverages(VALUE); +extern void rb_reset_coverages(void); + +/* + * call-seq: + * Coverage.start => nil + * + * Enables coverage measurement. + */ +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); + } +} + +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; +} + +/* + * call-seq: + * Coverage.result => hash + * + * Returns a hash that contains filename as key and coverage array as value + * and disables coverage measurement. + */ +static VALUE +rb_coverage_result(VALUE klass) +{ + VALUE coverages = rb_get_coverages(); + 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); + rb_reset_coverages(); + return coverages; +} /* Coverage provides coverage measurement feature for Ruby. + * This feature is experimental, so these APIs may be changed in future. * * = Usage * * (1) require "coverage.so" - * (2) require or load Ruby source file - * (3) Coverage.result will return a hash that contains filename as key and + * (2) do Coverage.start + * (3) require or load Ruby source file + * (4) Coverage.result will return a hash that contains filename as key and * coverage array as value. * * = Example @@ -37,11 +89,14 @@ extern void rb_enable_coverages(void); * [EOF] * * require "coverage.so" + * Coverage.start * require "foo.rb" - * p COVERAGE__ #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]} + * p Coverage.result #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]} */ void Init_coverage(void) { - rb_enable_coverages(); + rb_mCoverage = rb_define_module("Coverage"); + rb_define_module_function(rb_mCoverage, "start", rb_coverage_start, 0); + rb_define_module_function(rb_mCoverage, "result", rb_coverage_result, 0); } @@ -194,8 +194,8 @@ prepare_iseq_build(rb_iseq_t *iseq, iseq->coverage = Qfalse; if (!GET_THREAD()->parse_in_eval) { - extern VALUE rb_vm_get_coverages(void); - VALUE coverages = rb_vm_get_coverages(); + extern VALUE rb_get_coverages(void); + VALUE coverages = rb_get_coverages(); if (RTEST(coverages)) { iseq->coverage = rb_hash_lookup(coverages, filename); if (NIL_P(iseq->coverage)) iseq->coverage = Qfalse; @@ -4672,8 +4672,8 @@ debug_lines(const char *f) static VALUE coverage(const char *f, int n) { - extern VALUE rb_vm_get_coverages(void); - VALUE coverages = rb_vm_get_coverages(); + extern VALUE rb_get_coverages(void); + VALUE coverages = rb_get_coverages(); if (RTEST(coverages) && RBASIC(coverages)->klass == 0) { VALUE fname = rb_str_new2(f); VALUE lines = rb_ary_new2(n); @@ -2117,8 +2117,8 @@ clear_coverage_i(st_data_t key, st_data_t val, st_data_t dummy) static void clear_coverage(void) { - extern VALUE rb_vm_get_coverages(void); - VALUE coverages = rb_vm_get_coverages(); + extern VALUE rb_get_coverages(void); + VALUE coverages = rb_get_coverages(); if (RTEST(coverages)) { st_foreach(RHASH_TBL(coverages), clear_coverage_i, 0); } @@ -3548,37 +3548,22 @@ update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas } } -static int -coverage_result_i(st_data_t key, st_data_t val, st_data_t dummy) +VALUE +rb_get_coverages(void) { - VALUE coverage = (VALUE)val; - RBASIC(coverage)->klass = rb_cArray; - rb_ary_freeze(coverage); - return ST_CONTINUE; + return GET_VM()->coverages; } -static VALUE -rb_coverage_result(VALUE klass) +void +rb_set_coverages(VALUE coverages) { - 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; + GET_VM()->coverages = coverages; + rb_add_event_hook(update_coverage, RUBY_EVENT_COVERAGE, Qnil); } void -rb_enable_coverages(void) +rb_reset_coverages(void) { - VALUE rb_mCoverage; - - if (!RTEST(GET_VM()->coverages)) { - 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_coverage_result, 0); - } + GET_VM()->coverages = Qfalse; + rb_remove_event_hook(update_coverage); } @@ -1909,9 +1909,3 @@ rb_ruby_debug_ptr(void) { return ruby_vm_debug_ptr(GET_VM()); } - -VALUE -rb_vm_get_coverages(void) -{ - return GET_VM()->coverages; -} |