Fix for warning on return by value. Fix for std_string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11184 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5002c69cd6
commit
8c04b766d4
2 changed files with 24 additions and 18 deletions
|
|
@ -10,9 +10,11 @@ namespace std {
|
|||
class string;
|
||||
|
||||
%typemap(ctype) string "char *"
|
||||
%typemap(ctype) string * "char *"
|
||||
%typemap(ctype) const string & "char *"
|
||||
%typemap(couttype) string "char *"
|
||||
%typemap(couttype) const string & "char *"
|
||||
%typemap(couttype) string * "char *"
|
||||
|
||||
%typemap(in) string {
|
||||
if ($input) {
|
||||
|
|
@ -23,7 +25,7 @@ class string;
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string & {
|
||||
%typemap(in) const string &, string * {
|
||||
if ($input) {
|
||||
$1 = new std::string($input);
|
||||
}
|
||||
|
|
@ -33,13 +35,13 @@ class string;
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) const string & {
|
||||
%typemap(freearg) const string &, string * {
|
||||
if ($1)
|
||||
delete $1;
|
||||
}
|
||||
|
||||
%typemap(out) string, const string &, string * {
|
||||
const char *str = cppresult.c_str();
|
||||
const char *str = cppresult->c_str();
|
||||
size_t len = strlen(str);
|
||||
$result = (char *) malloc(len + 1);
|
||||
memcpy($result, str, len);
|
||||
|
|
|
|||
|
|
@ -293,6 +293,9 @@ public:
|
|||
call = Swig_cfunction_call(Getattr(n, "name"), parms);
|
||||
cres = Swig_cresult(type, "result", call);
|
||||
Setattr(n, "wrap:action", cres);
|
||||
|
||||
if (!SwigType_ispointer(type) && !SwigType_isreference(type))
|
||||
Setattr(n, "c:retval", "1");
|
||||
|
||||
functionWrapper(n);
|
||||
|
||||
|
|
@ -747,25 +750,26 @@ ready:
|
|||
if (!except || (Cmp(except, "0") != 0))
|
||||
Printf(action, "if (SWIG_exc.handled) {\nSWIG_rt_stack_pop();\nlongjmp(SWIG_rt_env, 1);\n}\n");
|
||||
}
|
||||
if (Cmp(nodeType(n), "constructor") != 0)
|
||||
Replace(action, "result =", "cppresult = $mod", DOH_REPLACE_FIRST);
|
||||
|
||||
// handle special cases of cpp return result
|
||||
|
||||
String *mod = NewString("$mod");
|
||||
if (SwigType_isreference(type))
|
||||
Replaceall(mod, "$mod", "");
|
||||
else if (SwigType_isenum(type))
|
||||
Replaceall(mod, "$mod", "(int)");
|
||||
else if (return_object && Getattr(n, "c:retval") && !SwigType_isarray(type))
|
||||
Replaceall(mod, "$mod", "&");
|
||||
else {
|
||||
Delete(mod);
|
||||
mod = empty_string;
|
||||
if (Cmp(nodeType(n), "constructor") != 0) {
|
||||
if (SwigType_isenum(type)) {
|
||||
// returning enum value
|
||||
Replace(action, "result =", "cppresult = (int)", DOH_REPLACE_FIRST);
|
||||
}
|
||||
else if (return_object && Getattr(n, "c:retval") && !SwigType_isarray(type)) {
|
||||
// returning object by value
|
||||
String *str = SwigType_str(SwigType_add_reference(SwigType_base(type)), "_result_ref");
|
||||
String *lstr = SwigType_lstr(type, 0);
|
||||
Replace(action, "result =", NewStringf("const %s = ", str), DOH_REPLACE_FIRST);
|
||||
Printf(action, "cppresult = (%s) &_result_ref;\n", lstr);
|
||||
Delete(str);
|
||||
Delete(lstr);
|
||||
}
|
||||
else
|
||||
Replace(action, "result =", "cppresult = ", DOH_REPLACE_FIRST);
|
||||
}
|
||||
|
||||
Replaceall(action, "$mod", mod);
|
||||
|
||||
// emit output typemap if needed
|
||||
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
||||
if ((tm = Swig_typemap_lookup_out("out", n, "cppresult", wrapper, action))) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue