ni: adds system to manage native local references to Nit objects
[nit.git] / clib / gc.c
index eb9df80..2cb8675 100644 (file)
--- a/clib/gc.c
+++ b/clib/gc.c
@@ -146,6 +146,7 @@ static void GC_collect(void) {
        struct stack_frame_t *frame = stack_frame_head;
        GC_static_object *staticObject = staticObjects.top;
        val_t object;
+       struct nitni_ref_array_link *local_ref_array_link; /* for native interface */
 
        gc_allocation_pointer = gc_heap_pointer;
        gc_scavenging_pointer = gc_heap_pointer;
@@ -167,6 +168,20 @@ static void GC_collect(void) {
                                frame->REG[j] = GC_evacuation((obj_t)object);
                        }
                }
+
+               /* Process C references to Nit objects */
+               local_ref_array_link = frame->nitni_local_ref_head;
+               while ( local_ref_array_link != NULL )
+               {
+                       for (j = 0; j < local_ref_array_link->count; j++) {
+                               object = local_ref_array_link->reg[j]->val;
+                               if (!ISNULL(object) && ISOBJ(object)) {
+                                       local_ref_array_link->reg[j]->val = GC_evacuation((obj_t)object);
+                               }
+                       }
+                       local_ref_array_link = local_ref_array_link->next;
+               }
+
                if (frame == frame->prev) break;
                frame = frame->prev;
        }