merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11821 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2010-01-11 00:59:12 +00:00
commit d8a371808a
190 changed files with 5425 additions and 2040 deletions

View file

@ -28,12 +28,14 @@
# The 'clean' target cleans up.
#
# Note that the RUNTOOL, COMPILETOOL and SWIGTOOL variables can be used
# for # invoking tools for the runtime tests and target language
# for invoking tools for the runtime tests and target language
# compiler (eg javac) respectively. For example, valgrind can be used
# for memory checking of the runtime tests using:
# make RUNTOOL="valgrind --leak-check-full"
# make RUNTOOL="valgrind --leak-check=full"
# and valgrind can be used when invoking SWIG using:
# make SWIGTOOL="valgrind --tool=memcheck"
# make SWIGTOOL="valgrind --tool=memcheck --trace-children=yes"
# Note: trace-children needed because of preinst-swig shell wrapper
# to the swig executable.
#
# The variables below can be overridden after including this makefile
#######################################################################
@ -78,8 +80,6 @@ CPP_TEST_BROKEN += \
exception_partial_info \
extend_variable \
li_std_vector_ptr \
namespace_union \
nested_structs \
overload_complicated \
template_default_pointer \
template_expr
@ -189,6 +189,7 @@ CPP_TEST_CASES += \
extend_placement \
extend_template \
extend_template_ns \
extern_c \
extern_namespace \
extern_throws \
features \
@ -238,9 +239,12 @@ CPP_TEST_CASES += \
namespace_template \
namespace_typedef_class \
namespace_typemap \
namespace_union \
namespace_virtual_method \
naturalvar \
nested_class \
nested_comment \
nested_workaround \
newobject1 \
null_pointer \
operator_overload \
@ -255,6 +259,7 @@ CPP_TEST_CASES += \
overload_template \
overload_template_fast \
pointer_reference \
preproc_constants \
primitive_ref \
private_assign \
protected_rename \
@ -297,6 +302,7 @@ CPP_TEST_CASES += \
static_array_member \
static_const_member \
static_const_member_2 \
struct_initialization_cpp \
struct_value \
template \
template_arg_replace \
@ -327,6 +333,8 @@ CPP_TEST_CASES += \
template_inherit_abstract \
template_int_const \
template_methods \
template_nested \
template_nested_typemaps \
template_ns \
template_ns2 \
template_ns3 \
@ -336,6 +344,8 @@ CPP_TEST_CASES += \
template_ns_inherit \
template_ns_scope \
template_partial_arg \
template_partial_specialization \
template_partial_specialization_typedef \
template_qualifier \
template_qualifier \
template_ref_type \
@ -409,6 +419,7 @@ CPP_STD_TEST_CASES += \
li_std_combinations \
li_std_deque \
li_std_except \
li_std_map \
li_std_pair \
li_std_string \
li_std_vector \
@ -430,6 +441,7 @@ C_TEST_CASES += \
arrays \
char_constant \
const_const \
constant_expr \
empty \
enums \
extern_declaration \
@ -447,17 +459,21 @@ C_TEST_CASES += \
li_cpointer \
li_math \
long_long \
memberin_extend_c \
name \
nested \
nested_structs \
newobject2 \
overload_extend \
overload_extendc \
preproc \
preproc_constants_c \
ret_by_value \
simple_array \
sizeof_pointer \
sneaky1 \
struct_rename \
struct_initialization \
typedef_struct \
typemap_subst \
union_parameter \

View file

@ -0,0 +1,11 @@
%module constant_expr;
/* Tests of constant expressions. */
%inline %{
/* % didn't work in SWIG 1.3.40 and earlier. */
const int X = 123%7;
#define FOO 12 % 6
double d_array[12 % 6];
%}

View file

@ -1,36 +1,6 @@
%module cpp_broken
// bug #1060789
%inline %{
#define MASK(shift, size) (((1 << (size)) - 1) << (shift))
#define SOME_MASK_DEF (80*MASK(8, 10))
%}
// bug #1060079
%inline %{
#define FIELD(name, width) unsigned int name:width
#define SOME_CONST 2
#define NEXT_CONST (2 * SOME_CONST)
typedef struct {
FIELD(a, SOME_CONST);
FIELD(b, NEXT_CONST);
} MyStruct_t;
%}
%{
#ifdef max
#undef max
#endif
%}
// bug #994301
%inline %{
#define max(a,b) ((a) > (b) ? (a) : (b))
%}
// bug #940318
%inline %{
typedef enum {
@ -40,36 +10,3 @@ eZero = 0
%}
// bug #754443
%inline %{
#define MAG_STYLE_BORDER_OFFS 0
#define MAG_STYLE_BORDER_BITS 3
#define MAG_STYLE_BORDER_MASK (((1UL<<MAG_STYLE_BORDER_BITS)-1)<<MAG_STYLE_BORDER_OFFS)
/* these CANNOT be combined */
#define MAG_STYLE_BORDER_NONE (1 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_STATIC (2 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_SIMPLE (3 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_RAISED (4 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_DOUBLE (5 << MAG_STYLE_BORDER_OFFS)
#define MAG_STYLE_BORDER_DEFAULT MAG_STYLE_BORDER_SIMPLE
#define MAG_STYLE_CAPTION_OFFS ( MAG_STYLE_BORDER_OFFS + MAG_STYLE_BORDER_BITS )
#define MAG_STYLE_CAPTION_BITS 8
#define MAG_STYLE_CAPTION_MASK (((1UL<<MAG_STYLE_CAPTION_BITS)-1)<<MAG_STYLE_CAPTION_OFFS)
/* these CAN be combined */
#define MAG_STYLE_CAPTION_NONE ( 1 << ( 0 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_PRESENT ( 1 << ( 1 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_SYSMENU ( 1 << ( 2 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_MINIMIZE ( 1 << ( 3 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_MAXIMIZE ( 1 << ( 4 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_RESIZE ( 1 << ( 5 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_TINYHOR ( 1 << ( 6 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_TINYVER ( 1 << ( 7 + MAG_STYLE_CAPTION_OFFS ))
#define MAG_STYLE_CAPTION_DEFAULT ( MAG_STYLE_CAPTION_RESIZE + MAG_STYLE_CAPTION_MAXIMIZE + MAG_STYLE_CAPTION_MINIMIZE + MAG_STYLE_CAPTION_SYSMENU + MAG_STYLE_CAPTION_PRESENT )
%}

View file

@ -1,5 +1,6 @@
using System;
using System.Reflection;
using System.ComponentModel;
using csharp_attributesNamespace;
public class runme
@ -171,6 +172,24 @@ public class runme
if (Attribute.GetCustomAttribute(member, typeof(Eurostar2Attribute)) == null)
throw new Exception("No attribute for " + member.Name);
}
// Enum value attributes
Type walesType = typeof(MoreStations.Wales);
{
MemberInfo member = (MemberInfo)walesType.GetMember("Cardiff")[0];
DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(System.ComponentModel.DescriptionAttribute));
if (attribute == null)
throw new Exception("No attribute for " + member.Name);
if (attribute.Description != "Cardiff city station")
throw new Exception("Incorrect attribute value for " + member.Name);
}
{
MemberInfo member = (MemberInfo)walesType.GetMember("Swansea")[0];
DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(System.ComponentModel.DescriptionAttribute));
if (attribute == null)
throw new Exception("No attribute for " + member.Name);
if (attribute.Description != "Swansea city station")
throw new Exception("Incorrect attribute value for " + member.Name);
}
// Enum csattribute typemap
{
Type cymrutype = typeof(Cymru);
@ -179,6 +198,8 @@ public class runme
if (tgv == null)
throw new Exception("No attribute for Cymru");
}
// No runtime test for directorinattributes and directoroutattributes
}
}
@ -237,3 +258,9 @@ public class ThreadSafeAttribute : Attribute {
public ThreadSafeAttribute() {}
}
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public class DirectorIntegerOutAttribute : Attribute {}
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public class DirectorIntegerInAttribute : Attribute {}

View file

