fix many/many memory leaks

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7904 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-11-30 21:32:27 +00:00
commit b66f1e672b
23 changed files with 627 additions and 251 deletions

View file

@ -116,7 +116,7 @@ static Node *copy_node(Node *n) {
Setattr(nn,"sym:needs_symtab", "1"); Setattr(nn,"sym:needs_symtab", "1");
} }
/* We don't copy any other symbol table attributes */ /* We don't copy any other symbol table attributes */
if (Strncmp(key,"sym:",4) == 0) { if (strncmp(ckey,"sym:",4) == 0) {
continue; continue;
} }
/* If children. We copy them recursively using this function */ /* If children. We copy them recursively using this function */
@ -124,7 +124,9 @@ static Node *copy_node(Node *n) {
/* Copy children */ /* Copy children */
Node *cn = k.item; Node *cn = k.item;
while (cn) { while (cn) {
appendChild(nn,copy_node(cn)); Node *copy = copy_node(cn);
appendChild(nn,copy);
Delete(copy);
cn = nextSibling(cn); cn = nextSibling(cn);
} }
continue; continue;
@ -313,7 +315,7 @@ static String *make_name(String *name,SwigType *decl) {
destructor = 1; destructor = 1;
} }
if (yyrename) { if (yyrename) {
String *s = yyrename; String *s = (yyrename);
yyrename = 0; yyrename = 0;
if (destructor) { if (destructor) {
Insert(s,0,"~"); Insert(s,0,"~");
@ -325,12 +327,12 @@ static String *make_name(String *name,SwigType *decl) {
/* Check to see if the name is in the hash */ /* Check to see if the name is in the hash */
if (!rename_hash) { if (!rename_hash) {
if (add_oldname) return Copy(add_oldname); if (add_oldname) return Copy(add_oldname);
return origname; return Copy(origname);
} }
rn = Swig_name_object_get(rename_hash, Namespaceprefix, name, decl); rn = Swig_name_object_get(rename_hash, Namespaceprefix, name, decl);
if (!rn) { if (!rn) {
if (add_oldname) return Copy(add_oldname); if (add_oldname) return Copy(add_oldname);
return name; return Copy(name);
} }
if (destructor) { if (destructor) {
if (Strcmp(rn,"$ignore") != 0) { if (Strcmp(rn,"$ignore") != 0) {
@ -384,7 +386,7 @@ static void add_symbols(Node *n) {
cparse_normalize_void(n); cparse_normalize_void(n);
} }
while (n) { while (n) {
String *symname; String *symname = 0;
/* for friends, we need to pop the scope once */ /* for friends, we need to pop the scope once */
String *old_prefix = 0; String *old_prefix = 0;
Symtab *old_scope = 0; Symtab *old_scope = 0;
@ -424,7 +426,7 @@ static void add_symbols(Node *n) {
*/ */
String *prefix = name ? Swig_scopename_prefix(name) : 0; String *prefix = name ? Swig_scopename_prefix(name) : 0;
if (prefix) { if (prefix) {
if (Classprefix && (Strcmp(prefix,Classprefix) == 0)) { if (Classprefix && (StringEqual(prefix,Classprefix))) {
String *base = Swig_scopename_last(name); String *base = Swig_scopename_last(name);
Setattr(n,"name",base); Setattr(n,"name",base);
Delete(base); Delete(base);
@ -462,14 +464,15 @@ static void add_symbols(Node *n) {
if (!SwigType_isfunction(decl)) { if (!SwigType_isfunction(decl)) {
String *makename = Getattr(n,"parser:makename"); String *makename = Getattr(n,"parser:makename");
if (makename) { if (makename) {
symname = make_name(makename,0);
Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */ Delattr(n,"parser:makename"); /* temporary information, don't leave it hanging around */
} else { } else {
makename = Getattr(n,"name"); makename = Getattr(n,"name");
symname = make_name(makename,0);
} }
symname = make_name(makename,0);
if (!symname) { if (!symname) {
symname = Getattr(n,"unnamed"); symname = Copy(Getattr(n,"unnamed"));
} }
if (symname) { if (symname) {
wrn = name_warning(n,symname,0); wrn = name_warning(n,symname,0);
@ -558,8 +561,13 @@ static void add_symbols(Node *n) {
/* restore the class scope if needed */ /* restore the class scope if needed */
if (isfriend) { if (isfriend) {
Swig_symbol_setscope(old_scope); Swig_symbol_setscope(old_scope);
Namespaceprefix = old_prefix; if (old_prefix) {
Delete(Namespaceprefix);
Namespaceprefix = old_prefix;
}
} }
Delete(symname);
if (add_only_one) return; if (add_only_one) return;
n = nextSibling(n); n = nextSibling(n);
} }
@ -571,10 +579,10 @@ static void add_symbols(Node *n) {
static void add_symbols_copy(Node *n) { static void add_symbols_copy(Node *n) {
String *name; String *name;
int emode = 0; int emode = 0;
while (n) { while (n) {
char *cnodeType = Char(nodeType(n));
if (Strcmp(nodeType(n),"access") == 0) { if (strcmp(cnodeType,"access") == 0) {
String *kind = Getattr(n,"kind"); String *kind = Getattr(n,"kind");
if (Strcmp(kind,"public") == 0) { if (Strcmp(kind,"public") == 0) {
cplus_mode = CPLUS_PUBLIC; cplus_mode = CPLUS_PUBLIC;
@ -593,7 +601,8 @@ static void add_symbols_copy(Node *n) {
DohIncref(add_oldname); DohIncref(add_oldname);
/* If already renamed, we used that name */ /* If already renamed, we used that name */
if (Strcmp(add_oldname, Getattr(n,"name")) != 0) { if (Strcmp(add_oldname, Getattr(n,"name")) != 0) {
yyrename = add_oldname; Delete(yyrename);
yyrename = Copy(add_oldname);
} }
} }
Delattr(n,"sym:needs_symtab"); Delattr(n,"sym:needs_symtab");
@ -610,9 +619,10 @@ static void add_symbols_copy(Node *n) {
if (Getattr(n,"requires_symtab")) { if (Getattr(n,"requires_symtab")) {
Swig_symbol_newscope(); Swig_symbol_newscope();
Swig_symbol_setscopename(name); Swig_symbol_setscopename(name);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} }
if (Strcmp(nodeType(n),"class") == 0) { if (strcmp(cnodeType,"class") == 0) {
inclass = 1; inclass = 1;
if (Strcmp(Getattr(n,"kind"),"class") == 0) { if (Strcmp(Getattr(n,"kind"),"class") == 0) {
cplus_mode = CPLUS_PRIVATE; cplus_mode = CPLUS_PRIVATE;
@ -620,33 +630,34 @@ static void add_symbols_copy(Node *n) {
cplus_mode = CPLUS_PUBLIC; cplus_mode = CPLUS_PUBLIC;
} }
} }
if (Strcmp(nodeType(n),"extend") == 0) { if (strcmp(cnodeType,"extend") == 0) {
emode = cplus_mode; emode = cplus_mode;
cplus_mode = CPLUS_PUBLIC; cplus_mode = CPLUS_PUBLIC;
} }
add_symbols_copy(firstChild(n)); add_symbols_copy(firstChild(n));
if (Strcmp(nodeType(n),"extend") == 0) { if (strcmp(cnodeType,"extend") == 0) {
cplus_mode = emode; cplus_mode = emode;
} }
if (Getattr(n,"requires_symtab")) { if (Getattr(n,"requires_symtab")) {
Setattr(n,"symtab", Swig_symbol_popscope()); Setattr(n,"symtab", Swig_symbol_popscope());
Delattr(n,"requires_symtab"); Delattr(n,"requires_symtab");
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} }
if (add_oldname) { if (add_oldname) {
Delete(add_oldname); Delete(add_oldname);
} }
if (Strcmp(nodeType(n),"class") == 0) { if (strcmp(cnodeType,"class") == 0) {
inclass = 0; inclass = 0;
} }
add_oldname = 0; add_oldname = 0;
} else { } else {
if (Strcmp(nodeType(n),"extend") == 0) { if (strcmp(cnodeType,"extend") == 0) {
emode = cplus_mode; emode = cplus_mode;
cplus_mode = CPLUS_PUBLIC; cplus_mode = CPLUS_PUBLIC;
} }
add_symbols_copy(firstChild(n)); add_symbols_copy(firstChild(n));
if (Strcmp(nodeType(n),"extend") == 0) { if (strcmp(cnodeType,"extend") == 0) {
cplus_mode = emode; cplus_mode = emode;
} }
} }
@ -775,6 +786,7 @@ static void merge_extensions(Node *cls, Node *am) {
qargs = Swig_symbol_type_qualify(args,0); qargs = Swig_symbol_type_qualify(args,0);
Append(prefix,qargs); Append(prefix,qargs);
Delete(nname); Delete(nname);
Delete(qargs);
nname = prefix; nname = prefix;
} }
return nname; return nname;
@ -810,6 +822,7 @@ static void merge_extensions(Node *cls, Node *am) {
Append(bases,s); Append(bases,s);
if (q) { if (q) {
base = NewStringf("%s::%s", q, Getattr(s,"name")); base = NewStringf("%s::%s", q, Getattr(s,"name"));
Delete(q);
} else { } else {
base = NewString(Getattr(s,"name")); base = NewString(Getattr(s,"name"));
} }
@ -903,6 +916,7 @@ static String *resolve_node_scope(String *cname) {
String *base = Swig_scopename_last(name); String *base = Swig_scopename_last(name);
String *tprefix = Swig_scopename_prefix(name); String *tprefix = Swig_scopename_prefix(name);
Insert(scopes,0,base); Insert(scopes,0,base);
Delete(base);
Delete(name); Delete(name);
name = tprefix; name = tprefix;
} }
@ -930,6 +944,7 @@ static String *resolve_node_scope(String *cname) {
/* set the scope to the inner class */ /* set the scope to the inner class */
Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); Swig_symbol_setscope(Getattr(nscope_inner,"symtab"));
/* save the last namespace prefix */ /* save the last namespace prefix */
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
/* and return the node name, including the inner class prefix */ /* and return the node name, including the inner class prefix */
break; break;
@ -940,6 +955,7 @@ static String *resolve_node_scope(String *cname) {
Setattr(ns2,"symtab", Getattr(ns1,"symtab")); Setattr(ns2,"symtab", Getattr(ns1,"symtab"));
add_symbols(ns2); add_symbols(ns2);
Swig_symbol_setscope(Getattr(ns1,"symtab")); Swig_symbol_setscope(Getattr(ns1,"symtab"));
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
if (nscope_inner) { if (nscope_inner) {
if (Getattr(nscope_inner,"symtab") != Getattr(ns2,"symtab")) { if (Getattr(nscope_inner,"symtab") != Getattr(ns2,"symtab")) {
@ -1250,7 +1266,9 @@ static void default_arguments(Node *n) {
/* Create new function and add to symbol table */ /* Create new function and add to symbol table */
{ {
Node *new_function = new_node(Copy(nodeType(function))); SwigType *ntype = Copy(nodeType(function));
char *cntype = Char(ntype);
Node *new_function = new_node(ntype);
SwigType *decl = Copy(Getattr(function,"decl")); SwigType *decl = Copy(Getattr(function,"decl"));
int constqualifier = SwigType_isconst(decl); int constqualifier = SwigType_isconst(decl);
String *ccode = Copy(Getattr(function,"code")); String *ccode = Copy(Getattr(function,"code"));
@ -1270,6 +1288,7 @@ static void default_arguments(Node *n) {
Setattr(new_function,"storage", cstorage); Setattr(new_function,"storage", cstorage);
Setattr(new_function,"type", ctype); Setattr(new_function,"type", ctype);
Setattr(new_function,"throw", cthrow); Setattr(new_function,"throw", cthrow);
Delete(ccode); Delete(ccode);
Delete(cstorage); Delete(cstorage);
Delete(ctype); Delete(ctype);
@ -1284,14 +1303,26 @@ static void default_arguments(Node *n) {
} }
/* copy specific attributes for global (or in a namespace) template functions - these are not templated class methods */ /* copy specific attributes for global (or in a namespace) template functions - these are not templated class methods */
if (Strcmp(nodeType(function),"template") == 0) { if (strcmp(cntype,"template") == 0) {
Node *templatetype = Getattr(function,"templatetype"); Node *templatetype = Getattr(function,"templatetype");
Node *symtypename = Getattr(function,"sym:typename"); Node *symtypename = Getattr(function,"sym:typename");
Parm *templateparms = Getattr(function,"templateparms"); Parm *templateparms = Getattr(function,"templateparms");
if (templatetype) Setattr(new_function,"templatetype",Copy(templatetype)); if (templatetype) {
if (symtypename) Setattr(new_function,"sym:typename",Copy(symtypename)); Node *tmp = Copy(templatetype);
if (templateparms) Setattr(new_function,"templateparms",CopyParmList(templateparms)); Setattr(new_function,"templatetype",tmp);
} else if (Strcmp(nodeType(function),"constructor") == 0) { Delete(tmp);
}
if (symtypename) {
Node *tmp = Copy(symtypename);
Setattr(new_function,"sym:typename",tmp);
Delete(tmp);
}
if (templateparms) {
Parm *tmp = CopyParmList(templateparms);
Setattr(new_function,"templateparms",tmp);
Delete(tmp);
}
} else if (strcmp(cntype,"constructor") == 0) {
/* only copied for constructors as this is not a user defined feature - it is hard coded in the parser */ /* only copied for constructors as this is not a user defined feature - it is hard coded in the parser */
if (GetFlag(function,"feature:new")) SetFlag(new_function,"feature:new"); if (GetFlag(function,"feature:new")) SetFlag(new_function,"feature:new");
} }
@ -1304,6 +1335,8 @@ static void default_arguments(Node *n) {
set_nextSibling(function, new_function); set_nextSibling(function, new_function);
function = new_function; function = new_function;
Delete(ntype);
} }
} else { } else {
function = 0; function = 0;
@ -1659,14 +1692,16 @@ clear_directive : CLEAR tm_list SEMI {
constant_directive : CONSTANT ID EQUAL definetype SEMI { constant_directive : CONSTANT ID EQUAL definetype SEMI {
if (($4.type != T_ERROR) && ($4.type != T_SYMBOL)) { if (($4.type != T_ERROR) && ($4.type != T_SYMBOL)) {
SwigType *type = NewSwigType($4.type);
$$ = new_node("constant"); $$ = new_node("constant");
Setattr($$,"name",$2); Setattr($$,"name",$2);
Setattr($$,"type",NewSwigType($4.type)); Setattr($$,"type",type);
Setattr($$,"value",$4.val); Setattr($$,"value",$4.val);
if ($4.rawval) Setattr($$,"rawval", $4.rawval); if ($4.rawval) Setattr($$,"rawval", $4.rawval);
Setattr($$,"storage","%constant"); Setattr($$,"storage","%constant");
SetFlag($$,"feature:immutable"); SetFlag($$,"feature:immutable");
add_symbols($$); add_symbols($$);
Delete(type);
} else { } else {
if ($4.type == T_ERROR) { if ($4.type == T_ERROR) {
Swig_warning(WARN_PARSE_UNSUPPORTED_VALUE,cparse_file,cparse_line,"Unsupported constant value (ignored)\n"); Swig_warning(WARN_PARSE_UNSUPPORTED_VALUE,cparse_file,cparse_line,"Unsupported constant value (ignored)\n");
@ -1792,6 +1827,7 @@ fragment_directive: FRAGMENT LPAREN fname COMMA kwargs RPAREN HBLOCK {
} }
| FRAGMENT LPAREN fname COMMA kwargs RPAREN LBRACE { | FRAGMENT LPAREN fname COMMA kwargs RPAREN LBRACE {
Hash *p = $5; Hash *p = $5;
String *code;
skip_balanced('{','}'); skip_balanced('{','}');
$$ = new_node("fragment"); $$ = new_node("fragment");
Setattr($$,"value",Getattr($3,"value")); Setattr($$,"value",Getattr($3,"value"));
@ -1800,7 +1836,9 @@ fragment_directive: FRAGMENT LPAREN fname COMMA kwargs RPAREN HBLOCK {
Setattr($$,"kwargs",nextSibling(p)); Setattr($$,"kwargs",nextSibling(p));
Delitem(scanner_ccode,0); Delitem(scanner_ccode,0);
Delitem(scanner_ccode,DOH_END); Delitem(scanner_ccode,DOH_END);
Setattr($$,"code",Copy(scanner_ccode)); code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
| FRAGMENT LPAREN fname RPAREN SEMI { | FRAGMENT LPAREN fname RPAREN SEMI {
$$ = new_node("fragment"); $$ = new_node("fragment");
@ -1902,10 +1940,13 @@ inline_directive : INLINE HBLOCK {
$$ = 0; $$ = 0;
} else { } else {
String *code;
$$ = new_node("insert"); $$ = new_node("insert");
Delitem(scanner_ccode,0); Delitem(scanner_ccode,0);
Delitem(scanner_ccode,DOH_END); Delitem(scanner_ccode,DOH_END);
Setattr($$,"code", Copy(scanner_ccode)); code = Copy(scanner_ccode);
Setattr($$,"code", code);
Delete(code);
cpps=Copy(scanner_ccode); cpps=Copy(scanner_ccode);
start_inline(Char(cpps), cparse_start_line); start_inline(Char(cpps), cparse_start_line);
Delete(cpps); Delete(cpps);
@ -1941,12 +1982,15 @@ insert_directive : HBLOCK {
Setattr($$,"code",$5); Setattr($$,"code",$5);
} }
| INSERT LPAREN idstring RPAREN LBRACE { | INSERT LPAREN idstring RPAREN LBRACE {
String *code;
skip_balanced('{','}'); skip_balanced('{','}');
$$ = new_node("insert"); $$ = new_node("insert");
Setattr($$,"section",$3); Setattr($$,"section",$3);
Delitem(scanner_ccode,0); Delitem(scanner_ccode,0);
Delitem(scanner_ccode,DOH_END); Delitem(scanner_ccode,DOH_END);
Setattr($$,"code", Copy(scanner_ccode)); code = Copy(scanner_ccode);
Setattr($$,"code", code);
Delete(code);
} }
; ;
@ -1975,7 +2019,9 @@ module_directive: MODULE options idstring {
if (!import_mode) { if (!import_mode) {
/* first module included, we apply global /* first module included, we apply global
ModuleName, which can be modify by -module */ ModuleName, which can be modify by -module */
Setattr($$,"name",Copy(ModuleName)); String *mname = Copy(ModuleName);
Setattr($$,"name",mname);
Delete(mname);
} else { } else {
/* import mode, we just pass the idstring */ /* import mode, we just pass the idstring */
Setattr($$,"name",$3); Setattr($$,"name",$3);
@ -1991,6 +2037,7 @@ module_directive: MODULE options idstring {
name_directive : NAME LPAREN idstring RPAREN { name_directive : NAME LPAREN idstring RPAREN {
Swig_warning(WARN_DEPRECATED_NAME,cparse_file,cparse_line, "%%name is deprecated. Use %%rename instead.\n"); Swig_warning(WARN_DEPRECATED_NAME,cparse_file,cparse_line, "%%name is deprecated. Use %%rename instead.\n");
Delete(yyrename);
yyrename = NewString($3); yyrename = NewString($3);
$$ = 0; $$ = 0;
} }
@ -2314,13 +2361,16 @@ typemap_directive : TYPEMAP LPAREN typemap_type RPAREN tm_list stringbrace {
while (len && isspace(cstr[0])) { --len; ++cstr; } while (len && isspace(cstr[0])) { --len; ++cstr; }
while (len && isspace(cstr[len - 1])) { --len; } while (len && isspace(cstr[len - 1])) { --len; }
code = NewStringWithSize(cstr, len); code = NewStringWithSize(cstr, len);
break;
} }
} }
kw = nextSibling(kw); kw = nextSibling(kw);
} }
Setattr($$,"kwargs", $3.kwargs); Setattr($$,"kwargs", $3.kwargs);
} }
Setattr($$,"code", code ? code : NewString($6)); code = code ? code : NewString($6);
Setattr($$,"code", code);
Delete(code);
appendChild($$,$5); appendChild($$,$5);
} }
} }
@ -2381,10 +2431,13 @@ tm_tail : COMMA typemap_parm tm_tail {
; ;
typemap_parm : type typemap_parameter_declarator { typemap_parm : type typemap_parameter_declarator {
Parm *parm;
SwigType_push($1,$2.type); SwigType_push($1,$2.type);
$$ = new_node("typemapitem"); $$ = new_node("typemapitem");
Setattr($$,"pattern",NewParm($1,$2.id)); parm = NewParm($1,$2.id);
Setattr($$,"pattern",parm);
Setattr($$,"parms", $2.parms); Setattr($$,"parms", $2.parms);
Delete(parm);
/* $$ = NewParm($1,$2.id); /* $$ = NewParm($1,$2.id);
Setattr($$,"parms",$2.parms); */ Setattr($$,"parms",$2.parms); */
} }
@ -2449,15 +2502,18 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
SwigType *rty = Swig_symbol_typedef_reduce(ty,tscope); SwigType *rty = Swig_symbol_typedef_reduce(ty,tscope);
ty = Swig_symbol_type_qualify(rty,tscope); ty = Swig_symbol_type_qualify(rty,tscope);
Setattr(p,"type",ty); Setattr(p,"type",ty);
Delete(ty);
Delete(rty); Delete(rty);
} else { } else {
ty = Swig_symbol_type_qualify(ty,tscope); ty = Swig_symbol_type_qualify(ty,tscope);
Setattr(p,"type",ty); Setattr(p,"type",ty);
Delete(ty);
} }
} }
} else { } else {
value = Swig_symbol_type_qualify(value,tscope); value = Swig_symbol_type_qualify(value,tscope);
Setattr(p,"value",value); Setattr(p,"value",value);
Delete(value);
} }
p = nextSibling(p); p = nextSibling(p);
@ -2484,6 +2540,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
nn = Getattr(nn,"sym:nextSibling"); /* repeat for overloaded templated functions */ nn = Getattr(nn,"sym:nextSibling"); /* repeat for overloaded templated functions */
continue; continue;
} else { } else {
String *tname = Copy($5);
int def_supplied = 0; int def_supplied = 0;
/* Expand the template */ /* Expand the template */
Node *templ = Swig_symbol_clookup($5,0); Node *templ = Swig_symbol_clookup($5,0);
@ -2535,7 +2592,8 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
templnode = copy_node(nn); templnode = copy_node(nn);
/* We need to set the node name based on name used to instantiate */ /* We need to set the node name based on name used to instantiate */
Setattr(templnode,"name",Copy($5)); Setattr(templnode,"name",tname);
Delete(tname);
if (!specialized) { if (!specialized) {
Delattr(templnode,"sym:typename"); Delattr(templnode,"sym:typename");
} else { } else {
@ -2549,6 +2607,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
String *nname = NewStringf("__dummy_%d__", cnt++); String *nname = NewStringf("__dummy_%d__", cnt++);
Swig_cparse_template_expand(templnode,nname,temparms,tscope); Swig_cparse_template_expand(templnode,nname,temparms,tscope);
Setattr(templnode,"sym:name",nname); Setattr(templnode,"sym:name",nname);
Delete(nname);
Setattr(templnode,"feature:onlychildren", Setattr(templnode,"feature:onlychildren",
"typemap,typemapitem,typemapcopy,typedef,types,fragment"); "typemap,typemapitem,typemapcopy,typedef,types,fragment");
} }
@ -2582,6 +2641,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
Swig_symbol_inherit(st); Swig_symbol_inherit(st);
} }
} }
Delete(bases);
} }
} }
Swig_symbol_setscope(csyms); Swig_symbol_setscope(csyms);
@ -2593,10 +2653,11 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
the class */ the class */
if (extendhash) { if (extendhash) {
String *stmp = 0;
String *clsname; String *clsname;
Node *am; Node *am;
if (Namespaceprefix) { if (Namespaceprefix) {
clsname = NewStringf("%s::%s", Namespaceprefix, Getattr(templnode,"name")); clsname = stmp = NewStringf("%s::%s", Namespaceprefix, Getattr(templnode,"name"));
} else { } else {
clsname = Getattr(templnode,"name"); clsname = Getattr(templnode,"name");
} }
@ -2610,6 +2671,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
appendChild(templnode,am); appendChild(templnode,am);
Delattr(extendhash,clsname); Delattr(extendhash,clsname);
} }
if (stmp) Delete(stmp);
} }
/* Add to classes hash */ /* Add to classes hash */
if (!classes) classes = NewHash(); if (!classes) classes = NewHash();
@ -2618,8 +2680,11 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
if (Namespaceprefix) { if (Namespaceprefix) {
String *temp = NewStringf("%s::%s", Namespaceprefix, Getattr(templnode,"name")); String *temp = NewStringf("%s::%s", Namespaceprefix, Getattr(templnode,"name"));
Setattr(classes,temp,templnode); Setattr(classes,temp,templnode);
Delete(temp);
} else { } else {
Setattr(classes,Swig_symbol_qualifiedscopename(templnode),templnode); String *qs = Swig_symbol_qualifiedscopename(templnode);
Setattr(classes, qs,templnode);
Delete(qs);
} }
} }
} }
@ -2646,6 +2711,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
} }
} }
Swig_symbol_setscope(tscope); Swig_symbol_setscope(tscope);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} }
; ;
@ -2721,15 +2787,19 @@ c_decl : storage_class type declarator initializer c_decl_tail {
Setattr($$,"throw",$4.throw); Setattr($$,"throw",$4.throw);
if (!$5) { if (!$5) {
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr($$,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
} else { } else {
Node *n = $5; Node *n = $5;
/* Inherit attributes */ /* Inherit attributes */
while (n) { while (n) {
Setattr(n,"type",Copy($2)); String *type = Copy($2);
Setattr(n,"type",type);
Setattr(n,"storage",$1); Setattr(n,"storage",$1);
n = nextSibling(n); n = nextSibling(n);
Delete(type);
} }
} }
if ($4.bitfield) { if ($4.bitfield) {
@ -2781,7 +2851,9 @@ c_decl_tail : SEMI {
} }
if (!$4) { if (!$4) {
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr($$,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
} else { } else {
set_nextSibling($$,$4); set_nextSibling($$,$4);
@ -2886,29 +2958,37 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI {
Setattr(n,"unnamed",unnamed); Setattr(n,"unnamed",unnamed);
if (unnamedinstance) { if (unnamedinstance) {
Setattr($$,"type",NewString("enum ")); SwigType *cty = NewString("enum ");
Setattr($$,"type",cty);
Setattr($$,"unnamedinstance","1"); Setattr($$,"unnamedinstance","1");
Setattr(n,"unnamedinstance","1"); Setattr(n,"unnamedinstance","1");
Delete(cty);
} }
if ($8) { if ($8) {
Node *p = $8; Node *p = $8;
set_nextSibling(n,p); set_nextSibling(n,p);
while (p) { while (p) {
Setattr(p,"type",Copy(ty)); SwigType *cty = Copy(ty);
Setattr(p,"type",cty);
Setattr(p,"unnamed",unnamed); Setattr(p,"unnamed",unnamed);
Setattr(p,"storage",$1); Setattr(p,"storage",$1);
Delete(cty);
p = nextSibling(p); p = nextSibling(p);
} }
} else { } else {
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr(n,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr(n,"code",code);
Delete(code);
} }
} }
/* Ensure that typedef enum ABC {foo} XYZ; uses XYZ for sym:name, like structs. /* Ensure that typedef enum ABC {foo} XYZ; uses XYZ for sym:name, like structs.
* Note that class_rename/yyrename are bit of a mess so used this simple approach to change the name. */ * Note that class_rename/yyrename are bit of a mess so used this simple approach to change the name. */
if ($7.id && $3 && Cmp($1,"typedef") == 0) { if ($7.id && $3 && Cmp($1,"typedef") == 0) {
Setattr($$, "parser:makename", NewString($7.id)); String *name = NewString($7.id);
Setattr($$, "parser:makename", name);
Delete(name);
} }
add_symbols($$); /* Add enum to tag space */ add_symbols($$); /* Add enum to tag space */
@ -2916,6 +2996,7 @@ c_enum_decl : storage_class ENUM ename LBRACE enumlist RBRACE SEMI {
add_symbols($5); /* Add enum values to id space */ add_symbols($5); /* Add enum values to id space */
add_symbols(n); add_symbols(n);
Delete(unnamed);
} }
; ;
@ -2946,7 +3027,9 @@ c_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end {
Setattr($$,"decl",decl); Setattr($$,"decl",decl);
Setattr($$,"parms",$6.parms); Setattr($$,"parms",$6.parms);
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr($$,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
} }
if ($6.defarg) { if ($6.defarg) {
@ -3006,6 +3089,7 @@ cpp_class_decl :
} }
} }
Delete(class_rename);
class_rename = make_name($3,0); class_rename = make_name($3,0);
Classprefix = NewString($3); Classprefix = NewString($3);
/* Deal with inheritance */ /* Deal with inheritance */
@ -3042,7 +3126,9 @@ cpp_class_decl :
Swig_symbol_inherit(st); Swig_symbol_inherit(st);
} }
} }
Delete(bases);
} }
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
cparse_start_line = cparse_line; cparse_start_line = cparse_line;
@ -3052,10 +3138,12 @@ cpp_class_decl :
if (template_parameters) { if (template_parameters) {
Parm *tp = template_parameters; Parm *tp = template_parameters;
while(tp) { while(tp) {
String *tpname = Copy(Getattr(tp,"name"));
Node *tn = new_node("templateparm"); Node *tn = new_node("templateparm");
Setattr(tn,"name",Getattr(tp,"name")); Setattr(tn,"name",tpname);
Swig_symbol_cadd(Copy(Getattr(tp,"name")),tn); Swig_symbol_cadd(tpname,tn);
tp = nextSibling(tp); tp = nextSibling(tp);
Delete(tpname);
} }
} }
inclass = 1; inclass = 1;
@ -3064,6 +3152,7 @@ cpp_class_decl :
SwigType *ty; SwigType *ty;
Symtab *cscope = prev_symtab; Symtab *cscope = prev_symtab;
Node *am = 0; Node *am = 0;
String *scpname = 0;
inclass = 0; inclass = 0;
$$ = new_node("class"); $$ = new_node("class");
Setline($$,cparse_start_line); Setline($$,cparse_start_line);
@ -3090,7 +3179,9 @@ cpp_class_decl :
Delete(clsname); Delete(clsname);
} }
if (!classes) classes = NewHash(); if (!classes) classes = NewHash();
Setattr(classes,Swig_symbol_qualifiedscopename(0),$$); scpname = Swig_symbol_qualifiedscopename(0);
Setattr(classes,scpname,$$);
Delete(scpname);
appendChild($$,$7); appendChild($$,$7);
if (am) appendChild($$,am); if (am) appendChild($$,am);
@ -3117,11 +3208,15 @@ cpp_class_decl :
SwigType *decltype = Getattr($9,"decl"); SwigType *decltype = Getattr($9,"decl");
if (Cmp($1,"typedef") == 0) { if (Cmp($1,"typedef") == 0) {
if (!decltype || !Len(decltype)) { if (!decltype || !Len(decltype)) {
String *cname;
name = Getattr($9,"name"); name = Getattr($9,"name");
Setattr($$,"tdname",Copy(name)); cname = Copy(name);
Setattr($$,"tdname",cname);
Delete(cname);
/* Use typedef name as class name */ /* Use typedef name as class name */
if (class_rename && (Strcmp(class_rename,$3) == 0)) { if (class_rename && (Strcmp(class_rename,$3) == 0)) {
Delete(class_rename);
class_rename = NewString(name); class_rename = NewString(name);
} }
if (!Getattr(classes,name)) { if (!Getattr(classes,name)) {
@ -3151,27 +3246,33 @@ cpp_class_decl :
/* we add the declaration in the original namespace */ /* we add the declaration in the original namespace */
appendChild(nscope_inner,$$); appendChild(nscope_inner,$$);
Swig_symbol_setscope(Getattr(nscope_inner,"symtab")); Swig_symbol_setscope(Getattr(nscope_inner,"symtab"));
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
add_symbols($$); add_symbols($$);
if (nscope) $$ = nscope; if (nscope) $$ = nscope;
/* but the variable definition in the current scope */ /* but the variable definition in the current scope */
Swig_symbol_setscope(cscope); Swig_symbol_setscope(cscope);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
add_symbols($9); add_symbols($9);
} else { } else {
yyrename = NewString(class_rename); Delete(yyrename);
yyrename = Copy(class_rename);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
add_symbols($$); add_symbols($$);
add_symbols($9); add_symbols($9);
} }
Swig_symbol_setscope(cscope); Swig_symbol_setscope(cscope);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} }
/* An unnamed struct, possibly with a typedef */ /* An unnamed struct, possibly with a typedef */
| storage_class cpptype LBRACE { | storage_class cpptype LBRACE {
Delete(class_rename);
class_rename = make_name(0,0); class_rename = make_name(0,0);
if (strcmp($2,"class") == 0) { if (strcmp($2,"class") == 0) {
cplus_mode = CPLUS_PRIVATE; cplus_mode = CPLUS_PRIVATE;
@ -3182,6 +3283,7 @@ cpp_class_decl :
cparse_start_line = cparse_line; cparse_start_line = cparse_line;
inclass = 1; inclass = 1;
Classprefix = NewStringEmpty(); Classprefix = NewStringEmpty();
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} cpp_members RBRACE declarator c_decl_tail { } cpp_members RBRACE declarator c_decl_tail {
String *unnamed; String *unnamed;
@ -3210,8 +3312,10 @@ cpp_class_decl :
Node *p = $8; Node *p = $8;
set_nextSibling(n,p); set_nextSibling(n,p);
while (p) { while (p) {
String *type = Copy(unnamed);
Setattr(p,"unnamed",unnamed); Setattr(p,"unnamed",unnamed);
Setattr(p,"type",Copy(unnamed)); Setattr(p,"type",type);
Delete(type);
Setattr(p,"storage",$1); Setattr(p,"storage",$1);
p = nextSibling(p); p = nextSibling(p);
} }
@ -3222,6 +3326,7 @@ cpp_class_decl :
String *name = 0; String *name = 0;
if ($1 && (strcmp($1,"typedef") == 0)) { if ($1 && (strcmp($1,"typedef") == 0)) {
if (!Len($7.type)) { if (!Len($7.type)) {
String *scpname = 0;
name = $7.id; name = $7.id;
Setattr($$,"tdname",name); Setattr($$,"tdname",name);
Setattr($$,"name",name); Setattr($$,"name",name);
@ -3247,7 +3352,9 @@ cpp_class_decl :
Delete(clsname); Delete(clsname);
} }
if (!classes) classes = NewHash(); if (!classes) classes = NewHash();
Setattr(classes,Swig_symbol_qualifiedscopename(0),$$); scpname = Swig_symbol_qualifiedscopename(0);
Setattr(classes,scpname,$$);
Delete(scpname);
} else { } else {
Swig_symbol_setscopename((char*)"<unnamed>"); Swig_symbol_setscopename((char*)"<unnamed>");
} }
@ -3258,11 +3365,14 @@ cpp_class_decl :
/* Pop the scope */ /* Pop the scope */
Setattr($$,"symtab",Swig_symbol_popscope()); Setattr($$,"symtab",Swig_symbol_popscope());
if (class_rename) { if (class_rename) {
Delete(yyrename);
yyrename = NewString(class_rename); yyrename = NewString(class_rename);
} }
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
add_symbols($$); add_symbols($$);
add_symbols(n); add_symbols(n);
Delete(unnamed);
} }
; ;
@ -3316,6 +3426,7 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para
} }
if (sti) { if (sti) {
Swig_symbol_setscope(sti); Swig_symbol_setscope(sti);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
$6 = ni; $6 = ni;
} }
@ -3526,6 +3637,7 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN { template_para
} }
$$ = ntop; $$ = ntop;
Swig_symbol_setscope(cscope); Swig_symbol_setscope(cscope);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
if (error) $$ = 0; if (error) $$ = 0;
} }
@ -3589,9 +3701,12 @@ template_parms : rawparms {
cpp_using_decl : USING idcolon SEMI { cpp_using_decl : USING idcolon SEMI {
String *uname = Swig_symbol_type_qualify($2,0); String *uname = Swig_symbol_type_qualify($2,0);
String *name = Swig_scopename_last($2);
$$ = new_node("using"); $$ = new_node("using");
Setattr($$,"uname",uname); Setattr($$,"uname",uname);
Setattr($$,"name", Swig_scopename_last($2)); Setattr($$,"name", name);
Delete(uname);
Delete(name);
add_symbols($$); add_symbols($$);
} }
| USING NAMESPACE idcolon SEMI { | USING NAMESPACE idcolon SEMI {
@ -3637,6 +3752,7 @@ cpp_namespace_decl : NAMESPACE idcolon LBRACE {
Swig_symbol_newscope(); Swig_symbol_newscope();
Swig_symbol_setscopename($2); Swig_symbol_setscopename($2);
} }
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
} interface RBRACE { } interface RBRACE {
Node *n = $5; Node *n = $5;
@ -3645,6 +3761,7 @@ cpp_namespace_decl : NAMESPACE idcolon LBRACE {
Setattr(n,"symtab", Swig_symbol_popscope()); Setattr(n,"symtab", Swig_symbol_popscope());
Swig_symbol_setscope($1); Swig_symbol_setscope($1);
$$ = n; $$ = n;
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
add_symbols($$); add_symbols($$);
} }
@ -3666,6 +3783,7 @@ cpp_namespace_decl : NAMESPACE idcolon LBRACE {
Setattr($$,"unnamed","1"); Setattr($$,"unnamed","1");
Setattr($$,"symtab", Swig_symbol_popscope()); Setattr($$,"symtab", Swig_symbol_popscope());
Swig_symbol_setscope($1); Swig_symbol_setscope($1);
Delete(Namespaceprefix);
Namespaceprefix = Swig_symbol_qualifiedscopename(0); Namespaceprefix = Swig_symbol_qualifiedscopename(0);
add_symbols($$); add_symbols($$);
} }
@ -3750,8 +3868,10 @@ cpp_member : c_declaration { $$ = $1; }
symname= make_name(Getattr($$,"name"), Getattr($$,"decl")); symname= make_name(Getattr($$,"name"), Getattr($$,"decl"));
if (Strcmp(symname,Getattr($$,"name")) == 0) { if (Strcmp(symname,Getattr($$,"name")) == 0) {
/* No renaming operation. Set name to class name */ /* No renaming operation. Set name to class name */
Delete(yyrename);
yyrename = NewString(Getattr(current_class,"sym:name")); yyrename = NewString(Getattr(current_class,"sym:name"));
} else { } else {
Delete(yyrename);
yyrename = symname; yyrename = symname;
} }
} }
@ -3793,7 +3913,9 @@ cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end {
Setattr($$,"throws",$6.throws); Setattr($$,"throws",$6.throws);
Setattr($$,"throw",$6.throw); Setattr($$,"throw",$6.throw);
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr($$,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
SetFlag($$,"feature:new"); SetFlag($$,"feature:new");
} else { } else {
@ -3805,15 +3927,20 @@ cpp_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end {
/* A destructor (hopefully) */ /* A destructor (hopefully) */
cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end { cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end {
String *name = NewStringf("~%s",$2);
$$ = new_node("destructor"); $$ = new_node("destructor");
Setattr($$,"name",NewStringf("~%s",$2)); Setattr($$,"name",name);
Delete(name);
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr($$,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
{ {
String *decl = NewStringEmpty(); String *decl = NewStringEmpty();
SwigType_add_function(decl,$4); SwigType_add_function(decl,$4);
Setattr($$,"decl",decl); Setattr($$,"decl",decl);
Delete(decl);
} }
Setattr($$,"throws",$6.throws); Setattr($$,"throws",$6.throws);
Setattr($$,"throw",$6.throw); Setattr($$,"throw",$6.throw);
@ -3823,32 +3950,36 @@ cpp_destructor_decl : NOT idtemplate LPAREN parms RPAREN cpp_end {
/* A virtual destructor */ /* A virtual destructor */
| VIRTUAL NOT idtemplate LPAREN parms RPAREN cpp_vend { | VIRTUAL NOT idtemplate LPAREN parms RPAREN cpp_vend {
String *name;
char *c;
$$ = new_node("destructor"); $$ = new_node("destructor");
/* Check for template names. If the class is a template /* Check for template names. If the class is a template
and the constructor is missing the template part, we and the constructor is missing the template part, we
add it */ add it */
{ if ((c = strstr(Char(Classprefix),"<"))) {
char *c = Strstr(Classprefix,"<"); if (!Strstr($3,"<")) {
if (c) { $3 = NewStringf("%s%s",$3,c);
if (!Strstr($3,"<")) { }
$3 = NewStringf("%s%s",$3,c); }
}
}
}
Setattr($$,"storage","virtual"); Setattr($$,"storage","virtual");
Setattr($$,"name",NewStringf("~%s",$3)); name = NewStringf("~%s",$3);
Setattr($$,"name",name);
Delete(name);
Setattr($$,"throws",$7.throws); Setattr($$,"throws",$7.throws);
Setattr($$,"throw",$7.throw); Setattr($$,"throw",$7.throw);
if ($7.val) { if ($7.val) {
Setattr($$,"value","0"); Setattr($$,"value","0");
} }
if (Len(scanner_ccode)) { if (Len(scanner_ccode)) {
Setattr($$,"code",Copy(scanner_ccode)); String *code = Copy(scanner_ccode);
Setattr($$,"code",code);
Delete(code);
} }
{ {
String *decl = NewStringEmpty(); String *decl = NewStringEmpty();
SwigType_add_function(decl,$5); SwigType_add_function(decl,$5);
Setattr($$,"decl",decl); Setattr($$,"decl",decl);
Delete(decl);
} }
add_symbols($$); add_symbols($$);
@ -4219,7 +4350,9 @@ valparm : parm {
if (!SwigType_isfunction(decl)) { if (!SwigType_isfunction(decl)) {
String *value = Getattr(n,"value"); String *value = Getattr(n,"value");
if (value) { if (value) {
Setattr($1,"type",Copy(value)); String *v = Copy(value);
Setattr($1,"type",v);
Delete(v);
n = 0; n = 0;
} }
} }
@ -4237,10 +4370,12 @@ valparm : parm {
Setattr($$,"value",$1.val); Setattr($$,"value",$1.val);
} }
| STRING { | STRING {
String *v = NewString($1);
$$ = NewParm(0,0); $$ = NewParm(0,0);
Setfile($$,cparse_file); Setfile($$,cparse_file);
Setline($$,cparse_line); Setline($$,cparse_line);
Setattr($$,"value",NewString($1)); Setattr($$,"value",v);
Delete(v);
} }
; ;
@ -5041,21 +5176,27 @@ enumlist : enumlist COMMA edecl {
; ;
edecl : ID { edecl : ID {
SwigType *type = NewSwigType(T_INT);
$$ = new_node("enumitem"); $$ = new_node("enumitem");
Setattr($$,"name",$1); Setattr($$,"name",$1);
Setattr($$,"type",NewSwigType(T_INT)); Setattr($$,"type",type);
SetFlag($$,"feature:immutable"); SetFlag($$,"feature:immutable");
Delete(type);
} }
| ID EQUAL etype { | ID EQUAL etype {
$$ = new_node("enumitem"); $$ = new_node("enumitem");
Setattr($$,"name",$1); Setattr($$,"name",$1);
Setattr($$,"enumvalue", $3.val); Setattr($$,"enumvalue", $3.val);
if ($3.type == T_CHAR) { if ($3.type == T_CHAR) {
SwigType *type = NewSwigType(T_CHAR);
Setattr($$,"value",$3.val); Setattr($$,"value",$3.val);
Setattr($$,"type",NewSwigType(T_CHAR)); Setattr($$,"type",type);
Delete(type);
} else { } else {
SwigType *type = NewSwigType(T_INT);
Setattr($$,"value",$1); Setattr($$,"value",$1);
Setattr($$,"type",NewSwigType(T_INT)); Setattr($$,"type",type);
Delete(type);
} }
SetFlag($$,"feature:immutable"); SetFlag($$,"feature:immutable");
} }
@ -5219,14 +5360,18 @@ exprcompound : expr PLUS expr {
$$.type = T_INT; $$.type = T_INT;
} }
| type LPAREN { | type LPAREN {
String *qty;
skip_balanced('(',')'); skip_balanced('(',')');
$1 = Swig_symbol_type_qualify($1,0); qty = Swig_symbol_type_qualify($1,0);
if (SwigType_istemplate($1)) { if (SwigType_istemplate(qty)) {
$1 = SwigType_namestr($1); String *nstr = SwigType_namestr(qty);
Delete(qty);
qty = nstr;
} }
$$.val = NewStringf("%s%s",$1,scanner_ccode); $$.val = NewStringf("%s%s",qty,scanner_ccode);
Clear(scanner_ccode); Clear(scanner_ccode);
$$.type = T_INT; $$.type = T_INT;
Delete(qty);
} }
; ;

View file

@ -125,7 +125,7 @@ cparse_template_expand(Node *n, String *tname, String *rname, String *templatear
/* Change the node type back to normal */ /* Change the node type back to normal */
if (!expanded) { if (!expanded) {
expanded = 1; expanded = 1;
set_nodeType(n,Getattr(n,k_templatetype)); Setattr(n,k_nodetype,Getattr(n,k_templatetype));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist); ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
expanded = 0; expanded = 0;
return ret; return ret;
@ -133,9 +133,9 @@ cparse_template_expand(Node *n, String *tname, String *rname, String *templatear
/* Called when template appears inside another template */ /* Called when template appears inside another template */
/* Member templates */ /* Member templates */
set_nodeType(n,Getattr(n,k_templatetype)); Setattr(n,k_nodetype,Getattr(n,k_templatetype));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist); ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
set_nodeType(n,k_template); Setattr(n,k_nodetype,k_template);
return ret; return ret;
} }
} else if (StringEqual(nodeType,k_cdecl)) { } else if (StringEqual(nodeType,k_cdecl)) {

View file

@ -18,14 +18,17 @@ char cvsroot_base_c[] = "$Header$";
* DohDelete() * DohDelete()
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
/* #define SWIG_DEBUG_DELETE */ #ifndef SWIG_DEBUG_DELETE
#define SWIG_DEBUG_DELETE 0
#endif
void void
DohDelete(DOH *obj) { DohDelete(DOH *obj) {
DohBase *b = (DohBase *) obj; DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo; DohObjInfo *objinfo;
if (!obj) return; if (!obj) return;
#ifdef SWIG_DEBUG_DELETE #if SWIG_DEBUG_DELETE
if (!DohCheck(b)) { if (!DohCheck(b)) {
fputs("DOH: Fatal error. Attempt to delete a non-doh object.\n",stderr); fputs("DOH: Fatal error. Attempt to delete a non-doh object.\n",stderr);
abort(); abort();

View file

@ -332,6 +332,7 @@ class Allocate : public Dispatcher {
if (!nabstract) { if (!nabstract) {
nabstract = NewList(); nabstract = NewList();
Setattr(n,"abstract",nabstract); Setattr(n,"abstract",nabstract);
Delete(nabstract);
} }
Append(nabstract,nn); Append(nabstract,nn);
if (!Getattr(n,"abstract:firstnode")) { if (!Getattr(n,"abstract:firstnode")) {
@ -557,6 +558,7 @@ public:
List *abstract = NewList(); List *abstract = NewList();
Append(abstract,na); Append(abstract,na);
Setattr(n,"abstract",abstract); Setattr(n,"abstract",abstract);
Delete(abstract);
} }
} }
} }

View file

@ -482,4 +482,5 @@ void emit_action(Node *n, Wrapper *f) {
Printv(f->code,tm,"\n",NIL); Printv(f->code,tm,"\n",NIL);
} }
} }
} }

View file

@ -956,7 +956,11 @@ Language::globalfunctionHandler(Node *n) {
Delete(cbname); Delete(cbname);
} }
Setattr(n,"parms",nonvoid_parms(parms)); Setattr(n,"parms",nonvoid_parms(parms));
Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cfunction_call(name,parms))); String *call = Swig_cfunction_call(name,parms);
String *cres = Swig_cresult(type,"result", call);
Setattr(n,"wrap:action", cres);
Delete(cres);
Delete(call);
functionWrapper(n); functionWrapper(n);
} }
Swig_restore(n); Swig_restore(n);
@ -1207,11 +1211,10 @@ Language::membervariableHandler(Node *n) {
} }
if (!AttributeFunctionGet) { if (!AttributeFunctionGet) {
String *mname = Swig_name_member(ClassPrefix, symname);
String *mrename_get, *mrename_set; String *mrename_get = Swig_name_get(mname);
String *mrename_set = Swig_name_set(mname);
mrename_get = Swig_name_get(Swig_name_member(ClassPrefix, symname)); Delete(mname);
mrename_set = Swig_name_set(Swig_name_member(ClassPrefix, symname));
/* Create a function to set the value of the variable */ /* Create a function to set the value of the variable */
@ -1234,10 +1237,14 @@ Language::membervariableHandler(Node *n) {
String *base = Getattr(sn,"name"); String *base = Getattr(sn,"name");
target = NewStringf("%s::%s", base,name); target = NewStringf("%s::%s", base,name);
} else { } else {
target = NewStringf("(*%s)->%s",Swig_cparm_name(0,0),name); String *pname = Swig_cparm_name(0,0);
target = NewStringf("(*%s)->%s",pname,name);
Delete(pname);
} }
} else { } else {
target = NewStringf("%s->%s", Swig_cparm_name(0,0),name); String *pname = Swig_cparm_name(0,0);
target = NewStringf("%s->%s", pname,name);
Delete(pname);
} }
tm = Swig_typemap_lookup_new("memberin",n,target,0); tm = Swig_typemap_lookup_new("memberin",n,target,0);
} }
@ -1254,12 +1261,16 @@ Language::membervariableHandler(Node *n) {
make_set_wrapper = 0; make_set_wrapper = 0;
} }
} else { } else {
Replace(tm,"$source", Swig_cparm_name(0,1), DOH_REPLACE_ANY); String *pname0 = Swig_cparm_name(0,0);
String *pname1 = Swig_cparm_name(0,1);
Replace(tm,"$source", pname1, DOH_REPLACE_ANY);
Replace(tm,"$target", target, DOH_REPLACE_ANY); Replace(tm,"$target", target, DOH_REPLACE_ANY);
Replace(tm,"$input",Swig_cparm_name(0,1),DOH_REPLACE_ANY); Replace(tm,"$input",pname1,DOH_REPLACE_ANY);
Replace(tm,"$self",Swig_cparm_name(0,0),DOH_REPLACE_ANY); Replace(tm,"$self",pname0,DOH_REPLACE_ANY);
Setattr(n,"wrap:action", tm); Setattr(n,"wrap:action", tm);
Delete(tm); Delete(tm);
Delete(pname0);
Delete(pname1);
} }
Delete(target); Delete(target);
} }
@ -1307,7 +1318,7 @@ Language::membervariableHandler(Node *n) {
cpp_member_func(Char(gname),Char(gname),type,0); cpp_member_func(Char(gname),Char(gname),type,0);
Delete(ActionFunc); Delete(ActionFunc);
} else { } else {
String *cname = Copy(Swig_name_get(name)); String *cname = Swig_name_get(name);
cpp_member_func(Char(cname),Char(gname),type,0); cpp_member_func(Char(cname),Char(gname),type,0);
Delete(cname); Delete(cname);
} }
@ -1320,7 +1331,7 @@ Language::membervariableHandler(Node *n) {
cpp_member_func(Char(gname),Char(gname),vty,p); cpp_member_func(Char(gname),Char(gname),vty,p);
Delete(ActionFunc); Delete(ActionFunc);
} else { } else {
String *cname = Copy(Swig_name_set(name)); String *cname = Swig_name_set(name);
cpp_member_func(Char(cname),Char(gname),vty,p); cpp_member_func(Char(cname),Char(gname),vty,p);
Delete(cname); Delete(cname);
} }
@ -2459,8 +2470,9 @@ int Language::variableWrapper(Node *n) {
String *tm = Swig_typemap_lookup_new("globalin", n, name, 0); String *tm = Swig_typemap_lookup_new("globalin", n, name, 0);
Swig_VarsetToFunction(n); Swig_VarsetToFunction(n);
String *sname = Swig_name_set(symname);
Setattr(n,"sym:name", Swig_name_set(symname)); Setattr(n,"sym:name", sname);
Delete(sname);
/* String *tm = Swig_typemap_lookup((char *) "globalin",type,name,name,Swig_cparm_name(0,0),name,0);*/ /* String *tm = Swig_typemap_lookup((char *) "globalin",type,name,name,Swig_cparm_name(0,0),name,0);*/
@ -2471,11 +2483,13 @@ int Language::variableWrapper(Node *n) {
make_set_wrapper = 0; make_set_wrapper = 0;
} }
} else { } else {
Replace(tm,"$source", Swig_cparm_name(0,0), DOH_REPLACE_ANY); String *pname0 = Swig_cparm_name(0,0);
Replace(tm,"$source", pname0, DOH_REPLACE_ANY);
Replace(tm,"$target", name, DOH_REPLACE_ANY); Replace(tm,"$target", name, DOH_REPLACE_ANY);
Replace(tm,"$input",Swig_cparm_name(0,0),DOH_REPLACE_ANY); Replace(tm,"$input",pname0,DOH_REPLACE_ANY);
Setattr(n,"wrap:action", tm); Setattr(n,"wrap:action", tm);
Delete(tm); Delete(tm);
Delete(pname0);
} }
if (make_set_wrapper) { if (make_set_wrapper) {
functionWrapper(n); functionWrapper(n);
@ -2493,7 +2507,9 @@ int Language::variableWrapper(Node *n) {
} }
} }
Swig_VargetToFunction(n); Swig_VargetToFunction(n);
Setattr(n,"sym:name", Swig_name_get(symname)); String *gname = Swig_name_get(symname);
Setattr(n,"sym:name", gname);
Delete(gname);
functionWrapper(n); functionWrapper(n);
Swig_restore(n); Swig_restore(n);
return SWIG_OK; return SWIG_OK;

