Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ext/rubydex/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<Graph>>` that gets stored internally
// as a void pointer
Expand Down
26 changes: 21 additions & 5 deletions ext/rubydex/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,37 @@ 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);
}

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;
}
Expand Down
Loading