Skip to content

Commit

Permalink
Merge pull request #222 from casperisfine/typed-data
Browse files Browse the repository at this point in the history
Migrate to the TypedData API
  • Loading branch information
tenderlove authored Nov 30, 2023
2 parents 91d12e7 + aaeef71 commit bd885f9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ext/stackprof/stackprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,12 @@ stackprof_gc_mark(void *data)
}
}

static size_t
stackprof_memsize(const void *data)
{
return sizeof(_stackprof);
}

static void
stackprof_atfork_prepare(void)
{
Expand Down Expand Up @@ -889,6 +895,15 @@ stackprof_at_exit(ruby_vm_t* vm)
ruby_vm_running = 0;
}

static const rb_data_type_t stackprof_type = {
"StackProf",
{
stackprof_gc_mark,
NULL,
stackprof_memsize,
}
};

void
Init_stackprof(void)
{
Expand Down Expand Up @@ -936,8 +951,8 @@ Init_stackprof(void)
/* Need to run this to warm the symbol table before we call this during GC */
rb_gc_latest_gc_info(sym_state);

gc_hook = Data_Wrap_Struct(rb_cObject, stackprof_gc_mark, NULL, &_stackprof);
rb_global_variable(&gc_hook);
gc_hook = TypedData_Wrap_Struct(rb_cObject, &stackprof_type, &_stackprof);

_stackprof.raw_samples = NULL;
_stackprof.raw_samples_len = 0;
Expand Down

0 comments on commit bd885f9

Please sign in to comment.