From 5d3deb2db19f23a0d37dc207bc983e4f37afbfc9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 24 Jun 2009 17:20:17 +0000 Subject: [PATCH] Fixes for compactdefaultargs and pass by value where the class being passed by value has no default constructor - previously it used SwigValueWrapper git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11312 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 ++++++ Examples/test-suite/default_args.i | 2 ++ Source/Swig/cwrap.c | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 822d2feed..d5b0062be 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,12 @@ Version 1.3.40 (in progress) ============================ +2009-06-24: wsfulton + Fix wrapping methods with default arguments and the compactdefaultargs feature + where a class is passed by value and is assigned a default value. The SwigValueWrapper + template workaround for a missing default constructor is no longer used as the code + generated does not call the default constructor. + 2009-06-16: wsfulton [Java,C#] Fix enum marshalling when %ignore is used on one of the enum items. Incorrect enum values were being passed to the C++ layer or compilation errors resulted. diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index 69c90e2e6..839d28e3e 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -119,6 +119,7 @@ // tests valuewrapper +%feature("compactdefaultargs") MyClass2::set; %inline %{ enum MyType { Val1, Val2 }; @@ -134,6 +135,7 @@ void set(MyClass1 cl1 = Val1) {} // This could have been written : set(MyClass1 cl1 = MyClass1(Val1)) // But it works in C++ since there is a "conversion" constructor in MyClass1. + void set2(MyClass1 cl1 = Val1) {} }; %} diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 7c6837a2b..121ea150a 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -195,7 +195,11 @@ int Swig_cargs(Wrapper *w, ParmList *p) { String *type = Getattr(p, "type"); /* default values only emitted if in compact default args mode */ String *pvalue = (compactdefargs) ? Getattr(p, "value") : 0; - SwigType *altty = SwigType_alttype(type, 0); + + /* When using compactdefaultargs, the code generated initialises a variable via a constructor call that accepts the + * default value as a parameter. The default constructor is not called and therefore SwigValueWrapper is not needed. */ + SwigType *altty = pvalue ? 0 : SwigType_alttype(type, 0); + int tycode = SwigType_type(type); if (tycode == T_REFERENCE) { if (pvalue) {