mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7e16f9e777
commit
caf3933bab
4 changed files with 43 additions and 9 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Tue Jul 8 22:56:23 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* 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@atdot.net>
|
||||
|
||||
* lib/debug.rb, lib/profile.rb: fix to use RubyVM.
|
||||
|
|
2
iseq.c
2
iseq.c
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
6
parse.y
6
parse.y
|
@ -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);
|
||||
|
@ -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;
|
||||
|
|
29
thread.c
29
thread.c
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue