Various memory cleanup.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@388 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2000-04-05 22:46:00 +00:00
commit bc14ebb87e

View file

@ -197,6 +197,7 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
while ((c = Getc(argstr)) != EOF) { while ((c = Getc(argstr)) != EOF) {
if (c == ',') { if (c == ',') {
Append(arglist,argname); Append(arglist,argname);
Delete(argname);
argname = NewString(""); argname = NewString("");
} else if (isidchar(c)) { } else if (isidchar(c)) {
Putc(c,argname); Putc(c,argname);
@ -207,6 +208,7 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
} }
if (Len(argname)) { if (Len(argname)) {
Append(arglist,argname); Append(arglist,argname);
Delete(argname);
} }
} }
@ -221,16 +223,19 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
while(strstr(Char(macrovalue)," \001")) { while(strstr(Char(macrovalue)," \001")) {
Replace(macrovalue," \001","\001", DOH_REPLACE_NOQUOTE); Replace(macrovalue," \001","\001", DOH_REPLACE_NOQUOTE);
} }
/* Replace '##' with a special token */ /* Replace '##' with a special token */
Replace(macrovalue,"\001\001","\002", DOH_REPLACE_NOQUOTE); Replace(macrovalue,"\001\001","\002", DOH_REPLACE_NOQUOTE);
/* Go create the macro */ /* Go create the macro */
macro = NewHash(); macro = NewHash();
Setattr(macro,"name", macroname); Setattr(macro,"name", macroname);
if (arglist) Delete(macroname);
if (arglist) {
Setattr(macro,"args",arglist); Setattr(macro,"args",arglist);
Delete(arglist);
}
Setattr(macro,"value",macrovalue); Setattr(macro,"value",macrovalue);
Delete(macrovalue);
Setline(macro,line); Setline(macro,line);
Setfile(macro,file); Setfile(macro,file);
if (swigmacro) { if (swigmacro) {
@ -242,10 +247,14 @@ DOHHash *Preprocessor_define(DOHString_or_char *str, int swigmacro)
cpp_error(Getfile(str),Getline(str),"Macro '%s' redefined. Previous definition in \'%s\', Line %d\n", macroname, Getfile(m1), Getline(m1)); cpp_error(Getfile(str),Getline(str),"Macro '%s' redefined. Previous definition in \'%s\', Line %d\n", macroname, Getfile(m1), Getline(m1));
} }
Setattr(symbols,macroname,macro); Setattr(symbols,macroname,macro);
Delete(str);
Delete(argstr);
return macro; return macro;
macro_error: macro_error:
return 0; Delete(str);
Delete(argstr);
return 0;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -323,6 +332,7 @@ find_args(DOHString *s)
Chop(str); Chop(str);
if (Len(args) || Len(str)) if (Len(args) || Len(str))
Append(args,str); Append(args,str);
Delete(str);
/* if (Len(str) && (c != ')')) /* if (Len(str) && (c != ')'))
Append(args,str); */ Append(args,str); */
@ -452,8 +462,11 @@ expand_macro(DOHString_or_char *name, DOHList *args)
Replace(ns,"\002","",DOH_REPLACE_ANY); /* Get rid of concatenation tokens */ Replace(ns,"\002","",DOH_REPLACE_ANY); /* Get rid of concatenation tokens */
Replace(ns,"\001","#",DOH_REPLACE_ANY); /* Put # back (non-standard C) */ Replace(ns,"\001","#",DOH_REPLACE_ANY); /* Put # back (non-standard C) */
/* Expand this macro even further */ /* Expand this macro even further */
e = Preprocessor_replace(ns); e = Preprocessor_replace(ns);
Delete(ns);
Delattr(macro,"*expanded*"); Delattr(macro,"*expanded*");
if (Getattr(macro,"swigmacro")) { if (Getattr(macro,"swigmacro")) {
DOHString *g; DOHString *g;
@ -465,6 +478,7 @@ expand_macro(DOHString_or_char *name, DOHList *args)
Printf(f,"%s\n", g); Printf(f,"%s\n", g);
Printf(f,"}\n"); Printf(f,"}\n");
Delete(g); Delete(g);
Delete(e);
e = f; e = f;
} }
Delete(temp); Delete(temp);
@ -545,6 +559,7 @@ Preprocessor_replace(DOH *s)
Putc(c,arg); Putc(c,arg);
} }
Append(args,arg); Append(args,arg);
Delete(arg);
} }
if (!args) { if (!args) {
cpp_error(Getfile(id),Getline(id),"No arguments given to defined()\n"); cpp_error(Getfile(id),Getline(id),"No arguments given to defined()\n");
@ -559,6 +574,7 @@ Preprocessor_replace(DOH *s)
} }
if (i < Len(args)) Putc('0',ns); if (i < Len(args)) Putc('0',ns);
else Putc('1',ns); else Putc('1',ns);
Delete(args);
state = 0; state = 0;
break; break;
} }
@ -939,8 +955,11 @@ Preprocessor_parse(DOH *s)
Printf(ns,"%%constant %s %s; /*%s*/\n", Getattr(m,"name"),v1,comment); Printf(ns,"%%constant %s %s; /*%s*/\n", Getattr(m,"name"),v1,comment);
cpp_lines--; cpp_lines--;
} }
Delete(v1);
} }
} Delete(v);
}
Delete(m);
} }
} else if (Cmp(id,"undef") == 0) { } else if (Cmp(id,"undef") == 0) {
if (allow) Preprocessor_undef(value); if (allow) Preprocessor_undef(value);
@ -1037,6 +1056,7 @@ Preprocessor_parse(DOH *s)
Delete(s2); Delete(s2);
} }
Delete(s1); Delete(s1);
Delete(fn);
} }
} else if (Cmp(id,"pragma") == 0) { } else if (Cmp(id,"pragma") == 0) {
} else { } else {
@ -1193,6 +1213,8 @@ Preprocessor_parse(DOH *s)
Delete(value); Delete(value);
Delete(comment); Delete(comment);
Delete(chunk); Delete(chunk);
/* fprintf(stderr,"cpp: %d\n", Len(Getattr(cpp,"symbols"))); */
return ns; return ns;
} }