Skip to content

Commit

Permalink
* thread.c (rb_enable_coverages): hide coverage array by setting 0 to
Browse files Browse the repository at this point in the history
  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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
mame committed Jul 8, 2008
1 parent 7e16f9e commit caf3933
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Tue Jul 8 22:56:23 2008 Yusuke Endoh <[email protected]>

* 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 <[email protected]>

* lib/debug.rb, lib/profile.rb: fix to use RubyVM.
Expand Down
2 changes: 1 addition & 1 deletion iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
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;
}
}
Expand Down
6 changes: 2 additions & 4 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4674,10 +4674,11 @@ coverage(const char *f, int n)
{
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);
Expand Down Expand Up @@ -4718,9 +4719,6 @@ yycompile0(VALUE arg, int tracing)

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;
Expand Down
29 changes: 25 additions & 4 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3535,7 +3535,7 @@ static void
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) {
Expand All @@ -3548,16 +3548,37 @@ 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 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);
}
}

0 comments on commit caf3933

Please sign in to comment.