@ -158,7 +158,8 @@ public class li_std_vector_runme {
} catch (ArgumentNullException) {
}
{
myDoubleVector = new DoubleVector() { 123.4, 567.8, 901.2 };
// Collection initializer test, requires C# 3.0
// myDoubleVector = new DoubleVector() { 123.4, 567.8, 901.2 };
}
// IndexOf() test
@ -542,8 +543,8 @@ public class li_std_vector_runme {
// Dispose()
{
using (StructVector vs = new StructVector() { new Struct(0.0), new Struct(11.1) } )
using (DoubleVector vd = new DoubleVector() { 0.0, 11.1 } ) {
using (StructVector vs = new StructVector( new Struct[] { new Struct(0.0), new Struct(11.1) } ) )
using (DoubleVector vd = new DoubleVector( new double[] { 0.0, 11.1 } ) ) {
}
}

View file

@ -0,0 +1,70 @@
using System;
using System.Reflection;
using preproc_constants_cNamespace;
// Same as preproc_constants_c.i testcase, but bool types are int instead
public class runme {
static void Main() {
assert( typeof(int) == preproc_constants_c.CONST_INT1.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_INT2.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT1.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT2.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT3.GetType() );
assert( typeof(uint) == preproc_constants_c.CONST_UINT4.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG1.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG2.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG3.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_LONG4.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG1.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG2.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG3.GetType() );
assert( typeof(long) == preproc_constants_c.CONST_LLONG4.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG1.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG2.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG3.GetType() );
assert( typeof(ulong) == preproc_constants_c.CONST_ULLONG4.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE1.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE2.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE3.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE4.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE5.GetType() );
assert( typeof(double) == preproc_constants_c.CONST_DOUBLE6.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_BOOL1.GetType() );
assert( typeof(int) == preproc_constants_c.CONST_BOOL2.GetType() );
assert( typeof(char) == preproc_constants_c.CONST_CHAR.GetType() );
assert( typeof(string) == preproc_constants_c.CONST_STRING1.GetType() );
assert( typeof(string) == preproc_constants_c.CONST_STRING2.GetType() );
assert( typeof(int) == preproc_constants_c.INT_AND_BOOL.GetType() );
// assert( typeof(int) == preproc_constants_c.INT_AND_CHAR.GetType() );
assert( typeof(int) == preproc_constants_c.INT_AND_INT.GetType() );
assert( typeof(uint) == preproc_constants_c.INT_AND_UINT.GetType() );
assert( typeof(int) == preproc_constants_c.INT_AND_LONG.GetType() );
assert( typeof(uint) == preproc_constants_c.INT_AND_ULONG.GetType() );
assert( typeof(long) == preproc_constants_c.INT_AND_LLONG.GetType() );
assert( typeof(ulong) == preproc_constants_c.INT_AND_ULLONG.GetType() );
assert( typeof(int ) == preproc_constants_c.BOOL_AND_BOOL.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_MULTIPLY.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_DIVIDE.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_PLUS.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_MINUS.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LSHIFT.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_RSHIFT.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LTE.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_GTE.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_INEQUALITY.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_EQUALITY.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_AND.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_XOR.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_OR.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
}
static void assert(bool assertion) {
if (!assertion)
throw new ApplicationException("test failed");
}
}

View file

@ -0,0 +1,69 @@
using System;
using System.Reflection;
using preproc_constantsNamespace;
public class runme {
static void Main() {
assert( typeof(int) == preproc_constants.CONST_INT1.GetType() );
assert( typeof(int) == preproc_constants.CONST_INT2.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT1.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT2.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT3.GetType() );
assert( typeof(uint) == preproc_constants.CONST_UINT4.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG1.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG2.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG3.GetType() );
assert( typeof(int) == preproc_constants.CONST_LONG4.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG1.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG2.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG3.GetType() );
assert( typeof(long) == preproc_constants.CONST_LLONG4.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG1.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG2.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG3.GetType() );
assert( typeof(ulong) == preproc_constants.CONST_ULLONG4.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE1.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE2.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE3.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE4.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE5.GetType() );
assert( typeof(double) == preproc_constants.CONST_DOUBLE6.GetType() );
assert( typeof(bool) == preproc_constants.CONST_BOOL1.GetType() );
assert( typeof(bool) == preproc_constants.CONST_BOOL2.GetType() );
assert( typeof(char) == preproc_constants.CONST_CHAR.GetType() );
assert( typeof(string) == preproc_constants.CONST_STRING1.GetType() );
assert( typeof(string) == preproc_constants.CONST_STRING2.GetType() );
assert( typeof(int) == preproc_constants.INT_AND_BOOL.GetType() );
// assert( typeof(int) == preproc_constants.INT_AND_CHAR.GetType() );
assert( typeof(int) == preproc_constants.INT_AND_INT.GetType() );
assert( typeof(uint) == preproc_constants.INT_AND_UINT.GetType() );
assert( typeof(int) == preproc_constants.INT_AND_LONG.GetType() );
assert( typeof(uint) == preproc_constants.INT_AND_ULONG.GetType() );
assert( typeof(long) == preproc_constants.INT_AND_LLONG.GetType() );
assert( typeof(ulong) == preproc_constants.INT_AND_ULLONG.GetType() );
assert( typeof(int ) == preproc_constants.BOOL_AND_BOOL.GetType() );
assert( typeof(int) == preproc_constants.EXPR_MULTIPLY.GetType() );
assert( typeof(int) == preproc_constants.EXPR_DIVIDE.GetType() );
assert( typeof(int) == preproc_constants.EXPR_PLUS.GetType() );
assert( typeof(int) == preproc_constants.EXPR_MINUS.GetType() );
assert( typeof(int) == preproc_constants.EXPR_LSHIFT.GetType() );
assert( typeof(int) == preproc_constants.EXPR_RSHIFT.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_LTE.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_GTE.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_INEQUALITY.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_EQUALITY.GetType() );
assert( typeof(int) == preproc_constants.EXPR_AND.GetType() );
assert( typeof(int) == preproc_constants.EXPR_XOR.GetType() );
assert( typeof(int) == preproc_constants.EXPR_OR.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
}
static void assert(bool assertion) {
if (!assertion)
throw new ApplicationException("test failed");
}
}

View file

@ -1,4 +1,4 @@
%module csharp_attributes
%module(directors="1") csharp_attributes
// Test the inattributes and outattributes typemaps
%typemap(cstype, outattributes="[IntOut]", inattributes="[IntIn]") int "int"
@ -15,6 +15,8 @@ public:
int GlobalFunction(int myInt) { return myInt; }
%}
//%include "enumsimple.swg"
//%include "enumtypesafe.swg"
// Test the attributes feature
%csattributes MoreStations::MoreStations() "[InterCity1]"
@ -25,6 +27,8 @@ int GlobalFunction(int myInt) { return myInt; }
%csattributes Wales "[InterCity6]"
%csattributes Paddington() "[InterCity7]"
%csattributes DidcotParkway "[InterCity8]"
%csattributes MoreStations::Cardiff "[System.ComponentModel.Description(\"Cardiff city station\")]"
%csattributes Swansea "[System.ComponentModel.Description(\"Swansea city station\")]"
%typemap(csattributes) MoreStations "[Eurostar1]"
%typemap(csattributes) MoreStations::Wales "[Eurostar2]"
@ -46,3 +50,13 @@ enum Cymru { Llanelli };
double MoreStations::WestonSuperMare = 0.0;
%}
// Test directorinattributes and directoroutattributes
%typemap(imtype, directoroutattributes="[DirectorIntegerOut]", directorinattributes="[DirectorIntegerIn]") int "int"
%feature("director") YetMoreStations;
%inline %{
struct YetMoreStations {
virtual int Slough(int x) {}
virtual ~YetMoreStations() {}
};
%}

View file

@ -3,6 +3,11 @@ This was reported in bug #909389 */
%module derived_nested
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::CC;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::DD;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::EE;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::FF;
%inline %{
class A { int x; };
@ -11,5 +16,12 @@ class B {
class D : public A { int z; }; //ok
};
struct BB {
class CC { int y; };
class DD : public A { int z; };
struct EE : public A { int z; };
struct FF : public A { int z; } ff_instance; // Bug 1960977
void useEE(const EE& e) {}
};
%}

View file

@ -8,6 +8,7 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance1;
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance2;
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) globalinstance3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);
%inline %{
@ -64,7 +65,7 @@ typedef struct _iFoo
enum {
Phoo = +50,
Char = 'a'
} e;
} e;
} iFoo;
%}
#else
@ -77,5 +78,20 @@ struct iFoo
};
};
%}
#endif
// enum declaration and initialization
%inline %{
enum Exclamation {
goodness,
gracious,
me
} enumInstance = me;
enum ContainYourself {
slap = 10,
my,
thigh
} Slap = slap, My = my, Thigh = thigh, *pThigh = &Thigh, arrayContainYourself[3] = {slap, my, thigh};
%}

View file

@ -0,0 +1,16 @@
%module extern_c
%inline %{
extern "C" {
void RealFunction(int value);
typedef void Function1(int value); // Fails
typedef int Integer1;
}
typedef void Function2(int value); // Works
typedef int Integer2;
%}
%{
void RealFunction(int value) {}
%}

View file

@ -34,6 +34,12 @@ public class java_director_runme {
System.gc();
System.runFinalization();
// Give the finalizers a chance to run
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
/* Watch the Quux objects formerly in the QuuxContainer object
get reaped */
System.gc();
@ -73,3 +79,14 @@ class java_director_MyQuux extends Quux {
return "java_director_MyQuux:" + member();
}
}
class java_director_JavaExceptionTest extends JavaExceptionTest {
public java_director_JavaExceptionTest() {
super();
}
public void etest() throws Exception {
super.etest();
}
}

View file

