ext/ruby_prof/rp_measurement.c in ruby-prof-1.1.0 vs ext/ruby_prof/rp_measurement.c in ruby-prof-1.2.0

- old
+ new

@@ -38,78 +38,73 @@ double measurement = measurer->measure(trace_arg); return measurement * measurer->multiplier; } /* ======= prof_measurement_t ========*/ -prof_measurement_t *prof_measurement_create(void) +prof_measurement_t* prof_measurement_create(void) { prof_measurement_t* result = ALLOC(prof_measurement_t); result->total_time = 0; result->self_time = 0; result->wait_time = 0; result->called = 0; result->object = Qnil; return result; } -static void -prof_measurement_ruby_gc_free(void *data) +void prof_measurement_mark(void* data) { + prof_measurement_t* measurement_data = (prof_measurement_t*)data; + + if (measurement_data->object != Qnil) + rb_gc_mark(measurement_data->object); +} + +static void prof_measurement_ruby_gc_free(void* data) +{ + // Measurements are freed by their owning object (call info or method) prof_measurement_t* measurement = (prof_measurement_t*)data; + measurement->object = Qnil; +} +void prof_measurement_free(prof_measurement_t* measurement) +{ /* Has this measurement object been accessed by Ruby? If yes clean it up so to avoid a segmentation fault. */ if (measurement->object != Qnil) { RDATA(measurement->object)->dmark = NULL; RDATA(measurement->object)->dfree = NULL; RDATA(measurement->object)->data = NULL; measurement->object = Qnil; } -} -void -prof_measurement_free(prof_measurement_t* measurement) -{ - prof_measurement_ruby_gc_free(measurement); xfree(measurement); } -size_t -prof_measurement_size(const void *data) +size_t prof_measurement_size(const void* data) { return sizeof(prof_measurement_t); } -void -prof_measurement_mark(void *data) +VALUE prof_measurement_wrap(prof_measurement_t* measurement) { - prof_measurement_t* measurement = (prof_measurement_t*)data; - if (measurement->object != Qnil) - rb_gc_mark(measurement->object); -} - -VALUE -prof_measurement_wrap(prof_measurement_t* measurement) -{ if (measurement->object == Qnil) { - measurement->object = Data_Wrap_Struct(cRpMeasurement, prof_measurement_mark, prof_measurement_ruby_gc_free, measurement); + measurement->object = Data_Wrap_Struct(cRpMeasurement, NULL, prof_measurement_ruby_gc_free, measurement); } return measurement->object; } -static VALUE -prof_measurement_allocate(VALUE klass) +static VALUE prof_measurement_allocate(VALUE klass) { - prof_measurement_t *measurement = prof_measurement_create(); + prof_measurement_t* measurement = prof_measurement_create(); measurement->object = prof_measurement_wrap(measurement); return measurement->object; } -prof_measurement_t* -prof_get_measurement(VALUE self) +prof_measurement_t* prof_get_measurement(VALUE self) { /* Can't use Data_Get_Struct because that triggers the event hook ending up in endless recursion. */ prof_measurement_t* result = DATA_PTR(self); @@ -121,12 +116,11 @@ /* call-seq: total_time -> float Returns the total amount of time spent in this method and its children. */ -static VALUE -prof_measurement_total_time(VALUE self) +static VALUE prof_measurement_total_time(VALUE self) { prof_measurement_t* result = prof_get_measurement(self); return rb_float_new(result->total_time); } @@ -144,36 +138,33 @@ /* call-seq: wait_time -> float Returns the total amount of time this method waited for other threads. */ -static VALUE -prof_measurement_wait_time(VALUE self) +static VALUE prof_measurement_wait_time(VALUE self) { prof_measurement_t* result = prof_get_measurement(self); return rb_float_new(result->wait_time); } /* call-seq: called -> int Returns the total amount of times this method was called. */ -static VALUE -prof_measurement_called(VALUE self) +static VALUE prof_measurement_called(VALUE self) { - prof_measurement_t *result = prof_get_measurement(self); + prof_measurement_t* result = prof_get_measurement(self); return INT2NUM(result->called); } /* call-seq: called=n -> n Sets the call count to n. */ -static VALUE -prof_measurement_set_called(VALUE self, VALUE called) +static VALUE prof_measurement_set_called(VALUE self, VALUE called) { - prof_measurement_t *result = prof_get_measurement(self); + prof_measurement_t* result = prof_get_measurement(self); result->called = NUM2INT(called); return called; } /* :nodoc: */