View file

@ -185,8 +185,9 @@ static void install_opts(int argc, char *argv[]) {
} }
if (!noopt) { if (!noopt) {
/* Printf(stdout,"%s\n", opt); */ /* Printf(stdout,"%s\n", opt); */
Delete(Preprocessor_define(opt, 0)); Preprocessor_define(opt, 0);
} }
Delete(opt);
} }
} }
} }
@ -337,6 +338,7 @@ static void SWIG_dump_runtime() {
Delete(s); Delete(s);
Close(runtime); Close(runtime);
Delete(runtime);
SWIG_exit(EXIT_SUCCESS); SWIG_exit(EXIT_SUCCESS);
} }
@ -357,9 +359,10 @@ void SWIG_getoptions(int argc, char *argv[])
includefiles[includecount++] = Swig_copy_string(argv[i]+2); includefiles[includecount++] = Swig_copy_string(argv[i]+2);
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strncmp(argv[i],"-D",2) == 0) { } else if (strncmp(argv[i],"-D",2) == 0) {
DOH *d = NewString(argv[i]+2); String *d = NewString(argv[i]+2);
Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Delete(Preprocessor_define((DOH *) d,0)); Preprocessor_define((DOH *) d,0);
Delete(d);
// Create a symbol // Create a symbol
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-E") == 0) { } else if (strcmp(argv[i],"-E") == 0) {
@ -374,7 +377,7 @@ void SWIG_getoptions(int argc, char *argv[])
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-c++") == 0) { } else if (strcmp(argv[i],"-c++") == 0) {
CPlusPlus=1; CPlusPlus=1;
Delete(Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0)); Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
Swig_cparse_cplusplus(1); Swig_cparse_cplusplus(1);
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-fcompact") == 0) { } else if (strcmp(argv[i],"-fcompact") == 0) {
@ -461,8 +464,8 @@ void SWIG_getoptions(int argc, char *argv[])
if (!outfile_name_h) { if (!outfile_name_h) {
Printf(basename, ".%s", hpp_extension); Printf(basename, ".%s", hpp_extension);
outfile_name_h = Swig_copy_string(Char(basename)); outfile_name_h = Swig_copy_string(Char(basename));
Delete(basename);
} }
Delete(basename);
} }
Swig_mark_arg(i+1); Swig_mark_arg(i+1);
i++; i++;
@ -651,13 +654,13 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Set up some default symbols (available in both SWIG interface files // Set up some default symbols (available in both SWIG interface files
// and C files) // and C files)
Delete(Preprocessor_define((DOH *) "SWIG 1", 0)); Preprocessor_define((DOH *) "SWIG 1", 0);
Delete(Preprocessor_define((DOH *) "__STDC__", 0)); Preprocessor_define((DOH *) "__STDC__", 0);
#ifdef MACSWIG #ifdef MACSWIG
Delete(Preprocessor_define((DOH *) "SWIGMAC 1", 0)); Preprocessor_define((DOH *) "SWIGMAC 1", 0);
#endif #endif
#ifdef SWIGWIN32 #ifdef SWIGWIN32
Delete(Preprocessor_define((DOH *) "SWIGWIN32 1", 0)); Preprocessor_define((DOH *) "SWIGWIN32 1", 0);
#endif #endif
// Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C // Set the SWIG version value in format 0xAABBCC from package version expected to be in format A.B.C
@ -678,7 +681,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
/* Turn on contracts */ /* Turn on contracts */
Swig_contract_mode_set(1); Swig_contract_mode_set(1);
Delete(Preprocessor_define(vers,0)); Preprocessor_define(vers,0);
/* Turn off directors mode */ /* Turn off directors mode */
Wrapper_director_mode_set(0); Wrapper_director_mode_set(0);
@ -715,7 +718,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
// Define the __cplusplus symbol // Define the __cplusplus symbol
if (CPlusPlus) if (CPlusPlus)
Delete(Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0)); Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0);
// Parse language dependent options // Parse language dependent options
lang->main(argc,argv); lang->main(argc,argv);
@ -827,6 +830,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
} }
Seek(fs,0,SEEK_SET); Seek(fs,0,SEEK_SET);
cpps = Preprocessor_parse(fs); cpps = Preprocessor_parse(fs);
Delete(fs);
} else { } else {
df = Swig_open(input_file); df = Swig_open(input_file);
cpps = NewFileFromFile(df); cpps = NewFileFromFile(df);
@ -965,9 +969,15 @@ int SWIG_main(int argc, char *argv[], Language *l) {
if (dump_xml) { if (dump_xml) {
Swig_print_xml(top, xmlout); Swig_print_xml(top, xmlout);
} }
Delete(top);
} }
if (tm_debug) Swig_typemap_debug(); if (tm_debug) Swig_typemap_debug();
if (memory_debug) DohMemoryDebug(); if (memory_debug) DohMemoryDebug();
// Deletes
Delete(libfiles);
Preprocessor_delete();
while (freeze); while (freeze);

View file

@ -423,6 +423,7 @@ Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *maxargs) {
for (/* empty */; num_braces > 0; num_braces--) for (/* empty */; num_braces > 0; num_braces--)
Printf(f, "}\n"); Printf(f, "}\n");
Printf(f,"}\n"); /* braces closes "if" for this method */ Printf(f,"}\n"); /* braces closes "if" for this method */
Delattr(ni,"wrap:parms");
} }
Delete(dispatch); Delete(dispatch);
return f; return f;

View file

@ -164,7 +164,7 @@ public:
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nortti") == 0) { } else if (strcmp(argv[i],"-nortti") == 0) {
/* Turn on no RTTI mode */ /* Turn on no RTTI mode */
Delete(Preprocessor_define((DOH *) "SWIG_NORTTI", 0)); Preprocessor_define((DOH *) "SWIG_NORTTI", 0);
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-modern") == 0) { } else if (strcmp(argv[i],"-modern") == 0) {
apply = 0; apply = 0;
@ -189,11 +189,11 @@ public:
} }
if (cppcast) { if (cppcast) {
Delete(Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0)); Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
} }
if (!global_name) global_name = NewString("cvar"); if (!global_name) global_name = NewString("cvar");
Delete(Preprocessor_define("SWIGPYTHON 1", 0)); Preprocessor_define("SWIGPYTHON 1", 0);
SWIG_typemap_lang("python"); SWIG_typemap_lang("python");
SWIG_config_file("python.swg"); SWIG_config_file("python.swg");
allow_overloading(); allow_overloading();
@ -2304,6 +2304,7 @@ public:
if (!shadow_list) { if (!shadow_list) {
shadow_list = NewList(); shadow_list = NewList();
Setattr(getCurrentClass(),"shadow_methods", shadow_list); Setattr(getCurrentClass(),"shadow_methods", shadow_list);
Delete(shadow_list);
} }
Append(shadow_list, symname); Append(shadow_list, symname);
} else { } else {
@ -2560,27 +2561,29 @@ public:
Language::membervariableHandler(n); Language::membervariableHandler(n);
shadow = oldshadow; shadow = oldshadow;
String *mname = Swig_name_member(class_name,symname);
String *sname = Swig_name_set(mname);
String *gname = Swig_name_get(mname);
if (shadow) { if (shadow) {
int assignable = is_assignable(n); int assignable = is_assignable(n);
if (!modern) { if (!modern) {
if (assignable) { if (assignable) {
Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", Swig_name_set(Swig_name_member(class_name,symname)), "\n", NIL); Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL);
} }
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", Swig_name_get(Swig_name_member(class_name,symname)),"\n", NIL); Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname,"\n", NIL);
} }
if (!classic) { if (!classic) {
if (!assignable) { if (!assignable) {
Printv(f_shadow,tab4, modern ? "" : "if _newclass:", Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname," = property(", module, ".", gname,")\n", NIL);
symname," = property(", module, ".",
Swig_name_get(Swig_name_member(class_name,symname)),")\n", NIL);
} else { } else {
Printv(f_shadow,tab4, modern ? "" : "if _newclass:", Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname," = property(", module, ".", gname,", ", module, ".", sname,")\n", NIL);
symname," = property(",
module, ".", Swig_name_get(Swig_name_member(class_name,symname)),", ",
module, ".", Swig_name_set(Swig_name_member(class_name,symname)),")\n", NIL);
} }
} }
} }
Delete(mname);
Delete(sname);
Delete(gname);
return SWIG_OK; return SWIG_OK;
} }
@ -2597,7 +2600,9 @@ public:
t = Getattr(n,"type"); t = Getattr(n,"type");
symname = Getattr(n,"sym:name"); symname = Getattr(n,"sym:name");
if (SwigType_isconst(t) && !Getattr(n, "value")) { if (SwigType_isconst(t) && !Getattr(n, "value")) {
Printf(f_shadow_stubs,"%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, Swig_name_member(class_name,symname)); String *mname = Swig_name_member(class_name,symname);
Printf(f_shadow_stubs,"%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname);
Delete(mname);
} }
} }
return SWIG_OK; return SWIG_OK;

