From: Peep P. <so...@us...> - 2004-07-21 12:09:57
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10469 Modified Files: compile.c Log Message: Fixed some memory allocation problems Index: compile.c =================================================================== RCS file: /cvsroot/agd/server/src/compile.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- compile.c 20 Jun 2004 14:01:42 -0000 1.27 +++ compile.c 21 Jul 2004 12:09:47 -0000 1.28 @@ -152,7 +152,7 @@ } #ifdef DEBUG - debug("define_id", "hash collision! \"%s\" && \"%s\" == %d!\n", name, target->name, hash); + printf("[define_id] hash collision! \"%s\" && \"%s\" == %d!\n", name, target->name, hash); #endif temp = *elem; @@ -167,19 +167,25 @@ } idp->hashed_name = hash; - idp->name = stringdup(name); + idp->name = name; idp->type = type; idp->lpc_type = lpc_type; idp->args = args; idp->num_arg = num_arg; idp->base_scope = scope_level; idp->index = assign_index(idp->type); - +/* #ifdef DEBUG - debug("define_id", "%s [hash %u] base_scope %d index %d\n", - idp->name, strhash(idp->name), idp->base_scope, idp->index); + if(type != ID_DFUN && conf.debuglevel > 0) { + if(start_with_newline) { + start_with_newline = 0; + puts(""); + } + printf("[define_id] %s base_scope %d index %d\n", + idp->name, idp->base_scope, idp->index); + } #endif - +*/ return idp; } @@ -205,12 +211,12 @@ def_id_t *idp; unsigned hash = strhash(name); - /* Now look in local table. */ + /* First look in local table. */ idp = find_elem(lid_tbl, LOCAL_HASH_SIZE, hash); if(idp) return idp; - /* First look in global table. */ + /* Now look in global table. */ idp = find_elem(gid_tbl, GLOBAL_HASH_SIZE, hash); if(idp) return idp; @@ -264,7 +270,7 @@ idp = tbl[i].data; if(idp->base_scope > scope_level) { unassign_index(idp->type); - free(idp->name); + free(idp->name); /* xxx */ if(idp->args) free(idp->args); free(idp); @@ -345,6 +351,9 @@ { int x; +/* if(operand == T_ANY) + return 1;*/ + if(operand & T_ARRAY) x = TYPE_ARRAY; else switch(operand) { @@ -377,10 +386,12 @@ op = &operator_table[operator-F_ADD]; - if(!is_operand_valid(opr1, op) || + /* Urgh. */ + if((opr1 != T_ANY && opr2 != T_ANY) && + (!is_operand_valid(opr1, op) || (op->num_operand == 2 && opr2 && !is_operand_valid(opr2, op)) - || (op->both_same_type && opr1 != opr2)) { + || (op->both_same_type && opr1 != opr2))) { switch(op->num_operand) { case 1: sprintf(buf, "wrong type argument to unary "); @@ -416,17 +427,22 @@ void add_function(def_id_t *idp, int lineno) { - lineno = 0; /* XXX */ - if(idp->index < this_prog->numfunc) { /* Adding a definition for a prototype. */ function_t *f; f = this_prog->functions[idp->index]; f->type = idp->lpc_type; f->num_arg = idp->num_arg; +#if 0 + /* Urrrgh. The prototype already has args. */ f->args = xmalloc(sizeof(int) * f->num_arg); - memcpy(f->args, idp->args, f->num_arg); + memcpy(f->args, idp->args, f->num_arg * sizeof(int)); +#endif f->lineno = lineno; + f->line_numbers = NULL; + f->codelen = curr_fun->codelen; + f->code = xmalloc(sizeof(int) * f->codelen); + memcpy(f->code, curr_fun->code, f->codelen * sizeof(int)); } else { curr_fun_check(); curr_fun->type = idp->lpc_type; @@ -470,7 +486,7 @@ this_ob->numglobals++; this_ob->globals = xrealloc(this_ob->globals, this_ob->numglobals * sizeof(variable_t)); v = &this_ob->globals[this_ob->numglobals-1]; - v->name = name; + v->name = stringdup(name); /* Going to be stored. */ v->type = lpc_type; init_var(v); } else /* LVAR */{ |