Remove numerous hard coded 'result' variable name in generated c/c++ wrappers. The variable name is now defined in just one place, making it possible to change the name easily if a target language so wishes - see cwrap.c.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12830 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d1dc016b68
commit
24133bacd7
29 changed files with 252 additions and 227 deletions
|
|
@ -2445,7 +2445,7 @@ public:
|
|||
/* This part below still needs cleanup */
|
||||
|
||||
/* Return the function value */
|
||||
tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode);
|
||||
tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode);
|
||||
|
||||
if (tm) {
|
||||
if (builtin_self) {
|
||||
|
|
@ -2455,7 +2455,7 @@ public:
|
|||
} else {
|
||||
Replaceall(tm, "$self", "obj0");
|
||||
}
|
||||
Replaceall(tm, "$source", "result");
|
||||
Replaceall(tm, "$source", Swig_cresult_name());
|
||||
Replaceall(tm, "$target", "resultobj");
|
||||
Replaceall(tm, "$result", "resultobj");
|
||||
if (builtin_ctor) {
|
||||
|
|
@ -2491,7 +2491,7 @@ public:
|
|||
}
|
||||
if (unwrap) {
|
||||
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
|
||||
Append(f->code, "director = SWIG_DIRECTOR_CAST(result);\n");
|
||||
Printf(f->code, "director = SWIG_DIRECTOR_CAST(%s);\n", Swig_cresult_name());
|
||||
Append(f->code, "if (director) {\n");
|
||||
Append(f->code, " resultobj = director->swig_get_self();\n");
|
||||
Append(f->code, " Py_INCREF(resultobj);\n");
|
||||
|
|
@ -2521,23 +2521,23 @@ public:
|
|||
|
||||
/* Look to see if there is any newfree cleanup code */
|
||||
if (GetFlag(n, "feature:new")) {
|
||||
if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
|
||||
Replaceall(tm, "$source", "result");
|
||||
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
|
||||
Replaceall(tm, "$source", Swig_cresult_name());
|
||||
Printf(f->code, "%s\n", tm);
|
||||
Delete(tm);
|
||||
}
|
||||
}
|
||||
|
||||
/* See if there is any return cleanup code */
|
||||
if ((tm = Swig_typemap_lookup("ret", n, "result", 0))) {
|
||||
Replaceall(tm, "$source", "result");
|
||||
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
|
||||
Replaceall(tm, "$source", Swig_cresult_name());
|
||||
Printf(f->code, "%s\n", tm);
|
||||
Delete(tm);
|
||||
}
|
||||
|
||||
if (director_method) {
|
||||
if ((tm = Swig_typemap_lookup("directorfree", n, "result", 0))) {
|
||||
Replaceall(tm, "$input", "result");
|
||||
if ((tm = Swig_typemap_lookup("directorfree", n, Swig_cresult_name(), 0))) {
|
||||
Replaceall(tm, "$input", Swig_cresult_name());
|
||||
Replaceall(tm, "$result", "resultobj");
|
||||
Printf(f->code, "%s\n", tm);
|
||||
Delete(tm);
|
||||
|
|
@ -4818,33 +4818,32 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n");
|
||||
if (Len(parse_args) > 0) {
|
||||
if (use_parse || !modernargs) {
|
||||
Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist);
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", Swig_cresult_name(), parse_args, arglist);
|
||||
} else {
|
||||
Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist);
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunctionObjArgs(method %s, NULL);\n", Swig_cresult_name(), arglist);
|
||||
}
|
||||
} else {
|
||||
if (modernargs) {
|
||||
Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n");
|
||||
Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n");
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_Call(method, (PyObject*) args, NULL);\n", Swig_cresult_name());
|
||||
} else {
|
||||
Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n");
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, NULL, NULL);\n", Swig_cresult_name());
|
||||
}
|
||||
}
|
||||
Append(w->code, "#else\n");
|
||||
if (Len(parse_args) > 0) {
|
||||
if (use_parse || !modernargs) {
|
||||
Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n",
|
||||
pyname, parse_args, arglist);
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", Swig_cresult_name(), pyname, parse_args, arglist);
|
||||
} else {
|
||||
Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
|
||||
Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist);
|
||||
Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", Swig_cresult_name(), pyname);
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", Swig_cresult_name(), arglist);
|
||||
}
|
||||
} else {
|
||||
if (!modernargs) {
|
||||
Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname);
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", Swig_cresult_name(), pyname);
|
||||
} else {
|
||||
Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
|
||||
Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n");
|
||||
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n", Swig_cresult_name());
|
||||
}
|
||||
}
|
||||
Append(w->code, "#endif\n");
|
||||
|
|
@ -4853,13 +4852,13 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
|
||||
|
||||
/* exception handling */
|
||||
tm = Swig_typemap_lookup("director:except", n, "result", 0);
|
||||
tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0);
|
||||
if (!tm) {
|
||||
tm = Getattr(n, "feature:director:except");
|
||||
if (tm)
|
||||
tm = Copy(tm);
|
||||
}
|
||||
Append(w->code, "if (!result) {\n");
|
||||
Printf(w->code, "if (!%s) {\n", Swig_cresult_name());
|
||||
Append(w->code, " PyObject *error = PyErr_Occurred();\n");
|
||||
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
|
||||
Replaceall(tm, "$error", "error");
|
||||
|
|
@ -4886,7 +4885,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
|
||||
if (outputs > 1) {
|
||||
Wrapper_add_local(w, "output", "PyObject *output");
|
||||
Append(w->code, "if (!PyTuple_Check(result)) {\n");
|
||||
Printf(w->code, "if (!PyTuple_Check(%s)) {\n", Swig_cresult_name());
|
||||
Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname);
|
||||
Append(w->code, "}\n");
|
||||
}
|
||||
|
|
@ -4903,14 +4902,14 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
* occurs in Language::cDeclaration().
|
||||
*/
|
||||
Setattr(n, "type", return_type);
|
||||
tm = Swig_typemap_lookup("directorout", n, "result", w);
|
||||
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
|
||||
Setattr(n, "type", type);
|
||||
if (tm != 0) {
|
||||
if (outputs > 1) {
|
||||
Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
|
||||
Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
|
||||
Replaceall(tm, "$input", "output");
|
||||
} else {
|
||||
Replaceall(tm, "$input", "result");
|
||||
Replaceall(tm, "$input", Swig_cresult_name());
|
||||
}
|
||||
char temp[24];
|
||||
sprintf(temp, "%d", idx);
|
||||
|
|
@ -4940,10 +4939,10 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
|
||||
if (outputs > 1) {
|
||||
Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
|
||||
Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
|
||||
Replaceall(tm, "$input", "output");
|
||||
} else {
|
||||
Replaceall(tm, "$input", "result");
|
||||
Replaceall(tm, "$input", Swig_cresult_name());
|
||||
}
|
||||
Replaceall(tm, "$result", Getattr(p, "name"));
|
||||
Printv(w->code, tm, "\n", NIL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue