From 46ec93785a1a74e869d035a4a794d214b5186a00 Mon Sep 17 00:00:00 2001 From: Lindley French Date: Wed, 23 Jun 2021 00:00:37 -0700 Subject: [PATCH 1/5] Expose to javaout typemaps. --- Source/Modules/java.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 958da8ed1..614431192 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3179,6 +3179,7 @@ public: else Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); + Replaceall(tm, "$imfuncname", overloaded_name); Replaceall(tm, "$jnicall", imcall); } else { Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, "No javaout typemap defined for %s\n", SwigType_str(t, 0)); From 112f9d59eab046486ab9eeef238cb16507b9246a Mon Sep 17 00:00:00 2001 From: Lindley French Date: Thu, 24 Jun 2021 15:49:49 -0700 Subject: [PATCH 2/5] Also expose in proxyClassFunctionHandler --- Source/Modules/java.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 614431192..9fc340954 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2694,6 +2694,7 @@ public: Replaceall(imcall, "$imfuncname", intermediary_function_name); } + Replaceall(tm, "$imfuncname", intermediary_function_name); Replaceall(tm, "$jnicall", imcall); } else { Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, "No javaout typemap defined for %s\n", SwigType_str(t, 0)); From e10da8a9a108ee88cd84417e775f4f03a895fe68 Mon Sep 17 00:00:00 2001 From: Lindley French Date: Wed, 2 Feb 2022 15:34:19 -0800 Subject: [PATCH 3/5] Update docs. --- Doc/Manual/Java.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index dc403a98c..3b24c5ba8 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -6439,6 +6439,11 @@ This special variable expands to the intermediary class name. Usually this is th unless the jniclassname attribute is specified in the %module directive.

+

+$imfuncname
+This special variable expands to the name of the function on the $imclassname that will be used in $jnicall. +

+

$javainterfacename
This special variable is only expanded when the interface feature is applied to a class. From 62e0685df61bd636cb101eb58a27e0e14074b0c2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 30 May 2022 19:00:04 +0100 Subject: [PATCH 4/5] Test and document imfuncname special variable expansion --- CHANGES.current | 4 ++++ Doc/Manual/Java.html | 3 ++- .../java/java_typemaps_proxy_runme.java | 9 +++++++++ Examples/test-suite/java_typemaps_proxy.i | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 46c567a02..95114d3f6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-05-30: LindleyF + [Java] #2042 Add new special variable expansion: $imfuncname. + Expands to the function name called in the intermediary class. + 2022-02-02: olly [Ruby] https://sourceforge.net/p/swig/bugs/1136/ Fix remove of prefix from method name to only remove it at the start. diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index 03e3c9124..4a4b1750f 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -6441,7 +6441,8 @@ unless the jniclassname attribute is specified in the

