Fix handling of default arguments after ignored ones in Python.
Don't skip checking subsequent arguments just because one of them has "in" typemap with numinputs=0 attribute. Add a unit test showing the problem which is relatively rare as it doesn't happen for the class methods and is hidden unless autodoc feature is used for the global functions. Closes #377.
This commit is contained in:
parent
d64c241e1c
commit
6988b00aba
4 changed files with 28 additions and 5 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 3.0.6 (in progress)
|
Version 3.0.6 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2015-04-27: vadz
|
||||||
|
[Python] Fix "default" typemap used after an argument with "numinputs=0" (#377).
|
||||||
|
|
||||||
2015-04-24: wsfulton
|
2015-04-24: wsfulton
|
||||||
[Python] Fix #256. Code generated with '-builtin -modernargs' segfaults for any
|
[Python] Fix #256. Code generated with '-builtin -modernargs' segfaults for any
|
||||||
method taking zero arguments.
|
method taking zero arguments.
|
||||||
|
|
|
||||||
|
|
@ -278,3 +278,17 @@ struct ConstMethods {
|
||||||
} Pointf;
|
} Pointf;
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
// Default arguments after ignored ones.
|
||||||
|
%typemap(in, numinputs=0) int square_error { $1 = 2; };
|
||||||
|
%typemap(default, noblock=1) int def17 { $1 = 17; };
|
||||||
|
|
||||||
|
// Enabling autodoc feature has a side effect of disabling the generation of
|
||||||
|
// aliases for functions that can hide problems with default arguments at
|
||||||
|
// Python level.
|
||||||
|
%feature("autodoc","0") slightly_off_square;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
inline int slightly_off_square(int square_error, int def17) { return def17*def17 + square_error; }
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,13 @@ def run(module_name):
|
||||||
default_args.trickyvalue3(10); default_args.trickyvalue3(10, 10)
|
default_args.trickyvalue3(10); default_args.trickyvalue3(10, 10)
|
||||||
default_args.seek(); default_args.seek(10)
|
default_args.seek(); default_args.seek(10)
|
||||||
|
|
||||||
|
if default_args.slightly_off_square(10) != 102:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if default_args.slightly_off_square() != 291:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
run('default_args')
|
run('default_args')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2003,17 +2003,16 @@ public:
|
||||||
Parm *pnext;
|
Parm *pnext;
|
||||||
|
|
||||||
for (p = plist; p; p = pnext) {
|
for (p = plist; p; p = pnext) {
|
||||||
pnext = NIL;
|
pnext = nextSibling(p);
|
||||||
String *tm = Getattr(p, "tmap:in");
|
String *tm = Getattr(p, "tmap:in");
|
||||||
if (tm) {
|
if (tm) {
|
||||||
pnext = Getattr(p, "tmap:in:next");
|
Parm *in_next = Getattr(p, "tmap:in:next");
|
||||||
|
if (in_next)
|
||||||
|
pnext = in_next;
|
||||||
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
|
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pnext) {
|
|
||||||
pnext = nextSibling(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
// "default" typemap can contain arbitrary C++ code, so while it could, in
|
// "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
|
// principle, be possible to examine it and check if it's just something
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue