Skip to content

Commit

Permalink
Migrate to the TypedData API
Browse files Browse the repository at this point in the history
It's a single object so not really worth implementing write barriers
or any other advanced features.

The only goal here is to stop using a deprecated API.
  • Loading branch information
byroot committed Nov 30, 2023
1 parent 91d12e7 commit aaeef71
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 aaeef71

Please sign in to comment.