orangeduck / tgc

A Tiny Garbage Collector for C
Other
968 stars 64 forks source link

But in tgc_mark with TGC_ROOT pointer? #10

Closed erikvanbilsen closed 7 years ago

erikvanbilsen commented 7 years ago

First of all: thanks for sharing you GC. It is one of the easiest-but-functional ones around!

I think this is a bug, but maybe I am not understanding the code correctly? The tgc_mark function contains this for loop:

  for (i = 0; i < gc->nslots; i++) {
    if (gc->items[i].hash ==        0) { continue; }
    if (gc->items[i].flags & TGC_MARK) { continue; }
    if (gc->items[i].flags & TGC_ROOT) {
      gc->items[i].flags |= TGC_MARK;
      if (gc->items[i].flags & TGC_LEAF) { return; }
      for (k = 0; k < gc->items[i].size/sizeof(void*); k++) {
        tgc_mark_ptr(gc, ((void**)gc->items[i].ptr)[k]);
      }
      return;
    }
  }

Why does it always exit the function when the first TGC_ROOT pointer is encountered? This prevents marking other pointers and marking the stack later on. Shouldn't those two return statements be continue statements instead?

orangeduck commented 7 years ago

Hi,

Yeah that looks like a bug - good catch! As you say those two return statements should be continue instead. Let me fix it now.

Thanks,

Dan

orangeduck commented 7 years ago

Fixed in e193133e43af0862f51edfb9b518e212ea084412

erikvanbilsen commented 7 years ago

That's fast!

Thanks, Erik