relevance-rcov 0.8.3.2 → 0.8.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,27 +2,22 @@
2
2
  #include <ruby/st.h>
3
3
  #include <stdlib.h>
4
4
 
5
+ #define DEBUG 0
6
+
5
7
  static char callsite_hook_set_p;
6
8
 
7
9
  typedef struct {
8
- const char *sourcefile;
9
- unsigned int sourceline;
10
- VALUE curr_meth;
10
+ const char *sourcefile;
11
+ unsigned int sourceline;
12
+ VALUE curr_meth;
11
13
  } type_def_site;
14
+
12
15
  static VALUE caller_info = 0;
13
16
  static VALUE method_def_site_info = 0;
14
17
 
15
18
  static int caller_stack_len = 1;
16
19
 
17
- /*
18
- *
19
- * callsite hook and associated functions
20
- *
21
- * */
22
-
23
- static VALUE
24
- record_callsite_info(VALUE args)
25
- {
20
+ static VALUE record_callsite_info(VALUE args) {
26
21
  VALUE caller_ary;
27
22
  VALUE curr_meth;
28
23
  VALUE count_hash;
@@ -32,58 +27,57 @@ record_callsite_info(VALUE args)
32
27
  caller_ary = pargs[0];
33
28
  curr_meth = pargs[1];
34
29
  count_hash = rb_hash_aref(caller_info, curr_meth);
30
+
35
31
  if(TYPE(count_hash) != T_HASH) {
36
- /* Qnil, anything else should be impossible unless somebody's been
37
- * messing with ObjectSpace */
38
- count_hash = rb_hash_new();
39
- rb_hash_aset(caller_info, curr_meth, count_hash);
32
+ /* Qnil, anything else should be impossible unless somebody's been
33
+ * messing with ObjectSpace */
34
+ count_hash = rb_hash_new();
35
+ rb_hash_aset(caller_info, curr_meth, count_hash);
40
36
  }
37
+
41
38
  count = rb_hash_aref(count_hash, caller_ary);
39
+
42
40
  if(count == Qnil)
43
- count = INT2FIX(0);
41
+ count = INT2FIX(0);
42
+
44
43
  count = INT2FIX(FIX2UINT(count) + 1);
45
44
  rb_hash_aset(count_hash, caller_ary, count);
46
- /* * /
47
- printf("CALLSITE: %s -> %s %d\n", RSTRING_PTR(rb_inspect(curr_meth)),
48
- RSTRING_PTR(rb_inspect(caller_ary)), FIX2INT(count));
49
- / * */
45
+
46
+ if(DEBUG == 1)
47
+ printf("CALLSITE: %s -> %s %d\n", RSTRING_PTR(rb_inspect(curr_meth)), RSTRING_PTR(rb_inspect(caller_ary)), FIX2INT(count));
50
48
 
51
49
  return Qnil;
52
50
  }
53
51
 
54
-
55
- static VALUE
56
- record_method_def_site(VALUE args)
57
- {
52
+ static VALUE record_method_def_site(VALUE args) {
58
53
  type_def_site *pargs = (type_def_site *)args;
59
54
  VALUE def_site_info;
60
- // VALUE hash;
61
55
 
62
56
  if( RTEST(rb_hash_aref(method_def_site_info, pargs->curr_meth)) )
63
- return Qnil;
57
+ return Qnil;
58
+
64
59
  def_site_info = rb_ary_new();
65
60
  rb_ary_push(def_site_info, rb_str_new2(pargs->sourcefile));
66
61
  rb_ary_push(def_site_info, INT2NUM(pargs->sourceline+1));
67
62
  rb_hash_aset(method_def_site_info, pargs->curr_meth, def_site_info);
68
- /* * /
69
- printf("DEFSITE: %s:%d for %s\n", pargs->sourcefile, pargs->sourceline+1,
70
- RSTRING_PTR(rb_inspect(pargs->curr_meth)));
71
- / * */
63
+
64
+ if(DEBUG == 1)
65
+ printf("DEFSITE: %s:%d for %s\n", pargs->sourcefile, pargs->sourceline+1, RSTRING_PTR(rb_inspect(pargs->curr_meth)));
72
66
 
73
67
  return Qnil;
74
68
  }
75
69
 
76
- static VALUE
77
- callsite_custom_backtrace(int lev)
78
- {
70
+ static VALUE callsite_custom_backtrace(int lev) {
79
71
  ID id;
80
72
  VALUE klass;
81
73
  VALUE klass_path;
82
74
  VALUE eval_string;
83
75
 
84
76
  rb_frame_method_id_and_class(&id, &klass);
77
+
85
78
  if (id == ID_ALLOCATOR)
86
79
  return Qnil;
80
+
87
81
  if (klass) {
88
82
  if (TYPE(klass) == T_ICLASS) {
89
83
  klass = RBASIC(klass)->klass;
@@ -100,6 +94,7 @@ callsite_custom_backtrace(int lev)
100
94
 
101
95
  klass_path = rb_class_path(klass);
102
96
  VALUE reciever = rb_funcall(rb_binding_new(), rb_intern("eval"), 1, rb_str_new2("self"));
97
+
103
98
  if (rb_funcall(klass, rb_intern("=="), 1, reciever) == Qtrue) {
104
99
  klass_path = rb_sprintf("\"#<Class:%s>\"", RSTRING_PTR(klass_path));
105
100
  OBJ_FREEZE(klass_path);
@@ -109,10 +104,7 @@ callsite_custom_backtrace(int lev)
109
104
  return rb_eval_string(RSTRING_PTR(eval_string));
110
105
  }
111
106
 
112
- static void
113
- coverage_event_callsite_hook(rb_event_flag_t event, VALUE node,
114
- VALUE self, ID mid, VALUE klass)
115
- {
107
+ static void coverage_event_callsite_hook(rb_event_flag_t event, VALUE node, VALUE self, ID mid, VALUE klass) {
116
108
  VALUE caller_ary;
117
109
  VALUE curr_meth;
118
110
  VALUE args[2];
@@ -142,9 +134,10 @@ coverage_event_callsite_hook(rb_event_flag_t event, VALUE node,
142
134
 
143
135
  klass_path = rb_class_path(klass);
144
136
  VALUE reciever = rb_funcall(rb_binding_new(), rb_intern("eval"), 1, rb_str_new2("self"));
137
+
145
138
  if (rb_funcall(klass, rb_intern("=="), 1, reciever) == Qtrue) {
146
139
  klass_path = rb_sprintf("#<Class:%s>", RSTRING_PTR(klass_path));
147
- OBJ_FREEZE(klass_path);
140
+ OBJ_FREEZE(klass_path);
148
141
  }
149
142
 
150
143
  rb_ary_push(curr_meth, klass_path);
@@ -162,43 +155,36 @@ coverage_event_callsite_hook(rb_event_flag_t event, VALUE node,
162
155
  args.curr_meth = curr_meth;
163
156
  rb_protect(record_method_def_site, (VALUE)&args, NULL);
164
157
  }
158
+
165
159
  if(status)
166
160
  rb_gv_set("$!", Qnil);
167
161
  }
168
162
 
169
-
170
- static VALUE
171
- cov_install_callsite_hook(VALUE self)
172
- {
163
+ static VALUE cov_install_callsite_hook(VALUE self) {
173
164
  if(!callsite_hook_set_p) {
174
- if(TYPE(caller_info) != T_HASH)
175
- caller_info = rb_hash_new();
176
- callsite_hook_set_p = 1;
177
- VALUE something = 0;
178
- rb_add_event_hook(coverage_event_callsite_hook,
179
- RUBY_EVENT_CALL, something);
180
- return Qtrue;
181
- } else
182
- return Qfalse;
165
+ if(TYPE(caller_info) != T_HASH)
166
+ caller_info = rb_hash_new();
167
+ callsite_hook_set_p = 1;
168
+ VALUE something = 0;
169
+ rb_add_event_hook(coverage_event_callsite_hook,
170
+ RUBY_EVENT_CALL, something);
171
+ return Qtrue;
172
+ }
173
+ else
174
+ return Qfalse;
183
175
  }
184
176
 
185
-
186
- static VALUE
187
- cov_remove_callsite_hook(VALUE self)
188
- {
189
- if(!callsite_hook_set_p)
190
- return Qfalse;
191
- else {
192
- rb_remove_event_hook(coverage_event_callsite_hook);
193
- callsite_hook_set_p = 0;
194
- return Qtrue;
195
- }
177
+ static VALUE cov_remove_callsite_hook(VALUE self) {
178
+ if(!callsite_hook_set_p)
179
+ return Qfalse;
180
+ else {
181
+ rb_remove_event_hook(coverage_event_callsite_hook);
182
+ callsite_hook_set_p = 0;
183
+ return Qtrue;
184
+ }
196
185
  }
197
186
 
198
-
199
- static VALUE
200
- cov_generate_callsite_info(VALUE self)
201
- {
187
+ static VALUE cov_generate_callsite_info(VALUE self) {
202
188
  VALUE ret;
203
189
 
204
190
  ret = rb_ary_new();
@@ -207,52 +193,42 @@ cov_generate_callsite_info(VALUE self)
207
193
  return ret;
208
194
  }
209
195
 
210
-
211
- static VALUE
212
- cov_reset_callsite(VALUE self)
213
- {
196
+ static VALUE cov_reset_callsite(VALUE self) {
214
197
  if(callsite_hook_set_p) {
215
- rb_raise(rb_eRuntimeError,
216
- "Cannot reset the callsite info in the middle of a traced run.");
217
- return Qnil;
198
+ rb_raise(rb_eRuntimeError, "Cannot reset the callsite info in the middle of a traced run.");
199
+ return Qnil;
218
200
  }
219
-
201
+
220
202
  caller_info = rb_hash_new();
221
203
  method_def_site_info = rb_hash_new();
222
204
  return Qnil;
223
205
  }
224
206
 
225
- void
226
- Init_rcov_callsite()
227
- {
228
- VALUE mRcov;
229
- VALUE mRCOV__;
230
- ID id_rcov = rb_intern("Rcov");
231
- ID id_coverage__ = rb_intern("RCOV__");
232
- // ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
233
-
234
- if(rb_const_defined(rb_cObject, id_rcov))
235
- mRcov = rb_const_get(rb_cObject, id_rcov);
236
- else
237
- mRcov = rb_define_module("Rcov");
238
-
239
- if(rb_const_defined(mRcov, id_coverage__))
240
- mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
241
- else
242
- mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
207
+ void Init_rcov_callsite() {
208
+ VALUE mRcov;
209
+ VALUE mRCOV__;
210
+ ID id_rcov = rb_intern("Rcov");
211
+ ID id_coverage__ = rb_intern("RCOV__");
212
+ // ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
213
+
214
+ if(rb_const_defined(rb_cObject, id_rcov))
215
+ mRcov = rb_const_get(rb_cObject, id_rcov);
216
+ else
217
+ mRcov = rb_define_module("Rcov");
218
+
219
+ if(rb_const_defined(mRcov, id_coverage__))
220
+ mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
221
+ else
222
+ mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
243
223
 
244
- callsite_hook_set_p = 0;
245
- caller_info = rb_hash_new();
246
- method_def_site_info = rb_hash_new();
247
- rb_gc_register_address(&caller_info);
248
- rb_gc_register_address(&method_def_site_info);
249
-
250
- rb_define_singleton_method(mRCOV__, "install_callsite_hook",
251
- cov_install_callsite_hook, 0);
252
- rb_define_singleton_method(mRCOV__, "remove_callsite_hook",
253
- cov_remove_callsite_hook, 0);
254
- rb_define_singleton_method(mRCOV__, "generate_callsite_info",
255
- cov_generate_callsite_info, 0);
256
- rb_define_singleton_method(mRCOV__, "reset_callsite", cov_reset_callsite, 0);
224
+ callsite_hook_set_p = 0;
225
+ caller_info = rb_hash_new();
226
+ method_def_site_info = rb_hash_new();
227
+ rb_gc_register_address(&caller_info);
228
+ rb_gc_register_address(&method_def_site_info);
229
+
230
+ rb_define_singleton_method(mRCOV__, "install_callsite_hook", cov_install_callsite_hook, 0);
231
+ rb_define_singleton_method(mRCOV__, "remove_callsite_hook", cov_remove_callsite_hook, 0);
232
+ rb_define_singleton_method(mRCOV__, "generate_callsite_info", cov_generate_callsite_info, 0);
233
+ rb_define_singleton_method(mRCOV__, "reset_callsite", cov_reset_callsite, 0);
257
234
  }
258
- /* vim: set sw=8 expandtab: */
@@ -17,236 +17,195 @@ static st_table* coverinfo = 0;
17
17
  static char coverage_hook_set_p;
18
18
 
19
19
  struct cov_array {
20
- unsigned int len;
21
- unsigned int *ptr;
20
+ unsigned int len;
21
+ unsigned int *ptr;
22
22
  };
23
23
 
24
24
  static struct cov_array *cached_array = 0;
25
25
  static char *cached_file = 0;
26
26
 
27
- /*
28
- *
29
- * coverage hook and associated functions
30
- *
31
- * */
32
- static struct cov_array *
33
- coverage_increase_counter_uncached(char *sourcefile, unsigned int sourceline,
34
- char mark_only)
35
- {
27
+ static struct cov_array * coverage_increase_counter_uncached(char *sourcefile, unsigned int sourceline, char mark_only) {
36
28
  struct cov_array *carray = NULL;
37
29
 
38
30
  if(sourcefile == NULL) {
39
- /* "can't happen", just ignore and avoid segfault */
40
- return NULL;
41
- } else if(!st_lookup(coverinfo, (st_data_t)sourcefile, (st_data_t*)&carray)) {
42
- VALUE arr;
43
-
44
- arr = rb_hash_aref(oSCRIPT_LINES__, rb_str_new2(sourcefile));
45
- if(NIL_P(arr))
46
- return 0;
47
- rb_check_type(arr, T_ARRAY);
48
- carray = calloc(1, sizeof(struct cov_array));
49
- carray->ptr = calloc(RARRAY_LEN(arr), sizeof(unsigned int));
50
- carray->len = RARRAY_LEN(arr);
51
- st_insert(coverinfo, (st_data_t)strdup(sourcefile),
52
- (st_data_t) carray);
53
- } else {
54
- /* recovered carray, sanity check */
55
- assert(carray && "failed to create valid carray");
31
+ /* "can't happen", just ignore and avoid segfault */
32
+ return NULL;
33
+ }
34
+ else if(!st_lookup(coverinfo, (st_data_t)sourcefile, (st_data_t*)&carray)) {
35
+ VALUE arr;
36
+
37
+ arr = rb_hash_aref(oSCRIPT_LINES__, rb_str_new2(sourcefile));
38
+ if(NIL_P(arr))
39
+ return 0;
40
+ rb_check_type(arr, T_ARRAY);
41
+ carray = calloc(1, sizeof(struct cov_array));
42
+ carray->ptr = calloc(RARRAY_LEN(arr), sizeof(unsigned int));
43
+ carray->len = RARRAY_LEN(arr);
44
+ st_insert(coverinfo, (st_data_t)strdup(sourcefile), (st_data_t) carray);
45
+ }
46
+ else {
47
+ /* recovered carray, sanity check */
48
+ assert(carray && "failed to create valid carray");
56
49
  }
57
50
 
58
51
  if(mark_only) {
59
- if(!carray->ptr[sourceline])
60
- carray->ptr[sourceline] = 1;
61
- } else {
62
- if (carray && carray->len > sourceline) {
63
- carray->ptr[sourceline]++;
64
- }
52
+ if(!carray->ptr[sourceline])
53
+ carray->ptr[sourceline] = 1;
54
+ }
55
+ else {
56
+ if (carray && carray->len > sourceline) {
57
+ carray->ptr[sourceline]++;
58
+ }
65
59
  }
66
60
 
67
61
  return carray;
68
62
  }
69
63
 
70
-
71
- static void
72
- coverage_mark_caller()
73
- {
74
- // if @coverage_hook_activated
75
- // COVER[file] ||= Array.new(SCRIPT_LINES__[file].size, 0)
76
- // COVER[file][line - 1] ||= 0
77
- // COVER[file][line - 1] += 1
78
- // end
79
-
64
+ static void coverage_mark_caller() {
80
65
  coverage_increase_counter_uncached(rb_sourcefile(), rb_sourceline(), 1);
81
66
  }
82
67
 
83
-
84
- static void
85
- coverage_increase_counter_cached(char *sourcefile, int sourceline)
86
- {
87
- if(cached_file == sourcefile && cached_array && cached_array->len > sourceline) {
88
- cached_array->ptr[sourceline]++;
89
- return;
90
- }
91
- cached_file = sourcefile;
92
- cached_array = coverage_increase_counter_uncached(sourcefile, sourceline, 0);
68
+ static void coverage_increase_counter_cached(char *sourcefile, int sourceline) {
69
+ if(cached_file == sourcefile && cached_array && cached_array->len > sourceline) {
70
+ cached_array->ptr[sourceline]++;
71
+ return;
72
+ }
73
+ cached_file = sourcefile;
74
+ cached_array = coverage_increase_counter_uncached(sourcefile, sourceline, 0);
93
75
  }
94
76
 
95
- static void
96
- coverage_event_coverage_hook(rb_event_flag_t event, VALUE node,
97
- VALUE self, ID mid, VALUE klass)
98
- {
99
- char *sourcefile;
100
- unsigned int sourceline;
101
- static unsigned int in_hook = 0;
102
-
103
- if(in_hook) {
104
- return;
105
- }
106
-
107
- in_hook++;
108
-
109
- #if COVERAGE_DEBUG_EVENTS
110
- do {
111
- int status;
112
- VALUE old_exception;
113
- old_exception = rb_gv_get("$!");
114
- rb_protect(rb_inspect, klass, &status);
115
- if(!status) {
116
- printf("EVENT: %d %s %s %s %d\n", event,
117
- klass ? RSTRING(rb_inspect(klass))->ptr : "",
118
- mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
119
- : "unknown",
120
- node ? node->nd_file : "", node ? nd_line(node) : 0);
121
- } else {
122
- printf("EVENT: %d %s %s %d\n", event,
123
- mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
124
- : "unknown",
125
- node ? node->nd_file : "", node ? nd_line(node) : 0);
126
- }
127
- rb_gv_set("$!", old_exception);
128
- } while (0);
129
- #endif
130
-
131
- if(event & RUBY_EVENT_C_CALL) {
132
- coverage_mark_caller();
133
- }
134
- if(event & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN | RUBY_EVENT_CLASS)) {
135
- in_hook--;
136
- return;
137
- }
138
-
139
- // printf("NODE? %s , %s\n", rb_id2name(rb_frame_this_func()), RSTRING_PTR(rb_inspect(node)));
140
-
141
- sourcefile = rb_sourcefile();
142
- sourceline = rb_sourceline();
77
+ static void coverage_event_coverage_hook(rb_event_flag_t event, VALUE node, VALUE self, ID mid, VALUE klass) {
78
+ char *sourcefile;
79
+ unsigned int sourceline;
80
+ static unsigned int in_hook = 0;
143
81
 
144
- if (0 == sourceline || 0 == sourcefile) {
145
- in_hook--;
146
- return;
147
- }
82
+ if(in_hook) {
83
+ return;
84
+ }
148
85
 
149
- coverage_increase_counter_cached(sourcefile, sourceline);
150
- if(event & RUBY_EVENT_CALL)
151
- coverage_mark_caller();
152
- in_hook--;
86
+ in_hook++;
87
+
88
+ #if COVERAGE_DEBUG_EVENTS
89
+ do {
90
+ int status;
91
+ VALUE old_exception;
92
+ old_exception = rb_gv_get("$!");
93
+ rb_protect(rb_inspect, klass, &status);
94
+ if(!status) {
95
+ printf("EVENT: %d %s %s %s %d\n", event,
96
+ klass ? RSTRING(rb_inspect(klass))->ptr : "",
97
+ mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
98
+ : "unknown",
99
+ node ? node->nd_file : "", node ? nd_line(node) : 0);
100
+ }
101
+ else {
102
+ printf("EVENT: %d %s %s %d\n", event,
103
+ mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid))
104
+ : "unknown",
105
+ node ? node->nd_file : "", node ? nd_line(node) : 0);
106
+ }
107
+ rb_gv_set("$!", old_exception);
108
+ } while (0);
109
+ #endif
110
+
111
+ if(event & RUBY_EVENT_C_CALL) {
112
+ coverage_mark_caller();
113
+ }
114
+ if(event & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN | RUBY_EVENT_CLASS)) {
115
+ in_hook--;
116
+ return;
117
+ }
118
+
119
+ sourcefile = rb_sourcefile();
120
+ sourceline = rb_sourceline();
121
+
122
+ if (0 == sourceline || 0 == sourcefile) {
123
+ in_hook--;
124
+ return;
125
+ }
126
+
127
+ coverage_increase_counter_cached(sourcefile, sourceline);
128
+ if(event & RUBY_EVENT_CALL)
129
+ coverage_mark_caller();
130
+ in_hook--;
153
131
  }
154
132
 
155
-
156
- static VALUE
157
- cov_install_coverage_hook(VALUE self)
158
- {
133
+ static VALUE cov_install_coverage_hook(VALUE self) {
159
134
  if(!coverage_hook_set_p) {
160
- if(!coverinfo)
161
- coverinfo = st_init_strtable();
162
- coverage_hook_set_p = 1;
163
- /* TODO: allow C_CALL too, since it's supported already
164
- * the overhead is around ~30%, tested on typo */
165
- VALUE holder = 0;
166
- rb_add_event_hook(coverage_event_coverage_hook,
167
- RUBY_EVENT_ALL & ~RUBY_EVENT_C_CALL &
168
- ~RUBY_EVENT_C_RETURN & ~RUBY_EVENT_CLASS, holder);
169
- return Qtrue;
135
+ if(!coverinfo)
136
+ coverinfo = st_init_strtable();
137
+ coverage_hook_set_p = 1;
138
+ /* TODO: allow C_CALL too, since it's supported already
139
+ * the overhead is around ~30%, tested on typo */
140
+ VALUE holder = 0;
141
+ rb_add_event_hook(coverage_event_coverage_hook,
142
+ RUBY_EVENT_ALL & ~RUBY_EVENT_C_CALL &
143
+ ~RUBY_EVENT_C_RETURN & ~RUBY_EVENT_CLASS, holder);
144
+ return Qtrue;
170
145
  }
171
146
  else
172
- return Qfalse;
147
+ return Qfalse;
173
148
  }
174
149
 
175
-
176
- static int
177
- populate_cover(st_data_t key, st_data_t value, st_data_t cover)
178
- {
179
- VALUE rcover;
180
- VALUE rkey;
181
- VALUE rval;
182
- struct cov_array *carray;
183
- unsigned int i;
184
-
185
- rcover = (VALUE)cover;
186
- carray = (struct cov_array *) value;
187
- rkey = rb_str_new2((char*) key);
188
- rval = rb_ary_new2(carray->len);
189
- for(i = 0; i < carray->len; i++)
190
- rb_ary_push(rval, UINT2NUM(carray->ptr[i]));
191
-
192
- rb_hash_aset(rcover, rkey, rval);
193
-
194
- return ST_CONTINUE;
150
+ static int populate_cover(st_data_t key, st_data_t value, st_data_t cover) {
151
+ VALUE rcover;
152
+ VALUE rkey;
153
+ VALUE rval;
154
+ struct cov_array *carray;
155
+ unsigned int i;
156
+
157
+ rcover = (VALUE)cover;
158
+ carray = (struct cov_array *) value;
159
+ rkey = rb_str_new2((char*) key);
160
+ rval = rb_ary_new2(carray->len);
161
+ for(i = 0; i < carray->len; i++)
162
+ rb_ary_push(rval, UINT2NUM(carray->ptr[i]));
163
+
164
+ rb_hash_aset(rcover, rkey, rval);
165
+
166
+ return ST_CONTINUE;
195
167
  }
196
168
 
197
-
198
- static int
199
- free_table(st_data_t key, st_data_t value, st_data_t ignored)
200
- {
201
- struct cov_array *carray;
202
-
203
- carray = (struct cov_array *) value;
204
- free((char *)key);
205
- free(carray->ptr);
206
- free(carray);
207
-
208
- return ST_CONTINUE;
169
+ static int free_table(st_data_t key, st_data_t value, st_data_t ignored) {
170
+ struct cov_array *carray;
171
+
172
+ carray = (struct cov_array *) value;
173
+ free((char *)key);
174
+ free(carray->ptr);
175
+ free(carray);
176
+
177
+ return ST_CONTINUE;
209
178
  }
210
179
 
211
-
212
- static VALUE
213
- cov_remove_coverage_hook(VALUE self)
214
- {
215
- if(!coverage_hook_set_p)
216
- return Qfalse;
217
- else {
218
- rb_remove_event_hook(coverage_event_coverage_hook);
219
- coverage_hook_set_p = 0;
220
- return Qtrue;
221
- }
180
+ static VALUE cov_remove_coverage_hook(VALUE self) {
181
+ if(!coverage_hook_set_p)
182
+ return Qfalse;
183
+ else {
184
+ rb_remove_event_hook(coverage_event_coverage_hook);
185
+ coverage_hook_set_p = 0;
186
+ return Qtrue;
187
+ }
222
188
  }
223
189
 
224
-
225
- static VALUE
226
- cov_generate_coverage_info(VALUE self)
227
- {
190
+ static VALUE cov_generate_coverage_info(VALUE self) {
228
191
  VALUE cover;
229
192
 
230
193
  if(rb_const_defined_at(mRCOV__, id_cover)) {
231
- rb_mod_remove_const(mRCOV__, ID2SYM(id_cover));
194
+ rb_mod_remove_const(mRCOV__, ID2SYM(id_cover));
232
195
  }
233
196
 
234
197
  cover = rb_hash_new();
235
198
  if(coverinfo)
236
- st_foreach(coverinfo, populate_cover, cover);
199
+ st_foreach(coverinfo, populate_cover, cover);
237
200
  rb_define_const(mRCOV__, "COVER", cover);
238
201
 
239
202
  return cover;
240
203
  }
241
204
 
242
-
243
- static VALUE
244
- cov_reset_coverage(VALUE self)
245
- {
205
+ static VALUE cov_reset_coverage(VALUE self) {
246
206
  if(coverage_hook_set_p) {
247
- rb_raise(rb_eRuntimeError,
248
- "Cannot reset the coverage info in the middle of a traced run.");
249
- return Qnil;
207
+ rb_raise(rb_eRuntimeError, "Cannot reset the coverage info in the middle of a traced run.");
208
+ return Qnil;
250
209
  }
251
210
 
252
211
  cached_array = 0;
@@ -258,10 +217,7 @@ cov_reset_coverage(VALUE self)
258
217
  return Qnil;
259
218
  }
260
219
 
261
-
262
- static VALUE
263
- cov_ABI(VALUE self)
264
- {
220
+ static VALUE cov_ABI(VALUE self) {
265
221
  VALUE ret;
266
222
 
267
223
  ret = rb_ary_new();
@@ -272,44 +228,37 @@ cov_ABI(VALUE self)
272
228
  return ret;
273
229
  }
274
230
 
275
-
276
- void
277
- Init_rcovrt()
278
- {
279
- ID id_rcov = rb_intern("Rcov");
280
- ID id_coverage__ = rb_intern("RCOV__");
281
- ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
282
-
283
- id_cover = rb_intern("COVER");
284
-
285
- if(rb_const_defined(rb_cObject, id_rcov))
286
- mRcov = rb_const_get(rb_cObject, id_rcov);
287
- else
288
- mRcov = rb_define_module("Rcov");
289
-
290
- if(rb_const_defined(mRcov, id_coverage__))
291
- mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
292
- else
293
- mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
294
-
295
- if(rb_const_defined(rb_cObject, id_script_lines__))
296
- oSCRIPT_LINES__ = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
297
- else {
298
- oSCRIPT_LINES__ = rb_hash_new();
299
- rb_const_set(rb_cObject, id_script_lines__, oSCRIPT_LINES__);
300
- }
301
-
302
- coverage_hook_set_p = 0;
303
-
304
- rb_define_singleton_method(mRCOV__, "install_coverage_hook",
305
- cov_install_coverage_hook, 0);
306
- rb_define_singleton_method(mRCOV__, "remove_coverage_hook",
307
- cov_remove_coverage_hook, 0);
308
- rb_define_singleton_method(mRCOV__, "generate_coverage_info",
309
- cov_generate_coverage_info, 0);
310
- rb_define_singleton_method(mRCOV__, "reset_coverage", cov_reset_coverage, 0);
311
- rb_define_singleton_method(mRCOV__, "ABI", cov_ABI, 0);
312
-
313
- Init_rcov_callsite();
231
+ void Init_rcovrt() {
232
+ ID id_rcov = rb_intern("Rcov");
233
+ ID id_coverage__ = rb_intern("RCOV__");
234
+ ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
235
+
236
+ id_cover = rb_intern("COVER");
237
+
238
+ if(rb_const_defined(rb_cObject, id_rcov))
239
+ mRcov = rb_const_get(rb_cObject, id_rcov);
240
+ else
241
+ mRcov = rb_define_module("Rcov");
242
+
243
+ if(rb_const_defined(mRcov, id_coverage__))
244
+ mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
245
+ else
246
+ mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
247
+
248
+ if(rb_const_defined(rb_cObject, id_script_lines__))
249
+ oSCRIPT_LINES__ = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
250
+ else {
251
+ oSCRIPT_LINES__ = rb_hash_new();
252
+ rb_const_set(rb_cObject, id_script_lines__, oSCRIPT_LINES__);
253
+ }
254
+
255
+ coverage_hook_set_p = 0;
256
+
257
+ rb_define_singleton_method(mRCOV__, "install_coverage_hook", cov_install_coverage_hook, 0);
258
+ rb_define_singleton_method(mRCOV__, "remove_coverage_hook", cov_remove_coverage_hook, 0);
259
+ rb_define_singleton_method(mRCOV__, "generate_coverage_info", cov_generate_coverage_info, 0);
260
+ rb_define_singleton_method(mRCOV__, "reset_coverage", cov_reset_coverage, 0);
261
+ rb_define_singleton_method(mRCOV__, "ABI", cov_ABI, 0);
262
+
263
+ Init_rcov_callsite();
314
264
  }
315
- /* vim: set sw=8 expandtab: */