View file

@ -2041,10 +2041,11 @@ public:
String *freefunc = NewString(""); String *freefunc = NewString("");
String *freebody = NewString(""); String *freebody = NewString("");
String *pname0 = Swig_cparm_name(0,0);
Printv(freefunc, "free_", klass->mname, NIL); Printv(freefunc, "free_", klass->mname, NIL);
Printv(freebody, "SWIGINTERN void\n", Printv(freebody, "SWIGINTERN void\n",
freefunc, "(", klass->type, " *", Swig_cparm_name(0,0), ") {\n", freefunc, "(", klass->type, " *", pname0, ") {\n",
tab4, NIL); tab4, NIL);
if (Extend) { if (Extend) {
@ -2052,7 +2053,7 @@ public:
if (wrap) { if (wrap) {
Printv(f_wrappers, wrap, NIL); Printv(f_wrappers, wrap, NIL);
} }
/* Printv(freebody, Swig_name_destroy(name), "(", Swig_cparm_name(0,0), ")", NIL); */ /* Printv(freebody, Swig_name_destroy(name), "(", pname0, ")", NIL); */
Printv(freebody,Getattr(n,"wrap:action"), NIL); Printv(freebody,Getattr(n,"wrap:action"), NIL);
} else { } else {
String *action = Getattr(n,"wrap:action"); String *action = Getattr(n,"wrap:action");
@ -2061,14 +2062,14 @@ public:
} else { } else {
/* In the case swig emits no destroy function. */ /* In the case swig emits no destroy function. */
if (CPlusPlus) if (CPlusPlus)
Printf(freebody, "delete %s;\n", Swig_cparm_name(0,0)); Printf(freebody, "delete %s;\n", pname0);
else else
Printf(freebody, "free((char*) %s);\n", Swig_cparm_name(0,0)); Printf(freebody, "free((char*) %s);\n", pname0);
} }
} }
if (GetFlag(n,"feature:trackobjects")) { if (GetFlag(n,"feature:trackobjects")) {
Printf(freebody, " SWIG_RubyRemoveTracking(%s);\n", Swig_cparm_name(0,0)); Printf(freebody, " SWIG_RubyRemoveTracking(%s);\n", pname0);
} }
Printv(freebody, "}\n\n", NIL); Printv(freebody, "}\n\n", NIL);
@ -2078,6 +2079,7 @@ public:
current = NO_CPP; current = NO_CPP;
Delete(freefunc); Delete(freefunc);
Delete(freebody); Delete(freebody);
Delete(pname0);
return SWIG_OK; return SWIG_OK;
} }

