Add "freearg" template

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10037 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Joseph Wang 2007-10-25 11:30:11 +00:00
commit 54f0b11ddf
2 changed files with 47 additions and 10 deletions

View file

@ -96,24 +96,38 @@ SWIG_InitializeModule(0);
}
%typemap(in,noblock=1) char* {
$1 = %reinterpret_cast(%const_cast(CHAR(STRING_ELT($input, 0)),
char *), $1_ltype);
$1 = %reinterpret_cast(strdup(CHAR(STRING_ELT($input, 0))), $1_ltype);
}
%typemap(freearg,noblock=1) char* {
free($1);
}
%typemap(in,noblock=1) char *[ANY] {
$1 = %reinterpret_cast(%const_cast(CHAR(STRING_ELT($input, 0)),
char *),
$1_ltype);
$1 = %reinterpret_cast(strdup(CHAR(STRING_ELT($input, 0))), $1_ltype);
}
%typemap(freearg,noblock=1) char *[ANY] {
free($1);
}
%typemap(in,noblock=1) char[ANY] {
$1 = %const_cast(CHAR(STRING_ELT($input, 0)), char *);
$1 = strdup(CHAR(STRING_ELT($input, 0)));
}
%typemap(freearg,noblock=1) char[ANY] {
free($1);
}
%typemap(in,noblock=1) char[] {
$1 = %const_cast(CHAR(STRING_ELT($input, 0)), char *);
$1 = strdup(CHAR(STRING_ELT($input, 0)));
}
%typemap(freearg,noblock=1) char[] {
free($1);
}
%typemap(memberin) char[] %{
if ($input) strcpy($1, $input);
else

View file

@ -1766,6 +1766,7 @@ int R::functionWrapper(Node *n) {
String *s_inputTypes = NewString("");
String *s_inputMap = NewString("");
bool inFirstArg = true;
bool inFirstType = true;
Parm *curP;
for (p =l, i = 0 ; i < nargs ; i++) {
@ -1897,8 +1898,9 @@ int R::functionWrapper(Node *n) {
if(tm) {
replaceRClass(tm, Getattr(curP, "type"));
}
Printf(s_inputTypes, "'%s'%s", tm, p ? ", " : "");
Printf(s_inputMap, "%s='%s'%s", name, tm, p ? ", " : "");
Printf(s_inputTypes, "%s'%s'", inFirstType ? "" : ", ", tm);
Printf(s_inputMap, "%s%s='%s'", inFirstType ? "" : ", ", name, tm);
inFirstType = false;
if(funcptr_name)
Delete(funcptr_name);
@ -1914,6 +1916,20 @@ int R::functionWrapper(Node *n) {
Printv(f->def, ")\n{\n", NIL);
Printv(sfun->def, ")\n{\n", NIL);
/* Insert cleanup code */
String *cleanup = NewString("");
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:freearg"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
p = Getattr(p, "tmap:freearg:next");
} else {
p = nextSibling(p);
}
}
emit_action(n, f);
@ -1994,10 +2010,17 @@ int R::functionWrapper(Node *n) {
Insert(outargs, 0, tmp);
Delete(tmp);
Printf(f->code, "%s", outargs);
Printv(f->code, outargs, NIL);
Delete(outargs);
}
/* Output cleanup code */
Printv(f->code, cleanup, NIL);
Delete(cleanup);
Printv(f->code, UnProtectWrapupCode, NIL);