From: Wolfgang Bumiller Date: Sat, 28 Apr 2012 13:57:19 +0000 (+0200) Subject: ast_value and ast_function are linked together when using ast_function_new, note... X-Git-Tag: 0.1-rc1~562 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0f38a560b6f38bc62f853e671dfd5fdeb1c4f2c2;p=xonotic%2Fgmqcc.git ast_value and ast_function are linked together when using ast_function_new, note however, that neither will delete the other in their _delete functions. --- diff --git a/ast.c b/ast.c index a42b0fa..773c498 100644 --- a/ast.c +++ b/ast.c @@ -90,6 +90,10 @@ void ast_value_delete(ast_value* self) case TYPE_STRING: mem_d((void*)self->constval.vstring); break; + case TYPE_FUNCTION: + /* unlink us from the function node */ + self->constval.vfunc->vtype = NULL; + break; /* NOTE: delete function? currently collected in * the parser structure */ @@ -176,12 +180,22 @@ void ast_block_delete(ast_block *self) ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype) { + if (!vtype) + return NULL; + if (vtype->isconst) + return NULL; + if (vtype->vtype != TYPE_FUNCTION) + return NULL; + ast_instantiate(ast_function, ctx, ast_function_delete); self->vtype = vtype; self->name = name ? util_strdup(name) : NULL; MEM_VECTOR_INIT(self, blocks); + vtype->isconst = true; + vtype->constval.vfunc = self; + return self; } @@ -192,8 +206,15 @@ void ast_function_delete(ast_function *self) size_t i; if (self->name) mem_d((void*)self->name); - if (self->vtype) - ast_value_delete(self->vtype); + if (self->vtype) { + /* ast_value_delete(self->vtype); */ + self->vtype->isconst = false; + self->vtype->constval.vfunc = NULL; + /* We use unref - if it was stored in a global table it is supposed + * to be deleted from *there* + */ + ast_unref(self->vtype); + } for (i = 0; i < self->blocks_count; ++i) ast_delete(self->blocks[i]); MEM_VECTOR_CLEAR(self, blocks); diff --git a/ast.h b/ast.h index 382190c..eb456b1 100644 --- a/ast.h +++ b/ast.h @@ -107,6 +107,7 @@ struct ast_value_s MEM_VECTOR_MAKE(ast_value*, params); }; ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype, bool keep); +/* This will NOT delete an underlying ast_function */ void ast_value_delete(ast_value*); bool ast_value_set_name(ast_value*, const char *name); @@ -192,6 +193,7 @@ struct ast_function_s MEM_VECTOR_MAKE(ast_block*, blocks); }; ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype); +/* This will NOT delete the underlying ast_value */ void ast_function_delete(ast_function*); MEM_VECTOR_PROTO(ast_function, ast_block*, blocks);