Fix handling of "default" typemap in Python.

Use "compact" arguments form for the function if "default" typemap is defined
for any of its arguments to allow omitting this argument when calling it from
Python.

Closes #377.
This commit is contained in:
Vadim Zeitlin 2015-04-22 20:37:55 +02:00
commit 5569d91bd0
4 changed files with 27 additions and 7 deletions

View file

@ -1999,9 +1999,9 @@ public:
* at C++ code level where they can always be handled.
* ------------------------------------------------------------ */
bool is_representable_as_pyargs(Node *n) {
bool is_representable = true;
ParmList *plist = CopyParmList(Getattr(n, "parms"));
Swig_typemap_attach_parms("default", plist, NULL);
Parm *p;
Parm *pnext;
@ -2017,16 +2017,23 @@ public:
if (!pnext) {
pnext = nextSibling(p);
}
// "default" typemap can contain arbitrary C++ code, so while it could, in
// principle, be possible to examine it and check if it's just something
// simple of the form "$1 = expression" and then use convertValue() to
// check if expression can be used in Python, but for now we just
// pessimistically give up and prefer to handle this at C++ level only.
if (Getattr(p, "tmap:default"))
return false;
if (String *value = Getattr(p, "value")) {
String *type = Getattr(p, "type");
if (!convertValue(value, type)) {
is_representable = false;
break;
}
if (!convertValue(value, type))
return false;
}
}
return is_representable;
return true;
}