From d47ee18b1afbc88ca441b3295d89933158571b16 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 5 May 2017 23:33:36 -0400 Subject: [PATCH] Fix gc mark function in compiler. GNU readline is not valgrind clean or it is being used incorrectly. --- Makefile | 2 +- core/compile.c | 13 ++++++++----- core/gc.c | 4 ++-- core/util.c | 3 +-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 103c3307..ed0e1093 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ debug: $(GST_TARGET) gdb $(GST_TARGET) valgrind: $(GST_TARGET) - valgrind ./$(GST_TARGET) + valgrind --leak-check=full ./$(GST_TARGET) clean: rm $(GST_TARGET) || true diff --git a/core/compile.c b/core/compile.c index 71418bbb..72e2b2a9 100644 --- a/core/compile.c +++ b/core/compile.c @@ -1140,7 +1140,7 @@ GstFunction *gst_compiler_compile(GstCompiler *c, GstValue form) { /* Stl */ /***/ -/* GC mark mark all memory used by the compiler */ +/* GC mark all memory used by the compiler */ static void gst_compiler_mark(Gst *vm, void *data, uint32_t len) { SlotTracker *st; GstScope *scope; @@ -1149,16 +1149,19 @@ static void gst_compiler_mark(Gst *vm, void *data, uint32_t len) { return; /* Mark compiler */ gst_mark_value(vm, gst_wrap_buffer(c->buffer)); - /* Mark trackers */ + /* Mark trackers - the trackers themselves are all on the stack. */ st = (SlotTracker *) c->trackers; while (st) { - gst_mark_mem(vm, st->slots); + if (st->slots) + gst_mark_mem(vm, st->slots); st = st->next; } /* Mark scopes */ scope = c->tail; while (scope) { - gst_mark_mem(vm, scope->freeHeap); + gst_mark_mem(vm, scope); + if (scope->freeHeap) + gst_mark_mem(vm, scope->freeHeap); gst_mark_value(vm, gst_wrap_array(scope->literalsArray)); gst_mark_value(vm, gst_wrap_table(scope->locals)); gst_mark_value(vm, gst_wrap_table(scope->literals)); @@ -1173,7 +1176,7 @@ static const GstUserType gst_stl_compilertype = { "std.compiler", NULL, NULL, - NULL, + NULL, &gst_compiler_mark }; diff --git a/core/gc.c b/core/gc.c index eb1c705b..ca328f51 100644 --- a/core/gc.c +++ b/core/gc.c @@ -176,8 +176,8 @@ void gst_mark(Gst *vm, GstValueUnion x, GstType type) { break; case GST_USERDATA: - if (gc_header(x.string - sizeof(GstUserdataHeader))->color != vm->black) { - GstUserdataHeader *h = (GstUserdataHeader *)x.pointer - 1; + if (gc_header(gst_udata_header(x.pointer))->color != vm->black) { + GstUserdataHeader *h = gst_udata_header(x.pointer); gc_header(h)->color = vm->black; if (h->type->gcmark) h->type->gcmark(vm, x.pointer, h->size); diff --git a/core/util.c b/core/util.c index 1c5be32e..2f2bf546 100644 --- a/core/util.c +++ b/core/util.c @@ -79,7 +79,7 @@ void *gst_check_userdata(Gst *vm, uint32_t i, const GstUserType *type) { GstValue x = gst_arg(vm, i); GstUserdataHeader *h; if (x.type != GST_USERDATA) return NULL; - h = ((GstUserdataHeader *)x.data.pointer) - 1; + h = gst_udata_header(x.data.pointer); if (h->type != type) return NULL; return x.data.pointer; } @@ -111,7 +111,6 @@ GstValue gst_cmodule_struct(Gst *vm, const GstModuleItem *mod) { ++m; } return gst_wrap_struct(gst_struct_end(vm, st)); - } void gst_module_put(Gst *vm, const char *packagename, GstValue mod) {