summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-22 20:10:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-22 20:10:40 +0000
commitf856c1237b3a673a0b7dc9da45055abb52b51c17 (patch)
tree76b26ed1ee31e96cce77e9b05fff8da3bd651fff
parent3f3bec4911df7359198bc7cd2431168f422dfb01 (diff)
tracepoint.c: wrap data in a struct
* ext/-test-/tracepoint/tracepoint.c (struct tracepoint_track): wrap tracepoint tracking data in a struct to be placed on the stack. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/-test-/tracepoint/tracepoint.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/ext/-test-/tracepoint/tracepoint.c b/ext/-test-/tracepoint/tracepoint.c
index f72f57c..3334a25 100644
--- a/ext/-test-/tracepoint/tracepoint.c
+++ b/ext/-test-/tracepoint/tracepoint.c
@@ -1,38 +1,45 @@
#include "ruby/ruby.h"
#include "ruby/debug.h"
-static size_t newobj_count;
-static size_t free_count;
-static size_t gc_start_count;
-static size_t gc_end_count;
-static size_t objects_count;
-static VALUE objects[10];
+struct tracepoint_track {
+ size_t newobj_count;
+ size_t free_count;
+ size_t gc_start_count;
+ size_t gc_end_count;
+ size_t objects_count;
+ VALUE objects[10];
+};
-void
+#define objects_max (sizeof(((struct tracepoint_track *)NULL)->objects)/sizeof(VALUE))
+
+static void
tracepoint_track_objspace_events_i(VALUE tpval, void *data)
{
rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval);
+ struct tracepoint_track *track = data;
+
switch (rb_tracearg_event_flag(tparg)) {
case RUBY_INTERNAL_EVENT_NEWOBJ:
{
VALUE obj = rb_tracearg_object(tparg);
- if (objects_count < sizeof(objects)/sizeof(VALUE)) objects[objects_count++] = obj;
- newobj_count++;
+ if (track->objects_count < objects_max)
+ track->objects[track->objects_count++] = obj;
+ track->newobj_count++;
break;
}
case RUBY_INTERNAL_EVENT_FREEOBJ:
{
- free_count++;
+ track->free_count++;
break;
}
case RUBY_INTERNAL_EVENT_GC_START:
{
- gc_start_count++;
+ track->gc_start_count++;
break;
}
case RUBY_INTERNAL_EVENT_GC_END:
{
- gc_end_count++;
+ track->gc_end_count++;
break;
}
default:
@@ -40,28 +47,24 @@ tracepoint_track_objspace_events_i(VALUE tpval, void *data)
}
}
-VALUE
+static VALUE
tracepoint_track_objspace_events(VALUE self)
{
+ struct tracepoint_track track = {0, 0, 0, 0, 0, {}};
VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ |
RUBY_INTERNAL_EVENT_GC_START | RUBY_INTERNAL_EVENT_GC_END,
- tracepoint_track_objspace_events_i, 0);
+ tracepoint_track_objspace_events_i, &track);
VALUE result = rb_ary_new();
- size_t i;
-
- newobj_count = free_count = gc_start_count = objects_count = 0;
rb_tracepoint_enable(tpval);
rb_yield(Qundef);
rb_tracepoint_disable(tpval);
- rb_ary_push(result, SIZET2NUM(newobj_count));
- rb_ary_push(result, SIZET2NUM(free_count));
- rb_ary_push(result, SIZET2NUM(gc_start_count));
- rb_ary_push(result, SIZET2NUM(gc_end_count));
- for (i=0; i<objects_count; i++) {
- rb_ary_push(result, objects[i]);
- }
+ rb_ary_push(result, SIZET2NUM(track.newobj_count));
+ rb_ary_push(result, SIZET2NUM(track.free_count));
+ rb_ary_push(result, SIZET2NUM(track.gc_start_count));
+ rb_ary_push(result, SIZET2NUM(track.gc_end_count));
+ rb_ary_cat(result, track.objects, track.objects_count);
return result;
}
@@ -69,10 +72,6 @@ tracepoint_track_objspace_events(VALUE self)
void
Init_tracepoint(void)
{
- size_t i;
VALUE mBug = rb_define_module("Bug");
rb_define_module_function(mBug, "tracepoint_track_objspace_events", tracepoint_track_objspace_events, 0);
- for (i=0; i<sizeof(objects)/sizeof(VALUE); i++) {
- rb_global_variable(objects+i);
- }
}