* include/ruby/intern.h: remove prototypes about coverage.

* iseq.c (prepare_iseq_build): add prototype.

* parse.y (coverage): ditto.

* thread.c (clear_coverage): ditto.

* thread.c (update_coverage): use rb_sourceline.

* thread.c (rb_get_coverages): rename and move to vm.c.

* vm.c (rb_vm_get_coverages): ditto.

* ext/coverage/coverage.c: add rdoc.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-07-03 14:27:43 +00:00
Родитель da1263d2ac
Коммит ae3a03eb07
7 изменённых файлов: 76 добавлений и 17 удалений

Просмотреть файл

@ -1,3 +1,21 @@
Thu Jul 3 23:26:36 2008 Yusuke Endoh <mame@tsg.ne.jp>
* include/ruby/intern.h: remove prototypes about coverage.
* iseq.c (prepare_iseq_build): add prototype.
* parse.y (coverage): ditto.
* thread.c (clear_coverage): ditto.
* thread.c (update_coverage): use rb_sourceline.
* thread.c (rb_get_coverages): rename and move to vm.c.
* vm.c (rb_vm_get_coverages): ditto.
* ext/coverage/coverage.c: add rdoc.
Thu Jul 3 21:51:21 2008 Yusuke Endoh <mame@tsg.ne.jp>
* ext/coverage/coverage.c, ext/coverage/extconf.rb: eliminate

Просмотреть файл

@ -1,11 +1,47 @@
/************************************************
coverage.c -
$Author: $
Copyright (c) 2008 Yusuke Endoh
************************************************/
#include "ruby.h"
VALUE rb_mCoverage;
extern void rb_enable_coverages(void);
/* Coverage provides coverage measurement feature for Ruby.
*
* = 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
* coverage array as value.
*
* = Example
*
* [foo.rb]
* s = 0
* 10.times do |x|
* s += x
* end
*
* if s == 45
* p :ok
* else
* p :ng
* end
* [EOF]
*
* require "coverage.so"
* require "foo.rb"
* p COVERAGE__ #=> {"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, "result", rb_get_coverages, 0);
}

Просмотреть файл

@ -626,8 +626,6 @@ VALUE rb_mutex_synchronize(VALUE self);
VALUE rb_barrier_new(void);
VALUE rb_barrier_wait(VALUE self);
VALUE rb_barrier_release(VALUE self);
VALUE rb_get_coverages(void);
void rb_enable_coverages(void);
/* time.c */
VALUE rb_time_new(time_t, long);
VALUE rb_time_nano_new(time_t, long);

3
iseq.c
Просмотреть файл

@ -194,7 +194,8 @@ prepare_iseq_build(rb_iseq_t *iseq,
iseq->coverage = Qfalse;
if (!GET_THREAD()->parse_in_eval) {
VALUE coverages = rb_get_coverages();
extern VALUE rb_vm_get_coverages(void);
VALUE coverages = rb_vm_get_coverages();
if (RTEST(coverages)) {
iseq->coverage = rb_hash_aref(coverages, filename);
if (NIL_P(iseq->coverage)) iseq->coverage = Qfalse;

Просмотреть файл

@ -4672,7 +4672,8 @@ debug_lines(const char *f)
static VALUE
coverage(const char *f, int n)
{
VALUE coverages = rb_get_coverages();
extern VALUE rb_vm_get_coverages(void);
VALUE coverages = rb_vm_get_coverages();
if (RTEST(coverages)) {
VALUE fname = rb_str_new2(f);
VALUE lines = rb_ary_new2(n);

Просмотреть файл

@ -2116,7 +2116,8 @@ clear_coverage_i(st_data_t key, st_data_t val, st_data_t dummy)
static void
clear_coverage(void)
{
VALUE coverages = rb_get_coverages();
extern VALUE rb_vm_get_coverages(void);
VALUE coverages = rb_vm_get_coverages();
if (RTEST(coverages)) {
st_foreach(RHASH_TBL(coverages), clear_coverage_i, 0);
}
@ -3529,19 +3530,12 @@ rb_check_deadlock(rb_vm_t *vm)
}
}
VALUE
rb_get_coverages(void)
{
return GET_VM()->coverages;
}
static void
update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
{
rb_control_frame_t *cfp = GET_THREAD()->cfp;
VALUE coverage = cfp->iseq->coverage;
VALUE coverage = GET_THREAD()->cfp->iseq->coverage;
if (coverage) {
long line = vm_get_sourceline(cfp) - 1;
long line = rb_sourceline() - 1;
long count;
if (RARRAY_PTR(coverage)[line] == Qnil) {
rb_bug("bug");
@ -3556,8 +3550,13 @@ update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas
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();
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);
}
}

6
vm.c
Просмотреть файл

@ -1909,3 +1909,9 @@ rb_ruby_debug_ptr(void)
{
return ruby_vm_debug_ptr(GET_VM());
}
VALUE
rb_vm_get_coverages(void)
{
return GET_VM()->coverages;
}