mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
array.c (mrb_ary_delete): protect return value; fix #6339
The C local variable is not protected from GC, so we use the function mrb_gc_protect() to keep the value. We also keep the arena position by mrb_gc_arena_save(), then restoring the position for every new return value, to minimize arena size. Small cosmetic changes (pre-increment to post-increment) are also made in this commit.
This commit is contained in:
+5
-2
@@ -1557,12 +1557,15 @@ mrb_ary_delete(mrb_state *mrb, mrb_value self)
|
||||
|
||||
mrb_value ret = obj;
|
||||
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
for (; i < len; ++i) {
|
||||
for (; i < len; i++) {
|
||||
mrb_value elem = val_ptr[i];
|
||||
|
||||
if (mrb_equal(mrb, elem, obj)) {
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
mrb_gc_protect(mrb, elem);
|
||||
ret = elem;
|
||||
continue;
|
||||
}
|
||||
@@ -1576,7 +1579,7 @@ mrb_ary_delete(mrb_state *mrb, mrb_value self)
|
||||
val_ptr[j] = elem;
|
||||
}
|
||||
|
||||
++j;
|
||||
j++;
|
||||
}
|
||||
|
||||
if (i == j) {
|
||||
|
||||
Reference in New Issue
Block a user