Skip to content

Commit 34c219b

Browse files
committed
Merge branch 'imfunc'
* imfunc: Add special variable imfuncname expansion for C# and D Test and document imfuncname special variable expansion Update docs. Also expose in proxyClassFunctionHandler Expose to javaout typemaps. Conflicts: CHANGES.current
2 parents 1d6f4b4 + 954f29b commit 34c219b

File tree

11 files changed

+117
-0
lines changed

11 files changed

+117
-0
lines changed

CHANGES.current

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-05-30: wsfulton
11+
[C#, D] Add new special variable expansion: $imfuncname.
12+
Expands to the function name called in the intermediary class.
13+
14+
2022-05-30: LindleyF
15+
[Java] #2042 Add new special variable expansion: $imfuncname.
16+
Expands to the function name called in the intermediary class.
17+
1018
2022-05-28: jkuebart
1119
[Java] On some versions of Android, specifically Android 6,
1220
detaching the current thread from the JVM after every invocation

Doc/Manual/CSharp.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ <H2><a name="CSharp_differences_java">23.2 Differences to the Java module</a></H
550550
unless the imclassname attribute is specified in the <a href="CSharp.html#CSharp_module_directive">%module directive</a>.
551551
</p>
552552

553+
<p>
554+
<b><tt>$imfuncname</tt></b><br>
555+
This special variable expands to the name of the function in the intermediary class that will be used in $imcall.
556+
Like, $imcall, this special variable is only expanded in the "csout", "csvarin" and "csvarout" typemaps.
557+
</p>
558+
553559
<p>
554560
The directory <tt>Examples/csharp</tt> has a number of simple examples.
555561
Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C#

Doc/Manual/D.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ <H3><a name="D_special_variables">24.3.7 Special variable macros</a></H3>
267267
</pre></div>
268268
</dd>
269269

270+
<dt><tt>$imfuncname</tt></dt>
271+
<dd><p>
272+
This special variable expands to the name of the function in the intermediary class that will be used in $imcall.
273+
Like, $imcall, this special variable is only expanded in the "dout" typemap.
274+
</p></dd>
275+
270276
<dt><a name="D_importtype"></a><tt>$importtype(SomeDType)</tt></dt>
271277
<dd>
272278
<p>This macro is used in the <tt>dimports</tt> typemap if a dependency on another D type generated by SWIG is added by a custom typemap.</p>

Doc/Manual/Java.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6456,6 +6456,12 @@ <H3><a name="Java_special_variables">27.9.7 Java special variables</a></H3>
64566456
unless the jniclassname attribute is specified in the <a href="Java.html#Java_module_directive">%module directive</a>.
64576457
</p>
64586458

6459+
<p>
6460+
<b><tt>$imfuncname</tt></b><br>
6461+
This special variable expands to the name of the function in the intermediary class that will be used in $jnicall.
6462+
Like, $jnicall, this special variable is only expanded in the "javaout" typemap.
6463+
</p>
6464+
64596465
<p>
64606466
<b><tt>$javainterfacename</tt></b><br>
64616467
This special variable is only expanded when the <tt>interface</tt> feature is applied to a class.

Examples/test-suite/csharp/csharp_typemaps_runme.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ public void Run() {
107107
Console.Error.WriteLine("Test failed (thread " + threadId + "): " + e.Message);
108108
Failed = true;
109109
}
110+
111+
// $imfuncname substitution
112+
ProxyA pa = new ProxyA();
113+
if (pa.imfuncname_test() != 123)
114+
throw new ApplicationException("imfuncname_test is not 123");
115+
if (ProxyA.imfuncname_static_test() != 234)
116+
throw new ApplicationException("imfuncname_test is not 234");
117+
if (csharp_typemaps.imfuncname_global_test() != 345)
118+
throw new ApplicationException("imfuncname_test is not 345");
119+
120+
pa.variab = 1000;
121+
if (pa.variab != 1000 + 111 + 222)
122+
throw new ApplicationException("pa.variab is not 1333");
123+
csharp_typemaps.global_variab = 1000;
124+
if (csharp_typemaps.global_variab != 1000 + 333 + 444)
125+
throw new ApplicationException("csharp_typemaps.variab is not 1777");
110126
}
111127
}
112128

Examples/test-suite/csharp_typemaps.i

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,42 @@ namespace Glob {
136136
bool MVar::svar = false;
137137
%}
138138

139+
// $imfuncname substitution
140+
%typemap(csout) int imfuncname_test {
141+
return $modulePINVOKE.$imfuncname(swigCPtr) + 123;
142+
}
143+
%typemap(csout) int imfuncname_static_test {
144+
return $modulePINVOKE.$imfuncname() + 234;
145+
}
146+
%typemap(csout) int imfuncname_global_test {
147+
return $modulePINVOKE.$imfuncname() + 345;
148+
}
149+
150+
%typemap(csvarout, excode=SWIGEXCODE2) int variab %{
151+
get {
152+
int ret = $modulePINVOKE.$imfuncname(swigCPtr) + 222;$excode
153+
return ret;
154+
} %}
155+
%typemap(csvarin, excode=SWIGEXCODE2) int variab %{
156+
set {
157+
$modulePINVOKE.$imfuncname(swigCPtr, value + 111);$excode
158+
} %}
159+
160+
%typemap(csvarout, excode=SWIGEXCODE2) int global_variab %{
161+
get {
162+
int ret = $modulePINVOKE.$imfuncname() + 333;$excode
163+
return ret;
164+
} %}
165+
%typemap(csvarin, excode=SWIGEXCODE2) int global_variab %{
166+
set {
167+
$modulePINVOKE.$imfuncname(value + 444);$excode
168+
} %}
169+
%inline %{
170+
struct ProxyA {
171+
int imfuncname_test() { return 0; }
172+
static int imfuncname_static_test() { return 0; }
173+
int variab;
174+
};
175+
int imfuncname_global_test() { return 0; }
176+
int global_variab;
177+
%}

