mirror of https://github.com/swig/swig
Fix handling of typedef'd function pointers for Go
Add equivalent runtime tests for Python and Java
This commit is contained in:
parent
72ba741d1c
commit
dcc5911839
|
@ -7,6 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 3.0.13 (in progress)
|
||||
============================
|
||||
|
||||
2017-03-17: wsfulton
|
||||
[Go] Fix handling of typedef'd function pointers and typedef'd member function pointers
|
||||
such as:
|
||||
|
||||
typedef int (*FnPtr_td)(int, int);
|
||||
int do_op(int x, int y, FnPtr_td op);
|
||||
|
||||
2017-03-16: wsfulton
|
||||
Add support for member const function pointers such as:
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import . "./typedef_funcptr"
|
||||
|
||||
func main() {
|
||||
a := 100
|
||||
b := 10
|
||||
|
||||
if Do_op(a,b,Addf) != 110 {
|
||||
panic(0)
|
||||
}
|
||||
if Do_op(a,b,Subf) != 90 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if Do_op_typedef_int(a,b,Addf) != 110 {
|
||||
panic(0)
|
||||
}
|
||||
if Do_op_typedef_int(a,b,Subf) != 90 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if Do_op_typedef_Integer(a,b,Addf) != 110 {
|
||||
panic(0)
|
||||
}
|
||||
if Do_op_typedef_Integer(a,b,Subf) != 90 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
import typedef_funcptr.*;
|
||||
|
||||
public class typedef_funcptr_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("typedef_funcptr");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
int a = 100;
|
||||
int b = 10;
|
||||
|
||||
if (typedef_funcptr.do_op(a,b,typedef_funcptr.addf) != 110)
|
||||
throw new RuntimeException("addf failed");
|
||||
if (typedef_funcptr.do_op(a,b,typedef_funcptr.subf) != 90)
|
||||
throw new RuntimeException("subf failed");
|
||||
|
||||
if (typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.addf) != 110)
|
||||
throw new RuntimeException("addf failed");
|
||||
if (typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.subf) != 90)
|
||||
throw new RuntimeException("subf failed");
|
||||
|
||||
if (typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.addf) != 110)
|
||||
throw new RuntimeException("addf failed");
|
||||
if (typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.subf) != 90)
|
||||
throw new RuntimeException("subf failed");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
import typedef_funcptr
|
||||
|
||||
a = 100
|
||||
b = 10
|
||||
|
||||
if typedef_funcptr.do_op(a,b,typedef_funcptr.addf) != 110:
|
||||
raise RuntimeError("addf failed")
|
||||
if typedef_funcptr.do_op(a,b,typedef_funcptr.subf) != 90:
|
||||
raise RuntimeError("subf failed")
|
||||
|
||||
if typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.addf) != 110:
|
||||
raise RuntimeError("addf failed")
|
||||
if typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.subf) != 90:
|
||||
raise RuntimeError("subf failed")
|
||||
|
||||
if typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.addf) != 110:
|
||||
raise RuntimeError("addf failed")
|
||||
if typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.subf) != 90:
|
||||
raise RuntimeError("subf failed")
|
||||
|
|
@ -21,6 +21,16 @@ extern "C"
|
|||
Integer do_op(Integer x, Integer y, Integer (*op)(Integer, Integer)) {
|
||||
return (*op)(x,y);
|
||||
}
|
||||
|
||||
typedef int (*FnPtr_int_td)(int, int);
|
||||
int do_op_typedef_int(int x, int y, FnPtr_int_td op) {
|
||||
return (*op)(x,y);
|
||||
}
|
||||
|
||||
typedef Integer (*FnPtr_Integer_td)(Integer, Integer);
|
||||
Integer do_op_typedef_Integer(Integer x, Integer y, FnPtr_Integer_td op) {
|
||||
return (*op)(x,y);
|
||||
}
|
||||
%}
|
||||
|
||||
%constant int addf(int x, int y);
|
||||
|
|
|
@ -6241,7 +6241,7 @@ private:
|
|||
Setattr(undefined_enum_types, t, ret);
|
||||
Delete(tt);
|
||||
}
|
||||
} else if (SwigType_isfunctionpointer(type) || SwigType_isfunction(type)) {
|
||||
} else if (SwigType_isfunctionpointer(t) || SwigType_isfunction(t)) {
|
||||
ret = NewString("_swig_fnptr");
|
||||
} else if (SwigType_ismemberpointer(t)) {
|
||||
ret = NewString("_swig_memberptr");
|
||||
|
|
Loading…
Reference in New Issue