From aaeef7163f38b720e18bf902a246b1439d000467 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 30 Nov 2023 12:58:00 +0100 Subject: [PATCH] Migrate to the TypedData API 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. --- ext/stackprof/stackprof.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/stackprof/stackprof.c b/ext/stackprof/stackprof.c index e7864b8..4cd865c 100644 --- a/ext/stackprof/stackprof.c +++ b/ext/stackprof/stackprof.c @@ -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) { @@ -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) { @@ -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;