Examples/test-suite/java/java_typemaps_proxy_runme.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public static void main(String argv[]) {
7676
java_typemaps_proxyJNI.Without_member_method(nullPtr, nullPtr);
7777
java_typemaps_proxyJNI.delete_Without(nullPtr);
7878
java_typemaps_proxyJNI.global_method_without(nullPtr);
79+
80+
// $imfuncname substitution
81+
ProxyA pa = new ProxyA();
82+
if (pa.imfuncname_test() != 123)
83+
throw new RuntimeException("imfuncname_test is not 123");
84+
if (ProxyA.imfuncname_static_test() != 234)
85+
throw new RuntimeException("imfuncname_test is not 234");
86+
if (java_typemaps_proxy.imfuncname_global_test() != 345)
87+
throw new RuntimeException("imfuncname_test is not 345");
7988
}
8089
}
8190

Examples/test-suite/java_typemaps_proxy.i

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,20 @@ void global_method_constwithout(const ConstWithout *p) {}
125125
%}
126126

127127

128+
// $imfuncname substitution
129+
%typemap(javaout) int imfuncname_test {
130+
return $moduleJNI.$imfuncname(swigCPtr, this) + 123;
131+
}
132+
%typemap(javaout) int imfuncname_static_test {
133+
return $moduleJNI.$imfuncname() + 234;
134+
}
135+
%typemap(javaout) int imfuncname_global_test {
136+
return $moduleJNI.$imfuncname() + 345;
137+
}
138+
%inline %{
139+
struct ProxyA {
140+
int imfuncname_test() { return 0; }
141+
static int imfuncname_static_test() { return 0; }
142+
};
143+
int imfuncname_global_test() { return 0; }
144+
%}

Source/Modules/csharp.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,7 @@ class CSHARP:public Language {
25952595
} else {
25962596
Replaceall(imcall, "$imfuncname", intermediary_function_name);
25972597
}
2598+
Replaceall(tm, "$imfuncname", intermediary_function_name);
25982599
Replaceall(tm, "$imcall", imcall);
25992600
} else {
26002601
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 @@ class CSHARP:public Language {
26382639
if ((tm = Swig_typemap_lookup("csvarin", variable_parm, "", 0))) {
26392640
substituteClassname(cvariable_type, tm);
26402641
Replaceall(tm, "$csinput", "value");
2642+
Replaceall(tm, "$imfuncname", intermediary_function_name);
26412643
Replaceall(tm, "$imcall", imcall);
26422644
excodeSubstitute(n, tm, "csvarin", variable_parm);
26432645
Printf(proxy_class_code, "%s", tm);
@@ -2652,6 +2654,7 @@ class CSHARP:public Language {
26522654
else
26532655
Replaceall(tm, "$owner", "false");
26542656
substituteClassname(t, tm);
2657+
Replaceall(tm, "$imfuncname", intermediary_function_name);
26552658
Replaceall(tm, "$imcall", imcall);
26562659
excodeSubstitute(n, tm, "csvarout", n);
26572660
Printf(proxy_class_code, "%s", tm);
@@ -3164,6 +3167,7 @@ class CSHARP:public Language {
31643167
else
31653168
Replaceall(tm, "$owner", "false");
31663169
substituteClassname(t, tm);
3170+
Replaceall(tm, "$imfuncname", overloaded_name);
31673171
Replaceall(tm, "$imcall", imcall);
31683172
} else {
31693173
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 @@ class CSHARP:public Language {
32023206
if ((tm = Getattr(p, "tmap:csvarin"))) {
32033207
substituteClassname(pt, tm);
32043208
Replaceall(tm, "$csinput", "value");
3209+
Replaceall(tm, "$imfuncname", overloaded_name);
32053210
Replaceall(tm, "$imcall", imcall);
32063211
excodeSubstitute(n, tm, "csvarin", p);
32073212
Printf(module_class_code, "%s", tm);
@@ -3216,6 +3221,7 @@ class CSHARP:public Language {
32163221
else
32173222
Replaceall(tm, "$owner", "false");
32183223
substituteClassname(t, tm);
3224+
Replaceall(tm, "$imfuncname", overloaded_name);
32193225
Replaceall(tm, "$imcall", imcall);
32203226
excodeSubstitute(n, tm, "csvarout", n);
32213227
Printf(module_class_code, "%s", tm);

Source/Modules/d.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,6 +2898,7 @@ class D : public Language {
28982898
} else {
28992899
Replaceall(imcall, "$imfuncname", intermediary_function_name);
29002900
}
2901+
Replaceall(tm, "$imfuncname", intermediary_function_name);
29012902
Replaceall(tm, "$imcall", imcall);
29022903
} else {
29032904
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
@@ -3100,6 +3101,7 @@ class D : public Language {
31003101
else
31013102
Replaceall(tm, "$owner", "false");
31023103
replaceClassname(tm, t);
3104+
Replaceall(tm, "$imfuncname", overloaded_name);
31033105
Replaceall(tm, "$imcall", imcall);
31043106
} else {
31053107
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,

0 commit comments

Comments
 (0)