diff --git a/CHANGES.current b/CHANGES.current index 01a2f73fc..68f7daa54 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,14 @@ 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. + 2022-05-28: jkuebart [Java] On some versions of Android, specifically Android 6, detaching the current thread from the JVM after every invocation 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/Doc/Manual/Java.html b/Doc/Manual/Java.html index 5a631956f..6f1785256 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -6456,6 +6456,12 @@ 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 in the intermediary class that will be used in $jnicall. +Like, $jnicall, this special variable is only expanded in the "javaout" typemap. +

+

$javainterfacename
This special variable is only expanded when the interface feature is applied to a class. 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/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 77d706835..20b86fc01 100644 --- a/Examples/test-suite/java_typemaps_proxy.i +++ b/Examples/test-suite/java_typemaps_proxy.i @@ -125,3 +125,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; } +%} diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index 55aae1d0e..294f7c20f 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -2595,6 +2595,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)); @@ -2638,6 +2639,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); @@ -2652,6 +2654,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); @@ -3164,6 +3167,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)); @@ -3202,6 +3206,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); @@ -3216,6 +3221,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 71264105d..ff32dbf0b 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, diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 558231cf8..ea7e4607a 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2691,6 +2691,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)); @@ -3176,6 +3177,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));