From: Peep P. <so...@us...> - 2004-06-07 15:45:11
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8933 Modified Files: object.c Log Message: Rearranged headers; various fixes Index: object.c =================================================================== RCS file: /cvsroot/agd/server/src/object.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- object.c 1 Apr 2004 19:10:53 -0000 1.13 +++ object.c 7 Jun 2004 15:45:02 -0000 1.14 @@ -1,8 +1,22 @@ -/* Definitions of dfuns related to objects. */ -#include "std.h" -#include "lpc_incl.h" +/* +#include "config.h" +*/ +#include <stdlib.h> +/*#include "arch.h"*/ +#include "sys.h" +#include "compile_options.h" -list_t all_objects; +#include "list.h" +#include "lpc.h" +#include "object.h" +#include "net.h" +#include "vars.h" + +list_t all_objects, + to_be_dested; /* Objects which have the destructed flag + set, but are still in memory. This is so + that destruct_all() in net.c has less + objects to traverse. */ object_t *master; @@ -16,12 +30,9 @@ int i; function_t *f = p; - for(i=0;i<f->args.length;i++) - free_var(f->args.data[i]); - if(f->args.data) - xfree(f->args.data); + if(f->args) + xfree(f->args); - /* Can't do this. Need string tables. */ #if 0 for(i=0;i<f->code.length;i++) { if((int) f->code.data[i] == F_PUSH_STRING) { @@ -31,12 +42,14 @@ } } #endif - xfree(f->code.data); + + xfree(f->code); } void destruct(object_t *ob) { int i; + list_t *p; if(!ob) return; @@ -50,11 +63,13 @@ ob->iaob->ob = NULL; } - for(i=0;i<ob->refs.length;i++) { - variable_t *v = ob->refs.data[i]; + for(p=&ob->refs;p->next;p=p->next) { + variable_t *v = p->data; v->u.ob = NULL; } + list_remove(&all_objects, ob); + list_push(&to_be_dested, ob); #ifdef DEBUG debug("dfun", "destructed \"%s\"\n", ob->name); #endif @@ -62,11 +77,11 @@ void actual_destruct(object_t *ob) { - list_remove(&all_objects, ob); +/* list_remove(&all_objects, ob);*/ unref_prog(&ob->prog); - free_array(&ob->variables, (void (*)(void*))free_var); + free_array(&ob->globals, (void (*)(void*))free_var); if(ob->name) xfree(ob->name); @@ -77,24 +92,21 @@ { if(!ob) return; - array_push(&ob->refs, v); - ob->ref++; + + ob->numref++; + if(v) { + list_push(&ob->refs, v); + } } void unref_ob(object_t *ob, variable_t *v) { if(!ob) return; - array_remove_by_data(&ob->refs, v); - ob->ref--; -} -#if 0 -void ref_prog(program_t *prog) -{ - prog->ref++; + list_remove(&ob->refs, v); + ob->numref--; } -#endif void unref_prog(program_t **prog) { @@ -105,6 +117,11 @@ p->ref--; if(p->ref <= 0) { + int i; + for(i=0;i<p->num_str;i++) + xfree(p->str_tbl[i]); + xfree(p->str_tbl); + free_array(&p->functions, free_fun); free_array(&p->fun_table, NULL); xfree(p); @@ -121,7 +138,9 @@ for(p = &all_objects; p; p = p->next) { object_t *ob = p->data; - /* I'd rather not have the check for ob->name here. */ + /* I'd rather not have the check for ob->name here. + * It's only here because of net.c, which creates a temporary + * ob with NULL name. */ if(ob->name && strcmp(path, ob->name) == 0) { return ob; } @@ -165,7 +184,7 @@ } /* path = remove_extension(path); ? */ - ob = type_xmalloc(object_t); + ob = xmalloc(sizeof(object_t)); memset(ob, 0, sizeof(object_t)); ob->name = path; @@ -190,6 +209,7 @@ object_t *clone_object(char *path) { object_t *base_ob, *new_ob; + int i; base_ob = find_object(path); if(!base_ob) { @@ -203,7 +223,7 @@ #endif /* ref_ob(base_ob, NULL);*/ - new_ob = type_xmalloc(object_t); + new_ob = xmalloc(sizeof(object_t)); memset(new_ob, 0, sizeof(object_t)); new_ob->parent = base_ob; new_ob->name = xmalloc(strlen(base_ob->name) + 10); @@ -212,8 +232,14 @@ new_ob->prog = base_ob->prog; ref_prog(new_ob->prog); - /* Memory leak? */ - new_ob->variables = *copy_array(&base_ob->variables, (void*(*)(void*)) copy_var); + new_ob->numglobals = base_ob->numglobals; + new_ob->globals = xmalloc(sizeof(variable_t) * new_ob->numglobals); + for(i=0;i<new_ob->numglobals;i++) { + variable_t *v = &new_ob->globals[i]; + *v = base_ob->globals[i]; + if(v->name) + v->name = stringdup(v->name); + } apply(new_ob, "create", NULL); list_push(&all_objects, new_ob); |