From 8e71cab642704ed790a0bea9d586d65199f6f764 Mon Sep 17 00:00:00 2001 From: CPunch Date: Wed, 28 Oct 2020 18:29:50 -0500 Subject: [PATCH] fixed segfault on parser objection --- src/cobj.c | 3 +++ src/cparse.c | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cobj.c b/src/cobj.c index 4c99c9b..90e26bd 100644 --- a/src/cobj.c +++ b/src/cobj.c @@ -23,6 +23,9 @@ CObj *cosmoO_allocateObject(CState *state, size_t sz, CObjType type) { obj->next = state->objects; state->objects = obj; +#ifdef GC_DEBUG + printf("allocated %p with OBJ_TYPE %d\n", obj, type); +#endif return obj; } diff --git a/src/cparse.c b/src/cparse.c index 52b8459..ea850e6 100644 --- a/src/cparse.c +++ b/src/cparse.c @@ -995,14 +995,13 @@ CObjFunction* cosmoP_compileString(CState *state, const char *source) { popLocals(&parser, -1); // needed to close over the values - if (parser.hadError) { // free the function too - cosmoO_freeObject(state, (CObj*)parser.compiler->function); + if (parser.hadError) { // we don't free the function, the state already has a reference to it in it's linked list of objects! endCompiler(&parser, 0); freeParseState(&parser); // the VM still expects a result on the stack TODO: push the error string to the stack cosmoV_pushValue(state, cosmoV_newNil()); - cosmoM_unfreezeGC(state); + cosmoM_unfreezeGC(state); return NULL; } @@ -1012,6 +1011,6 @@ CObjFunction* cosmoP_compileString(CState *state, const char *source) { endCompiler(&parser, 0); freeParseState(&parser); - cosmoM_unfreezeGC(state); + cosmoM_unfreezeGC(state); return resFunc; } \ No newline at end of file