View file

@ -198,6 +198,8 @@ int main(int margc, char **margv) {
dl = (fac)(); dl = (fac)();
} }
} }
return SWIG_main(argc,argv,dl); int res = SWIG_main(argc,argv,dl);
delete dl;
return res;
} }

View file

@ -131,7 +131,7 @@ class TypePass : private Dispatcher {
if (first == cls) return; /* The Marcelo check */ if (first == cls) return; /* The Marcelo check */
if (!cls) cls = first; if (!cls) cls = first;
List *alist = 0;
List *ilist = Getattr(cls,bases); List *ilist = Getattr(cls,bases);
if (!ilist) { if (!ilist) {
List *nlist = Getattr(cls,baselist); List *nlist = Getattr(cls,baselist);
@ -184,7 +184,7 @@ class TypePass : private Dispatcher {
bcls = 0; bcls = 0;
} else { } else {
if (Getattr(bcls,"typepass:visit")) { if (Getattr(bcls,"typepass:visit")) {
if (!ilist) ilist = NewList(); if (!ilist) ilist = alist = NewList();
Append(ilist,bcls); Append(ilist,bcls);
} else { } else {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(cls),Getline(cls),"Base class '%s' undefined.\n", bname); Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(cls),Getline(cls),"Base class '%s' undefined.\n", bname);
@ -214,6 +214,8 @@ class TypePass : private Dispatcher {
Setattr(cls,bases,ilist); Setattr(cls,bases,ilist);
} }
} }
if (alist) Delete(alist);
if (!ilist) return; if (!ilist) return;
int len = Len(ilist); int len = Len(ilist);
int i; int i;
@ -269,9 +271,8 @@ class TypePass : private Dispatcher {
append_list(allbases,Getattr(cls,"privatebases")); append_list(allbases,Getattr(cls,"privatebases"));
if (Len(allbases)) { if (Len(allbases)) {
Setattr(cls,"allbases",allbases); Setattr(cls,"allbases",allbases);
} else {
Delete(allbases);
} }
Delete(allbases);
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------

View file

@ -29,6 +29,7 @@ static int imported_depth = 0; /* Depth of %imported files */
static int single_include = 1; /* Only include each file once */ static int single_include = 1; /* Only include each file once */
static Hash *included_files = 0; static Hash *included_files = 0;
static List *dependencies = 0; static List *dependencies = 0;
static SwigScanner *id_scan = 0;
/* Test a character to see if it starts an identifier */ /* Test a character to see if it starts an identifier */
#define isidentifier(c) ((isalpha(c)) || (c == '_') || (c == '$')) #define isidentifier(c) ((isalpha(c)) || (c == '_') || (c == '$'))
@ -72,8 +73,7 @@ copy_location(const DOH *s1, DOH *s2) {
} }
static String *cpp_include(String_or_char *fn, int sysfile) { static String *cpp_include(String_or_char *fn, int sysfile) {
String *s; String *s = sysfile ? Swig_include_sys(fn) : Swig_include(fn);
s = sysfile ? Swig_include_sys(fn) : Swig_include(fn);
if (s && single_include) { if (s && single_include) {
String *file = Getfile(s); String *file = Getfile(s);
if (Getattr(included_files,file)) { if (Getattr(included_files,file)) {
@ -180,9 +180,58 @@ void Preprocessor_init(void) {
cpp = NewHash(); cpp = NewHash();
s = NewHash(); s = NewHash();
Setattr(cpp,k_symbols,s); Setattr(cpp,k_symbols,s);
Delete(s);
Preprocessor_expr_init(); /* Initialize the expression evaluator */ Preprocessor_expr_init(); /* Initialize the expression evaluator */
included_files = NewHash(); included_files = NewHash();
id_scan = NewSwigScanner();;
} }
void Preprocessor_delete(void) {
Delete(k_args);
Delete(k_define);
Delete(k_defined);
Delete(k_else);
Delete(k_elif);
Delete(k_endif);
Delete(k_expanded);
Delete(k_if);
Delete(k_ifdef);
Delete(k_ifndef);
Delete(k_name);
Delete(k_swigmacro);
Delete(k_symbols);
Delete(k_undef);
Delete(k_value);
Delete(k_error);
Delete(k_warning);
Delete(k_pragma);
Delete(k_level);
Delete(k_line);
Delete(k_include);
Delete(k_varargs);
Delete(k_dinclude);
Delete(k_dimport);
Delete(k_dextern);
Delete(k_ddefine);
Delete(k_dline);
Delete(k_LINE);
Delete(k_FILE);
Delete(cpp);
Delete(included_files);
Preprocessor_expr_delete();
DelSwigScanner(id_scan);
Delete(dependencies);
Delete(Swig_last_file());
Delete(Swig_add_directory(0));
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* void Preprocessor_include_all() - Instruct preprocessor to include all files * void Preprocessor_include_all() - Instruct preprocessor to include all files
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -418,7 +467,7 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
/* Go create the macro */ /* Go create the macro */
macro = NewHash(); macro = NewHash();
Setattr(macro,k_name, macroname); Setattr(macro,k_name,macroname);
if (arglist) { if (arglist) {
Setattr(macro,k_args,arglist); Setattr(macro,k_args,arglist);
@ -428,7 +477,6 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
} }
} }
Setattr(macro,k_value,macrovalue); Setattr(macro,k_value,macrovalue);
Delete(macrovalue);
Setline(macro,line); Setline(macro,line);
Setfile(macro,file); Setfile(macro,file);
if (swigmacro) { if (swigmacro) {
@ -441,9 +489,13 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
Swig_error(Getfile(m1),Getline(m1),"previous definition of '%s'.\n",macroname); Swig_error(Getfile(m1),Getline(m1),"previous definition of '%s'.\n",macroname);
goto macro_error; goto macro_error;
} }
} else {
Setattr(symbols,macroname,macro);
Delete(macro);
} }
Setattr(symbols,macroname,macro);
Delete(macroname); Delete(macroname);
Delete(macrovalue);
Delete(str); Delete(str);
Delete(argstr); Delete(argstr);
@ -454,6 +506,7 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro)
Delete(argstr); Delete(argstr);
Delete(arglist); Delete(arglist);
Delete(macroname); Delete(macroname);
Delete(macrovalue);
return 0; return 0;
} }
@ -1056,16 +1109,12 @@ Preprocessor_replace(DOH *s)
static int static int
check_id(DOH *s) check_id(DOH *s)
{ {
static SwigScanner *scan = 0;
int c; int c;
int hastok = 0; int hastok = 0;
SwigScanner *scan = id_scan;
Seek(s,0,SEEK_SET); Seek(s,0,SEEK_SET);
if (!scan) {
scan = NewSwigScanner();
}
SwigScanner_clear(scan); SwigScanner_clear(scan);
s = Copy(s); s = Copy(s);
Seek(s,SEEK_SET,0); Seek(s,SEEK_SET,0);
@ -1113,8 +1162,7 @@ static void add_chunk(DOH *ns, DOH *chunk, int allow) {
static void static void
push_imported() { push_imported() {
if (imported_depth == 0) { if (imported_depth == 0) {
DOH *m = Preprocessor_define("SWIGIMPORTED 1", 0); Preprocessor_define("SWIGIMPORTED 1", 0);
Delete(m);
} }
++imported_depth; ++imported_depth;
} }
@ -1145,10 +1193,10 @@ String *
Preprocessor_parse(String *s) Preprocessor_parse(String *s)
{ {
String *ns; /* New string containing the preprocessed text */ String *ns; /* New string containing the preprocessed text */
String *chunk, *sval, *decl; String *chunk, *decl;
Hash *symbols; Hash *symbols;
String *id = 0, *value = 0, *comment = 0; String *id = 0, *value = 0, *comment = 0;
int i, state, val, e, c; int i, state, e, c;
int start_line = 0; int start_line = 0;
int allow = 1; int allow = 1;
int level = 0; int level = 0;
@ -1371,7 +1419,6 @@ Preprocessor_parse(String *s)
} }
Delete(v); Delete(v);
} }
Delete(m);
} }
} else if (StringEqual(id,k_undef)) { } else if (StringEqual(id,k_undef)) {
if (allow) Preprocessor_undef(value); if (allow) Preprocessor_undef(value);
@ -1420,8 +1467,9 @@ Preprocessor_parse(String *s)
cond_lines[level] = Getline(id); cond_lines[level] = Getline(id);
level++; level++;
if (allow) { if (allow) {
int val;
String *sval = Preprocessor_replace(value);
start_level = level; start_level = level;
sval = Preprocessor_replace(value);
Seek(sval,0,SEEK_SET); Seek(sval,0,SEEK_SET);
/* Printf(stdout,"Evaluating '%s'\n", sval); */ /* Printf(stdout,"Evaluating '%s'\n", sval); */
val = Preprocessor_expr(sval,&e); val = Preprocessor_expr(sval,&e);
@ -1447,7 +1495,8 @@ Preprocessor_parse(String *s)
allow = 0; allow = 0;
mask = 0; mask = 0;
} else if (level == start_level) { } else if (level == start_level) {
sval = Preprocessor_replace(value); int val;
String *sval = Preprocessor_replace(value);
Seek(sval,0,SEEK_SET); Seek(sval,0,SEEK_SET);
val = Preprocessor_expr(sval,&e); val = Preprocessor_expr(sval,&e);
if (e) { if (e) {
@ -1689,7 +1738,7 @@ Preprocessor_parse(String *s)
} }
if (allow) { if (allow) {
Seek(value,0,SEEK_SET); Seek(value,0,SEEK_SET);
Delete(Preprocessor_define(value,1)); Preprocessor_define(value,1);
} }
StringPutc('\n',ns); StringPutc('\n',ns);
addline(ns,value,0); addline(ns,value,0);

View file

@ -226,6 +226,13 @@ Preprocessor_expr_init (void) {
if (!scan) scan = NewSwigScanner(); if (!scan) scan = NewSwigScanner();
} }
void
Preprocessor_expr_delete (void) {
SwigScanner_clear(scan);
DelSwigScanner(scan);
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Tokenizer * Tokenizer
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */

View file

@ -24,12 +24,14 @@ extern char *Preprocessor_expr_error(void);
extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro); extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro);
extern void Preprocessor_undef(const String_or_char *name); extern void Preprocessor_undef(const String_or_char *name);
extern void Preprocessor_init(void); extern void Preprocessor_init(void);
extern void Preprocessor_delete(void);
extern String *Preprocessor_parse(String *s); extern String *Preprocessor_parse(String *s);
extern void Preprocessor_include_all(int); extern void Preprocessor_include_all(int);
extern void Preprocessor_import_all(int); extern void Preprocessor_import_all(int);
extern void Preprocessor_ignore_missing(int); extern void Preprocessor_ignore_missing(int);
extern List *Preprocessor_depend(void); extern List *Preprocessor_depend(void);
extern void Preprocessor_expr_init(void); extern void Preprocessor_expr_init(void);
extern void Preprocessor_expr_delete(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -87,7 +87,7 @@ Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value
Delete(lstrn); Delete(lstrn);
} else { } else {
String *lstrname = SwigType_lstr(t,name); String *lstrname = SwigType_lstr(t,name);
Printf(decl,"%s", lstrname); Append(decl,lstrname);
Delete(lstrname); Delete(lstrname);
} }
} }
@ -156,34 +156,19 @@ Swig_wrapped_var_assign(SwigType *t, const String_or_char *name) {
* argument behaviour is required. * argument behaviour is required.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int Swig_cargs(Wrapper *w, ParmList *p) { int Swig_cargs(Wrapper *w, ParmList *p) {
int i; int i = 0;
SwigType *pt; int compactdefargs = ParmList_is_compactdefargs(p);
String *pvalue;
String *pname;
String *local;
String *lname;
SwigType *altty;
String *type;
int tycode;
int compactdefargs = ParmList_is_compactdefargs(p);
i = 0;
while (p != 0) { while (p != 0) {
lname = Swig_cparm_name(p,i); String *lname = Swig_cparm_name(p,i);
pt = Getattr(p,"type"); SwigType *pt = Getattr(p,"type");
if ((SwigType_type(pt) != T_VOID)) { if ((SwigType_type(pt) != T_VOID)) {
pname = Getattr(p,"name"); String *local = 0;
String *type = Getattr(p,"type");
/* default values only emitted if in compact default args mode */ /* default values only emitted if in compact default args mode */
if (compactdefargs) String *pvalue = (compactdefargs) ? Getattr(p,"value") : 0;
pvalue = Getattr(p,"value"); SwigType *altty = SwigType_alttype(type,0);
else int tycode = SwigType_type(type);
pvalue = 0;
type = Getattr(p,"type");
altty = SwigType_alttype(type,0);
tycode = SwigType_type(type);
if (tycode == T_REFERENCE) { if (tycode == T_REFERENCE) {
if (pvalue) { if (pvalue) {
SwigType *tvalue; SwigType *tvalue;
@ -222,8 +207,10 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
Delete(altty); Delete(altty);
} }
Wrapper_add_localv(w,lname,local,NIL); Wrapper_add_localv(w,lname,local,NIL);
Delete(local);
i++; i++;
} }
Delete(lname);
p = nextSibling(p); p = nextSibling(p);
} }
return(i); return(i);
@ -272,13 +259,15 @@ String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_ch
{ {
char *c = Char(decl) + Len(decl) - 1; char *c = Char(decl) + Len(decl) - 1;
if (!((*c == ';') || (*c == '}'))) if (!((*c == ';') || (*c == '}')))
Printf(fcall, ";"); Append(fcall, ";");
} }
Printf(fcall,"\n"); Append(fcall,"\n");
if (SwigType_type(t) == T_REFERENCE) { if (SwigType_type(t) == T_REFERENCE) {
Printf(fcall,"%s = (%s) &_result_ref;\n", name, SwigType_lstr(t,0)); String *lstr = SwigType_lstr(t,0);
Printf(fcall,"}\n"); Printf(fcall,"%s = (%s) &_result_ref;\n", name, lstr);
Append(fcall,"}\n");
Delete(lstr);
} }
return fcall; return fcall;
} }
@ -333,9 +322,9 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) {
String *rcaststr = SwigType_rcaststr(rpt, pname); String *rcaststr = SwigType_rcaststr(rpt, pname);
if (comma) { if (comma) {
Printf(func, ",%s", rcaststr); Printv(func, ",", rcaststr, NIL);
} else { } else {
Printf(func, "%s", rcaststr); Append(func,rcaststr);
} }
Delete(rpt); Delete(rpt);
Delete(pname); Delete(pname);
@ -369,23 +358,28 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self) {
SwigType *pt; SwigType *pt;
int comma = 0; int comma = 0;
if (!self) self = (char *) "(this)->";
func = NewStringEmpty(); func = NewStringEmpty();
nname = SwigType_namestr(name);
if (!p) return func; if (!p) return func;
if (!self) self = (char *) "(this)->";
Append(func,self); Append(func,self);
nname = SwigType_namestr(name);
pt = Getattr(p,"type"); pt = Getattr(p,"type");
/* If the method is invoked through a dereferenced pointer, we don't add any casts /* If the method is invoked through a dereferenced pointer, we don't add any casts
(needed for smart pointers). Otherwise, we cast to the appropriate type */ (needed for smart pointers). Otherwise, we cast to the appropriate type */
if (Strstr(func,"*this")) { if (Strstr(func,"*this")) {
Replaceall(func,"this", Swig_cparm_name(p,0)); String *pname = Swig_cparm_name(p,0);
Replaceall(func,"this", pname);
Delete(pname);
} else { } else {
String *rcaststr = SwigType_rcaststr(pt, Swig_cparm_name(p,0)); String *pname = Swig_cparm_name(p,0);
String *rcaststr = SwigType_rcaststr(pt, pname);
Replaceall(func,"this", rcaststr); Replaceall(func,"this", rcaststr);
Delete(rcaststr); Delete(rcaststr);
Delete(pname);
} }
/* /*
@ -407,9 +401,10 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self) {
if ((SwigType_type(pt) != T_VOID)) { if ((SwigType_type(pt) != T_VOID)) {
String *pname = Swig_cparm_name(p,i); String *pname = Swig_cparm_name(p,i);
String *rcaststr = SwigType_rcaststr(pt, pname); String *rcaststr = SwigType_rcaststr(pt, pname);
if (comma) Printf(func,","); if (comma) Append(func,",");
Printf(func,"%s", rcaststr); Append(func,rcaststr);
Delete(rcaststr); Delete(rcaststr);
Delete(pname);
comma = 1; comma = 1;
i++; i++;
} }
@ -464,10 +459,11 @@ Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_se
func = NewStringEmpty(); func = NewStringEmpty();
Printf(func,"new %s(", nname); Printf(func,"new %s(", nname);
while (p) { while (p) {
String *pname;
pt = Getattr(p,"type"); pt = Getattr(p,"type");
if ((SwigType_type(pt) != T_VOID)) { if ((SwigType_type(pt) != T_VOID)) {
if (comma) Printf(func,","); String *rcaststr = 0;
String *pname = 0;
if (comma) Append(func,",");
if (!Getattr(p, "arg:byname")) { if (!Getattr(p, "arg:byname")) {
pname = Swig_cparm_name(p,i); pname = Swig_cparm_name(p,i);
i++; i++;
@ -477,12 +473,15 @@ Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_se
else else
pname = Copy(Getattr(p, "name")); pname = Copy(Getattr(p, "name"));
} }
Printf(func,"%s", SwigType_rcaststr(pt, pname)); rcaststr = SwigType_rcaststr(pt, pname);
comma = 1; Append(func,rcaststr);
Delete(rcaststr);
comma = 1;
Delete(pname);
} }
p = nextSibling(p); p = nextSibling(p);
} }
Printf(func,")"); Append(func,")");
Delete(nname); Delete(nname);
return func; return func;
} }
@ -567,9 +566,11 @@ Swig_unref_call(Node *n) {
Node *cn = Swig_methodclass(n); Node *cn = Swig_methodclass(n);
String* unref = Swig_rflag_search(cn,"feature:unref","feature:nounref"); String* unref = Swig_rflag_search(cn,"feature:unref","feature:nounref");
if (unref) { if (unref) {
String *pname = Swig_cparm_name(0,0);
unref = NewString(unref); unref = NewString(unref);
Replaceall(unref,"$this",Swig_cparm_name(0,0)); Replaceall(unref,"$this",pname);
Replaceall(unref,"$self",Swig_cparm_name(0,0)); Replaceall(unref,"$self",pname);
Delete(pname);
} }
return unref; return unref;
} }
@ -603,9 +604,15 @@ Swig_ref_call(Node *n, const String* lname) {
String * String *
Swig_cdestructor_call(Node *n) { Swig_cdestructor_call(Node *n) {
String* unref = Swig_unref_call(n); String* unref = Swig_unref_call(n);
if (unref) return unref;
return NewStringf("free((char *) %s);",Swig_cparm_name(0,0)); if (unref) {
return unref;
} else {
String *pname = Swig_cparm_name(0,0);
String *call = NewStringf("free((char *) %s);",pname);
Delete(pname);
return call;
}
} }
@ -620,9 +627,14 @@ Swig_cdestructor_call(Node *n) {
String * String *
Swig_cppdestructor_call(Node *n) { Swig_cppdestructor_call(Node *n) {
String* unref = Swig_unref_call(n); String* unref = Swig_unref_call(n);
if (unref) return unref; if (unref) {
return unref;
return NewStringf("delete %s;",Swig_cparm_name(0,0)); } else {
String *pname = Swig_cparm_name(0,0);
String *call = NewStringf("delete %s;",pname);
Delete(pname);
return call;
}
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -637,20 +649,25 @@ Swig_cppdestructor_call(Node *n) {
String * String *
Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self) { Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self) {
String *func; String *func;
String *pname0 = Swig_cparm_name(0,0);
String *pname1 = Swig_cparm_name(0,1);
func = NewStringEmpty(); func = NewStringEmpty();
if (!self) self = NewString("(this)->"); if (!self) self = NewString("(this)->");
else self = NewString(self); else self = NewString(self);
Replaceall(self,"this",Swig_cparm_name(0,0)); Replaceall(self,"this",pname0);
if (SwigType_type(type) != T_ARRAY) { if (SwigType_type(type) != T_ARRAY) {
if (!Strstr(type,"enum $unnamed")) { if (!Strstr(type,"enum $unnamed")) {
Printf(func,"if (%s) %s%s = %s",Swig_cparm_name(0,0), self,name, String *dref = Swig_wrapped_var_deref(type, pname1);
Swig_wrapped_var_deref(type, Swig_cparm_name(0,1))); Printf(func,"if (%s) %s%s = %s",pname0, self,name,dref);
Delete(dref);
} else { } else {
Printf(func,"if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", Printf(func,"if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s",
Swig_cparm_name(0,0), self, name, self, name, Swig_cparm_name(0,1)); pname0, self, name, self, name, pname1);
} }
} }
Delete(self); Delete(self);
Delete(pname0);
Delete(pname1);
return(func); return(func);
} }
@ -668,12 +685,17 @@ String *
Swig_cmemberget_call(const String_or_char *name, SwigType *t, Swig_cmemberget_call(const String_or_char *name, SwigType *t,
String_or_char *self) { String_or_char *self) {
String *func; String *func;
String *call;
String *pname0 = Swig_cparm_name(0,0);
if (!self) self = NewString("(this)->"); if (!self) self = NewString("(this)->");
else self = NewString(self); else self = NewString(self);
Replaceall(self,"this",Swig_cparm_name(0,0)); Replaceall(self,"this",pname0);
func = NewStringEmpty(); func = NewStringEmpty();
Printf(func,"%s (%s%s)", Swig_wrapped_var_assign(t,""),self, name); call = Swig_wrapped_var_assign(t,"");
Printf(func,"%s (%s%s)", call,self, name);
Delete(self); Delete(self);
Delete(call);
Delete(pname0);
return func; return func;
} }
@ -783,10 +805,10 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
/* Generate action code for the access */ /* Generate action code for the access */
if (!(flags & CWRAP_EXTEND)) { if (!(flags & CWRAP_EXTEND)) {
String *call = Swig_cmethod_call(name,p,self); String *call = Swig_cmethod_call(name,p,self);
String *result = Swig_cresult(Getattr(n,"type"),"result", call); String *cres = Swig_cresult(Getattr(n,"type"),"result", call);
Setattr(n,"wrap:action", result); Setattr(n,"wrap:action", cres);
Delete(call); Delete(call);
Delete(result); Delete(cres);
} else { } else {
/* Methods with default arguments are wrapped with additional methods for each default argument, /* Methods with default arguments are wrapped with additional methods for each default argument,
* however, only one extra %extend method is generated. */ * however, only one extra %extend method is generated. */
@ -816,10 +838,14 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
int i = 0; int i = 0;
Parm *pp = p; Parm *pp = p;
String *func = NewStringf("%s(", mangled); String *func = NewStringf("%s(", mangled);
String *cres;
if (Cmp(Getattr(n,"storage"),"static") != 0) { if (Cmp(Getattr(n,"storage"),"static") != 0) {
String *fadd = NewStringf("(%s*)(%s)->operator ->()", cname, Swig_cparm_name(pp,i)); String *pname = Swig_cparm_name(pp,i);
String *fadd = NewStringf("(%s*)(%s)->operator ->()", cname, pname);
Append(func,fadd); Append(func,fadd);
Delete(fadd); Delete(fadd);
Delete(pname);
pp = nextSibling(pp); pp = nextSibling(pp);
if (pp) Append(func,","); if (pp) Append(func,",");
} else{ } else{
@ -839,9 +865,15 @@ Swig_MethodToFunction(Node *n, String *classname, int flags) {
} }
} }
Append(func,")"); Append(func,")");
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", func)); cres = Swig_cresult(Getattr(n,"type"),"result", func);
Setattr(n,"wrap:action", cres);
Delete(cres);
} else { } else {
Setattr(n,"wrap:action", Swig_cresult(Getattr(n,"type"),"result", Swig_cfunction_call(mangled,p))); String *call = Swig_cfunction_call(mangled,p);
String *cres = Swig_cresult(Getattr(n,"type"),"result", call);
Setattr(n,"wrap:action", cres);
Delete(call);
Delete(cres);
} }
Delete(membername); Delete(membername);
@ -962,7 +994,8 @@ Swig_ConstructorToFunction(Node *n, String *classname,
if (flags & CWRAP_EXTEND) { if (flags & CWRAP_EXTEND) {
/* Constructors with default arguments are wrapped with additional constructor methods for each default argument, /* Constructors with default arguments are wrapped with additional constructor methods for each default argument,
* however, only one extra %extend method is generated. */ * however, only one extra %extend method is generated. */
String *call;
String *cres;
String *defaultargs = Getattr(n,"defaultargs"); String *defaultargs = Getattr(n,"defaultargs");
String *code = Getattr(n,"code"); String *code = Getattr(n,"code");
String *membername = Swig_name_construct(classname); String *membername = Swig_name_construct(classname);
@ -979,9 +1012,12 @@ Swig_ConstructorToFunction(Node *n, String *classname,
if (!defaultargs && code) { if (!defaultargs && code) {
Swig_add_extension_code(n, mangled, parms, type, code, cparse_cplusplus); Swig_add_extension_code(n, mangled, parms, type, code, cparse_cplusplus);
} }
Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cfunction_call(mangled,parms))); call = Swig_cfunction_call(mangled,parms);
cres = Swig_cresult(type,"result", call);
Setattr(n,"wrap:action", cres);
Delete(cres);
Delete(call);
Delete(membername); Delete(membername);
Delete(mangled); Delete(mangled);
} else { } else {
@ -1009,7 +1045,9 @@ Swig_ConstructorToFunction(Node *n, String *classname,
* implemented in the target language, calls to those methods will * implemented in the target language, calls to those methods will
* generate Swig::DirectorPureVirtualException exceptions. * generate Swig::DirectorPureVirtualException exceptions.
*/ */
Append(action, Swig_cresult(type, "result", director_call)); String *cres = Swig_cresult(type, "result", director_call);
Append(action, cres);
Delete(cres);
} else { } else {
/* (scottm): The code for creating a new director is now a string /* (scottm): The code for creating a new director is now a string
template that gets passed in via the director_ctor argument. template that gets passed in via the director_ctor argument.
@ -1018,22 +1056,35 @@ Swig_ConstructorToFunction(Node *n, String *classname,
$director_new: Call new for director class $director_new: Call new for director class
$nondirector_new: Call new for non-director class $nondirector_new: Call new for non-director class
*/ */
String *cres;
Append(action, director_ctor); Append(action, director_ctor);
Replaceall( action, "$comparison", tmp_none_comparison); Replaceall( action, "$comparison", tmp_none_comparison);
Replaceall( action, "$director_new",
Swig_cresult(type, "result", director_call) ); cres = Swig_cresult(type, "result", director_call);
Replaceall( action, "$nondirector_new", Replaceall( action, "$director_new",cres);
Swig_cresult(type, "result", nodirector_call) ); Delete(cres);
cres = Swig_cresult(type, "result", nodirector_call);
Replaceall( action, "$nondirector_new", cres);
Delete(cres);
} }
Setattr(n, "wrap:action", action); Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison); Delete(tmp_none_comparison);
Delete(action); Delete(action);
Delete(directorname); Delete(directorname);
} else { } else {
Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cppconstructor_call(classname,parms))); String *call = Swig_cppconstructor_call(classname,parms);
String *cres = Swig_cresult(type,"result", call);
Setattr(n,"wrap:action", cres);
Delete(cres);
Delete(call);
} }
} else { } else {
Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cconstructor_call(classname))); String *call = Swig_cconstructor_call(classname);
String *cres = Swig_cresult(type,"result", call);
Setattr(n,"wrap:action", cres);
Delete(cres);
Delete(call);
} }
} }
Setattr(n,"type",type); Setattr(n,"type",type);
@ -1065,6 +1116,8 @@ Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags)
type = NewString("void"); type = NewString("void");
if (flags & CWRAP_EXTEND) { if (flags & CWRAP_EXTEND) {
String *cres;
String *call;
String *membername, *mangled, *code; String *membername, *mangled, *code;
membername = Swig_name_destroy(classname); membername = Swig_name_destroy(classname);
mangled = Swig_name_mangle(membername); mangled = Swig_name_mangle(membername);
@ -1072,14 +1125,26 @@ Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags)
if (code) { if (code) {
Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus); Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus);
} }
Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cfunction_call(mangled,p))); call = Swig_cfunction_call(mangled,p);
cres = NewStringf("%s;\n", call);
Setattr(n,"wrap:action", cres);
Delete(membername); Delete(membername);
Delete(mangled); Delete(mangled);
Delete(call);
Delete(cres);
} else { } else {
if (cplus) { if (cplus) {
Setattr(n,"wrap:action", NewStringf("%s\n",Swig_cppdestructor_call(n))); String *call = Swig_cppdestructor_call(n);
String *cres = NewStringf("%s\n",call);
Setattr(n,"wrap:action", cres);
Delete(call);
Delete(cres);
} else { } else {
Setattr(n,"wrap:action", NewStringf("%s\n", Swig_cdestructor_call(n))); String *call = Swig_cdestructor_call(n);
String *cres = NewStringf("%s\n", call);
Setattr(n,"wrap:action", cres);
Delete(call);
Delete(cres);
} }
} }
Setattr(n,"type",type); Setattr(n,"type",type);
@ -1107,6 +1172,8 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
String *membername; String *membername;
String *mangled; String *mangled;
String *self= 0; String *self= 0;
String *sname;
varref = flags & CWRAP_VAR_REFERENCE; varref = flags & CWRAP_VAR_REFERENCE;
if (flags & CWRAP_SMART_POINTER) { if (flags & CWRAP_SMART_POINTER) {
@ -1116,7 +1183,8 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
name = Getattr(n,"name"); name = Getattr(n,"name");
type = Getattr(n,"type"); type = Getattr(n,"type");
membername = Swig_name_member(classname, Swig_name_set(name)); sname = Swig_name_set(name);
membername = Swig_name_member(classname, sname);
mangled = Swig_name_mangle(membername); mangled = Swig_name_mangle(membername);
t = NewString(classname); t = NewString(classname);
@ -1135,13 +1203,23 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
Delete(p); Delete(p);
if (flags & CWRAP_EXTEND) { if (flags & CWRAP_EXTEND) {
String *call;
String *cres;
String *code = Getattr(n,"code"); String *code = Getattr(n,"code");
if (code) { if (code) {
Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus); Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus);
} }
Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cfunction_call(mangled,parms))); call = Swig_cfunction_call(mangled,parms);
cres = NewStringf("%s;\n", call);
Setattr(n,"wrap:action", cres);
Delete(call);
Delete(cres);
} else { } else {
Setattr(n,"wrap:action", NewStringf("%s;\n", Swig_cmemberset_call(name,type,self))); String *call = Swig_cmemberset_call(name,type,self);
String *cres = NewStringf("%s;\n", call);
Setattr(n,"wrap:action", cres);
Delete(call);
Delete(cres);
} }
Setattr(n,"type",void_type); Setattr(n,"type",void_type);
Setattr(n,"parms", parms); Setattr(n,"parms", parms);
@ -1149,6 +1227,7 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) {
Delete(ty); Delete(ty);
Delete(void_type); Delete(void_type);
Delete(membername); Delete(membername);
Delete(sname);
Delete(mangled); Delete(mangled);
Delete(self); Delete(self);
varref = 0; varref = 0;
@ -1171,6 +1250,7 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
String *membername; String *membername;
String *mangled; String *mangled;
String *self = 0; String *self = 0;
String *gname;
varref = flags & CWRAP_VAR_REFERENCE; varref = flags & CWRAP_VAR_REFERENCE;
if (flags & CWRAP_SMART_POINTER) { if (flags & CWRAP_SMART_POINTER) {
@ -1185,8 +1265,9 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
name = Getattr(n,"name"); name = Getattr(n,"name");
type = Getattr(n,"type"); type = Getattr(n,"type");
membername = Swig_name_member(classname, Swig_name_get(name)); gname = Swig_name_get(name);
membername = Swig_name_member(classname, gname);
mangled = Swig_name_mangle(membername); mangled = Swig_name_mangle(membername);
t = NewString(classname); t = NewString(classname);
@ -1196,19 +1277,31 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) {
ty = Swig_wrapped_var_type(type); ty = Swig_wrapped_var_type(type);
if (flags & CWRAP_EXTEND) { if (flags & CWRAP_EXTEND) {
String *call;
String *cres;
String *code = Getattr(n,"code"); String *code = Getattr(n,"code");
if (code) { if (code) {
Swig_add_extension_code(n, mangled, parms, ty, code, cparse_cplusplus); Swig_add_extension_code(n, mangled, parms, ty, code, cparse_cplusplus);
} }
Setattr(n,"wrap:action", Swig_cresult(ty,"result",Swig_cfunction_call(mangled,parms))); call = Swig_cfunction_call(mangled,parms);
cres = Swig_cresult(ty,"result",call);
Setattr(n,"wrap:action", cres);
Delete(cres);
Delete(call);
} else { } else {
Setattr(n,"wrap:action", Swig_cresult(ty,"result",Swig_cmemberget_call(name,type,self))); String *call = Swig_cmemberget_call(name,type,self);
String *cres = Swig_cresult(ty,"result",call);
Setattr(n,"wrap:action", cres);
Delete(call);
Delete(cres);
} }
Setattr(n,"type",ty); Setattr(n,"type",ty);
Setattr(n,"parms", parms); Setattr(n,"parms", parms);
Delete(parms); Delete(parms);
Delete(ty); Delete(ty);
Delete(membername); Delete(membername);
Delete(gname);
Delete(mangled); Delete(mangled);
varref = 0; varref = 0;
return SWIG_OK; return SWIG_OK;
@ -1236,9 +1329,18 @@ Swig_VarsetToFunction(Node *n) {
Delete(ty); Delete(ty);
if (!Strstr(type,"enum $unnamed")) { if (!Strstr(type,"enum $unnamed")) {
Setattr(n,"wrap:action", NewStringf("%s = %s;\n", nname, Swig_wrapped_var_deref(type,Swig_cparm_name(0,0)))); String *pname = Swig_cparm_name(0,0);
String *dref = Swig_wrapped_var_deref(type,pname);
String *call = NewStringf("%s = %s;\n", nname, dref);
Setattr(n,"wrap:action", call);
Delete(call);
Delete(dref);
Delete(pname);
} else { } else {
Setattr(n,"wrap:action", NewStringf("if (sizeof(int) == sizeof(%s)) *(int*)(void*)&(%s) = %s;\n", nname, nname, Swig_cparm_name(0,0))); String *pname = Swig_cparm_name(0,0);
String *call = NewStringf("if (sizeof(int) == sizeof(%s)) *(int*)(void*)&(%s) = %s;\n", nname, nname, pname);
Setattr(n,"wrap:action", call);
Delete(call);
} }
Setattr(n,"type","void"); Setattr(n,"type","void");
Setattr(n,"parms",parms); Setattr(n,"parms",parms);
@ -1255,6 +1357,7 @@ Swig_VarsetToFunction(Node *n) {
int int
Swig_VargetToFunction(Node *n) { Swig_VargetToFunction(Node *n) {
String *cres, *call;
String *name, *nname; String *name, *nname;
SwigType *type, *ty; SwigType *type, *ty;
@ -1263,8 +1366,11 @@ Swig_VargetToFunction(Node *n) {
nname = SwigType_namestr(name); nname = SwigType_namestr(name);
ty = Swig_wrapped_var_type(type); ty = Swig_wrapped_var_type(type);
call = Swig_wrapped_var_assign(type,nname);
Setattr(n,"wrap:action", Swig_cresult(ty,"result",Swig_wrapped_var_assign(type,nname))); cres = Swig_cresult(ty,"result",call);
Setattr(n,"wrap:action", cres);
Delete(cres);
Delete(call);
Setattr(n,"type",ty); Setattr(n,"type",ty);
Delattr(n,"parms"); Delattr(n,"parms");
Delete(nname); Delete(nname);

View file

@ -68,15 +68,19 @@ Swig_swiglib_get() {
* Adds a directory to the SWIG search path. * Adds a directory to the SWIG search path.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void List *
Swig_add_directory(const String_or_char *dirname) { Swig_add_directory(const String_or_char *dirname) {
String *dir = 0; String *dir = 0;
if (!directories) directories = NewList(); if (!directories) directories = NewList();
assert(directories); assert(directories);
dir = NewString((char *) dirname); if (dirname) {
assert(dir); dir = NewString((char *) dirname);
Setattr(dir,"sysdir","1"); assert(dir);
Append(directories, dir); Setattr(dir,"sysdir","1");
Append(directories, dir);
Delete(dir);
}
return directories;
} }

View file

@ -537,10 +537,13 @@ Swig_name_object_inherit(Hash *namehash, String *base, String *derived) {
if (!newh) { if (!newh) {
newh = NewHash(); newh = NewHash();
Setattr(namehash,nkey,newh); Setattr(namehash,nkey,newh);
Delete(newh);
} }
for (oi = First(n); oi.key; oi = Next(oi)) { for (oi = First(n); oi.key; oi = Next(oi)) {
if (!Getattr(newh,oi.key)) { if (!Getattr(newh,oi.key)) {
Setattr(newh,oi.key,Copy(oi.item)); String *ci = Copy(oi.item);
Setattr(newh,oi.key,ci);
Delete(ci);
} }
} }
} }
@ -700,8 +703,10 @@ Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, con
} else { } else {
fhash = Getattr(n,decl); fhash = Getattr(n,decl);
if (!fhash) { if (!fhash) {
String *cdecl = Copy(decl);
fhash = NewHash(); fhash = NewHash();
Setattr(n,Copy(decl),fhash); Setattr(n,cdecl,fhash);
Delete(cdecl);
Delete(fhash); Delete(fhash);
} }
} }

View file

@ -355,7 +355,7 @@ void SwigType_add_default(String *def, SwigType *nr)
SwigType *SwigType_default(SwigType *t) { SwigType *SwigType_default(SwigType *t) {
String *r1, *def; String *r1, *def, *cdef;
String *r = 0; String *r = 0;
char *cr; char *cr;
@ -440,10 +440,10 @@ SwigType *SwigType_default(SwigType *t) {
#ifdef SWIG_NEW_TYPE_DEFAULT #ifdef SWIG_NEW_TYPE_DEFAULT
SwigType_del_array(nr); SwigType_del_array(nr);
SwigType_add_default(def, nr); SwigType_add_default(def, nr);
Delete(nr);
#else #else
Append(def,"SWIGTYPE"); Append(def,"SWIGTYPE");
#endif #endif
Delete(nr);
} }
} else if (SwigType_ismemberpointer(r)) { } else if (SwigType_ismemberpointer(r)) {
if (strcmp(cr,"m(CLASS).SWIGTYPE") == 0) { if (strcmp(cr,"m(CLASS).SWIGTYPE") == 0) {
@ -469,7 +469,9 @@ SwigType *SwigType_default(SwigType *t) {
if (r != t) Delete(r); if (r != t) Delete(r);
#ifdef SWIG_DEFAULT_CACHE #ifdef SWIG_DEFAULT_CACHE
/* The cache produces strange results, see enum_template.i case */ /* The cache produces strange results, see enum_template.i case */
Setattr(default_cache,t,Copy(def)); cdef = Copy(def);
Setattr(default_cache,t, cdef);
Delete(cdef);
#endif #endif
if (StringEqual(def,t)) { if (StringEqual(def,t)) {
Delete(def); Delete(def);
@ -1055,6 +1057,7 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) {
} }
Clear(t); Clear(t);
Append(t,nt); Append(t,nt);
Delete(nt);
Delete(elem); Delete(elem);
} }

View file

@ -97,7 +97,7 @@ typedef DOH SwigType;
/* --- File interface --- */ /* --- File interface --- */
extern void Swig_add_directory(const String_or_char *dirname); extern List *Swig_add_directory(const String_or_char *dirname);
extern void Swig_push_directory(const String_or_char *dirname); extern void Swig_push_directory(const String_or_char *dirname);
extern void Swig_pop_directory(); extern void Swig_pop_directory();
extern String *Swig_last_file(); extern String *Swig_last_file();

View file

@ -277,11 +277,14 @@ Swig_symbol_init() {
ccurrent = NewHash(); ccurrent = NewHash();
set_nodeType(current_symtab,k_symboltable); set_nodeType(current_symtab,k_symboltable);
Setattr(current_symtab,k_symtab,current); Setattr(current_symtab,k_symtab,current);
Delete(current);
Setattr(current_symtab,k_csymtab, ccurrent); Setattr(current_symtab,k_csymtab, ccurrent);
Delete(ccurrent);
/* Set the global scope */ /* Set the global scope */
symtabs = NewHash(); symtabs = NewHash();
Setattr(symtabs,empty_string,current_symtab); Setattr(symtabs,empty_string,current_symtab);
Delete(current_symtab);
global_scope = current_symtab; global_scope = current_symtab;
} }
@ -378,6 +381,7 @@ Swig_symbol_newscope()
set_nodeType(h,k_symboltable); set_nodeType(h,k_symboltable);
Setattr(h,k_symtab,hsyms); Setattr(h,k_symtab,hsyms);
Delete(hsyms);
set_parentNode(h,current_symtab); set_parentNode(h,current_symtab);
n = lastChild(current_symtab); n = lastChild(current_symtab);
@ -390,8 +394,9 @@ Swig_symbol_newscope()
current = hsyms; current = hsyms;
ccurrent = NewHash(); ccurrent = NewHash();
Setattr(h,k_csymtab,ccurrent); Setattr(h,k_csymtab,ccurrent);
Delete(ccurrent);
current_symtab = h; current_symtab = h;
return current_symtab; return h;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -473,6 +478,7 @@ void Swig_symbol_inherit(Symtab *s) {
if (!inherit) { if (!inherit) {
inherit = NewList(); inherit = NewList();
Setattr(current_symtab,k_inherit, inherit); Setattr(current_symtab,k_inherit, inherit);
Delete(inherit);
} }
assert(s != current_symtab); assert(s != current_symtab);
for (i = 0; i < Len(inherit); i++) { for (i = 0; i < Len(inherit); i++) {

View file

@ -1101,7 +1101,7 @@ static void typemap_locals(DOHString *s, ParmList *l, Wrapper *f, int argnum) {
str = NewStringEmpty(); str = NewStringEmpty();
if (Strncmp(pn,"_global_",8) == 0) { if (strncmp(Char(pn),"_global_",8) == 0) {
isglobal = 1; isglobal = 1;
} }
@ -1159,7 +1159,10 @@ String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_
if (!s) return 0; if (!s) return 0;
/* Blocked */ /* Blocked */
if (Cmp(s,"pass") == 0) return 0; if (Cmp(s,"pass") == 0) {
Delete(mtype);
return 0;
}
s = Copy(s); /* Make a local copy of the typemap code */ s = Copy(s); /* Make a local copy of the typemap code */
@ -1345,6 +1348,7 @@ Printf(stdout, "Swig_typemap_lookup %s [%s %s]\n", op, type, pname ? pname : "NO
} }
sprintf(temp,"%s:%s",Char(op),Char(Getattr(kw,k_name))); sprintf(temp,"%s:%s",Char(op),Char(Getattr(kw,k_name)));
Setattr(node,tmop_name(temp), value); Setattr(node,tmop_name(temp), value);
Delete(value);
kw = nextSibling(kw); kw = nextSibling(kw);
} }
@ -1400,13 +1404,15 @@ Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p) {
String *type = Getattr(kw,k_type); String *type = Getattr(kw,k_type);
if (type) { if (type) {
Hash *v = NewHash(); Hash *v = NewHash();
Setattr(v,k_value,value);
Setattr(v,k_type,type); Setattr(v,k_type,type);
Setattr(v,k_value,value);
Delete(value);
value = v; value = v;
} }
Clear(temp); Clear(temp);
Printf(temp,"%s:%s",op,Getattr(kw,k_name)); Printf(temp,"%s:%s",op,Getattr(kw,k_name));
Setattr(p,tmop_name(temp),value); Setattr(p,tmop_name(temp),value);
Delete(value);
kw = nextSibling(kw); kw = nextSibling(kw);
} }
Delete(temp); Delete(temp);

View file

@ -794,7 +794,7 @@ SwigType *SwigType_typedef_resolve(SwigType *t) {
String *key = NewString(t); String *key = NewString(t);
if (r) { if (r) {
SwigType *r1; SwigType *r1;
Setattr(typedef_resolve_cache,key,r); Setattr(typedef_resolve_cache,key,r);
Setmeta(r,k_scope,resolved_scope); Setmeta(r,k_scope,resolved_scope);
r1 = Copy(r); r1 = Copy(r);
Delete(r); Delete(r);