From dafe2d6949ca2e4d1e267cef2238d72e405e8da2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 24 Oct 2017 23:12:04 +0100 Subject: [PATCH] Add director typemaps for pointer const ref types --- .../csharp/director_classes_runme.cs | 13 ++++++++-- .../test-suite/d/director_classes_runme.1.d | 13 ++++++++-- .../test-suite/d/director_classes_runme.2.d | 13 ++++++++-- Examples/test-suite/director_classes.i | 4 +++ .../java/director_classes_runme.java | 13 ++++++++-- .../perl5/director_classes_runme.pl | 4 ++- Lib/csharp/csharp.swg | 6 +++++ Lib/d/dswigtype.swg | 11 ++++++++ Lib/java/java.swg | 6 +++++ Lib/typemaps/swigtype.swg | 25 ++++++++++++++++--- Source/Modules/csharp.cxx | 18 +++++++------ Source/Modules/d.cxx | 18 +++++++------ Source/Modules/java.cxx | 18 +++++++------ 13 files changed, 126 insertions(+), 36 deletions(-) diff --git a/Examples/test-suite/csharp/director_classes_runme.cs b/Examples/test-suite/csharp/director_classes_runme.cs index 112561464..700492fb1 100644 --- a/Examples/test-suite/csharp/director_classes_runme.cs +++ b/Examples/test-suite/csharp/director_classes_runme.cs @@ -16,6 +16,7 @@ Expected output if PrintDebug enabled: Base - Val(444.555) Base - Ref(444.555) Base - Ptr(444.555) +Base - ConstPtrRef(444.555) Base - FullyOverloaded(int 10) Base - FullyOverloaded(bool 1) Base - SemiOverloaded(int -678) @@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1) Derived - Val(444.555) Derived - Ref(444.555) Derived - Ptr(444.555) +Derived - ConstPtrRef(444.555) Derived - FullyOverloaded(int 10) Derived - FullyOverloaded(bool 1) Derived - SemiOverloaded(int -678) @@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1) CSharpDerived - Val(444.555) CSharpDerived - Ref(444.555) CSharpDerived - Ptr(444.555) +CSharpDerived - ConstPtrRef(444.555) CSharpDerived - FullyOverloaded(int 10) CSharpDerived - FullyOverloaded(bool True) CSharpDerived - SemiOverloaded(-678) @@ -59,7 +62,7 @@ public class runme void run() { - if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------ "); + if (director_classes.PrintDebug) Console.WriteLine("------------ Start ------------"); Caller myCaller = new Caller(); @@ -85,7 +88,7 @@ public class runme makeCalls(myCaller, myBase); } - if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------ "); + if (director_classes.PrintDebug) Console.WriteLine("------------ Finish ------------"); } void makeCalls(Caller myCaller, Base myBase) @@ -99,6 +102,7 @@ public class runme if (myCaller.ValCall(dh).val != dh.val) throw new Exception("failed"); if (myCaller.RefCall(dh).val != dh.val) throw new Exception("failed"); if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("failed"); + if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("failed"); // Fully overloaded method test (all methods in base class are overloaded) if (NAMESPACE + myCaller.FullyOverloadedCall(10) != myBase.GetType() + "::FullyOverloaded(int)") throw new Exception("failed"); @@ -142,6 +146,11 @@ public class CSharpDerived : Base if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - Ptr({0})", x.val); return x; } + public override DoubleHolder ConstPtrRef(DoubleHolder x) + { + if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - ConstPtrRef({0})", x.val); + return x; + } public override String FullyOverloaded(int x) { if (director_classes.PrintDebug) Console.WriteLine("CSharpDerived - FullyOverloaded(int {0})", x); diff --git a/Examples/test-suite/d/director_classes_runme.1.d b/Examples/test-suite/d/director_classes_runme.1.d index 9c34db82a..e753f5f6d 100644 --- a/Examples/test-suite/d/director_classes_runme.1.d +++ b/Examples/test-suite/d/director_classes_runme.1.d @@ -18,6 +18,7 @@ * Base - Val(444.555) * Base - Ref(444.555) * Base - Ptr(444.555) + * Base - ConstPtrRef(444.555) * Base - FullyOverloaded(int 10) * Base - FullyOverloaded(bool 1) * Base - SemiOverloaded(int -678) @@ -28,6 +29,7 @@ * Derived - Val(444.555) * Derived - Ref(444.555) * Derived - Ptr(444.555) + * Derived - ConstPtrRef(444.555) * Derived - FullyOverloaded(int 10) * Derived - FullyOverloaded(bool 1) * Derived - SemiOverloaded(int -678) @@ -38,6 +40,7 @@ * DDerived - Val(444.555) * DDerived - Ref(444.555) * DDerived - Ptr(444.555) + * DDerived - ConstPtrRef(444.555) * DDerived - FullyOverloaded(int 10) * DDerived - FullyOverloaded(bool True) * DDerived - SemiOverloaded(-678) @@ -57,7 +60,7 @@ import director_classes.Derived; import director_classes.DoubleHolder; void main() { - if (PrintDebug) Stdout.formatln("------------ Start ------------ "); + if (PrintDebug) Stdout.formatln("------------ Start ------------"); auto myCaller = new Caller(); @@ -83,7 +86,7 @@ void main() { makeCalls(myCaller, myBase); } - if (PrintDebug) Stdout.formatln("------------ Finish ------------ "); + if (PrintDebug) Stdout.formatln("------------ Finish ------------"); } void makeCalls(Caller myCaller, Base myBase) { @@ -96,6 +99,7 @@ void makeCalls(Caller myCaller, Base myBase) { if (myCaller.ValCall(dh).val != dh.val) throw new Exception("[1] failed"); if (myCaller.RefCall(dh).val != dh.val) throw new Exception("[2] failed"); if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("[3] failed"); + if (myCaller.ConstPtrRefCall(dh).val != dh.val) throw new Exception("[3] failed"); // Fully overloaded method test (all methods in base class are overloaded) if (myCaller.FullyOverloadedCall(10) != myBaseType ~ "::FullyOverloaded(int)") throw new Exception("[4] failed"); @@ -136,6 +140,11 @@ public class DDerived : Base { return x; } + public override DoubleHolder ConstPtrRef(DoubleHolder x) { + if (PrintDebug) Stdout.formatln("DDerived - ConstPtrRef({0:d3})", x.val); + return x; + } + public override char[] FullyOverloaded(int x) { if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(int {0})", x); return "DDerived::FullyOverloaded(int)"; diff --git a/Examples/test-suite/d/director_classes_runme.2.d b/Examples/test-suite/d/director_classes_runme.2.d index 98e27b3cd..b16fa5461 100644 --- a/Examples/test-suite/d/director_classes_runme.2.d +++ b/Examples/test-suite/d/director_classes_runme.2.d @@ -18,6 +18,7 @@ * Base - Val(444.555) * Base - Ref(444.555) * Base - Ptr(444.555) + * Base - ConstPtrRef(444.555) * Base - FullyOverloaded(int 10) * Base - FullyOverloaded(bool 1) * Base - SemiOverloaded(int -678) @@ -28,6 +29,7 @@ * Derived - Val(444.555) * Derived - Ref(444.555) * Derived - Ptr(444.555) + * Derived - ConstPtrRef(444.555) * Derived - FullyOverloaded(int 10) * Derived - FullyOverloaded(bool 1) * Derived - SemiOverloaded(int -678) @@ -38,6 +40,7 @@ * DDerived - Val(444.555) * DDerived - Ref(444.555) * DDerived - Ptr(444.555) + * DDerived - ConstPtrRef(444.555) * DDerived - FullyOverloaded(int 10) * DDerived - FullyOverloaded(bool true) * DDerived - SemiOverloaded(-678) @@ -58,7 +61,7 @@ import director_classes.Derived; import director_classes.DoubleHolder; void main() { - if (PrintDebug) writeln("------------ Start ------------ "); + if (PrintDebug) writeln("------------ Start ------------"); auto myCaller = new Caller(); @@ -84,7 +87,7 @@ void main() { makeCalls(myCaller, myBase); } - if (PrintDebug) writeln("------------ Finish ------------ "); + if (PrintDebug) writeln("------------ Finish ------------"); } void makeCalls(Caller myCaller, Base myBase) { @@ -97,6 +100,7 @@ void makeCalls(Caller myCaller, Base myBase) { enforce(myCaller.ValCall(dh).val == dh.val, "[1] failed"); enforce(myCaller.RefCall(dh).val == dh.val, "[2] failed"); enforce(myCaller.PtrCall(dh).val == dh.val, "[3] failed"); + enforce(myCaller.ConstPtrRefCall(dh).val == dh.val, "[3] failed"); // Fully overloaded method test (all methods in base class are overloaded) enforce(myCaller.FullyOverloadedCall(10) == myBaseType ~ "::FullyOverloaded(int)", "[4] failed"); @@ -137,6 +141,11 @@ public class DDerived : Base { return x; } + public override DoubleHolder ConstPtrRef(DoubleHolder x) { + if (PrintDebug) writefln("DDerived - ConstPtrRef(%s)", x.val); + return x; + } + public override string FullyOverloaded(int x) { if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x); return "DDerived::FullyOverloaded(int)"; diff --git a/Examples/test-suite/director_classes.i b/Examples/test-suite/director_classes.i index 98c29e88c..8b54d8b9d 100644 --- a/Examples/test-suite/director_classes.i +++ b/Examples/test-suite/director_classes.i @@ -3,6 +3,7 @@ %warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ref; %warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::Ptr; +%warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Base::ConstPtrRef; %module(directors="1") director_classes @@ -43,6 +44,7 @@ public: virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Base - Val(" << x.val << ")" << std::endl; return x; } virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Base - Ref(" << x.val << ")" << std::endl; return x; } virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Base - Ptr(" << x->val << ")" << std::endl; return x; } + virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Base - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; } virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(int " << x << ")" << std::endl; return "Base::FullyOverloaded(int)"; } virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Base - FullyOverloaded(bool " << x << ")" << std::endl; return "Base::FullyOverloaded(bool)"; } @@ -68,6 +70,7 @@ public: virtual DoubleHolder Val(DoubleHolder x) { if (PrintDebug) std::cout << "Derived - Val(" << x.val << ")" << std::endl; return x; } virtual DoubleHolder& Ref(DoubleHolder& x) { if (PrintDebug) std::cout << "Derived - Ref(" << x.val << ")" << std::endl; return x; } virtual DoubleHolder* Ptr(DoubleHolder* x) { if (PrintDebug) std::cout << "Derived - Ptr(" << x->val << ")" << std::endl; return x; } + virtual DoubleHolder *const& ConstPtrRef(DoubleHolder *const& cprx) { if (PrintDebug) std::cout << "Derived - ConstPtrRef(" << cprx->val << ")" << std::endl; return cprx; } virtual std::string FullyOverloaded(int x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(int " << x << ")" << std::endl; return "Derived::FullyOverloaded(int)"; } virtual std::string FullyOverloaded(bool x) { if (PrintDebug) std::cout << "Derived - FullyOverloaded(bool " << x << ")" << std::endl; return "Derived::FullyOverloaded(bool)"; } @@ -99,6 +102,7 @@ public: DoubleHolder ValCall(DoubleHolder x) { return m_base->Val(x); } DoubleHolder& RefCall(DoubleHolder& x) { return m_base->Ref(x); } DoubleHolder* PtrCall(DoubleHolder* x) { return m_base->Ptr(x); } + DoubleHolder *const& ConstPtrRefCall(DoubleHolder *const& cprx) { return m_base->ConstPtrRef(cprx); } std::string FullyOverloadedCall(int x) { return m_base->FullyOverloaded(x); } std::string FullyOverloadedCall(bool x) { return m_base->FullyOverloaded(x); } std::string SemiOverloadedCall(int x) { return m_base->SemiOverloaded(x); } diff --git a/Examples/test-suite/java/director_classes_runme.java b/Examples/test-suite/java/director_classes_runme.java index 5fbb9ea35..5992b5dd9 100644 --- a/Examples/test-suite/java/director_classes_runme.java +++ b/Examples/test-suite/java/director_classes_runme.java @@ -16,6 +16,7 @@ Expected output if PrintDebug enabled: Base - Val(444.555) Base - Ref(444.555) Base - Ptr(444.555) +Base - ConstPtrRef(444.555) Base - FullyOverloaded(int 10) Base - FullyOverloaded(bool 1) Base - SemiOverloaded(int -678) @@ -26,6 +27,7 @@ Base - DefaultParms(10, 1.1) Derived - Val(444.555) Derived - Ref(444.555) Derived - Ptr(444.555) +Derived - ConstPtrRef(444.555) Derived - FullyOverloaded(int 10) Derived - FullyOverloaded(bool 1) Derived - SemiOverloaded(int -678) @@ -36,6 +38,7 @@ Derived - DefaultParms(10, 1.1) JavaDerived - Val(444.555) JavaDerived - Ref(444.555) JavaDerived - Ptr(444.555) +JavaDerived - ConstPtrRef(444.555) JavaDerived - FullyOverloaded(int 10) JavaDerived - FullyOverloaded(bool True) JavaDerived - SemiOverloaded(-678) @@ -67,7 +70,7 @@ public class director_classes_runme { void run() { - if (director_classes.getPrintDebug()) System.out.println("------------ Start ------------ "); + if (director_classes.getPrintDebug()) System.out.println("------------ Start ------------"); Caller myCaller = new Caller(); @@ -96,7 +99,7 @@ public class director_classes_runme { myBase.delete(); } - if (director_classes.getPrintDebug()) System.out.println("------------ Finish ------------ "); + if (director_classes.getPrintDebug()) System.out.println("------------ Finish ------------"); } void makeCalls(Caller myCaller, Base myBase) @@ -111,6 +114,7 @@ public class director_classes_runme { if (myCaller.ValCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed"); if (myCaller.RefCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed"); if (myCaller.PtrCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed"); + if (myCaller.ConstPtrRefCall(dh).getVal() != dh.getVal()) throw new RuntimeException("failed"); // Fully overloaded method test (all methods in base class are overloaded) if (!myCaller.FullyOverloadedCall(10).equals(baseSimpleName + "::FullyOverloaded(int)")) { @@ -170,6 +174,11 @@ class JavaDerived extends Base if (director_classes.getPrintDebug()) System.out.println("JavaDerived - Ptr(" + x.getVal() + ")"); return x; } + public DoubleHolder ConstPtrRef(DoubleHolder x) + { + if (director_classes.getPrintDebug()) System.out.println("JavaDerived - ConstPtrRef(" + x.getVal() + ")"); + return x; + } public String FullyOverloaded(int x) { if (director_classes.getPrintDebug()) System.out.println("JavaDerived - FullyOverloaded(int " + x + ")"); diff --git a/Examples/test-suite/perl5/director_classes_runme.pl b/Examples/test-suite/perl5/director_classes_runme.pl index a4fddeed9..5e72703e0 100644 --- a/Examples/test-suite/perl5/director_classes_runme.pl +++ b/Examples/test-suite/perl5/director_classes_runme.pl @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 29; +use Test::More tests => 32; BEGIN { use_ok 'director_classes' } require_ok 'director_classes'; @@ -10,6 +10,7 @@ require_ok 'director_classes'; sub Val { $_[1] } sub Ref { $_[1] } sub Ptr { $_[1] } + sub ConstPtrRef { $_[1] } sub FullyOverloaded { my $rv = shift->SUPER::FullyOverloaded(@_); $rv =~ s/Base/__PACKAGE__/sge; @@ -45,6 +46,7 @@ sub makeCalls { my($caller, $base) = @_; is($caller->ValCall($dh)->{val}, $dh->{val}, "$bname.Val"); is($caller->RefCall($dh)->{val}, $dh->{val}, "$bname.Ref"); is($caller->PtrCall($dh)->{val}, $dh->{val}, "$bname.Ptr"); + is($caller->ConstPtrRefCall($dh)->{val}, $dh->{val}, "$bname.ConstPtrRef"); is($caller->FullyOverloadedCall(1), "${bname}::FullyOverloaded(int)", "$bname.FullyOverloaded(int)"); diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index bf1e126d8..5b539332c 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -855,6 +855,12 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { $1 = ($1_ltype)&temp; %} %typemap(out) SWIGTYPE *const& %{ $result = (void *)*$1; %} +%typemap(directorin) SWIGTYPE *const& +%{ $input = (void *) $1; %} +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *const& +%{ $result = ($1_ltype)&$input; %} +%typemap(csdirectorin) SWIGTYPE *const& "($iminput == global::System.IntPtr.Zero) ? null : new $*csclassname($iminput, false)" +%typemap(csdirectorout) SWIGTYPE *const& "$*csclassname.getCPtr($cscall).Handle" /* Marshal C/C++ pointer to global::System.IntPtr */ %typemap(ctype) void *VOID_INT_PTR "void *" diff --git a/Lib/d/dswigtype.swg b/Lib/d/dswigtype.swg index 5043741d5..19b700052 100644 --- a/Lib/d/dswigtype.swg +++ b/Lib/d/dswigtype.swg @@ -182,3 +182,14 @@ $*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode return ret; } +%typemap(directorin) SWIGTYPE *const& + "$input = (void *) $1;" +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *const& + "$result = ($1_ltype)&$input;" +%typemap(ddirectorin, + nativepointer="cast($dtype)$winput" +) SWIGTYPE *const& "($winput is null) ? null : new $*dclassname($winput, false)" +%typemap(ddirectorout, + nativepointer="cast(void*)$dcall" +) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dcall)" + diff --git a/Lib/java/java.swg b/Lib/java/java.swg index b49826ba0..903387a1d 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -1173,6 +1173,12 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); } $1 = ($1_ltype)&temp; %} %typemap(out) SWIGTYPE *const& %{ *($1_ltype)&$result = *$1; %} +%typemap(directorin,descriptor="L$packagepath/$*javaclassname;") SWIGTYPE *const& +%{ *(($1_ltype)&$input) = ($*1_ltype) $1; %} +%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *const& +%{ $result = ($1_ltype)&$input; %} +%typemap(javadirectorin) SWIGTYPE *const& "($jniinput == 0) ? null : new $*javaclassname($jniinput, false)" +%typemap(javadirectorout) SWIGTYPE *const& "$*javaclassname.getCPtr($javacall)" /* Typemaps used for the generation of proxy and type wrapper class code */ %typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index b21240af8..be684211c 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -410,12 +410,16 @@ /* directorin */ -%typemap(directorin,noblock=1) SWIGTYPE *, SWIGTYPE *const& { +%typemap(directorin,noblock=1) SWIGTYPE { + $input = SWIG_NewPointerObj(%as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags); +} + +%typemap(directorin,noblock=1) SWIGTYPE * { $input = SWIG_NewPointerObj(%as_voidptr($1), $descriptor, %newpointer_flags); } -%typemap(directorin,noblock=1) SWIGTYPE { - $input = SWIG_NewPointerObj(%as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags); +%typemap(directorin,noblock=1) SWIGTYPE *const& { + $input = SWIG_NewPointerObj(%as_voidptr($1), $*descriptor, %newpointer_flags); } %typemap(directorin,noblock=1) SWIGTYPE & { @@ -461,6 +465,21 @@ } } +%typemap(directorout,noblock=1,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) + SWIGTYPE *const&(void *swig_argp, int swig_res, swig_owntype own) { + swig_res = SWIG_ConvertPtrAndOwn($input, &swig_argp, $*descriptor, %convertptr_flags | SWIG_POINTER_DISOWN, &own); + if (!SWIG_IsOK(swig_res)) { + %dirout_fail(swig_res,"$type"); + } + $result = %reinterpret_cast(&swig_argp, $ltype); + swig_acquire_ownership_obj(%as_voidptr(*$result), own /* & TODO: SWIG_POINTER_OWN */); +} +%typemap(directorfree,noblock=1,match="directorout") SWIGTYPE *const& { + if (director) { + SWIG_AcquirePtr($result, director->swig_release_ownership(%as_voidptr(*$input))); + } +} + %typemap(directorout,noblock=1,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &(void *swig_argp, int swig_res, swig_owntype own) { swig_res = SWIG_ConvertPtrAndOwn($input, &swig_argp, $descriptor, %convertptr_flags | SWIG_POINTER_DISOWN, &own); diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 3ab4c1505..9b28829ee 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3811,15 +3811,17 @@ public: /* If returning a reference, initialize the pointer to a sane default - if a C# exception occurs, then the pointer returns something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); + SwigType *noref_type = SwigType_del_reference(Copy(returntype)); + String *noref_ltype = SwigType_lstr(noref_type, 0); + String *return_ltype = SwigType_lstr(returntype, 0); - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - - Delete(non_ref_type); + Wrapper_add_localv(w, "result_default", "static", noref_ltype, "result_default", NIL); + Wrapper_add_localv(w, "c_result", return_ltype, "c_result", NIL); + Printf(w->code, "result_default = SwigValueInit< %s >();\n", noref_ltype); + Printf(w->code, "c_result = &result_default;\n"); + Delete(return_ltype); + Delete(noref_ltype); + Delete(noref_type); } Delete(base_typename); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index 28ea16d5d..451f449a1 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -1995,15 +1995,17 @@ public: /* If returning a reference, initialize the pointer to a sane default - if a D exception occurs, then the pointer returns something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); + SwigType *noref_type = SwigType_del_reference(Copy(returntype)); + String *noref_ltype = SwigType_lstr(noref_type, 0); + String *return_ltype = SwigType_lstr(returntype, 0); - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - - Delete(non_ref_type); + Wrapper_add_localv(w, "result_default", "static", noref_ltype, "result_default", NIL); + Wrapper_add_localv(w, "c_result", return_ltype, "c_result", NIL); + Printf(w->code, "result_default = SwigValueInit< %s >();\n", noref_ltype); + Printf(w->code, "c_result = &result_default;\n"); + Delete(return_ltype); + Delete(noref_ltype); + Delete(noref_type); } Delete(base_typename); diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 608c1c529..68f1bb273 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3945,15 +3945,17 @@ public: /* If returning a reference, initialize the pointer to a sane default - if a Java exception occurs, then the pointer returns something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); + SwigType *noref_type = SwigType_del_reference(Copy(returntype)); + String *noref_ltype = SwigType_lstr(noref_type, 0); + String *return_ltype = SwigType_lstr(returntype, 0); - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - - Delete(non_ref_type); + Wrapper_add_localv(w, "result_default", "static", noref_ltype, "result_default", NIL); + Wrapper_add_localv(w, "c_result", return_ltype, "c_result", NIL); + Printf(w->code, "result_default = SwigValueInit< %s >();\n", noref_ltype); + Printf(w->code, "c_result = &result_default;\n"); + Delete(return_ltype); + Delete(noref_ltype); + Delete(noref_type); } Delete(base_typename);