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

@ -114,6 +114,8 @@
%rename(renamed2arg) Foo::renameme(int x) const;
%rename(renamed1arg) Foo::renameme() const;
%typemap(default) double* null_by_default "$1=0;";
%inline %{
typedef void* MyHandle;
@ -144,6 +146,8 @@
// test default values for pointer arguments
int double_if_void_ptr_is_null(int n, void* p = NULL) { return p ? n : 2*n; }
int double_if_handle_is_null(int n, MyHandle h = 0) { return h ? n : 2*n; }
int double_if_dbl_ptr_is_null(int n, double* null_by_default)
{ return null_by_default ? n : 2*n; }
};
int Foo::bar = 1;
int Foo::spam = 2;

View file

@ -43,6 +43,12 @@ def run(module_name):
if f.double_if_handle_is_null(5) != 10:
raise RuntimeError
if f.double_if_dbl_ptr_is_null(6, None) != 12:
raise RuntimeError
if f.double_if_dbl_ptr_is_null(7) != 14:
raise RuntimeError
try:
f = default_args.Foo(1)
error = 1