remove many memory leaks and cleanup

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7898 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-11-29 01:47:10 +00:00
commit f714a2615d
21 changed files with 224 additions and 112 deletions

View file

@ -269,6 +269,8 @@ Language::~Language() {
Delete(symbols);
Delete(classtypes);
Delete(enumtypes);
Delete(director_ctor_code);
Delete(none_comparison);
}
/* ----------------------------------------------------------------------

View file

@ -185,7 +185,7 @@ static void install_opts(int argc, char *argv[]) {
}
if (!noopt) {
/* Printf(stdout,"%s\n", opt); */
Preprocessor_define(opt, 0);
Delete(Preprocessor_define(opt, 0));
}
}
}
@ -359,7 +359,7 @@ void SWIG_getoptions(int argc, char *argv[])
} else if (strncmp(argv[i],"-D",2) == 0) {
DOH *d = NewString(argv[i]+2);
Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Preprocessor_define((DOH *) d,0);
Delete(Preprocessor_define((DOH *) d,0));
// Create a symbol
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-E") == 0) {
@ -374,7 +374,7 @@ void SWIG_getoptions(int argc, char *argv[])
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-c++") == 0) {
CPlusPlus=1;
Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
Delete(Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0));
Swig_cparse_cplusplus(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-fcompact") == 0) {
@ -651,13 +651,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Set up some default symbols (available in both SWIG interface files
// and C files)
Preprocessor_define((DOH *) "SWIG 1", 0);
Preprocessor_define((DOH *) "__STDC__", 0);
Delete(Preprocessor_define((DOH *) "SWIG 1", 0));
Delete(Preprocessor_define((DOH *) "__STDC__", 0));
#ifdef MACSWIG
Preprocessor_define((DOH *) "SWIGMAC 1", 0);
Delete(Preprocessor_define((DOH *) "SWIGMAC 1", 0));
#endif
#ifdef SWIGWIN32
Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
Delete(Preprocessor_define((DOH *) "SWIGWIN32 1", 0));
#endif
// Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C
@ -678,7 +678,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
/* Turn on contracts */
Swig_contract_mode_set(1);
Preprocessor_define(vers,0);
Delete(Preprocessor_define(vers,0));
/* Turn off directors mode */
Wrapper_director_mode_set(0);
@ -715,7 +715,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Define the __cplusplus symbol
if (CPlusPlus)
Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
Delete(Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0));
// Parse language dependent options
lang->main(argc,argv);
@ -892,6 +892,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
}
Node *top = Swig_cparse(cpps);
Delete(cpps);
if (Verbose) {

View file

@ -23,6 +23,11 @@ struct Module {
strcpy(name, n);
next = 0;
}
~Module()
{
delete[] name;
}
};
static Module *modules = 0;

View file

@ -164,7 +164,7 @@ public:
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nortti") == 0) {
/* Turn on no RTTI mode */
Preprocessor_define((DOH *) "SWIG_NORTTI", 0);
Delete(Preprocessor_define((DOH *) "SWIG_NORTTI", 0));
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-modern") == 0) {
apply = 0;
@ -189,11 +189,11 @@ public:
}
if (cppcast) {
Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
Delete(Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0));
}
if (!global_name) global_name = NewString("cvar");
Preprocessor_define("SWIGPYTHON 1", 0);
Delete(Preprocessor_define("SWIGPYTHON 1", 0));
SWIG_typemap_lang("python");
SWIG_config_file("python.swg");
allow_overloading();
@ -489,6 +489,7 @@ public:
Delete(f_directors_h);
Close(f_runtime);
Delete(f_runtime);
return SWIG_OK;
}
@ -1209,8 +1210,10 @@ public:
num_arguments = emit_num_arguments(l);
num_required = emit_num_required(l);
varargs = emit_isvarargs(l);
strcpy(wname,Char(Swig_name_wrapper(iname)));
String *nw = Swig_name_wrapper(iname);
strcpy(wname,Char(nw));
Delete(nw);
if (overname) {
strcat(wname,Char(overname));
}
@ -1526,6 +1529,7 @@ public:
#else
Printf(f->code,"%s\n", tm);
#endif
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
"Unable to use return type %s in function %s.\n", SwigType_str(d,0), name);
@ -1559,6 +1563,7 @@ public:
Replaceall(tm,"$input","result");
Replaceall(tm,"$result","resultobj");
Printf(f->code,"%s\n",tm);
Delete(tm);
}
}
@ -1717,6 +1722,7 @@ public:
Replaceall(tm,"$target","pyobj");
Replaceall(tm,"$result","pyobj");
Printf(getf->code,"%s\n", tm);
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
"Unable to read variable of type %s\n", SwigType_str(t,0));
@ -1763,6 +1769,7 @@ public:
Replaceall(tm,"$target",name);
Replaceall(tm,"$value", value);
Printf(const_code,"%s,\n", tm);
Delete(tm);
have_tm = 1;
}
if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) {
@ -1770,6 +1777,7 @@ public:
Replaceall(tm,"$target",name);
Replaceall(tm,"$value",value);
Printf(f_init, "%s\n", tm);
Delete(tm);
have_tm = 1;
}
if (!have_tm) {
@ -2237,6 +2245,7 @@ public:
modern = oldmodern;
/* Restore shadow file back to original version */
Delete(f_shadow);
f_shadow = f_shadow_file;
return SWIG_OK;
@ -2957,6 +2966,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
tm = Swig_typemap_lookup_new("director:except", n, "result", 0);
if (!tm) {
tm = Getattr(n, "feature:director:except");
if (tm) tm = Copy(tm);
}
Printf(w->code, "if (result == NULL) {\n");
Printf(w->code, " PyObject *error = PyErr_Occurred();\n");
@ -2970,6 +2980,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Printf(w->code, " }\n");
}
Printf(w->code, "}\n");
Delete(tm);
/*
* Python method may return a simple object, or a tuple.
@ -3029,6 +3040,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
}
Replaceall(tm, "$result", "c_result");
Printv(w->code, tm, "\n", NIL);
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), classname, name);

View file

@ -240,7 +240,9 @@ class TypePass : private Dispatcher {
Swig_symbol_setscope(s);
/* Recursively hit base classes */
String *newcast = NewStringf("(%s *)%s", SwigType_namestr(Getattr(bclass,"name")), cast);
String *namestr = SwigType_namestr(Getattr(bclass,"name"));
String *newcast = NewStringf("(%s *)%s", namestr, cast);
Delete(namestr);
cplus_inherit_types_impl(first,bclass,clsname,bases,baselist,ispublic,newcast);
Delete(newcast);
}
@ -434,6 +436,7 @@ class TypePass : private Dispatcher {
/* If in a namespace, patch the class name */
if (nname) {
Setattr(n,"name",nname);
Delete(nname);
}
return SWIG_OK;
}