diff --git a/Examples/test-suite/java/java_typemaps_proxy_runme.java b/Examples/test-suite/java/java_typemaps_proxy_runme.java index 67a083114..0caeb1c65 100644 --- a/Examples/test-suite/java/java_typemaps_proxy_runme.java +++ b/Examples/test-suite/java/java_typemaps_proxy_runme.java @@ -76,6 +76,15 @@ public class java_typemaps_proxy_runme { java_typemaps_proxyJNI.Without_member_method(nullPtr, nullPtr); java_typemaps_proxyJNI.delete_Without(nullPtr); java_typemaps_proxyJNI.global_method_without(nullPtr); + + // $imfuncname substitution + ProxyA pa = new ProxyA(); + if (pa.imfuncname_test() != 123) + throw new RuntimeException("imfuncname_test is not 123"); + if (ProxyA.imfuncname_static_test() != 234) + throw new RuntimeException("imfuncname_test is not 234"); + if (java_typemaps_proxy.imfuncname_global_test() != 345) + throw new RuntimeException("imfuncname_test is not 345"); } } diff --git a/Examples/test-suite/java_typemaps_proxy.i b/Examples/test-suite/java_typemaps_proxy.i index 3e9b18335..b20dd385b 100644 --- a/Examples/test-suite/java_typemaps_proxy.i +++ b/Examples/test-suite/java_typemaps_proxy.i @@ -127,3 +127,20 @@ void global_method_constwithout(const ConstWithout *p) {} %} +// $imfuncname substitution +%typemap(javaout) int imfuncname_test { + return $moduleJNI.$imfuncname(swigCPtr, this) + 123; + } +%typemap(javaout) int imfuncname_static_test { + return $moduleJNI.$imfuncname() + 234; + } +%typemap(javaout) int imfuncname_global_test { + return $moduleJNI.$imfuncname() + 345; + } +%inline %{ +struct ProxyA { + int imfuncname_test() { return 0; } + static int imfuncname_static_test() { return 0; } +}; +int imfuncname_global_test() { return 0; } +%} From 954f29b032dfc0ef04e4b0ef0871b04a30068b6b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 30 May 2022 19:43:04 +0100 Subject: [PATCH 5/5] Add special variable imfuncname expansion for C# and D Same functionality as Java --- CHANGES.current | 4 ++ Doc/Manual/CSharp.html | 6 +++ Doc/Manual/D.html | 6 +++ .../csharp/csharp_typemaps_runme.cs | 16 ++++++++ Examples/test-suite/csharp_typemaps.i | 39 +++++++++++++++++++ Source/Modules/csharp.cxx | 6 +++ Source/Modules/d.cxx | 2 + 7 files changed, 79 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 95114d3f6..5e496424c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-05-30: wsfulton + [C#, D] Add new special variable expansion: $imfuncname. + Expands to the function name called in the intermediary class. + 2022-05-30: LindleyF [Java] #2042 Add new special variable expansion: $imfuncname. Expands to the function name called in the intermediary class. diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index fe8f7c4bd..405868b5c 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -550,6 +550,12 @@ This special variable expands to the intermediary class name. For C# this is usu unless the imclassname attribute is specified in the %module directive.

+

+$imfuncname
+This special variable expands to the name of the function in the intermediary class that will be used in $imcall. +Like, $imcall, this special variable is only expanded in the "csout", "csvarin" and "csvarout" typemaps. +

+

The directory Examples/csharp has a number of simple examples. Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C# diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html index f9f2d53ca..99ee027a1 100644 --- a/Doc/Manual/D.html +++ b/Doc/Manual/D.html @@ -267,6 +267,12 @@ SomeClass bar() { +

$imfuncname
+

+This special variable expands to the name of the function in the intermediary class that will be used in $imcall. +Like, $imcall, this special variable is only expanded in the "dout" typemap. +

+
$importtype(SomeDType)

This macro is used in the dimports typemap if a dependency on another D type generated by SWIG is added by a custom typemap.

diff --git a/Examples/test-suite/csharp/csharp_typemaps_runme.cs b/Examples/test-suite/csharp/csharp_typemaps_runme.cs index 846644f09..a9119a0c3 100644 --- a/Examples/test-suite/csharp/csharp_typemaps_runme.cs +++ b/Examples/test-suite/csharp/csharp_typemaps_runme.cs @@ -107,6 +107,22 @@ public class TestThread { Console.Error.WriteLine("Test failed (thread " + threadId + "): " + e.Message); Failed = true; } + + // $imfuncname substitution + ProxyA pa = new ProxyA(); + if (pa.imfuncname_test() != 123) + throw new ApplicationException("imfuncname_test is not 123"); + if (ProxyA.imfuncname_static_test() != 234) + throw new ApplicationException("imfuncname_test is not 234"); + if (csharp_typemaps.imfuncname_global_test() != 345) + throw new ApplicationException("imfuncname_test is not 345"); + + pa.variab = 1000; + if (pa.variab != 1000 + 111 + 222) + throw new ApplicationException("pa.variab is not 1333"); + csharp_typemaps.global_variab = 1000; + if (csharp_typemaps.global_variab != 1000 + 333 + 444) + throw new ApplicationException("csharp_typemaps.variab is not 1777"); } } diff --git a/Examples/test-suite/csharp_typemaps.i b/Examples/test-suite/csharp_typemaps.i index dc5b40c02..a73f01c44 100644 --- a/Examples/test-suite/csharp_typemaps.i +++ b/Examples/test-suite/csharp_typemaps.i @@ -136,3 +136,42 @@ namespace Glob { bool MVar::svar = false; %} +// $imfuncname substitution +%typemap(csout) int imfuncname_test { + return $modulePINVOKE.$imfuncname(swigCPtr) + 123; + } +%typemap(csout) int imfuncname_static_test { + return $modulePINVOKE.$imfuncname() + 234; + } +%typemap(csout) int imfuncname_global_test { + return $modulePINVOKE.$imfuncname() + 345; + } + +%typemap(csvarout, excode=SWIGEXCODE2) int variab %{ + get { + int ret = $modulePINVOKE.$imfuncname(swigCPtr) + 222;$excode + return ret; + } %} +%typemap(csvarin, excode=SWIGEXCODE2) int variab %{ + set { + $modulePINVOKE.$imfuncname(swigCPtr, value + 111);$excode + } %} + +%typemap(csvarout, excode=SWIGEXCODE2) int global_variab %{ + get { + int ret = $modulePINVOKE.$imfuncname() + 333;$excode + return ret; + } %} +%typemap(csvarin, excode=SWIGEXCODE2) int global_variab %{ + set { + $modulePINVOKE.$imfuncname(value + 444);$excode + } %} +%inline %{ +struct ProxyA { + int imfuncname_test() { return 0; } + static int imfuncname_static_test() { return 0; } + int variab; +}; +int imfuncname_global_test() { return 0; } +int global_variab; +%} diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index edb79e13e..f2f48d707 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -2572,6 +2572,7 @@ public: } else { Replaceall(imcall, "$imfuncname", intermediary_function_name); } + Replaceall(tm, "$imfuncname", intermediary_function_name); Replaceall(tm, "$imcall", imcall); } else { Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0)); @@ -2615,6 +2616,7 @@ public: if ((tm = Swig_typemap_lookup("csvarin", variable_parm, "", 0))) { substituteClassname(cvariable_type, tm); Replaceall(tm, "$csinput", "value"); + Replaceall(tm, "$imfuncname", intermediary_function_name); Replaceall(tm, "$imcall", imcall); excodeSubstitute(n, tm, "csvarin", variable_parm); Printf(proxy_class_code, "%s", tm); @@ -2629,6 +2631,7 @@ public: else Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); + Replaceall(tm, "$imfuncname", intermediary_function_name); Replaceall(tm, "$imcall", imcall); excodeSubstitute(n, tm, "csvarout", n); Printf(proxy_class_code, "%s", tm); @@ -3141,6 +3144,7 @@ public: else Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); + Replaceall(tm, "$imfuncname", overloaded_name); Replaceall(tm, "$imcall", imcall); } else { Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0)); @@ -3179,6 +3183,7 @@ public: if ((tm = Getattr(p, "tmap:csvarin"))) { substituteClassname(pt, tm); Replaceall(tm, "$csinput", "value"); + Replaceall(tm, "$imfuncname", overloaded_name); Replaceall(tm, "$imcall", imcall); excodeSubstitute(n, tm, "csvarin", p); Printf(module_class_code, "%s", tm); @@ -3193,6 +3198,7 @@ public: else Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); + Replaceall(tm, "$imfuncname", overloaded_name); Replaceall(tm, "$imcall", imcall); excodeSubstitute(n, tm, "csvarout", n); Printf(module_class_code, "%s", tm); diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx index b7283eac2..9d716f433 100644 --- a/Source/Modules/d.cxx +++ b/Source/Modules/d.cxx @@ -2898,6 +2898,7 @@ private: } else { Replaceall(imcall, "$imfuncname", intermediary_function_name); } + Replaceall(tm, "$imfuncname", intermediary_function_name); Replaceall(tm, "$imcall", imcall); } else { Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number, @@ -3100,6 +3101,7 @@ private: else Replaceall(tm, "$owner", "false"); replaceClassname(tm, t); + Replaceall(tm, "$imfuncname", overloaded_name); Replaceall(tm, "$imcall", imcall); } else { Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,