From ec58dca22f0eaf183ccdafd76d4abf9341d13815 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 27 Oct 2025 11:46:22 +0900 Subject: [PATCH] mruby-array-ext: use Data_Make_Struct() in ary_combination_init refactor to use the standard Data_Make_Struct() macro instead of manual RData allocation and linking. the macro provides automatic zero-initialization and is more idiomatic. ref #6655 Co-authored-by: Claude --- mrbgems/mruby-array-ext/src/array.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mrbgems/mruby-array-ext/src/array.c b/mrbgems/mruby-array-ext/src/array.c index 9e666fb63..41ed3612d 100644 --- a/mrbgems/mruby-array-ext/src/array.c +++ b/mrbgems/mruby-array-ext/src/array.c @@ -1310,13 +1310,11 @@ ary_combination_init(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "ib", &n, &permutation); - /* prepare objects in first to avoid memory leaks caused by NoMemoryError exceptions */ - struct RData *d = mrb_data_object_alloc(mrb, mrb->object_class, NULL, NULL); + struct RData *d; + struct mrb_combination_state *state; + Data_Make_Struct(mrb, mrb->object_class, struct mrb_combination_state, + &mrb_combination_state_type, state, d); - struct mrb_combination_state *state = (struct mrb_combination_state*)mrb_malloc(mrb, sizeof(*state)); - d->data = state; - d->type = &mrb_combination_state_type; - state->indices = NULL; state->n = n; state->array_size = RARRAY_LEN(self); state->permutation = permutation;