@ -28,7 +28,7 @@ public class java_jnitypes_runme {
double doubleArray[] = new double[] {10.0, 20.0};
Test objectArray[] = new Test[] {new Test(), test};
if (java_jnitypes.jnifunc(true) != true) testFailed("jboolean");
if (java_jnitypes.jnifunc_bool(true) != true) testFailed("jboolean");
if (java_jnitypes.jnifunc('A') != 'A') testFailed("jchar");
if (java_jnitypes.jnifunc((byte)100) != (byte)100) testFailed("jbyte");
if (java_jnitypes.jnifunc((short)100) != (short)100) testFailed("jshort");

View file

@ -0,0 +1,72 @@
import nested_class.*;
public class nested_class_runme {
static {
try {
System.loadLibrary("nested_class");
} 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[]) {
Outer outer = new Outer();
SWIGTYPE_p_Outer__InnerStruct1 is1 = outer.makeInnerStruct1();
SWIGTYPE_p_Outer__InnerClass1 ic1 = outer.makeInnerClass1();
SWIGTYPE_p_Outer__InnerUnion1 iu1 = outer.makeInnerUnion1();
SWIGTYPE_p_Outer__InnerStruct2 is2 = outer.makeInnerStruct2();
SWIGTYPE_p_Outer__InnerClass2 ic2 = outer.makeInnerClass2();
SWIGTYPE_p_Outer__InnerUnion2 iu2 = outer.makeInnerUnion2();
SWIGTYPE_p_Outer__InnerClass4Typedef ic4 = outer.makeInnerClass4Typedef();
SWIGTYPE_p_Outer__InnerStruct4Typedef is4 = outer.makeInnerStruct4Typedef();
SWIGTYPE_p_Outer__InnerUnion4Typedef iu4 = outer.makeInnerUnion4Typedef();
SWIGTYPE_p_Outer__InnerClass5 ic5 = outer.makeInnerClass5();
SWIGTYPE_p_Outer__InnerStruct5 is5 = outer.makeInnerStruct5();
SWIGTYPE_p_Outer__InnerUnion5 iu5 = outer.makeInnerUnion5();
ic5 = outer.makeInnerClass5Typedef();
is5 = outer.makeInnerStruct5Typedef();
iu5 = outer.makeInnerUnion5Typedef();
{
SWIGTYPE_p_Outer__InnerMultiple im1 = outer.getMultipleInstance1();
SWIGTYPE_p_Outer__InnerMultiple im2 = outer.getMultipleInstance2();
SWIGTYPE_p_Outer__InnerMultiple im3 = outer.getMultipleInstance3();
SWIGTYPE_p_Outer__InnerMultiple im4 = outer.getMultipleInstance4();
}
{
SWIGTYPE_p_Outer__InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1();
SWIGTYPE_p_Outer__InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2();
SWIGTYPE_p_Outer__InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3();
SWIGTYPE_p_Outer__InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4();
}
{
SWIGTYPE_p_Outer__InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1();
SWIGTYPE_p_Outer__InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2();
SWIGTYPE_p_Outer__InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3();
SWIGTYPE_p_Outer__InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4();
}
{
SWIGTYPE_p_Outer__InnerMultipleAnonTypedef1 mat1 = outer.makeInnerMultipleAnonTypedef1();
SWIGTYPE_p_Outer__InnerMultipleAnonTypedef2 mat2 = outer.makeInnerMultipleAnonTypedef2();
SWIGTYPE_p_Outer__InnerMultipleAnonTypedef3 mat3 = outer.makeInnerMultipleAnonTypedef3();
SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt = outer.makeInnerMultipleNamedTypedef();
SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt1 = outer.makeInnerMultipleNamedTypedef1();
SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt2 = outer.makeInnerMultipleNamedTypedef2();
SWIGTYPE_p_p_Outer__InnerMultipleNamedTypedef mnt3 = outer.makeInnerMultipleNamedTypedef3();
}
{
SWIGTYPE_p_Outer__InnerSameName isn = outer.makeInnerSameName();
}
}
}

View file

@ -0,0 +1,37 @@
import nested_structs.*;
public class nested_structs_runme {
static {
try {
System.loadLibrary("nested_structs");
} 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[]) {
Outer outer = new Outer();
nested_structs.setValues(outer, 10);
Outer_inner1 inner1 = outer.getInner1();
Outer_inner2 inner2 = outer.getInner2();
Outer_inner3 inner3 = outer.getInner3();
Outer_inner4 inner4 = outer.getInner4();
if (inner1.getVal() != 10) throw new RuntimeException("failed inner1");
if (inner2.getVal() != 20) throw new RuntimeException("failed inner2");
if (inner3.getVal() != 20) throw new RuntimeException("failed inner3");
if (inner4.getVal() != 40) throw new RuntimeException("failed inner4");
Outer_inside1 inside1 = outer.getInside1();
Outer_inside2 inside2 = outer.getInside2();
Outer_inside3 inside3 = outer.getInside3();
Outer_inside4 inside4 = outer.getInside4();
if (inside1.getVal() != 100) throw new RuntimeException("failed inside1");
if (inside2.getVal() != 200) throw new RuntimeException("failed inside2");
if (inside3.getVal() != 200) throw new RuntimeException("failed inside3");
if (inside4.getVal() != 400) throw new RuntimeException("failed inside4");
}
}

View file

@ -0,0 +1,31 @@
import nested_workaround.*;
public class nested_workaround_runme {
static {
try {
System.loadLibrary("nested_workaround");
} 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[]) {
{
Inner inner = new Inner(5);
Outer outer = new Outer();
Inner newInner = outer.doubleInnerValue(inner);
if (newInner.getValue() != 10)
throw new RuntimeException("inner failed");
}
{
Outer outer = new Outer();
Inner inner = outer.createInner(3);
Inner newInner = outer.doubleInnerValue(inner);
if (outer.getInnerValue(newInner) != 6)
throw new RuntimeException("inner failed");
}
}
}

View file

@ -0,0 +1,30 @@
import template_nested.*;
public class template_nested_runme {
static {
try {
System.loadLibrary("template_nested");
} 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[]) {
new T_NormalTemplateNormalClass().tmethod(new NormalClass());
new OuterClass().T_OuterTMethodNormalClass(new NormalClass());
TemplateFuncs tf = new TemplateFuncs();
if (tf.T_TemplateFuncs1Int(-10) != -10)
throw new RuntimeException("it failed");
if (tf.T_TemplateFuncs2Double(-12.3) != -12.3)
throw new RuntimeException("it failed");
T_NestedOuterTemplateDouble tn = new T_NestedOuterTemplateDouble();
if (tn.hohum(-12.3) != -12.3)
throw new RuntimeException("it failed");
}
}

View file

@ -0,0 +1,39 @@
import template_nested_typemaps.*;
public class template_nested_typemaps_runme {
static {
try {
System.loadLibrary("template_nested_typemaps");
} 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[]) {
BreezeString b = new BreezeString();
{
int v = 88;
short vTypemap = -99;
if (b.methodInt1(v) != v) throw new RuntimeException("failed");
if (b.methodInt2(v) != vTypemap) throw new RuntimeException("failed");
if (template_nested_typemaps.globalInt1(v) != v) throw new RuntimeException("failed");
if (template_nested_typemaps.globalInt2(v) != v) throw new RuntimeException("failed");
if (template_nested_typemaps.globalInt3(v) != vTypemap) throw new RuntimeException("failed");
}
{
short v = 88;
short vTypemap = -77;
if (b.methodShort1(v) != v) throw new RuntimeException("failed");
if (b.methodShort2(v) != vTypemap) throw new RuntimeException("failed");
if (template_nested_typemaps.globalShort1(v) != v) throw new RuntimeException("failed");
if (template_nested_typemaps.globalShort2(v) != v) throw new RuntimeException("failed");
if (template_nested_typemaps.globalShort3(v) != vTypemap) throw new RuntimeException("failed");
}
}
}

View file

@ -0,0 +1,59 @@
import template_partial_specialization.*;
public class template_partial_specialization_runme {
static {
try {
System.loadLibrary("template_partial_specialization");
} 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[]) {
// One parameter tests
new A().a();
new B().b();
new C().c();
new D().d();
new E().e();
new F().f();
new G().g();
new H().h();
new I().i();
new J().j();
new K().k();
new L().l();
new BB().b();
new BBB().b();
new BBBB().b();
new BBBBB().b();
new B1().b();
new B2().b();
new B3().b();
new B4().b();
// Two parameter tests
new A_().a();
new B_().b();
new C_().c();
new D_().d();
new E_().e();
new F_().f();
new G_().g();
new C1_().c();
new C2_().c();
new C3_().c();
new C4_().c();
new B1_().b();
new E1_().e();
new E2_().e();
}
}

View file

@ -0,0 +1,59 @@
import template_partial_specialization_typedef.*;
public class template_partial_specialization_typedef_runme {
static {
try {
System.loadLibrary("template_partial_specialization_typedef");
} 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[]) {
// One parameter tests
new A().a();
new B().b();
new C().c();
new D().d();
new E().e();
new F().f();
new G().g();
new H().h();
new I().i();
new J().j();
new K().k();
new L().l();
new BB().b();
new BBB().b();
new BBBB().b();
new BBBBB().b();
new B1().b();
new B2().b();
new B3().b();
new B4().b();
// Two parameter tests
new A_().a();
new B_().b();
new C_().c();
new D_().d();
new E_().e();
new F_().f();
new G_().g();
new C1_().c();
new C2_().c();
new C3_().c();
new C4_().c();
new B1_().b();
new E1_().e();
new E2_().e();
}
}

View file

@ -122,3 +122,11 @@ struct JObjectTest {
%}
%javaexception("Exception") etest "$action"
%inline %{
struct JavaExceptionTest {
virtual ~JavaExceptionTest() {}
virtual void etest() {}
};
%}

View file

@ -5,7 +5,7 @@
%inline %{
jboolean jnifunc(jboolean in) { return in; }
jboolean jnifunc_bool(jboolean in) { return in; } /* some JVM implementations won't allow overloading of the jboolean type with some of the others on the c++ level */
jchar jnifunc(jchar in) { return in; }
jbyte jnifunc(jbyte in) { return in; }
jshort jnifunc(jshort in) { return in; }

View file

@ -5,4 +5,4 @@
%cdata(int);
%cdata(double);
void *malloc(size_t size);

View file

@ -10,43 +10,43 @@
void RDouble(double &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PFloat(float *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (float)(FrVal + t); }
void RFloat(float &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (float)(FrVal + t); }
void PInt(int *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (int)(FrVal + t); }
void RInt(int &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (int)(FrVal + t); }
void PShort(short *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (short)(FrVal + t); }
void RShort(short &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (short)(FrVal + t); }
void PLong(long *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (long)(FrVal + t); }
void RLong(long &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (long)(FrVal + t); }
void PUInt(unsigned int *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (unsigned int)(FrVal + t); }
void RUInt(unsigned int &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (unsigned int)(FrVal + t); }
void PUShort(unsigned short *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (unsigned short)(FrVal + t); }
void RUShort(unsigned short &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (unsigned short)(FrVal + t); }
void PULong(unsigned long *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (unsigned long)(FrVal + t); }
void RULong(unsigned long &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (unsigned long)(FrVal + t); }
void PUChar(unsigned char *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (unsigned char)(FrVal + t); }
void RUChar(unsigned char &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (unsigned char)(FrVal + t); }
void PChar(signed char *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (signed char)(FrVal + t); }
void RChar(signed char &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (signed char)(FrVal + t); }
void PBool(bool *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
{ ToVal = *REFERENCE; *REFERENCE = (FrVal + t) ? true : false; }
void RBool(bool &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
{ ToVal = REFERENCE; REFERENCE = (FrVal + t) ? true : false; }
%}

View file

@ -125,15 +125,16 @@ std::vector<std::string> vecStr(std::vector<std::string> v) {
%inline %{
int *makeIntPtr(int v) { return new int(v); }
const short *makeConstShortPtr(int v) { return new short(v); }
double *makeDoublePtr(double v) { return new double(v); }
int extractInt(int *p) { return *p; }
short extractConstShort(const short *p) { return *p; }
%}
%template(pyvector) std::vector<swig::SwigPtr_PyObject>;
namespace std {
%template(ConstShortVector) vector<const short *>;
// %template(ConstIntVector) vector<const int *>; // interferes with vector<int *>... see new testcase li_std_vector_ptr
%template(ConstShortPtrVector) vector<const short *>;
}
%inline %{

View file

@ -1,3 +1,4 @@
// Bug 2359417
%module li_std_vector_ptr
%include "std_vector.i"

View file

@ -2,12 +2,12 @@ require("import") -- the import fn
import("overload_template_fast") -- import code
for k,v in pairs(overload_template_fast) do _G[k]=v end -- move to global
-- lua has only one numeric type, so max(int,int) and max(double,double) are the same
-- lua has only one numeric type, so maximum(int,int) and maximum(double,double) are the same
-- whichever one was wrapper first will be used (which is int)
f = foo()
a = max(3,4)
a = maximum(3,4)
-- mix 1
assert(mix1("hi") == 101)

View file

@ -1,6 +1,6 @@
%module memberin_extend
// Tests memberin typemap. The default char * memberin typemap will be used.
// Tests memberin typemap is not used for %extend.
// The test extends the struct with a pseudo member variable
%inline %{
@ -12,8 +12,19 @@ struct ExtendMe {
%{
#include <map>
std::map<ExtendMe*, char *> ExtendMeStringMap;
#define ExtendMe_thing_set(self_, val_) ExtendMeStringMap[self_]
#define ExtendMe_thing_get(self_) ExtendMeStringMap[self_]
void ExtendMe_thing_set(ExtendMe *self, const char *val) {
char *old_val = ExtendMeStringMap[self];
delete [] old_val;
if (val) {
ExtendMeStringMap[self] = new char[strlen(val)+1];
strcpy(ExtendMeStringMap[self], val);
} else {
ExtendMeStringMap[self] = 0;
}
}
char * ExtendMe_thing_get(ExtendMe *self) {
return ExtendMeStringMap[self];
}
%}
%extend ExtendMe {

View file

@ -0,0 +1,38 @@
%module memberin_extend_c
/* Example from the Manual, section 5.5.6: "Adding member functions to C structures" */
%{
typedef struct {
char name[50];
} Person;
%}
typedef struct {
%extend {
char name[50];
}
} Person;
%{
#include <ctype.h>
#include <string.h>
void make_upper(char *name) {
char *c;
for (c = name; *c; ++c)
*c = (char)toupper((int)*c);
}
/* Specific implementation of set/get functions forcing capitalization */
char *Person_name_get(Person *p) {
make_upper(p->name);
return p->name;
}
void Person_name_set(Person *p, char *val) {
strncpy(p->name,val,50);
make_upper(p->name);
}
%}

View file

@ -1,5 +1,7 @@
%module namespace_class
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola;
%inline %{
template<class T> void foobar(T t) {}
namespace test {
@ -210,7 +212,6 @@ namespace a
%}
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_CLASS
// %copyctor doesn't work with nested class workaround
%nocopyctor;

View file

@ -1,4 +1,7 @@
%module namespace_union
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
%inline %{
namespace SpatialIndex
{

View file

@ -12,6 +12,27 @@ struct TestStruct {
int a;
};
struct OuterStructNamed {
struct InnerStructNamed {
double dd;
} inner_struct_named;
union InnerUnionNamed {
double ee;
int ff;
} inner_union_named;
};
struct OuterStructUnnamed {
struct {
double xx;
} inner_struct_unnamed;
union {
double yy;
int zz;
} inner_union_unnamed;
};
typedef struct OuterStruct {
union {

View file

@ -0,0 +1,206 @@
%module nested_class
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion1;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass2;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct2;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion2;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass4Typedef;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct4Typedef;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion4Typedef;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass5;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct5;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion5;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultiple;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleDerived;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleAnonTypedef1;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe;
%inline %{
struct Outer {
typedef int Integer;
///////////////////////////////////////////
struct InnerStruct1 {
Integer x;
};
class InnerClass1 {
public:
Integer x;
};
union InnerUnion1 {
Integer x;
double y;
};
///////////////////////////////////////////
class {
public:
Integer a;
};
struct {
Integer b;
};
union {
Integer c;
double d;
};
///////////////////////////////////////////
class InnerClass2 {
public:
Integer x;
} InnerClass2Instance;
struct InnerStruct2 {
Integer x;
} InnerStruct2Instance;
union InnerUnion2 {
Integer x;
double y;
} InnerUnion2Instance;
///////////////////////////////////////////
class {
public:
Integer x;
} InnerClass3Instance;
struct {
Integer x;
} InnerStruct3Instance;
union {
Integer x;
double y;
} InnerUnion3Instance;
///////////////////////////////////////////
typedef class {
public:
Integer x;
} InnerClass4Typedef;
typedef struct {
Integer x;
} InnerStruct4Typedef;
typedef union {
Integer x;
double y;
} InnerUnion4Typedef;
///////////////////////////////////////////
typedef class InnerClass5 {
public:
Integer x;
} InnerClass5Typedef;
typedef struct InnerStruct5 {
Integer x;
} InnerStruct5Typedef;
typedef union InnerUnion5 {
Integer x;
double y;
} InnerUnion5Typedef;
// bug #909387 - inner declared types are treated as forward declarations
InnerStruct1* makeInnerStruct1() { return 0; }
InnerClass1* makeInnerClass1() { return 0; }
InnerUnion1* makeInnerUnion1() { return 0; }
InnerStruct2* makeInnerStruct2() { return 0; }
InnerClass2* makeInnerClass2() { return 0; }
InnerUnion2* makeInnerUnion2() { return 0; }
InnerStruct4Typedef* makeInnerStruct4Typedef() { return 0; }
InnerClass4Typedef* makeInnerClass4Typedef() { return 0; }
InnerUnion4Typedef* makeInnerUnion4Typedef() { return 0; }
InnerStruct5* makeInnerStruct5() { return 0; }
InnerClass5* makeInnerClass5() { return 0; }
InnerUnion5* makeInnerUnion5() { return 0; }
InnerStruct5Typedef* makeInnerStruct5Typedef() { return 0; }
InnerClass5Typedef* makeInnerClass5Typedef() { return 0; }
InnerUnion5Typedef* makeInnerUnion5Typedef() { return 0; }
///////////////////////////////////////////
struct InnerMultiple {
Integer x;
} MultipleInstance1, MultipleInstance2, *MultipleInstance3, MultipleInstance4[2];
struct InnerMultipleDerived : public InnerMultiple {
Integer xx;
} MultipleDerivedInstance1, MultipleDerivedInstance2, *MultipleDerivedInstance3, MultipleDerivedInstance4[2];
struct {
Integer x;
} MultipleInstanceAnon1, MultipleInstanceAnon2, *MultipleInstanceAnon3, MultipleInstanceAnon4[2];
struct : public InnerMultiple {
Integer xx;
} MultipleInstanceAnonDerived1, MultipleInstanceAnonDerived2, *MultipleInstanceAnonDerived3, MultipleInstanceAnonDerived4[2];
struct : public InnerMultiple {
Integer xx;
};
class : public InnerMultiple {
public:
Integer yy;
};
///////////////////////////////////////////
typedef struct {
Integer x;
} InnerMultipleAnonTypedef1, InnerMultipleAnonTypedef2, *InnerMultipleAnonTypedef3;
InnerMultipleAnonTypedef1* makeInnerMultipleAnonTypedef1() { return 0; }
InnerMultipleAnonTypedef2* makeInnerMultipleAnonTypedef2() { return 0; }
InnerMultipleAnonTypedef3* makeInnerMultipleAnonTypedef3() { return 0; }
typedef struct InnerMultipleNamedTypedef {
Integer x;
} InnerMultipleNamedTypedef1, InnerMultipleNamedTypedef2, *InnerMultipleNamedTypedef3;
InnerMultipleNamedTypedef* makeInnerMultipleNamedTypedef() { return 0; }
InnerMultipleNamedTypedef1* makeInnerMultipleNamedTypedef1() { return 0; }
InnerMultipleNamedTypedef2* makeInnerMultipleNamedTypedef2() { return 0; }
InnerMultipleNamedTypedef3* makeInnerMultipleNamedTypedef3() { return 0; }
///////////////////////////////////////////
typedef struct InnerSameName {
Integer x;
} InnerSameName;
InnerSameName* makeInnerSameName() { return 0; }
};
%}
// Ignore nested struct instance
%ignore Outer2::IgnoreMeInstance;
%{
struct Outer2 {
struct IgnoreMe {
int xx;
};
};
%}
struct Outer2 {
struct IgnoreMe {
int xx;
} IgnoreMeInstance;
};

View file

@ -1,23 +1,25 @@
%module nested_comment
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
// this example shows a problem with 'dump_nested' (parser.y).
// bug #949654
%inline %{
typedef struct s1 {
union {
int fsc; /* genie structure hiding - Conductor
*/
int fso; /* genie structure hiding - FSOptions
*/
struct {
double *vals;
int size;
} vector_val; /* matrix values are mainly used
in rlgc models */
char *name;
} n ;
} s2;
typedef struct s1 {
union {
int fsc; /* genie structure hiding - Conductor
*/
int fso; /* genie structure hiding - FSOptions
*/
struct {
double *vals;
int size;
} vector_val; /* matrix values are mainly used
in rlgc models */
char *name;
} n ;
} s2;
%}
// comment in nested struct

View file

@ -2,21 +2,26 @@
// bug #491476
%inline %{
struct {
struct {
int a;
} a, b;
} a;
struct Outer {
struct {
int val;
} inner1, inner2, *inner3, inner4[1];
struct Named {
int val;
} inside1, inside2, *inside3, inside4[1];
} outer;
%}
// bug #909387
%inline %{
struct foo {
struct happy; // no warning
struct sad { int x; }; // warning
happy *good(); // produces good code
sad *bad(); // produces bad code
};
void setValues(struct Outer *outer, int val) {
outer->inner1.val = val;
outer->inner2.val = val * 2;
outer->inner3 = &outer->inner2;
outer->inner4[0].val = val * 4;
val = val * 10;
outer->inside1.val = val;
outer->inside2.val = val * 2;
outer->inside3 = &outer->inside2;
outer->inside4[0].val = val * 4;
}
%}

View file

@ -0,0 +1,38 @@
%module nested_workaround
// Similar to "Nested classes" documentation example.
class Inner {
int val;
public:
Inner(int v = 0) : val(v) {}
void setValue(int v) { val = v; }
int getValue() const { return val; }
};
%nestedworkaround Outer::Inner;
%inline %{
class Outer {
public:
class Inner {
int val;
public:
Inner(int v = 0) : val(v) {}
void setValue(int v) { val = v; }
int getValue() const { return val; }
};
Inner createInner(int v) const { return Inner(v); }
int getInnerValue(const Inner& i) const { return i.getValue(); }
Inner doubleInnerValue(Inner inner) {
inner.setValue(inner.getValue() * 2);
return inner;
}
};
%}
// We've fooled SWIG into thinking that Inner is a global class, so now we need
// to trick the C++ compiler into understanding this apparent global type.
%{
typedef Outer::Inner Inner;
%}

View file

@ -17,7 +17,6 @@ CPP_TEST_CASES += \
CPP_TEST_BROKEN += \
implicittest \
li_implicit \
li_std_map \
li_std_set \
li_std_stream

View file

@ -5,3 +5,19 @@ enums.bar2(1)
enums.bar3(1)
enums.bar1(1)
if (enums.cvar.enumInstance != 2)
error
endif
if (enums.cvar.Slap != 10)
error
endif
if (enums.cvar.My != 11)
error
endif
if (enums.cvar.Thigh != 12)
error
endif

View file

@ -5,8 +5,8 @@ overload_template_fast
f = foo();
a = max(3,4);
b = max(3.4,5.2);
a = maximum(3,4);
b = maximum(3.4,5.2);
# mix 1
if (mix1("hi") != 101)

View file

@ -5,7 +5,7 @@ require "arrays_global.php";
check::functions(array(test_a,test_b,new_simplestruct,new_material));
check::classes(array(arrays_global,SimpleStruct,Material));
check::globals(array(array_c,array_sc,array_uc,array_s,array_us,array_i,array_ui,array_l,array_ul,array_ll,array_f,array_d,array_struct,array_structpointers,array_ipointers,array_enum,array_enumpointers,array_const_i,beginstring_fix44a,beginstring_fix44b,beginstring_fix44c,beginstring_fix44d,beginstring_fix44e,beginstring_fix44f,chitmat,hitmat_val,hitmat));
check::globals(array(array_c,array_sc,array_uc,array_s,array_us,array_i,array_ui,array_l,array_ul,array_ll,array_f,array_d,array_struct,array_structpointers,array_ipointers,array_enum,array_enumpointers,array_const_i,beginstring_fix44a,beginstring_fix44b,beginstring_fix44c,beginstring_fix44d,beginstring_fix44e,beginstring_fix44f,chitmat,hitmat_val,hitmat,simplestruct_double_field));
// The size of array_c is 2, but the last byte is \0, so we can only store a
// single byte string in it.
check::set(array_c,"Z");

View file

@ -5,7 +5,7 @@ require "arrays_global_twodim.php";
check::functions(array(fn_taking_arrays,get_2d_array,new_simplestruct,new_material));
check::classes(array(arrays_global_twodim,SimpleStruct,Material));
check::globals(array(array_c,array_sc,array_uc,array_s,array_us,array_i,array_ui,array_l,array_ul,array_ll,array_f,array_d,array_struct,array_structpointers,array_ipointers,array_enum,array_enumpointers,array_const_i,chitmat,hitmat_val,hitmat));
check::globals(array(array_c,array_sc,array_uc,array_s,array_us,array_i,array_ui,array_l,array_ul,array_ll,array_f,array_d,array_struct,array_structpointers,array_ipointers,array_enum,array_enumpointers,array_const_i,chitmat,hitmat_val,hitmat,simplestruct_double_field));
$a1=array(10,11,12,13);
$a2=array(14,15,16,17);
$a=array($a1,$a2);

View file

@ -4,15 +4,14 @@ require "arrays.php";
check::functions(array(fn_taking_arrays,newintpointer,setintfrompointer,getintfrompointer,array_pointer_func));
check::classes(array(arrays,SimpleStruct,ArrayStruct,CartPoseData_t));
// No new vars
check::globals(array());
check::globals(array(simplestruct_double_field,arraystruct_array_c,arraystruct_array_sc,arraystruct_array_uc,arraystruct_array_s,arraystruct_array_us,arraystruct_array_i,arraystruct_array_ui,arraystruct_array_l,arraystruct_array_ul,arraystruct_array_ll,arraystruct_array_f,arraystruct_array_d,arraystruct_array_struct,arraystruct_array_structpointers,arraystruct_array_ipointers,arraystruct_array_enum,arraystruct_array_enumpointers,arraystruct_array_const_i,cartposedata_t_p));
$ss=new simplestruct();
check::classname(simplestruct,$ss);
$as=new arraystruct();
$as->array_c="abc";
check::equal($as->array_c,"ab",'$as->array_c=="ab"');
check::equal($as->array_c,"a",'$as->array_c=="a"');
check::done();
?>

View file

@ -3,12 +3,12 @@
require "tests.php";
require "arrays_scope.php";
// No new functions
// New functions
check::functions(array(new_bar,bar_blah));
// No new classes
// New classes
check::classes(array(arrays_scope,Bar));
// now new vars
check::globals(array());
// New vars
check::globals(array(bar_adata,bar_bdata,bar_cdata));
$bar=new bar();

View file

@ -3,12 +3,12 @@
require "tests.php";
require "cpp_static.php";
// No new functions
check::functions(array());
// No new classes
// New functions
check::functions(array(staticfunctiontest_static_func,staticfunctiontest_static_func_2,staticfunctiontest_static_func_3));
// New classes
check::classes(array(StaticMemberTest,StaticFunctionTest));
// now new vars
check::globals(array());
// New vars
check::globals(array(staticmembertest_static_int));
check::done();
?>

View file

@ -11,11 +11,6 @@ check::classes(array(SpObject));
check::globals(array());
class MyObject extends SpObject{
function __construct() {
parent::__construct();
return;
}
function getFoo() {
return 123;
}

View file

@ -3,7 +3,7 @@ require "tests.php";
require "enum_scope_template.php";
check::classes(array("enum_scope_template", "TreeInt"));
check::functions("chops");
check::functions(array("chops","treeint_chops"));
check::equal(0,TreeInt_Oak,"0==TreeInt_Oak");
check::equal(1,TreeInt_Fir,"1==TreeInt_Fir");
check::equal(2,TreeInt_Cedar,"2==TreeInt_Cedar");

View file

@ -3,11 +3,11 @@
require "tests.php";
require "ignore_parameter.php";
// No new functions
check::functions(array(jaguar,lotus,tvr,ferrari));
// No new classes
check::classes(array(sportscars,minicooper,morrisminor,fordanglia,austinallegro));
// now new vars
// New functions
check::functions(array(jaguar,lotus,tvr,ferrari,sportscars_daimler,sportscars_astonmartin,sportscars_bugatti,sportscars_lamborghini));
// New classes
check::classes(array(ignore_parameter,SportsCars,MiniCooper,MorrisMinor,FordAnglia,AustinAllegro));
// No new vars
check::globals(array());
check::equal(jaguar(2,3.4),"hello",'jaguar(2,3.4)=="hello"');

View file

@ -3,14 +3,14 @@ require "tests.php";
require "li_carrays.php";
// Check functions.
check::functions(array(new_intarray,delete_intarray,intarray_getitem,intarray_setitem));
check::functions(array(new_intarray,delete_intarray,intarray_getitem,intarray_setitem,doublearray_getitem,doublearray_setitem,doublearray_cast,doublearray_frompointer,xyarray_getitem,xyarray_setitem,xyarray_cast,xyarray_frompointer,delete_abarray,abarray_getitem,abarray_setitem));
// Check classes.
// NB An "li_carrays" class is created as a mock namespace.
check::classes(array(li_carrays,doubleArray,AB,XY,XYArray));
// No new global variables.
check::globals(array());
// Check global variables.
check::globals(array(xy_x,xy_y,globalxyarray,ab_a,ab_b,globalabarray));
$d = new doubleArray(10);

View file

@ -17,9 +17,9 @@ check::equal(ref_bool(true), true, "ref_bool failed");
check::equal(ref_float(3.5), 3.5, "ref_float failed");
check::equal(ref_double(3.5), 3.5, "ref_double failed");
check::equal(ref_char('x'), 'x', "ref_char failed");
//check::equal(ref_longlong(0x123456789ABCDEF0), 0x123456789ABCDEF0, "ref_longlong failed");
//check::equal(ref_ulonglong(0xF23456789ABCDEF0), 0xF23456789ABCDEF0, "ref_ulonglong failed");
printf("TODO: long long and unsigned long long const reference typemaps\n");
check::equal(ref_longlong(0x123456789ABCDEF0), 0x123456789ABCDEF0, "ref_longlong failed");
# 0xF23456789ABCDEF0 won't fit in a long, so PHP makes it a double, but SWIG opts to return it as a string.
check::equal((double)ref_ulonglong(0xF23456789ABCDEF0), 0xF23456789ABCDEF0, "ref_ulonglong failed");
check::done();
?>

View file

@ -2,19 +2,25 @@
#ifdef SWIGPHP
%warnfilter(SWIGWARN_PARSE_KEYWORD) Empty();
// FIXME: this doesn't work for me:
%warnfilter(SWIGWARN_PARSE_KEYWORD) stdClass;
%warnfilter(SWIGWARN_PARSE_KEYWORD) directory;
%warnfilter(SWIGWARN_PARSE_KEYWORD) Hello::empty();
#endif
%inline %{
int Exception() { return 13; }
void Empty() {}
class stdClass
{
};
class directory
{
};
struct Hello
{
void empty() {}

View file

@ -0,0 +1,82 @@
%module preproc_constants
// Note: C types are slightly different to C++ types as (a && b) is int in C and bool in C++
// Simple constants
#define CONST_INT1 10
#define CONST_INT2 0xFF
#define CONST_UINT1 10u
#define CONST_UINT2 10U
#define CONST_UINT3 0xFFu
#define CONST_UINT4 0xFFU
#define CONST_LONG1 10l
#define CONST_LONG2 10L
#define CONST_LONG3 0xFFl
#define CONST_LONG4 0xFFL
#define CONST_LLONG1 10LL
#define CONST_LLONG2 10ll
#define CONST_LLONG3 0xFFll
#define CONST_LLONG4 0xFFLL
#define CONST_ULLONG1 10ull
#define CONST_ULLONG2 10ULL
#define CONST_ULLONG3 0xFFull
#define CONST_ULLONG4 0xFFULL
#define CONST_DOUBLE1 10e1
#define CONST_DOUBLE2 10E1
#define CONST_DOUBLE3 12.3
#define CONST_DOUBLE4 12.
#define CONST_DOUBLE5 12.3f
#define CONST_DOUBLE6 12.3F
#define CONST_BOOL1 true
#define CONST_BOOL2 false
#define CONST_CHAR 'x'
#define CONST_STRING1 "const string"
#define CONST_STRING2 "const" " string"
// Expressions - runtime tests check the type for any necessary type promotions of the expressions
#define INT_AND_BOOL 0xFF & true
//#define INT_AND_CHAR 0xFF & 'A' /* FIXME compile error */
#define INT_AND_INT 0xFF & 2
#define INT_AND_UINT 0xFF & 2u
#define INT_AND_LONG 0xFF & 2l
#define INT_AND_ULONG 0xFF & 2ul
#define INT_AND_LLONG 0xFF & 2ll
#define INT_AND_ULLONG 0xFF & 2ull
#define BOOL_AND_BOOL true & true // Note integral promotion to type int
//#define CHAR_AND_CHAR 'A' & 'B' // Note integral promotion to type int
/* FIXME ABOVE */
#define EXPR_MULTIPLY 0xFF * 2
#define EXPR_DIVIDE 0xFF / 2
//FIXME #define EXPR_MOD 0xFF % 2
#define EXPR_PLUS 0xFF + 2
#define EXPR_MINUS 0xFF + 2
#define EXPR_LSHIFT 0xFF << 2
#define EXPR_RSHIFT 0xFF >> 2
/* FIXME
#define EXPR_LT 0xFF < 255
#define EXPR_GT 0xFF > 255
*/
#define EXPR_LTE 0xFF <= 255
#define EXPR_GTE 0xFF >= 255
#define EXPR_INEQUALITY 0xFF != 255
#define EXPR_EQUALITY 0xFF == 255
#define EXPR_AND 0xFF & 1
#define EXPR_XOR 0xFF ^ 1
#define EXPR_OR 0xFF | 1
#define EXPR_LAND 0xFF && 1
#define EXPR_LOR 0xFF || 1
#define EXPR_CONDITIONAL true ? 2 : 2.2

View file

@ -0,0 +1,6 @@
%module preproc_constants_c
%define true 1 %enddef
%define false 0 %enddef
%include "preproc_constants.i"

View file

@ -49,7 +49,6 @@ CPP_TEST_CASES += \
li_implicit \
li_std_vectora \
li_std_vector_extra \
li_std_map \
li_std_multimap \
li_std_pair_extra \
li_std_set \

View file

@ -43,7 +43,7 @@ b = launder(a)
try:
b.pong()
except TypeError, e:
if str(e) == "Swig director type mismatch in output value of type 'std::string'":
if str(e) == "SWIG director type mismatch in output value of type 'std::string'":
ok = 1
else:
print "Unexpected error message: %s" % str(e)

View file

@ -5,3 +5,15 @@ _enums.bar2(1)
_enums.bar3(1)
_enums.bar1(1)
if _enums.cvar.enumInstance != 2:
raise RuntimeError
if _enums.cvar.Slap != 10:
raise RuntimeError
if _enums.cvar.My != 11:
raise RuntimeError
if _enums.cvar.Thigh != 12:
raise RuntimeError

View file

@ -0,0 +1,4 @@
import extern_c
extern_c.RealFunction(2)

View file

@ -0,0 +1,10 @@
from li_cdata import *
s = "ABC abc"
m = malloc(256)
memmove(m, s)
ss = cdata(m, 7)
if ss != "ABC abc":
raise "failed"

View file

@ -154,3 +154,23 @@ if extractInt(vi[0]) != 11:
if extractInt(vi[1]) != 22:
raise RuntimeError
# vector const pointer checks
csp = makeConstShortPtr(111)
error = 0
try:
vcs = ConstShortPtrVector((csp, dp)) # check vector<const unsigned short *> does not accept double * element
error = 1
except:
pass
if error:
raise RuntimeError
vcs = ConstShortPtrVector((csp, makeConstShortPtr(222)))
if extractConstShort(vcs[0]) != 111:
raise RuntimeError
if extractConstShort(vcs[1]) != 222:
raise RuntimeError

View file

@ -0,0 +1,6 @@
import memberin_extend_c
t = memberin_extend_c.Person()
t.name = "Fred Bloggs"
if t.name != "FRED BLOGGS":
raise RuntimeError("name wrong")

View file

@ -0,0 +1,13 @@
from nested_workaround import *
inner = Inner(5)
outer = Outer()
newInner = outer.doubleInnerValue(inner)
if newInner.getValue() != 10:
raise RuntimeError
outer = Outer()
inner = outer.createInner(3)
newInner = outer.doubleInnerValue(inner)
if outer.getInnerValue(newInner) != 6:
raise RuntimeError

View file

@ -1,8 +1,8 @@
from overload_template_fast import *
f = foo()
a = max(3,4)
b = max(3.4,5.2)
a = maximum(3,4)
b = maximum(3.4,5.2)
# mix 1
if (mix1("hi") != 101):

View file

@ -0,0 +1,20 @@
from struct_initialization import *
if cvar.instanceC1.x != 10:
raise RuntimeError
if cvar.instanceD1.x != 10:
raise RuntimeError
if cvar.instanceD2.x != 20:
raise RuntimeError
if cvar.instanceD3.x != 30:
raise RuntimeError
if cvar.instanceE1.x != 1:
raise RuntimeError
if cvar.instanceF1.x != 1:
raise RuntimeError

View file

@ -14,7 +14,6 @@ CPP_TEST_CASES = \
li_cstring \
li_factory \
li_std_functors \
li_std_map \
li_std_multimap \
li_std_pair_lang_object \
li_std_queue \

View file

@ -88,7 +88,7 @@ const char * testMary(Name *mary) {
%{
/*%typemap(in) (Name *multiname, int num) start */
temp_name = $*1_ltype("multiname num");
temp_count = strlen(temp_name.getNamePtr()->getName());
temp_count = (int)strlen(temp_name.getNamePtr()->getName());
(void)$input;
$1 = temp_name.getNamePtr();
$2 = temp_count + 100;
@ -103,7 +103,7 @@ $typemap(in, (Name *multiname, int num))
%inline %{
const char * testJim(Name *jim, int count) {
if (count != strlen(jim->getNamePtr()->getName()) + 100)
if (count != (int)strlen(jim->getNamePtr()->getName()) + 100)
return "size check failed";
else
return jim->getName();

View file

@ -5,6 +5,14 @@
%module static_const_member
#if SWIGJAVA
%javaconst(1) EN;
%javaconst(1) CHARTEST;
#elif SWIGCSHARP
%csconst(1) EN;
%csconst(1) CHARTEST;
#endif
%inline %{
class X {
@ -12,6 +20,7 @@ public:
static const int PN = 0;
static const int CN = 1;
static const int EN = 2;
static const char CHARTEST = 'A';
};
%}

View file

@ -0,0 +1,31 @@
// Test declaration and initialization of structs (C code)
%module struct_initialization
%inline %{
// Named types
struct StructA {
int x;
} instanceA1;
struct StructB {
int x;
} instanceB1, instanceB2, instanceB3;
struct StructC {
int x;
} instanceC1 = { 10 };
struct StructD {
int x;
} instanceD1 = { 10 }, instanceD2 = { 20 }, instanceD3 = { 30 };
struct StructE {
int x;
} instanceE1[3] = { { 1 }, { 2 }, { 3} };
struct StructF {
int x;
} instanceF1[3] = { { 1 }, { 2 } }, instanceF2[2] = { { -1 }, { -2 } }, instanceF3[2] = { { 11 }, { 22 } };
%}

View file

@ -0,0 +1,5 @@
// Test declaration and initialization of structs (C++ code)
%module struct_initialization_cpp
%include "struct_initialization.i" // C code

View file

@ -3,12 +3,6 @@
%module template_classes
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_CLASS
%{
%}
%inline %{
template <class T>
@ -27,21 +21,16 @@ public:
private:
Point<T> point;
template <class Data>
struct pair2nd_eq
{
};
struct Foo : Point<int>
{
};
Foo foo;
};
%}
@ -49,4 +38,3 @@ private:
%template(PointInt) Point<int>;
%template(RectangleInt) RectangleTest<int>;

View file

@ -0,0 +1,116 @@
%module template_nested
// Test nested templates - that is template classes and template methods within a class.
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner1;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner2;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate1;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate2;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate3;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedStruct;
namespace ns {
template <class T> struct ForwardTemplate;
}
%{
namespace ns {
template <class T> struct ForwardTemplate {
void tmethod(T t) {}
};
}
%}
%inline %{
namespace ns {
class NormalClass {
public:
NormalClass() {}
~NormalClass() {}
};
template <class T> struct NormalTemplate {
void tmethod(T t) {}
};
class OuterClass {
public:
template <class T> struct Inner1 {
template <class U> struct SuperInner1 {
void method1(U t) {}
};
template <class V> struct SuperInner2 {
void method1(V t) {}
};
template <class W> void tmethod(W w) {}
template <class X> void tmethodAgain(X x) {}
template <class Y> struct SuperBase : public SuperInner1<Y> {
void method1(Y y) {}
};
};
Inner1<int> useInner1(const Inner1<int>& inner) { return inner; }
template <class Z> void InnerTMethod(Z z) {}
template <class T> class Inner2 : public NormalTemplate<T> {
public:
template <class U> class SuperInner1 {
public:
SuperInner1() {}
void method1(U t) {}
};
template <class V> struct SuperInner2 {
void method1(V t) {}
};
int embeddedVar;
template <class X> void tmethod(X x) {}
template <class Y> struct SuperBase : public SuperInner1<Y> {
void method1(Y y) {}
};
};
Inner2<int> useInner2(const Inner2<int>& inner) { return inner; }
int iii;
};
struct ABC {
ABC() {}
~ABC() {}
};
struct TemplateFuncs {
template <class X> X templateMethod1(X x) { return x; }
template <class X> X templateMethod2(X x) { return x; }
};
template <typename UU> struct OuterTemplate {
template <typename VV> struct NestedInnerTemplate1 {
template <typename Z> void NestedInnerInnerTMethod(Z z) {}
void hohum() {}
};
template <typename W> void NestedInnerTMethod(UU u, W w) {}
template <typename VV> struct NestedInnerTemplate2 {
void hohum() {}
};
UU hohum(UU u) { return u; }
template <typename VV> struct NestedInnerTemplate3 : public NestedInnerTemplate2<VV> {
void hohum() {}
};
struct NestedStruct {
NestedStruct() {}
void hohum() {}
};
NestedInnerTemplate1<short> useNestedInnerTemplate1(const NestedInnerTemplate1<short>& inner) { return inner; }
NestedInnerTemplate2<short> useNestedInnerTemplate2(const NestedInnerTemplate2<short>& inner) { return inner; }
NestedInnerTemplate3<short> useNestedInnerTemplate3(const NestedInnerTemplate3<short>& inner) { return inner; }
NestedStruct useNestedStruct(const NestedStruct& inner) { return inner; }
};
}
%}
%template(T_NormalTemplateNormalClass) ns::NormalTemplate<ns::NormalClass>;
%template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod<ns::NormalClass>;
%template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1<int>;
%template(T_TemplateFuncs2Double) ns::TemplateFuncs::templateMethod2<double>;
%template(T_NestedOuterTemplateDouble) ns::OuterTemplate<double>;

View file

@ -0,0 +1,47 @@
#pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_TEMPLATE
%module template_nested_typemaps
// Testing that the typemaps invoked within a class via %template are picked up by appropriate methods
template <typename T> struct Typemap {
%typemap(in) T {
$1 = -99;
}
};
template <> struct Typemap<short> { // Note explicit specialization
%typemap(in) short {
$1 = -77;
}
};
%inline %{
int globalInt1(int s) { return s; }
short globalShort1(short s) { return s; }
template <typename T> struct Breeze {
int methodInt1(int s) { return s; }
#if defined(SWIG)
%template() Typemap<int>;
#endif
int methodInt2(int s) { return s; } // should pick up the typemap within Typemap<int>
void takeIt(T t) {}
short methodShort1(short s) { return s; }
#if defined(SWIG)
%template(TypemapShort) Typemap<short>; // should issue warning SWIGWARN_PARSE_NESTED_TEMPLATE
#endif
short methodShort2(short s) { return s; } // should pick up the typemap within Typemap<short>
};
int globalInt2(int s) { return s; }
short globalShort2(short s) { return s; }
%}
%template(BreezeString) Breeze<const char *>;
%inline %{
int globalInt3(int s) { return s; } // should pick up the typemap within Typemap<int>
short globalShort3(short s) { return s; } // should pick up the typemap within Typemap<short>
%}

View file

@ -0,0 +1,150 @@
%module template_partial_specialization
%inline %{
namespace One {
template <typename T> struct OneParm { void a() {} };
template <typename T> struct OneParm<T *> { void b() {} };
template <typename T> struct OneParm<T &> { void c() {} };
template <typename T> struct OneParm<T const &> { void d() {} };
template <typename T> struct OneParm<T * const &> { void e() {} };
template <> struct OneParm<int> { void f() {} };
template <> struct OneParm<int * const &> { void g() {} };
template <> struct OneParm<int **> { void h() {} };
template <> struct OneParm<float> { void i() {} };
template <> struct OneParm<float *> { void j() {} };
template <> struct OneParm<float **> { void k() {} };
template <> struct OneParm<float ***> { void l() {} };
}
%}
// partial specializations
%template(A) One::OneParm<double>;
%template(B) One::OneParm<double *>;
%template(C) One::OneParm<double &>;
%template(D) One::OneParm<const double &>;
%template(E) One::OneParm<double * const &>;
// explicit specializations
%template(F) One::OneParm<int>;
%template(G) One::OneParm<int * const &>;
%template(H) One::OneParm<int **>;
// %template scope explicit specializations
namespace ONE {
%template(I) One::OneParm<float>;
%template(J) ::One::OneParm<float *>;
}
%template(K) ::One::OneParm<float **>;
namespace One {
%template(L) OneParm<float ***>;
}
// %template scope partial specializations
namespace ONE {
%template(BB) One::OneParm<bool *>;
%template(BBB) ::One::OneParm<char *>;
}
%template(BBBB) ::One::OneParm<short *>;
namespace One {
%template(BBBBB) OneParm<long *>;
}
// non-exact match
%template(B1) One::OneParm<unsigned int **>;
%template(B2) One::OneParm<unsigned int ***>;
%template(B3) One::OneParm<const unsigned int *>;
%template(B4) One::OneParm<const unsigned int **>;
// Two parameter specialization tests
%inline %{
struct Concrete {};
namespace Two {
template <typename T1, typename T2> struct TwoParm { void a() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, T2 *> { void b() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, const T2 *> { void c() {} };
template <typename T1, typename T2> struct TwoParm<const T1 *, const T2 *> { void d() {} };
template <typename T1> struct TwoParm<T1 *, int *> { void e() {} };
template <typename T1> struct TwoParm<T1, int> { void f() {} };
template <> struct TwoParm<int *, const int *> { void g() {} };
template <> struct TwoParm<Concrete, Concrete *> { void h() {} };
}
%}
namespace Two {
%template(A_) TwoParm<double, double>;
%template(B_) TwoParm<double *, double *>;
%template(C_) TwoParm<double *, const double *>;
%template(D_) TwoParm<const int *, const int *>;
%template(E_) TwoParm<int *, int *>;
%template(F_) TwoParm<int *, int>;
%template(G_) TwoParm<int *, const int *>;
%template(C1_) TwoParm<Concrete *, const Concrete *>;
%template(C2_) TwoParm<int *, const ::Concrete *>;
}
%template(C3_) Two::TwoParm<double *, const ::Concrete *>;
%template(C4_) ::Two::TwoParm<void *, const ::Concrete *>;
%template(B1_) ::Two::TwoParm<char *, ::Concrete *>;
%template(E1_) Two::TwoParm<const int *, int *>;
%template(E2_) Two::TwoParm<int **, int *>;
%template(H_) Two::TwoParm< ::Concrete, ::Concrete * >;
// Many template parameters
%inline %{
template <typename T1, typename T2, typename T3, typename T4, typename T5> struct FiveParm { void a() {} };
template <typename T1> struct FiveParm<T1, int, int, double, short> { void b() {} };
%}
%template(FiveParm1) FiveParm<bool, int, int, double, short>;
%inline %{
template <typename T, int N = 0, int M = 0> struct ThreeParm;
template <typename T, int N, int M> struct ThreeParm { void a1() {} };
template <typename T> struct ThreeParm<T, 0, 0> { void a2() {} };
template <typename T, int N> struct ThreeParm<T, N, N> { void a3() {} };
%}
%template(ThreeParmInt) ThreeParm<int, 0, 0>;
#if 0
// TODO fix:
%inline %{
//namespace S {
template<typename T> struct X { void a() {} };
template<typename T> struct X<T *> { void b() {} };
// template<> struct X<int *> { void c() {} };
//}
%}
namespace AA { // thinks X is in AA namespace
%template(X2) X<int *>;
};
#endif
#if 0
namespace Space {
}
template<typename T> struct Vector {
#ifdef SWIG
%template() Space::VectorHelper<T>;
#endif
void gook(T i) {}
void geeko(double d) {}
void geeky(int d) {}
};
/*
template<typename T> struct Vector<T *> {
};
*/
//}
%}
%template(VectorIntPtr) Space::Vector<int *>; // should fail as Vector is in global namespace
// is this a regression - no fails in 1.3.40 too
// Note problem is removed by removing empty Space namespace!!
#endif

View file

@ -0,0 +1,130 @@
// This testcase is almost identical to template_partial_specialization but uses typedefs for %template
%module template_partial_specialization_typedef
%inline %{
namespace TypeDef {
typedef double Double;
typedef int * IntPtr;
typedef double * DoublePtr;
typedef double & DoubleRef;
typedef const double & ConstDoubleRef;
typedef double * const & DoublePtrConstRef;
typedef int Int;
typedef int * const & IntPtrConstRef;
typedef int ** IntPtrPtr;
typedef float Float;
typedef float * FloatPtr;
typedef float ** FloatPtrPtr;
typedef float *** FloatPtrPtrPtr;
typedef bool * BoolPtr;
typedef char * CharPtr;
typedef short * ShortPtr;
typedef long * LongPtr;
typedef unsigned int ** UnsignedIntPtrPtr;
typedef unsigned int *** UnsignedIntPtrPtrPtr;
typedef const unsigned int ** ConstUnsignedIntPtr;
typedef const unsigned int *** ConstUnsignedIntPtrPtr;
}
namespace One {
template <typename T> struct OneParm { void a() {} };
template <typename T> struct OneParm<T *> { void b() {} };
template <typename T> struct OneParm<T &> { void c() {} };
template <typename T> struct OneParm<T const &> { void d() {} };
template <typename T> struct OneParm<T * const &> { void e() {} };
template <> struct OneParm<int> { void f() {} };
template <> struct OneParm<int * const &> { void g() {} };
template <> struct OneParm<int **> { void h() {} };
template <> struct OneParm<float> { void i() {} };
template <> struct OneParm<float *> { void j() {} };
template <> struct OneParm<float **> { void k() {} };
template <> struct OneParm<float ***> { void l() {} };
}
%}
// partial specializations
%template(A) One::OneParm<TypeDef::Double>;
%template(B) One::OneParm<TypeDef::DoublePtr>;
%template(C) One::OneParm<TypeDef::DoubleRef>;
%template(D) One::OneParm<TypeDef::ConstDoubleRef>;
%template(E) One::OneParm<TypeDef::DoublePtrConstRef>;
// explicit specializations
%template(F) One::OneParm<TypeDef::Int>;
%template(G) One::OneParm<TypeDef::IntPtrConstRef>;
%template(H) One::OneParm<TypeDef::IntPtrPtr>;
// %template scope explicit specializations
namespace ONE {
%template(I) One::OneParm<TypeDef::Float>;
%template(J) ::One::OneParm<TypeDef::FloatPtr>;
}
%template(K) ::One::OneParm<TypeDef::FloatPtrPtr>;
namespace One {
%template(L) OneParm<TypeDef::FloatPtrPtrPtr>;
}
// %template scope partial specializations
namespace ONE {
%template(BB) One::OneParm<TypeDef::BoolPtr>;
%template(BBB) ::One::OneParm<TypeDef::CharPtr>;
}
%template(BBBB) ::One::OneParm<TypeDef::ShortPtr>;
namespace One {
%template(BBBBB) OneParm<TypeDef::LongPtr>;
}
// non-exact match
%template(B1) One::OneParm<TypeDef::UnsignedIntPtrPtr>;
%template(B2) One::OneParm<TypeDef::UnsignedIntPtrPtrPtr>;
%template(B3) One::OneParm<TypeDef::ConstUnsignedIntPtr>;
%template(B4) One::OneParm<TypeDef::ConstUnsignedIntPtrPtr>;
// Two parameter specialization tests
%inline %{
struct Concrete {};
namespace Two {
template <typename T1, typename T2> struct TwoParm { void a() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, T2 *> { void b() {} };
template <typename T1, typename T2> struct TwoParm<T1 *, const T2 *> { void c() {} };
template <typename T1, typename T2> struct TwoParm<const T1 *, const T2 *> { void d() {} };
template <typename T1> struct TwoParm<T1 *, int *> { void e() {} };
template <typename T1> struct TwoParm<T1, int> { void f() {} };
template <> struct TwoParm<int *, const int *> { void g() {} };
}
%}
%inline %{
namespace TypeDef {
typedef const double * ConstDoublePtr;
typedef const int * ConstIntPtr;
typedef int * IntPtr;
typedef Concrete * ConcretePtr;
typedef const Concrete * ConstConcretePtr;
typedef void * VoidPtr;
}
%}
namespace Two {
%template(A_) TwoParm<TypeDef::Double, TypeDef::Double>;
%template(B_) TwoParm<TypeDef::DoublePtr, TypeDef::DoublePtr>;
%template(C_) TwoParm<TypeDef::DoublePtr, TypeDef::ConstDoublePtr>;
%template(D_) TwoParm<TypeDef::ConstIntPtr, TypeDef::ConstIntPtr>;
%template(E_) TwoParm<TypeDef::IntPtr, TypeDef::IntPtr>;
%template(F_) TwoParm<TypeDef::IntPtr, TypeDef::Int>;
%template(G_) TwoParm<TypeDef::IntPtr, TypeDef::ConstIntPtr>;
%template(C1_) TwoParm<TypeDef::ConcretePtr, TypeDef::ConstConcretePtr>;
%template(C2_) TwoParm<TypeDef::IntPtr, TypeDef::ConstConcretePtr>;
}
%template(C3_) Two::TwoParm<TypeDef::DoublePtr, TypeDef::ConstConcretePtr>;
%template(C4_) ::Two::TwoParm<TypeDef::VoidPtr, TypeDef::ConstConcretePtr>;
%template(B1_) ::Two::TwoParm<TypeDef::CharPtr, TypeDef::ConcretePtr>;
%template(E1_) Two::TwoParm<TypeDef::ConstIntPtr, TypeDef::IntPtr>;
%template(E2_) Two::TwoParm<TypeDef::IntPtrPtr, TypeDef::IntPtr>;

View file

@ -2,6 +2,7 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState; // Ruby, wrong class name
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState_rstate; // Ruby, wrong class name
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
%inline %{
class nRState {

View file

@ -74,3 +74,14 @@ struct X {
};
}
%inline %{
namespace SpaceMan {
typedef double SpaceManDouble;
}
using namespace ::SpaceMan; // global namespace prefix
SpaceManDouble useSpaceMan(SpaceManDouble s) { return s; }
%}

View file

@ -24,6 +24,12 @@ public:
const B GetBconst() const {
return b;
}
::B GetBGlobalQualifier() {
return b;
}
const ::B GetBconstGlobalGlobalQualifier() const {
return b;
}
};
%}