summaryrefslogtreecommitdiff
path: root/ext/coverage/coverage.c
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-06 14:29:17 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-06 14:29:17 +0000
commit4225b29df96182f259289ed32a7ce40128b9a835 (patch)
tree5e5a17a195b10cfa7e0db26034fb3f68b40da4cf /ext/coverage/coverage.c
parent6a79276eddaafb5d80252b173c535e63f9d5c620 (diff)
* ext/coverage/coverage.c: Fully reset coverage to not persist global state.
It was returning old file coverages as empty arrays to the user. [ruby-core:74596] [Bug #12220] * ext/coverage/coverage.c (rb_coverages): remove unused static state. * thread.c: Moved and renamed coverage_clear_result_i to reset_coverage_i. * test/coverage/test_coverage.rb: improve precision of tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/coverage/coverage.c')
-rw-r--r--ext/coverage/coverage.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c
index f621280..9a9011a 100644
--- a/ext/coverage/coverage.c
+++ b/ext/coverage/coverage.c
@@ -11,8 +11,6 @@
#include "ruby.h"
#include "vm_core.h"
-static VALUE rb_coverages = Qundef;
-
/*
* call-seq:
* Coverage.start => nil
@@ -22,25 +20,15 @@ static VALUE rb_coverages = Qundef;
static VALUE
rb_coverage_start(VALUE klass)
{
- if (!RTEST(rb_get_coverages())) {
- if (rb_coverages == Qundef) {
- rb_coverages = rb_hash_new();
- rb_obj_hide(rb_coverages);
- }
- rb_set_coverages(rb_coverages);
+ VALUE coverages = rb_get_coverages();
+ if (!RTEST(coverages)) {
+ coverages = rb_hash_new();
+ rb_obj_hide(coverages);
+ rb_set_coverages(coverages);
}
return Qnil;
}
-/* Make coverage arrays empty so old covered files are no longer tracked. */
-static int
-coverage_clear_result_i(st_data_t key, st_data_t val, st_data_t h)
-{
- VALUE coverage = (VALUE)val;
- rb_ary_clear(coverage);
- return ST_CONTINUE;
-}
-
static int
coverage_peek_result_i(st_data_t key, st_data_t val, st_data_t h)
{
@@ -83,8 +71,6 @@ static VALUE
rb_coverage_result(VALUE klass)
{
VALUE ncoverages = rb_coverage_peek_result(klass);
- VALUE coverages = rb_get_coverages();
- st_foreach(RHASH_TBL(coverages), coverage_clear_result_i, ncoverages);
rb_reset_coverages();
return ncoverages;
}
@@ -129,5 +115,4 @@ Init_coverage(void)
rb_define_module_function(rb_mCoverage, "start", rb_coverage_start, 0);
rb_define_module_function(rb_mCoverage, "result", rb_coverage_result, 0);
rb_define_module_function(rb_mCoverage, "peek_result", rb_coverage_peek_result, 0);
- rb_gc_register_address(&rb_coverages);
}