From 9ee387a9696398894f6f502efe9dbf6f6b7706e6 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Tue, 9 Jun 2026 15:51:26 -0400 Subject: [PATCH] Switch to designated initializer syntax --- ext/rubydex/graph.c | 13 ++++++++++++- ext/rubydex/handle.h | 26 +++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ext/rubydex/graph.c b/ext/rubydex/graph.c index 84b709d21..5434990bd 100644 --- a/ext/rubydex/graph.c +++ b/ext/rubydex/graph.c @@ -45,7 +45,18 @@ static void graph_free(void *ptr) { } } -const rb_data_type_t graph_type = {"Graph", {0, graph_free, 0}, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY}; +const rb_data_type_t graph_type = { + .wrap_struct_name = "Graph", + .function = { + .dmark = NULL, + .dfree = graph_free, + .dsize = NULL, + .dcompact = NULL, + }, + .parent = NULL, + .data = NULL, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; // Custom allocator for the Graph class. Calls into Rust to create a new `Arc>` that gets stored internally // as a void pointer diff --git a/ext/rubydex/handle.h b/ext/rubydex/handle.h index 541a19cc1..dba57acd5 100644 --- a/ext/rubydex/handle.h +++ b/ext/rubydex/handle.h @@ -22,12 +22,25 @@ static void handle_free(void *ptr) { } static const rb_data_type_t handle_type = { - "RubydexHandle", {handle_mark, handle_free, 0}, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY}; + .wrap_struct_name = "RubydexHandle", + .function = { + .dmark = handle_mark, + .dfree = handle_free, + .dsize = NULL, + .dcompact = NULL, + }, + .parent = NULL, + .data = NULL, + .flags = RUBY_TYPED_FREE_IMMEDIATELY, +}; static VALUE rdxr_handle_alloc(VALUE klass) { HandleData *data = ALLOC(HandleData); - data->graph_obj = Qnil; - data->id = 0; + + *data = (HandleData) { + .graph_obj = Qnil, + .id = 0, + }; return TypedData_Wrap_Struct(klass, &handle_type, data); } @@ -35,8 +48,11 @@ static VALUE rdxr_handle_alloc(VALUE klass) { static VALUE rdxr_handle_initialize(VALUE self, VALUE graph_obj, VALUE id_val) { HandleData *data; TypedData_Get_Struct(self, HandleData, &handle_type, data); - data->graph_obj = graph_obj; - data->id = NUM2ULL(id_val); + + *data = (HandleData) { + .graph_obj = graph_obj, + .id = NUM2ULL(id_val), + }; return self; }