diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index f00df7534..ef14c1c11 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -317,6 +317,7 @@ C_TEST_CASES += \ char_constant \ const_const \ enums \ + extern_declaration \ function_typedef \ inctest \ lextype \ diff --git a/Examples/test-suite/extern_declaration.i b/Examples/test-suite/extern_declaration.i new file mode 100644 index 000000000..0acdcca70 --- /dev/null +++ b/Examples/test-suite/extern_declaration.i @@ -0,0 +1,27 @@ +%module extern_declaration + +// Test different calling conventions on Windows. Old versions of SWIG generated +// an incorrect extern declarations that wouldn't compile with Windows compilers. +#define SWIGEXPORT +#define SWIGSTDCALL +#define DLLIMPORT + +%{ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define DLLIMPORT __declspec(dllimport) +#else +# define DLLIMPORT +#endif +%} + +DLLIMPORT extern int externimport(int in); +SWIGEXPORT extern int externexport(int); +extern int SWIGSTDCALL externstdcall(int); + +%{ +SWIGEXPORT extern int externimport(int in) { return in; } +SWIGEXPORT extern int externexport(int in) { return in; } +extern int SWIGSTDCALL externstdcall(int in) { return in; } +%} + + diff --git a/Examples/test-suite/java/extern_declaration_runme.java b/Examples/test-suite/java/extern_declaration_runme.java new file mode 100644 index 000000000..e1d7eb180 --- /dev/null +++ b/Examples/test-suite/java/extern_declaration_runme.java @@ -0,0 +1,21 @@ + +import extern_declaration.*; + +public class extern_declaration_runme { + static { + try { + System.loadLibrary("extern_declaration"); + } 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[]) + { + if (extern_declaration.externimport(100) != 100) throw new RuntimeException("externimport failed"); + if (extern_declaration.externexport(200) != 200) throw new RuntimeException("externexport failed"); + if (extern_declaration.externstdcall(300) != 300) throw new RuntimeException("externstdcall failed"); + } +} +