remove many memory leaks and cleanup
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7898 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
cf1585fef7
commit
3413b92e7a
21 changed files with 224 additions and 112 deletions
|
|
@ -80,9 +80,11 @@ Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value
|
|||
if (value) {
|
||||
String *lcaststr = SwigType_lcaststr(t,value);
|
||||
String *lstr = SwigType_lstr(t,0);
|
||||
Printf(decl,"%s = (%s) %s", SwigType_lstr(t,name), lstr, lcaststr);
|
||||
String *lstrn = SwigType_lstr(t,name);
|
||||
Printf(decl,"%s = (%s) %s", lstrn, lstr, lcaststr);
|
||||
Delete(lcaststr);
|
||||
Delete(lstr);
|
||||
Delete(lstrn);
|
||||
} else {
|
||||
String *lstrname = SwigType_lstr(t,name);
|
||||
Printf(decl,"%s", lstrname);
|
||||
|
|
@ -194,7 +196,9 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
|
|||
tycode = SwigType_type(tvalue);
|
||||
if (tycode != T_USER) {
|
||||
/* plain primitive type, we copy the the def value */
|
||||
defvalue = NewStringf("%s = %s", SwigType_lstr(tvalue,defname),qvalue);
|
||||
String *lstr = SwigType_lstr(tvalue,defname);
|
||||
defvalue = NewStringf("%s = %s", lstr,qvalue);
|
||||
Delete(lstr);
|
||||
} else {
|
||||
/* user type, we copy the reference value */
|
||||
String *str = SwigType_str(type,defname);
|
||||
|
|
@ -239,9 +243,13 @@ String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_ch
|
|||
switch(SwigType_type(t)) {
|
||||
case T_VOID:
|
||||
break;
|
||||
case T_REFERENCE:
|
||||
Printf(fcall,"{\n");
|
||||
Printf(fcall,"%s = ", SwigType_str(t,"_result_ref"));
|
||||
case T_REFERENCE:
|
||||
{
|
||||
String *str = SwigType_str(t,"_result_ref");
|
||||
Printf(fcall,"{\n");
|
||||
Printf(fcall,"%s = ", str);
|
||||
Delete(str);
|
||||
}
|
||||
break;
|
||||
case T_USER:
|
||||
Printf(fcall,"%s = ", name);
|
||||
|
|
@ -249,7 +257,11 @@ String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_ch
|
|||
|
||||
default:
|
||||
/* Normal return value */
|
||||
Printf(fcall,"%s = (%s)", name, SwigType_lstr(t,0));
|
||||
{
|
||||
String *lstr = SwigType_lstr(t,0);
|
||||
Printf(fcall,"%s = (%s)", name, lstr);
|
||||
Delete(lstr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +323,7 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) {
|
|||
} else {
|
||||
Printf(func,"%s(", nname);
|
||||
}
|
||||
|
||||
Delete(nname);
|
||||
|
||||
while (p) {
|
||||
SwigType *pt = Getattr(p,"type");
|
||||
|
|
@ -770,7 +782,11 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
|
|||
|
||||
/* Generate action code for the access */
|
||||
if (!(flags & CWRAP_EXTEND)) {
|
||||
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", Swig_cmethod_call(name,p,self)));
|
||||
String *call = Swig_cmethod_call(name,p,self);
|
||||
String *result = Swig_cresult(Getattr(n,"type"),"result", call);
|
||||
Setattr(n,"wrap:action", result);
|
||||
Delete(call);
|
||||
Delete(result);
|
||||
} else {
|
||||
/* Methods with default arguments are wrapped with additional methods for each default argument,
|
||||
* however, only one extra %extend method is generated. */
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ Swig_fragment_register(Node* fragment) {
|
|||
Append(name,mangle);
|
||||
Delete(mangle);
|
||||
Delete(rtype);
|
||||
if (debug) Printf(stdout,"register fragment %s %s\n",name,type);
|
||||
}
|
||||
if (debug) Printf(stdout,"register fragment %s %s\n",name,type);
|
||||
if (!fragments) {
|
||||
fragments = NewHash();
|
||||
}
|
||||
|
|
@ -54,15 +54,14 @@ Swig_fragment_register(Node* fragment) {
|
|||
Hash *kwargs = Getattr(fragment,"kwargs");
|
||||
Setmeta(ccode,"section",section);
|
||||
if (kwargs) {
|
||||
kwargs = Copy(kwargs);
|
||||
Setmeta(ccode,"kwargs",kwargs);
|
||||
Delete(kwargs);
|
||||
}
|
||||
Setattr(fragments,name,ccode);
|
||||
if (debug) Printf(stdout,"registering fragment %s %s\n",name,section);
|
||||
Delete(section);
|
||||
Delete(ccode);
|
||||
}
|
||||
Delete(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -140,6 +139,7 @@ Swig_fragment_emit(Node *n) {
|
|||
pc = char_index(tok,',');
|
||||
if (pc) *pc = 0;
|
||||
}
|
||||
Delete(name);
|
||||
}
|
||||
Delete(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ Swig_search_path_any(int syspath) {
|
|||
} else {
|
||||
Append(slist,filename);
|
||||
}
|
||||
Delete(filename);
|
||||
}
|
||||
if (syspath) {
|
||||
for (i = 0; i < Len(llist); i++) {
|
||||
|
|
|
|||
|
|
@ -401,12 +401,15 @@ Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object)
|
|||
if (!n) {
|
||||
n = NewHash();
|
||||
Setattr(namehash,name,n);
|
||||
Delete(n);
|
||||
}
|
||||
/* Add an object based on the declarator value */
|
||||
if (!decl) {
|
||||
Setattr(n,"*",object);
|
||||
} else {
|
||||
Setattr(n,Copy(decl),object);
|
||||
SwigType *cd = Copy(decl);
|
||||
Setattr(n,cd,object);
|
||||
Delete(cd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -555,7 +558,9 @@ static void merge_features(Hash *features, Node *n) {
|
|||
|
||||
if (!features) return;
|
||||
for (ki = First(features); ki.key; ki = Next(ki)) {
|
||||
Setattr(n,ki.key,Copy(ki.item));
|
||||
String *ci = Copy(ki.item);
|
||||
Setattr(n,ki.key,ci);
|
||||
Delete(ci);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -683,18 +688,21 @@ Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, con
|
|||
if (!n) {
|
||||
n = NewHash();
|
||||
Setattr(features,name,n);
|
||||
Delete(n);
|
||||
}
|
||||
if (!decl) {
|
||||
fhash = Getattr(n,"*");
|
||||
if (!fhash) {
|
||||
fhash = NewHash();
|
||||
Setattr(n,"*",fhash);
|
||||
Delete(fhash);
|
||||
}
|
||||
} else {
|
||||
fhash = Getattr(n,decl);
|
||||
if (!fhash) {
|
||||
fhash = NewHash();
|
||||
Setattr(n,Copy(decl),fhash);
|
||||
Delete(fhash);
|
||||
}
|
||||
}
|
||||
if (value) {
|
||||
|
|
|
|||
|
|
@ -195,10 +195,10 @@ String *ParmList_str(ParmList *p) {
|
|||
String *out = NewStringEmpty();
|
||||
while(p) {
|
||||
String *pstr = SwigType_str(Getattr(p,"type"), Getattr(p,"name"));
|
||||
Append(out,pstr);
|
||||
StringAppend(out,pstr);
|
||||
p = nextSibling(p);
|
||||
if (p) {
|
||||
Append(out,",");
|
||||
StringAppend(out,",");
|
||||
}
|
||||
Delete(pstr);
|
||||
}
|
||||
|
|
@ -216,13 +216,13 @@ String *ParmList_str_defaultargs(ParmList *p) {
|
|||
while(p) {
|
||||
String *value = Getattr(p,"value");
|
||||
String *pstr = SwigType_str(Getattr(p,"type"), Getattr(p,"name"));
|
||||
Append(out,pstr);
|
||||
StringAppend(out,pstr);
|
||||
if (value) {
|
||||
Printf(out,"=%s", value);
|
||||
}
|
||||
p = nextSibling(p);
|
||||
if (p) {
|
||||
Append(out,",");
|
||||
StringAppend(out,",");
|
||||
}
|
||||
Delete(pstr);
|
||||
}
|
||||
|
|
@ -242,10 +242,10 @@ String *ParmList_protostr(ParmList *p) {
|
|||
p = nextSibling(p);
|
||||
} else {
|
||||
String *pstr = SwigType_str(Getattr(p,"type"), 0);
|
||||
Append(out,pstr);
|
||||
StringAppend(out,pstr);
|
||||
p = nextSibling(p);
|
||||
if (p) {
|
||||
Append(out,",");
|
||||
StringAppend(out,",");
|
||||
}
|
||||
Delete(pstr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -889,18 +889,22 @@ String *SwigType_lcaststr(SwigType *s, const String_or_char *name) {
|
|||
result = NewStringEmpty();
|
||||
|
||||
if (SwigType_isarray(s)) {
|
||||
Printf(result,"(%s)%s", SwigType_lstr(s,0),name);
|
||||
String *lstr = SwigType_lstr(s,0);
|
||||
Printf(result,"(%s)%s", lstr,name);
|
||||
Delete(lstr);
|
||||
} else if (SwigType_isreference(s)) {
|
||||
String *str = SwigType_str(s,0);
|
||||
Printf(result,"(%s)", str);
|
||||
Delete(str);
|
||||
if (name)
|
||||
Append(result,name);
|
||||
StringAppend(result,name);
|
||||
} else if (SwigType_isqualifier(s)) {
|
||||
Printf(result,"(%s)%s", SwigType_lstr(s,0),name);
|
||||
String *lstr = SwigType_lstr(s,0);
|
||||
Printf(result,"(%s)%s", lstr,name);
|
||||
Delete(lstr);
|
||||
} else {
|
||||
if (name)
|
||||
Append(result,name);
|
||||
StringAppend(result,name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1007,17 +1011,17 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
|
|||
List *tparms = SwigType_parmlist(e);
|
||||
int j;
|
||||
String *nt = SwigType_templateprefix(e);
|
||||
Append(nt,"<(");
|
||||
StringAppend(nt,"<(");
|
||||
for (j = 0; j < Len(tparms); j++) {
|
||||
SwigType_typename_replace(Getitem(tparms,j), pat, rep);
|
||||
Append(nt,Getitem(tparms,j));
|
||||
StringAppend(nt,Getitem(tparms,j));
|
||||
if (j < (Len(tparms)-1)) Putc(',',nt);
|
||||
}
|
||||
tsuffix = SwigType_templatesuffix(e);
|
||||
Printf(nt,")>%s", tsuffix);
|
||||
Delete(tsuffix);
|
||||
Clear(e);
|
||||
Append(e,nt);
|
||||
StringAppend(e,nt);
|
||||
Delete(nt);
|
||||
Delete(tparms);
|
||||
}
|
||||
|
|
@ -1036,18 +1040,18 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
|
|||
int j;
|
||||
List *fparms = SwigType_parmlist(e);
|
||||
Clear(e);
|
||||
Append(e,"f(");
|
||||
StringAppend(e,"f(");
|
||||
for (j = 0; j < Len(fparms); j++) {
|
||||
SwigType_typename_replace(Getitem(fparms,j), pat, rep);
|
||||
Append(e,Getitem(fparms,j));
|
||||
StringAppend(e,Getitem(fparms,j));
|
||||
if (j < (Len(fparms)-1)) Putc(',',e);
|
||||
}
|
||||
Append(e,").");
|
||||
StringAppend(e,").");
|
||||
Delete(fparms);
|
||||
} else if (SwigType_isarray(e)) {
|
||||
Replace(e,pat,rep, DOH_REPLACE_ID);
|
||||
}
|
||||
Append(nt,e);
|
||||
StringAppend(nt,e);
|
||||
}
|
||||
Clear(t);
|
||||
Append(t,nt);
|
||||
|
|
@ -1067,10 +1071,9 @@ SwigType_check_decl(SwigType *ty, const SwigType *decl) {
|
|||
t = SwigType_typedef_resolve_all(ty);
|
||||
t1 = SwigType_strip_qualifiers(t);
|
||||
t2 = SwigType_prefix(t1);
|
||||
r = Cmp(t2,decl);
|
||||
r = Equal(t2,decl);
|
||||
Delete(t);
|
||||
Delete(t1);
|
||||
Delete(t2);
|
||||
if (r == 0) return 1;
|
||||
return 0;
|
||||
return r == 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ Swig_symbol_dump_symtable() {
|
|||
|
||||
void
|
||||
Swig_symbol_init() {
|
||||
empty_string = NewStringEmpty();
|
||||
empty_string = NewString("");
|
||||
k_allowstypedef = NewString("allows_typedef");
|
||||
k_cdecl = NewString("cdecl");
|
||||
k_coloncolon = NewString("::");
|
||||
|
|
|
|||
|
|
@ -560,11 +560,12 @@ Swig_typemap_clear_apply(Parm *parms) {
|
|||
if (tm) {
|
||||
/* Clear typemaps that match our signature */
|
||||
Iterator ki, ki2;
|
||||
|
||||
char *ctsig = Char(tsig);
|
||||
for (ki = First(tm); ki.key; ki = Next(ki)) {
|
||||
if (Strncmp(ki.key,"tmap:",5) == 0) {
|
||||
char *ckey = Char(ki.key);
|
||||
if (strncmp(ckey,"tmap:",5) == 0) {
|
||||
int na = count_args(ki.key);
|
||||
if ((na == narg) && Strstr(ki.key,tsig)) {
|
||||
if ((na == narg) && strstr(ckey,ctsig)) {
|
||||
Hash *h = ki.item;
|
||||
for (ki2 = First(h); ki2.key; ki2 = Next(ki2)) {
|
||||
Delattr(h,ki2.key);
|
||||
|
|
@ -1255,7 +1256,7 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO
|
|||
*/
|
||||
st = Getattr(node,"sym:symtab");
|
||||
qsn = st ? Swig_symbol_qualifiedscopename(st) : 0;
|
||||
if (qsn && Len(qsn)) {
|
||||
if (qsn && StringLen(qsn)) {
|
||||
/* look qualified names first, such as
|
||||
|
||||
int *Foo::foo(int bar) -> Foo::foo
|
||||
|
|
@ -1540,6 +1541,7 @@ Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f)
|
|||
|
||||
/* increase argnum to consider numinputs */
|
||||
argnum += nmatch - 1;
|
||||
Delete(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1566,7 +1568,7 @@ static List *split_embedded(String *s) {
|
|||
int leading = 1;
|
||||
args = NewList();
|
||||
|
||||
c = Strstr(s,"(");
|
||||
c = strstr(Char(s),"(");
|
||||
c++;
|
||||
|
||||
start = c;
|
||||
|
|
@ -1605,7 +1607,7 @@ static void split_var(String *s, String **name, String **value) {
|
|||
char *eq;
|
||||
char *c;
|
||||
|
||||
eq = Strstr(s,"=");
|
||||
eq = strstr(Char(s),"=");
|
||||
if (!eq) {
|
||||
*name = 0;
|
||||
*value = 0;
|
||||
|
|
@ -1630,10 +1632,10 @@ static void split_var(String *s, String **name, String **value) {
|
|||
|
||||
static void replace_embedded_typemap(String *s) {
|
||||
char *start = 0;
|
||||
while (start = strstr(Char(s),"$TYPEMAP(")) {
|
||||
while ((start = strstr(Char(s),"$TYPEMAP("))) {
|
||||
|
||||
/* Gather the argument */
|
||||
char *start, *end=0,*c;
|
||||
char *end=0,*c;
|
||||
int level = 0;
|
||||
String *tmp;
|
||||
c = start;
|
||||
|
|
|
|||
|
|
@ -719,6 +719,7 @@ SwigType_function_parms(SwigType *t) {
|
|||
if (!firstp) firstp = p;
|
||||
if (pp) {
|
||||
set_nextSibling(pp,p);
|
||||
Delete(p);
|
||||
}
|
||||
pp = p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -858,7 +858,7 @@ SwigType *SwigType_typedef_qualified(SwigType *t)
|
|||
String *result;
|
||||
int i,len;
|
||||
if (!typedef_qualified_cache) typedef_qualified_cache = NewHash();
|
||||
result = Getattr(typedef_qualified_cache,t);
|
||||
result = HashGetAttr(typedef_qualified_cache,t);
|
||||
if (result) {
|
||||
String *rc = Copy(result);
|
||||
return rc;
|
||||
|
|
@ -1403,6 +1403,7 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata)
|
|||
SwigType *fr;
|
||||
SwigType *qr;
|
||||
String *tkey;
|
||||
String *cd;
|
||||
|
||||
if (!r_mangled) {
|
||||
r_mangled = NewHash();
|
||||
|
|
@ -1419,8 +1420,10 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata)
|
|||
}
|
||||
|
||||
tkey = Copy(t);
|
||||
Setattr(r_remembered, tkey, clientdata ? NewString(clientdata) : (void *) "");
|
||||
cd = clientdata ? NewString(clientdata) : NewStringEmpty();
|
||||
Setattr(r_remembered, tkey, cd);
|
||||
Delete(tkey);
|
||||
Delete(cd);
|
||||
|
||||
mt = SwigType_manglestr(t); /* Create mangled string */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue