1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-10 10:49:54 +00:00

Fix gc mark function in compiler.

GNU readline is not valgrind clean or it
is being used incorrectly.
This commit is contained in:
Calvin Rose 2017-05-05 23:33:36 -04:00
parent f817610d4a
commit d47ee18b1a
4 changed files with 12 additions and 10 deletions

View File

@ -41,7 +41,7 @@ debug: $(GST_TARGET)
gdb $(GST_TARGET) gdb $(GST_TARGET)
valgrind: $(GST_TARGET) valgrind: $(GST_TARGET)
valgrind ./$(GST_TARGET) valgrind --leak-check=full ./$(GST_TARGET)
clean: clean:
rm $(GST_TARGET) || true rm $(GST_TARGET) || true

View File

@ -1140,7 +1140,7 @@ GstFunction *gst_compiler_compile(GstCompiler *c, GstValue form) {
/* Stl */ /* 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) { static void gst_compiler_mark(Gst *vm, void *data, uint32_t len) {
SlotTracker *st; SlotTracker *st;
GstScope *scope; GstScope *scope;
@ -1149,16 +1149,19 @@ static void gst_compiler_mark(Gst *vm, void *data, uint32_t len) {
return; return;
/* Mark compiler */ /* Mark compiler */
gst_mark_value(vm, gst_wrap_buffer(c->buffer)); 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; st = (SlotTracker *) c->trackers;
while (st) { while (st) {
gst_mark_mem(vm, st->slots); if (st->slots)
gst_mark_mem(vm, st->slots);
st = st->next; st = st->next;
} }
/* Mark scopes */ /* Mark scopes */
scope = c->tail; scope = c->tail;
while (scope) { 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_array(scope->literalsArray));
gst_mark_value(vm, gst_wrap_table(scope->locals)); gst_mark_value(vm, gst_wrap_table(scope->locals));
gst_mark_value(vm, gst_wrap_table(scope->literals)); gst_mark_value(vm, gst_wrap_table(scope->literals));
@ -1173,7 +1176,7 @@ static const GstUserType gst_stl_compilertype = {
"std.compiler", "std.compiler",
NULL, NULL,
NULL, NULL,
NULL, NULL,
&gst_compiler_mark &gst_compiler_mark
}; };

View File

@ -176,8 +176,8 @@ void gst_mark(Gst *vm, GstValueUnion x, GstType type) {
break; break;
case GST_USERDATA: case GST_USERDATA:
if (gc_header(x.string - sizeof(GstUserdataHeader))->color != vm->black) { if (gc_header(gst_udata_header(x.pointer))->color != vm->black) {
GstUserdataHeader *h = (GstUserdataHeader *)x.pointer - 1; GstUserdataHeader *h = gst_udata_header(x.pointer);
gc_header(h)->color = vm->black; gc_header(h)->color = vm->black;
if (h->type->gcmark) if (h->type->gcmark)
h->type->gcmark(vm, x.pointer, h->size); h->type->gcmark(vm, x.pointer, h->size);

View File

@ -79,7 +79,7 @@ void *gst_check_userdata(Gst *vm, uint32_t i, const GstUserType *type) {
GstValue x = gst_arg(vm, i); GstValue x = gst_arg(vm, i);
GstUserdataHeader *h; GstUserdataHeader *h;
if (x.type != GST_USERDATA) return NULL; 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; if (h->type != type) return NULL;
return x.data.pointer; return x.data.pointer;
} }
@ -111,7 +111,6 @@ GstValue gst_cmodule_struct(Gst *vm, const GstModuleItem *mod) {
++m; ++m;
} }
return gst_wrap_struct(gst_struct_end(vm, st)); return gst_wrap_struct(gst_struct_end(vm, st));
} }
void gst_module_put(Gst *vm, const char *packagename, GstValue mod) { void gst_module_put(Gst *vm, const char *packagename, GstValue mod) {