From e476d9a344a84a0974bacb317b98034c22aa9576 Mon Sep 17 00:00:00 2001 From: dearblue Date: Tue, 3 Sep 2024 21:29:06 +0900 Subject: [PATCH] Need to restore the GC arena after some function calls When calling `mrb_equal()` or `mrb_funcall()` family functions, the GC arena should be restored if the loop is repeated by a non-immediate return value. In my opinion, restoring the GC arena is unnecessary when a non-immediate (true) value causes the function to return (e.g. the `mrb_ary_index_m()` function). The patch does not take into account the case of recursive calls and may be incomplete. --- mrbgems/mruby-data/src/data.c | 2 ++ mrbgems/mruby-metaprog/src/metaprog.c | 2 ++ mrbgems/mruby-sprintf/src/sprintf.c | 3 +++ mrbgems/mruby-struct/src/struct.c | 2 ++ src/array.c | 6 ++++++ 5 files changed, 15 insertions(+) diff --git a/mrbgems/mruby-data/src/data.c b/mrbgems/mruby-data/src/data.c index d66db29a6..2ac11abbe 100644 --- a/mrbgems/mruby-data/src/data.c +++ b/mrbgems/mruby-data/src/data.c @@ -366,10 +366,12 @@ mrb_data_equal(mrb_state *mrb, mrb_value s) mrb_value *ptr = RDATA_PTR(s); mrb_value *ptr2 = RDATA_PTR(s2); mrb_int len = RDATA_LEN(s); + int ai = mrb_gc_arena_save(mrb); for (mrb_int i=0; i0) FILL(' ', width-1); PUSH(c, n); } + mrb_gc_arena_restore(mrb, ai); } break; @@ -536,6 +538,7 @@ retry: } } PUSH(RSTRING_PTR(str), len); + mrb_gc_arena_restore(mrb, ai); } break; diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 5fc3c3230..cf01d652c 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -514,10 +514,12 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s) mrb_value *ptr = RSTRUCT_PTR(s); mrb_value *ptr2 = RSTRUCT_PTR(s2); mrb_int len = RSTRUCT_LEN(s); + int ai = mrb_gc_arena_save(mrb); for (mrb_int i=0; i