Permalink
Browse files

mrb_gc_unregister() to remove one registration; close #3160

when multiple mrb_gc_register() were called for the same object
  • Loading branch information...
matz committed Jun 10, 2016
1 parent 44de80f commit 09b11850a5df44d8e0ba5d031c57146e0c41547b
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/gc.c
View
@@ -453,7 +453,7 @@ mrb_gc_unregister(mrb_state *mrb, mrb_value obj)
mrb_sym root = mrb_intern_lit(mrb, GC_ROOT_NAME);
mrb_value table = mrb_gv_get(mrb, root);
struct RArray *a;
mrb_int i, j;
mrb_int i, len;
if (mrb_nil_p(table)) return;
if (mrb_type(table) != MRB_TT_ARRAY) {
@@ -462,12 +462,14 @@ mrb_gc_unregister(mrb_state *mrb, mrb_value obj)
}
a = mrb_ary_ptr(table);
mrb_ary_modify(mrb, a);
for (i=j=0; i<a->len; i++) {
if (!mrb_obj_eq(mrb, a->ptr[i], obj)) {
a->ptr[j++] = a->ptr[i];
len = a->len-1;
for (i=0; i<len; i++) {
if (mrb_obj_eq(mrb, a->ptr[i], obj)) {
memmove(&a->ptr[i], &a->ptr[i+1], len-i);
break;
}
}
a->len = j;
a->len--;
}
MRB_API struct RBasic*

0 comments on commit 09b1185

Please sign in to comment.