mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
thread.c (update_line_coverage): Use RUBY_EVENT_LINE
This change makes coverage use the general event type RUBY_EVENT_LINE instead of a special event type RUBY_EVENT_COVERAGE. Just a refactoring. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9fbd48ee71
commit
ec02c4861b
4 changed files with 30 additions and 26 deletions
|
@ -251,15 +251,12 @@ struct iseq_compile_data_ensure_node_stack {
|
||||||
#define ADD_TRACE(seq, event) \
|
#define ADD_TRACE(seq, event) \
|
||||||
ADD_ELEM((seq), (LINK_ELEMENT *)new_trace_body(iseq, (event)))
|
ADD_ELEM((seq), (LINK_ELEMENT *)new_trace_body(iseq, (event)))
|
||||||
|
|
||||||
#define ADD_TRACE_LINE_COVERAGE(seq, line) \
|
#define SETUP_LINE_COVERAGE(seq, line) \
|
||||||
do { \
|
do { \
|
||||||
if (ISEQ_COVERAGE(iseq) && \
|
if (ISEQ_COVERAGE(iseq) && \
|
||||||
ISEQ_LINE_COVERAGE(iseq) && \
|
ISEQ_LINE_COVERAGE(iseq) && \
|
||||||
(line) > 0 && \
|
(line) > 0) { \
|
||||||
(line) != ISEQ_COMPILE_DATA(iseq)->last_coverable_line) { \
|
|
||||||
RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \
|
RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \
|
||||||
ISEQ_COMPILE_DATA(iseq)->last_coverable_line = (line); \
|
|
||||||
ADD_INSN2((seq), (line), trace2, INT2FIX(RUBY_EVENT_COVERAGE), INT2FIX(COVERAGE_INDEX_LINES)); \
|
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define DECL_BRANCH_BASE(branches, first_line, first_column, last_line, last_column, type) \
|
#define DECL_BRANCH_BASE(branches, first_line, first_column, last_line, last_column, type) \
|
||||||
|
@ -5424,7 +5421,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
|
||||||
else {
|
else {
|
||||||
if (node->flags & NODE_FL_NEWLINE) {
|
if (node->flags & NODE_FL_NEWLINE) {
|
||||||
ISEQ_COMPILE_DATA(iseq)->last_line = line;
|
ISEQ_COMPILE_DATA(iseq)->last_line = line;
|
||||||
ADD_TRACE_LINE_COVERAGE(ret, line);
|
SETUP_LINE_COVERAGE(ret, line);
|
||||||
ADD_TRACE(ret, RUBY_EVENT_LINE);
|
ADD_TRACE(ret, RUBY_EVENT_LINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
iseq.c
1
iseq.c
|
@ -330,7 +330,6 @@ prepare_iseq_build(rb_iseq_t *iseq,
|
||||||
ISEQ_COMPILE_DATA(iseq)->storage_head->size =
|
ISEQ_COMPILE_DATA(iseq)->storage_head->size =
|
||||||
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
|
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
|
||||||
ISEQ_COMPILE_DATA(iseq)->option = option;
|
ISEQ_COMPILE_DATA(iseq)->option = option;
|
||||||
ISEQ_COMPILE_DATA(iseq)->last_coverable_line = -1;
|
|
||||||
|
|
||||||
ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL;
|
ISEQ_COMPILE_DATA(iseq)->ivar_cache_table = NULL;
|
||||||
|
|
||||||
|
|
1
iseq.h
1
iseq.h
|
@ -114,7 +114,6 @@ struct iseq_compile_data {
|
||||||
struct iseq_compile_data_storage *storage_head;
|
struct iseq_compile_data_storage *storage_head;
|
||||||
struct iseq_compile_data_storage *storage_current;
|
struct iseq_compile_data_storage *storage_current;
|
||||||
int last_line;
|
int last_line;
|
||||||
int last_coverable_line;
|
|
||||||
int label_no;
|
int label_no;
|
||||||
int node_level;
|
int node_level;
|
||||||
unsigned int ci_index;
|
unsigned int ci_index;
|
||||||
|
|
45
thread.c
45
thread.c
|
@ -4975,6 +4975,29 @@ rb_check_deadlock(rb_vm_t *vm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_line_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
|
||||||
|
{
|
||||||
|
VALUE coverage = rb_iseq_coverage(GET_EC()->cfp->iseq);
|
||||||
|
if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
|
||||||
|
VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
|
||||||
|
if (lines) {
|
||||||
|
long line = rb_sourceline() - 1;
|
||||||
|
long count;
|
||||||
|
VALUE num;
|
||||||
|
if (line >= RARRAY_LEN(lines)) { /* no longer tracked */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
num = RARRAY_AREF(lines, line);
|
||||||
|
if (!FIXNUM_P(num)) return;
|
||||||
|
count = FIX2LONG(num) + 1;
|
||||||
|
if (POSFIXABLE(count)) {
|
||||||
|
RARRAY_ASET(lines, line, LONG2FIX(count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
|
update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
|
@ -4982,24 +5005,6 @@ update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
|
||||||
if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
|
if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
|
||||||
long arg = FIX2INT(trace_arg->data);
|
long arg = FIX2INT(trace_arg->data);
|
||||||
switch (arg % 16) {
|
switch (arg % 16) {
|
||||||
case COVERAGE_INDEX_LINES: {
|
|
||||||
VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
|
|
||||||
if (lines) {
|
|
||||||
long line = rb_sourceline() - 1;
|
|
||||||
long count;
|
|
||||||
VALUE num;
|
|
||||||
if (line >= RARRAY_LEN(lines)) { /* no longer tracked */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
num = RARRAY_AREF(lines, line);
|
|
||||||
if (!FIXNUM_P(num)) return;
|
|
||||||
count = FIX2LONG(num) + 1;
|
|
||||||
if (POSFIXABLE(count)) {
|
|
||||||
RARRAY_ASET(lines, line, LONG2FIX(count));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COVERAGE_INDEX_BRANCHES: {
|
case COVERAGE_INDEX_BRANCHES: {
|
||||||
VALUE branches = RARRAY_AREF(coverage, COVERAGE_INDEX_BRANCHES);
|
VALUE branches = RARRAY_AREF(coverage, COVERAGE_INDEX_BRANCHES);
|
||||||
if (branches) {
|
if (branches) {
|
||||||
|
@ -5106,6 +5111,7 @@ rb_set_coverages(VALUE coverages, int mode, VALUE me2counter)
|
||||||
{
|
{
|
||||||
GET_VM()->coverages = coverages;
|
GET_VM()->coverages = coverages;
|
||||||
GET_VM()->coverage_mode = mode;
|
GET_VM()->coverage_mode = mode;
|
||||||
|
rb_add_event_hook2((rb_event_hook_func_t) update_line_coverage, RUBY_EVENT_LINE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
|
||||||
rb_add_event_hook2((rb_event_hook_func_t) update_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
|
rb_add_event_hook2((rb_event_hook_func_t) update_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
|
||||||
if (mode & COVERAGE_TARGET_METHODS) {
|
if (mode & COVERAGE_TARGET_METHODS) {
|
||||||
rb_add_event_hook2((rb_event_hook_func_t) update_method_coverage, RUBY_EVENT_CALL, me2counter, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
|
rb_add_event_hook2((rb_event_hook_func_t) update_method_coverage, RUBY_EVENT_CALL, me2counter, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
|
||||||
|
@ -5130,6 +5136,9 @@ rb_reset_coverages(void)
|
||||||
VALUE coverages = rb_get_coverages();
|
VALUE coverages = rb_get_coverages();
|
||||||
st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0);
|
st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0);
|
||||||
GET_VM()->coverages = Qfalse;
|
GET_VM()->coverages = Qfalse;
|
||||||
|
if (GET_VM()->coverage_mode & COVERAGE_TARGET_LINES) {
|
||||||
|
rb_remove_event_hook((rb_event_hook_func_t) update_line_coverage);
|
||||||
|
}
|
||||||
rb_remove_event_hook((rb_event_hook_func_t) update_coverage);
|
rb_remove_event_hook((rb_event_hook_func_t) update_coverage);
|
||||||
if (GET_VM()->coverage_mode & COVERAGE_TARGET_METHODS) {
|
if (GET_VM()->coverage_mode & COVERAGE_TARGET_METHODS) {
|
||||||
rb_remove_event_hook((rb_event_hook_func_t) update_method_coverage);
|
rb_remove_event_hook((rb_event_hook_func_t) update_method_coverage);
|
||||||
|
|
Loading…
Reference in a new issue