merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12002 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2010-04-30 03:03:24 +00:00
commit 07cb6351f1
181 changed files with 4467 additions and 6779 deletions

View file

@ -109,6 +109,12 @@ bool SetConstCharArrayStaticString(const char str[], unsigned int number) {
char *CharPingPong(char *str) {
return str;
}
char *CharArrayPingPong(char abcstr[]) {
return abcstr;
}
char *CharArrayDimsPingPong(char abcstr[16]) {
return abcstr;
}
// variables
char *global_char = NULL;

View file

@ -131,6 +131,7 @@ CPP_TEST_CASES += \
constructor_exception \
constructor_explicit \
constructor_ignore \
constructor_rename \
constructor_value \
contract \
conversion \
@ -198,6 +199,7 @@ CPP_TEST_CASES += \
fvirtual \
global_namespace \
global_ns_arg \
global_scope_types \
global_vars \
grouping \
ignore_parameter \
@ -241,6 +243,8 @@ CPP_TEST_CASES += \
namespace_typemap \
namespace_union \
namespace_virtual_method \
nspace \
nspace_extend \
naturalvar \
nested_class \
nested_comment \
@ -304,6 +308,7 @@ CPP_TEST_CASES += \
static_const_member_2 \
struct_initialization_cpp \
struct_value \
symbol_clash \
template \
template_arg_replace \
template_arg_scope \
@ -371,6 +376,7 @@ CPP_TEST_CASES += \
template_virtual \
template_whitespace \
threads \
threads_exception \
throw_exception \
typedef_array_member \
typedef_class \
@ -381,9 +387,11 @@ CPP_TEST_CASES += \
typedef_scope \
typedef_sizet \
typedef_struct \
typemap_global_scope \
typemap_namespace \
typemap_ns_using \
typemap_numinputs \
typemap_template \
typemap_out_optimal \
typemap_variables \
typemap_various \

View file

@ -5,7 +5,7 @@
/* % didn't work in SWIG 1.3.40 and earlier. */
const int X = 123%7;
#define FOO 12 % 6
double d_array[12 % 6];
#define FOO 12 % 9
double d_array[12 % 9];
%}

View file

@ -70,6 +70,8 @@ public:
void ret6(int*& a) {}
int*& ret7() {return GlobalIntPtr;}
void ret8(int*const& a) {}
int*const& ret9() {return GlobalIntPtr;}
ReturnValuesTest() : int3(NULL) {}
private:
ReturnValuesTest& operator=(const ReturnValuesTest&);
@ -112,7 +114,7 @@ int* const globalRet2() {return &GlobalInt;}
return b;
}
B const*& cbar(B const*& b) {
B *const& cbar(B *const& b) {
return b;
}
}

View file

@ -0,0 +1,12 @@
%module constructor_rename
%{
struct Foo {
Foo() {}
};
%}
struct Foo {
%rename(RenamedConstructor) Foo();
Foo() {}
};

View file

@ -69,14 +69,13 @@ run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \
CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \
CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` \
$*$(CSHARPPATHSEPARATOR)*.cs' csharp_compile && \
CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \
else \
cd $* && \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \
CSHARPSRCS='*.cs' csharp_compile && cd .. ; \
CSHARPSRCS='`find . -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \
fi
# Clean: remove testcase directories

View file

@ -0,0 +1,39 @@
using System;
public class runme
{
static void Main()
{
{
// constructors and destructors
nspace_extendNamespace.Outer.Inner1.Color color1 = new nspace_extendNamespace.Outer.Inner1.Color();
nspace_extendNamespace.Outer.Inner1.Color color = new nspace_extendNamespace.Outer.Inner1.Color(color1);
color1.Dispose();
color1 = null;
// class methods
color.colorInstanceMethod(20.0);
nspace_extendNamespace.Outer.Inner1.Color.colorStaticMethod(20.0);
nspace_extendNamespace.Outer.Inner1.Color created = nspace_extendNamespace.Outer.Inner1.Color.create();
created.Dispose();
}
{
// constructors and destructors
nspace_extendNamespace.Outer.Inner2.Color color2 = new nspace_extendNamespace.Outer.Inner2.Color();
nspace_extendNamespace.Outer.Inner2.Color color = new nspace_extendNamespace.Outer.Inner2.Color(color2);
color2.Dispose();
color2 = null;
// class methods
color.colorInstanceMethod(20.0);
nspace_extendNamespace.Outer.Inner2.Color.colorStaticMethod(20.0);
nspace_extendNamespace.Outer.Inner2.Color created = nspace_extendNamespace.Outer.Inner2.Color.create();
created.Dispose();
// Same class different namespaces
nspace_extendNamespace.Outer.Inner1.Color col1 = new nspace_extendNamespace.Outer.Inner1.Color();
nspace_extendNamespace.Outer.Inner2.Color col2 = nspace_extendNamespace.Outer.Inner2.Color.create();
col2.colors(col1, col1, col2, col2, col2);
}
}
}

View file

@ -0,0 +1,76 @@
using System;
public class runme
{
static void Main()
{
// constructors and destructors
nspaceNamespace.Outer.Inner1.Color color1 = new nspaceNamespace.Outer.Inner1.Color();
nspaceNamespace.Outer.Inner1.Color color = new nspaceNamespace.Outer.Inner1.Color(color1);
color1.Dispose();
color1 = null;
// class methods
color.colorInstanceMethod(20.0);
nspaceNamespace.Outer.Inner1.Color.colorStaticMethod(20.0);
nspaceNamespace.Outer.Inner1.Color created = nspaceNamespace.Outer.Inner1.Color.create();
created.Dispose();
// class enums
nspaceNamespace.Outer.SomeClass someClass = new nspaceNamespace.Outer.SomeClass();
nspaceNamespace.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel();
if (channel != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission)
throw new ApplicationException("Transmission wrong");
// class anonymous enums
int val1 = nspaceNamespace.Outer.Inner1.Color.ColorEnumVal1;
int val2 = nspaceNamespace.Outer.Inner1.Color.ColorEnumVal2;
if (val1 != 0 || val2 != 0x22)
throw new ApplicationException("ColorEnumVal wrong");
// instance member variables
color.instanceMemberVariable = 123;
if (color.instanceMemberVariable != 123)
throw new ApplicationException("instance member variable failed");
// static member variables
nspaceNamespace.Outer.Inner1.Color.staticMemberVariable = 789;
if (nspaceNamespace.Outer.Inner1.Color.staticMemberVariable != 789)
throw new ApplicationException("static member variable failed");
if (nspaceNamespace.Outer.Inner1.Color.staticConstMemberVariable != 222)
throw new ApplicationException("static const member variable failed");
if (nspaceNamespace.Outer.Inner1.Color.staticConstEnumMemberVariable != nspaceNamespace.Outer.Inner1.Color.Channel.Transmission)
throw new ApplicationException("static const enum member variable failed");
// check globals in a namespace don't get mangled with the nspaceNamespace option
nspaceNamespace.nspace.namespaceFunction(color);
nspaceNamespace.nspace.namespaceVar = 111;
if (nspaceNamespace.nspace.namespaceVar != 111)
throw new ApplicationException("global var failed");
// Same class different namespaces
nspaceNamespace.Outer.Inner1.Color col1 = new nspaceNamespace.Outer.Inner1.Color();
nspaceNamespace.Outer.Inner2.Color col2 = nspaceNamespace.Outer.Inner2.Color.create();
col2.colors(col1, col1, col2, col2, col2);
// global enums
nspaceNamespace.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel();
if (outerChannel1 != nspaceNamespace.Outer.Inner1.Channel.Transmission1)
throw new ApplicationException("Transmission1 wrong");
nspaceNamespace.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel();
if (outerChannel2 != nspaceNamespace.Outer.Inner2.Channel.Transmission2)
throw new ApplicationException("Transmission2 wrong");
// turn feature off / ignoring
nspaceNamespace.Outer.nspace ns = new nspaceNamespace.Outer.nspace();
ns.Dispose();
nspaceNamespace.NoNSpacePlease nons = new nspaceNamespace.NoNSpacePlease();
nons.Dispose();
// Derived class
nspaceNamespace.Outer.Inner3.Blue blue3 = new nspaceNamespace.Outer.Inner3.Blue();
blue3.blueInstanceMethod();
nspaceNamespace.Outer.Inner4.Blue blue4 = new nspaceNamespace.Outer.Inner4.Blue();
blue4.blueInstanceMethod();
}
}

View file

@ -1,5 +1,5 @@
%module extend_template
%module xxx
%module xxx // should be ignored
namespace oss { // this doesn't
%extend Foo<0> {
int test1(int x) { return x; }

View file

@ -11,8 +11,8 @@ class Klass6 {};
class Klass7 {};
struct KlassMethods {
static void methodA(::Klass1 v, const ::Klass2 cv, const ::Klass3 *cp, ::Klass4 *p, const ::Klass5 &cr, ::Klass6 &r, Klass7*& pr) {}
static void methodB( Klass1 v, const Klass2 cv, const Klass3 *cp, Klass4 *p, const Klass5 &cr, Klass6 &r, Klass7*& pr) {}
static void methodA(::Klass1 v, const ::Klass2 cv, const ::Klass3 *cp, ::Klass4 *p, const ::Klass5 &cr, ::Klass6 &r, ::Klass7*const& pr) {}
static void methodB( Klass1 v, const Klass2 cv, const Klass3 *cp, Klass4 *p, const Klass5 &cr, Klass6 &r, Klass7*const& pr) {}
};
%}
@ -28,8 +28,8 @@ class XYZ7 {};
}
struct XYZMethods {
static void methodA(::Space::XYZ1 v, const ::Space::XYZ2 cv, const ::Space::XYZ3 *cp, ::Space::XYZ4 *p, const ::Space::XYZ5 &cr, ::Space::XYZ6 &r, Space::XYZ7*& pr) {}
static void methodB( Space::XYZ1 v, const Space::XYZ2 cv, const Space::XYZ3 *cp, Space::XYZ4 *p, const Space::XYZ5 &cr, Space::XYZ6 &r, Space::XYZ7*& pr) {}
static void methodA(::Space::XYZ1 v, const ::Space::XYZ2 cv, const ::Space::XYZ3 *cp, ::Space::XYZ4 *p, const ::Space::XYZ5 &cr, ::Space::XYZ6 &r, ::Space::XYZ7*const& pr) {}
static void methodB( Space::XYZ1 v, const Space::XYZ2 cv, const Space::XYZ3 *cp, Space::XYZ4 *p, const Space::XYZ5 &cr, Space::XYZ6 &r, Space::XYZ7*const& pr) {}
};
%}

View file

@ -0,0 +1,44 @@
%module global_scope_types
// no constructor/destructor wrappers as they do not use global scope operator which we are trying to test here
%nodefaultctor Dingaling;
%nodefaultdtor Dingaling;
%inline %{
struct Dingaling {};
typedef Dingaling DINGALING;
template <typename T> struct MyTemplate {
T tt(T t) { return t; }
T& ttr(T& t) { return t; }
};
#ifndef SWIG
// This is added so that the code will not compile, if the global scope operator on Dingaling is omitted in the generated code
namespace Spac {
class Dingaling {
Dingaling();
Dingaling(const Dingaling& t);
Dingaling& operator=(const Dingaling t);
};
}
using namespace Spac;
#endif
namespace Spac {
struct Ting {};
typedef Ting TING;
class Test {
public:
void something(::Dingaling t, ::Dingaling* pt, ::Dingaling& rt, const ::Dingaling& crt) {}
void tsomething(MyTemplate< ::Dingaling > t1, MyTemplate< const ::Dingaling* > t2) {}
// void usomething(::MyTemplate< ::DINGALING > t3, ::MyTemplate< ::DINGALING *> t4) {} // needs fixing
void nothing(::Spac::Ting*, ::Spac::TING&) {}
};
}
void funcptrtest( void (*)(::Dingaling) ) {}
%}

View file

@ -37,26 +37,28 @@ CPP_TEST_CASES = \
include $(srcdir)/../common.mk
# Overridden variables here
SWIGOPT += -package $*
JAVA_PACKAGE = $*
SWIGOPT += -package $(JAVA_PACKAGE)
INTERFACEDIR = ../../
# Custom tests - tests with additional commandline options
# none!
nspace.%: JAVA_PACKAGE = $*Package
nspace_extend.%: JAVA_PACKAGE = $*Package
# Rules for the different types of tests
%.cpptest:
$(setup)
+(cd $* && $(swig_and_compile_cpp))
+(cd $(JAVA_PACKAGE) && $(swig_and_compile_cpp))
$(run_testcase)
%.ctest:
$(setup)
+(cd $* && $(swig_and_compile_c))
+(cd $(JAVA_PACKAGE) && $(swig_and_compile_c))
$(run_testcase)
%.multicpptest:
$(setup)
+(cd $* && $(swig_and_compile_multi_cpp))
+(cd $(JAVA_PACKAGE) && $(swig_and_compile_multi_cpp))
$(run_testcase)
# Makes a directory for the testcase if it does not exist
@ -66,24 +68,24 @@ setup = \
else \
echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
fi; \
if [ ! -d $* ]; then \
mkdir $*; \
if [ ! -d $(JAVA_PACKAGE) ]; then \
mkdir $(JAVA_PACKAGE); \
fi
# Compiles java files then runs the testcase. A testcase is only run if
# a file is found which has _runme.java appended after the testcase name.
# Note Java uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows, SHLIB_PATH on HPUX and DYLD_LIBRARY_PATH on Mac OS X.
run_testcase = \
cd $* && $(COMPILETOOL) $(JAVAC) -classpath . *.java && cd .. && \
cd $(JAVA_PACKAGE) && $(COMPILETOOL) $(JAVAC) -classpath . `find . -name "*.java"` && cd .. && \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
$(COMPILETOOL) $(JAVAC) -classpath . -d . $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_LIBRARY_PATH="$*:$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) -classpath . $*_runme; \
env LD_LIBRARY_PATH="$(JAVA_PACKAGE):$$LD_LIBRARY_PATH" PATH="$(JAVA_PACKAGE):$$PATH" SHLIB_PATH="$(JAVA_PACKAGE):$$SHLIB_PATH" DYLD_LIBRARY_PATH="$(JAVA_PACKAGE):$$DYLD_LIBRARY_PATH" $(RUNTOOL) $(JAVA) -classpath . $*_runme; \
fi
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
@if [ -d $(JAVA_PACKAGE) ]; then \
rm -rf $(JAVA_PACKAGE); \
fi
clean:

View file

@ -0,0 +1,44 @@
// This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name
public class nspace_extend_runme {
static {
try {
System.loadLibrary("nspace_extend");
} 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[]) {
{
// constructors and destructors
nspace_extendPackage.Outer.Inner1.Color color1 = new nspace_extendPackage.Outer.Inner1.Color();
nspace_extendPackage.Outer.Inner1.Color color = new nspace_extendPackage.Outer.Inner1.Color(color1);
color1.delete();
color1 = null;
// class methods
color.colorInstanceMethod(20.0);
nspace_extendPackage.Outer.Inner1.Color.colorStaticMethod(20.0);
nspace_extendPackage.Outer.Inner1.Color created = nspace_extendPackage.Outer.Inner1.Color.create();
}
{
// constructors and destructors
nspace_extendPackage.Outer.Inner2.Color color2 = new nspace_extendPackage.Outer.Inner2.Color();
nspace_extendPackage.Outer.Inner2.Color color = new nspace_extendPackage.Outer.Inner2.Color(color2);
color2.delete();
color2 = null;
// class methods
color.colorInstanceMethod(20.0);
nspace_extendPackage.Outer.Inner2.Color.colorStaticMethod(20.0);
nspace_extendPackage.Outer.Inner2.Color created = nspace_extendPackage.Outer.Inner2.Color.create();
// Same class different namespaces
nspace_extendPackage.Outer.Inner1.Color col1 = new nspace_extendPackage.Outer.Inner1.Color();
nspace_extendPackage.Outer.Inner2.Color col2 = nspace_extendPackage.Outer.Inner2.Color.create();
col2.colors(col1, col1, col2, col2, col2);
}
}
}

View file

@ -0,0 +1,80 @@
// This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name
public class nspace_runme {
static {
try {
System.loadLibrary("nspace");
} 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[]) {
// constructors and destructors
nspacePackage.Outer.Inner1.Color color1 = new nspacePackage.Outer.Inner1.Color();
nspacePackage.Outer.Inner1.Color color = new nspacePackage.Outer.Inner1.Color(color1);
color1.delete();
color1 = null;
// class methods
color.colorInstanceMethod(20.0);
nspacePackage.Outer.Inner1.Color.colorStaticMethod(20.0);
nspacePackage.Outer.Inner1.Color created = nspacePackage.Outer.Inner1.Color.create();
// class enums
nspacePackage.Outer.SomeClass someClass = new nspacePackage.Outer.SomeClass();
nspacePackage.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel();
if (channel != nspacePackage.Outer.Inner1.Color.Channel.Transmission)
throw new RuntimeException("Transmission wrong");
// class anonymous enums
int val1 = nspacePackage.Outer.Inner1.Color.ColorEnumVal1;
int val2 = nspacePackage.Outer.Inner1.Color.ColorEnumVal2;
if (val1 != 0 || val2 != 0x22)
throw new RuntimeException("ColorEnumVal wrong");
// instance member variables
color.setInstanceMemberVariable(123);
if (color.getInstanceMemberVariable() != 123)
throw new RuntimeException("instance member variable failed");
// static member variables
nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789);
if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789)
throw new RuntimeException("static member variable failed");
if (nspacePackage.Outer.Inner1.Color.staticConstMemberVariable != 222)
throw new RuntimeException("static const member variable failed");
if (nspacePackage.Outer.Inner1.Color.staticConstEnumMemberVariable != nspacePackage.Outer.Inner1.Color.Channel.Transmission)
throw new RuntimeException("static const enum member variable failed");
// Same class different namespaces
nspacePackage.Outer.Inner1.Color col1 = new nspacePackage.Outer.Inner1.Color();
nspacePackage.Outer.Inner2.Color col2 = nspacePackage.Outer.Inner2.Color.create();
col2.colors(col1, col1, col2, col2, col2);
// check globals in a namespace don't get mangled with the nspacePackage option
nspacePackage.nspace.namespaceFunction(color);
nspacePackage.nspace.setNamespaceVar(111);
if (nspacePackage.nspace.getNamespaceVar() != 111)
throw new RuntimeException("global var failed");
// global enums
nspacePackage.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel();
if (outerChannel1 != nspacePackage.Outer.Inner1.Channel.Transmission1)
throw new RuntimeException("Transmission1 wrong");
nspacePackage.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel();
if (outerChannel2 != nspacePackage.Outer.Inner2.Channel.Transmission2)
throw new RuntimeException("Transmission2 wrong");
// turn feature off / ignoring
nspacePackage.Outer.nspace ns = new nspacePackage.Outer.nspace();
nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease();
// Derived class
nspacePackage.Outer.Inner3.Blue blue3 = new nspacePackage.Outer.Inner3.Blue();
blue3.blueInstanceMethod();
nspacePackage.Outer.Inner4.Blue blue4 = new nspacePackage.Outer.Inner4.Blue();
blue4.blueInstanceMethod();
}
}

View file

@ -16,21 +16,21 @@
%typemap(jstype) Space::Classic ** " Classic "
%typemap(javain) Space::Classic ** "Classic.getCPtr($javainput)"
// Default typemaps for pass by value, ref, pointer and pointer reference should use pgcpp
// Default typemaps for pass by value, ref, pointer and pointer const reference should use pgcpp
%inline %{
namespace Space {
struct Classic {
Classic() {}
Classic(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {}
Classic(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5, bool b) {}
Classic(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {}
Classic(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5, bool b) {}
void method(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {}
void methodconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5) {}
void method(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {}
void methodconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5) {}
};
void function(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {}
void functionconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5) {}
void function(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {}
void functionconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5) {}
}
%}

View file

@ -295,7 +295,7 @@ Klass& reftest(Klass& k) {
k.append(" reftest");
return k;
}
Klass*& pointerreftest(Klass*& k) {
Klass *const& pointerreftest(Klass *const& k) {
k->append(" pointerreftest");
return k;
}
@ -334,7 +334,7 @@ std::string overload_rawbyptr(int i) { return "int"; }
std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; }
std::string overload_rawbyptrref(int i) { return "int"; }
std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; }
std::string overload_rawbyptrref(Klass *const&k) { return "rawbyptrref"; }

View file

@ -222,7 +222,7 @@ Klass& reftest(Klass& k) {
k.append(" reftest");
return k;
}
Klass*& pointerreftest(Klass*& k) {
Klass *const& pointerreftest(Klass *const& k) {
k->append(" pointerreftest");
return k;
}
@ -275,7 +275,7 @@ std::string overload_rawbyptr(int i) { return "int"; }
std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; }
std::string overload_rawbyptrref(int i) { return "int"; }
std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; }
std::string overload_rawbyptrref(Klass *const&k) { return "rawbyptrref"; }

View file

@ -74,12 +74,6 @@ const std::vector<Struct *> & vecstructptr(const std::vector<Struct *> & vec) {
const std::vector<const Struct *> & vecstructconstptr(const std::vector<const Struct *> & vec) { return vec; }
%}
#if defined(SWIGCSHARP)
// Also test const and non-const pointers, but not strictly necessary since std::vector was enhanced in swig-1.3.40
%template(StructurePtrVector) std::vector<Structure *>;
%template(StructureConstPtrVector) std::vector<const Structure *>;
#endif
#if !defined(SWIGR)
%template(IntPtrVector) std::vector<int *>;
%template(IntConstPtrVector) std::vector<const int *>;
@ -88,7 +82,6 @@ const std::vector<const Struct *> & vecstructconstptr(const std::vector<const St
%template(StructPtrVector) std::vector<Struct *>;
%template(StructConstPtrVector) std::vector<const Struct *>;
#if !defined(SWIGTCL)
%inline {
struct MyClass {};
typedef MyClass *MyClassPtr;
@ -106,7 +99,6 @@ const std::vector<const Struct *> & vecstructconstptr(const std::vector<const St
}
};
}
#endif
#if defined(SWIGRUBY)
%template(LanguageVector) std::vector< swig::LANGUAGE_OBJ >;

View file

@ -0,0 +1,12 @@
require("import") -- the import fn
import("char_strings") -- import code
assert (char_strings.CharPingPong("hi there") == "hi there")
assert (char_strings.CharPingPong(nil) == nil)
assert (char_strings.CharArrayPingPong("hi there") == "hi there")
assert (char_strings.CharArrayPingPong(nil) == nil)
assert (char_strings.CharArrayDimsPingPong("hi there") == "hi there")
assert (char_strings.CharArrayDimsPingPong(nil) == nil)

View file

@ -75,3 +75,8 @@ int wget(SpamPtr f) {
#endif
// Was causing runtime error in Ruby
%include <std_vector.i>
%template(IntVector) std::vector<int>;

View file

@ -0,0 +1,103 @@
// Test the nspace feature
%module nspace
// nspace feature only supported by these languages
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
%nspace;
%nonspace Outer::Inner2::NoNSpacePlease;
%copyctor;
%ignore Outer::Inner2::Color::Color();
#define CONSTANT100 100
%inline %{
namespace Outer {
class nspace {
};
namespace Inner1 {
enum Channel { Diffuse, Specular = 0x10, Transmission1 };
enum { ColorEnumVal1, ColorEnumVal2 = 0x11, ColorEnumVal3 };
struct Color {
static Color* create() { return new Color(); }
enum Channel { Diffuse, Specular = 0x20, Transmission };
enum { ColorEnumVal1, ColorEnumVal2 = 0x22, ColorEnumVal3 };
int instanceMemberVariable;
static int staticMemberVariable;
static const int staticConstMemberVariable = 222;
static const Channel staticConstEnumMemberVariable = Transmission;
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
}; // Color
int Color::staticMemberVariable = 0;
Color namespaceFunction(Color k) { return k; }
int namespaceVar = 0;
} // Inner1
namespace Inner2 {
enum Channel { Diffuse, Specular = 0x30, Transmission2 };
struct Color {
Color() : instanceMemberVariable(0) {}
static Color* create() { return new Color(); }
enum Channel { Diffuse, Specular = 0x40, Transmission };
enum { ColorEnumVal1, ColorEnumVal2 = 0x33, ColorEnumVal3 };
int instanceMemberVariable;
static int staticMemberVariable;
static const int staticConstMemberVariable = 333;
static const Channel staticConstEnumMemberVariable = Transmission;
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
void colors(const Inner1::Color& col1a,
const Outer::Inner1::Color& col1b,
const Color &col2a,
const Inner2::Color& col2b,
const Outer::Inner2::Color& col2c) {}
}; // Color
int Color::staticMemberVariable = 0;
class NoNSpacePlease {};
} // Inner2
// Derived class
namespace Inner3 {
struct Blue : Inner2::Color {
void blueInstanceMethod() {}
};
}
namespace Inner4 {
struct Blue : Inner2::Color {
void blueInstanceMethod() {}
};
}
class SomeClass {
public:
Inner1::Color::Channel GetInner1ColorChannel() { return Inner1::Color::Transmission; }
Inner2::Color::Channel GetInner2ColorChannel() { return Inner2::Color::Transmission; }
Inner1::Channel GetInner1Channel() { return Inner1::Transmission1; }
Inner2::Channel GetInner2Channel() { return Inner2::Transmission2; }
}; // SomeClass
} // Outer
namespace Outer {
struct MyWorldPart2 {};
}
struct GlobalClass {
void gmethod() {}
};
void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {}
%}
#endif

View file

@ -0,0 +1,50 @@
// Test the nspace feature and %extend
%module nspace_extend
// nspace feature only supported by these languages
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
%nspace;
%extend Outer::Inner1::Color {
Color() { return new Outer::Inner1::Color(); }
virtual ~Color() { delete $self; }
static Color* create() { return new Outer::Inner1::Color(); }
Color(const Color& other) { return new Outer::Inner1::Color(other); }
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
}
%inline %{
namespace Outer {
namespace Inner1 {
struct Color {
};
}
namespace Inner2 {
struct Color {
};
}
}
%}
%extend Outer::Inner2::Color {
Color() { return new Outer::Inner2::Color(); }
~Color() { delete $self; }
static Color* create() { return new Outer::Inner2::Color(); }
Color(const Color& other) { return new Outer::Inner2::Color(other); }
void colorInstanceMethod(double d) {}
static void colorStaticMethod(double d) {}
void colors(const Inner1::Color& col1a,
const Outer::Inner1::Color& col1b,
const Color &col2a,
const Inner2::Color& col2b,
const Outer::Inner2::Color& col2c) {}
}
#endif

View file

@ -29,10 +29,10 @@ struct Struct {
static Struct *pInstance;
};
void set(Struct *& s) {
void set(Struct *const& s) {
Struct::instance = *s;
}
Struct *& get() {
Struct *const& get() {
return Struct::pInstance;
}
%}

View file

@ -0,0 +1,3 @@
from constructor_rename import *
x = RenamedConstructor()

View file

@ -0,0 +1,36 @@
import threads_exception
t = threads_exception.Test()
try:
t.unknown()
except RuntimeError,e:
pass
try:
t.simple()
except RuntimeError,e:
if e.args[0] != 37:
raise RuntimeError
try:
t.message()
except RuntimeError,e:
if e.args[0] != "I died.":
raise RuntimeError
try:
t.hosed()
except threads_exception.Exc,e:
if e.code != 42:
raise RuntimeError
if e.msg != "Hosed":
raise RuntimeError
for i in range(1,4):
try:
t.multi(i)
except RuntimeError,e:
pass
except threads_exception.Exc,e:
pass

View file

@ -0,0 +1,28 @@
%module symbol_clash
// ::Vector and ::Text::Vector were incorrectly clashing in the target language symbol tables
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
#if defined(SWIGJAVA)
%include "enumtypeunsafe.swg"
#elif defined(SWIGCSHARP)
%include "enumsimple.swg"
#endif
%inline %{
class Vector
{
};
namespace Text
{
enum Preference
{
Raster,
Vector
};
}
%}
#endif

View file

@ -0,0 +1,54 @@
// Throw a lot of exceptions
// The Python runtime tests were previously failing with the -threads option on Windows due to SWIG_PYTHON_THREAD_BEGIN_ALLOW not being within the try block.
%module(threads="1") threads_exception
%{
struct A {};
%}
%inline %{
#include <string>
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
class Exc {
public:
Exc(int c, const char *m) {
code = c;
strncpy(msg,m,255);
}
int code;
char msg[256];
};
class Test {
public:
int simple() throw(int) {
throw(37);
return 1;
}
int message() throw(const char *) {
throw("I died.");
return 1;
}
int hosed() throw(Exc) {
throw(Exc(42,"Hosed"));
return 1;
}
int unknown() throw(A*) {
static A a;
throw &a;
return 1;
}
int multi(int x) throw(int, const char *, Exc) {
if (x == 1) throw(37);
if (x == 2) throw("Bleah!");
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
return 1;
}
};
%}

View file

@ -0,0 +1,215 @@
%module typemap_global_scope
// Test global scope operator :: for typemaps. Previously SWIG would not use a typemap that did not specify the global scope
// operator for a type that did have it, and vice-versa.
%typemap(in) SWIGTYPE "_this_will_not_compile_SWIGTYPE_ \"$type\""
%typemap(in) const SWIGTYPE & "_this_will_not_compile_const_SWIGTYPE_REF_ \"$type\""
%typemap(in) enum SWIGTYPE "_this_will_not_compile_enum_SWIGTYPE_ \"$type\""
%typemap(in) const enum SWIGTYPE & "_this_will_not_compile_const_enum_SWIGTYPE_REF_ \"$type\""
/////////////////////////////////////////////////////////////////////
// Structs
/////////////////////////////////////////////////////////////////////
%typemap(in) Test1, ::Test2, Space::Test3, ::Space::Test4 "/*in typemap for $type*/"
%typemap(in) const Test1 &, const ::Test2 &, const Space::Test3 &, const ::Space::Test4 & "/*in typemap for $type*/"
%inline %{
struct Test1 {};
struct Test2 {};
namespace Space {
struct Test3 {};
struct Test4 {};
}
%}
%inline %{
void test1a(Test1 t, const Test1 &tt) {}
void test1b(::Test1 t, const ::Test1 &tt) {}
void test2a(Test2 t, const Test2 &tt) {}
void test2b(::Test2 t, const ::Test2 &tt) {}
void test3a(Space::Test3 t, const Space::Test3 &tt) {}
void test3b(::Space::Test3 t, const ::Space::Test3 &tt) {}
namespace Space {
void test3c(Space::Test3 t, const Space::Test3 &tt) {}
void test3d(::Space::Test3 t, const ::Space::Test3 &tt) {}
void test3e(Test3 t, const Test3 &tt) {}
}
void test4a(Space::Test4 t, const Space::Test4 &tt) {}
void test4b(::Space::Test4 t, const ::Space::Test4 &tt) {}
namespace Space {
void test4c(Space::Test4 t, const Space::Test4 &tt) {}
void test4d(::Space::Test4 t, const ::Space::Test4 &tt) {}
void test4e(Test4 t, const Test4 &tt) {}
}
%}
/////////////////////////////////////////////////////////////////////
// Templates
/////////////////////////////////////////////////////////////////////
%inline %{
struct XX {};
%}
%typemap(in) TemplateTest1< ::XX >, ::TemplateTest2< ::XX >, Space::TemplateTest3< ::XX >, ::Space::TemplateTest4< ::XX > "/* in typemap for $type */"
%typemap(in) const TemplateTest1< XX > &, const ::TemplateTest2< XX > &, const Space::TemplateTest3< XX > &, const ::Space::TemplateTest4< XX > & "/* in typemap for $type */"
%inline %{
template<typename T> struct TemplateTest1 { T m_t; };
template<typename T> struct TemplateTest2 { T m_t; };
namespace Space {
template<typename T> struct TemplateTest3 { T m_t; };
template<typename T> struct TemplateTest4 { T m_t; };
}
%}
%template(TemplateTest1XX) TemplateTest1< ::XX >;
%template(TemplateTest2XX) TemplateTest2< ::XX >;
%template(TemplateTest3XX) Space::TemplateTest3< ::XX >;
%template(TemplateTest4XX) Space::TemplateTest4< ::XX >;
%inline %{
void test_template_1a(TemplateTest1< ::XX > t, const TemplateTest1< ::XX > &tt) {}
void test_template_1b(::TemplateTest1< ::XX > t, const ::TemplateTest1< ::XX > &tt) {}
void test_template_2a(TemplateTest2< ::XX > t, const TemplateTest2< ::XX > &tt) {}
void test_template_2b(::TemplateTest2< ::XX > t, const ::TemplateTest2< ::XX > &tt) {}
void test_template_3a(Space::TemplateTest3< ::XX > t, const Space::TemplateTest3< ::XX > &tt) {}
void test_template_3b(::Space::TemplateTest3< ::XX > t, const ::Space::TemplateTest3< ::XX > &tt) {}
namespace Space {
void test_template_3c(Space::TemplateTest3< ::XX > t, const Space::TemplateTest3< ::XX > &tt) {}
void test_template_3d(::Space::TemplateTest3< ::XX > t, const ::Space::TemplateTest3< ::XX > &tt) {}
void test_template_3e(TemplateTest3< ::XX > t, const TemplateTest3< ::XX > &tt) {}
}
void test_template_4a(Space::TemplateTest4< ::XX > t, const Space::TemplateTest4< ::XX > &tt) {}
void test_template_4b(::Space::TemplateTest4< ::XX > t, const ::Space::TemplateTest4< ::XX > &tt) {}
namespace Space {
void test_template_4c(Space::TemplateTest4< ::XX > t, const Space::TemplateTest4< ::XX > &tt) {}
void test_template_4d(::Space::TemplateTest4< ::XX > t, const ::Space::TemplateTest4< ::XX > &tt) {}
void test_template_4e(TemplateTest4< ::XX > t, const TemplateTest4< ::XX > &tt) {}
}
%}
/////////////////////////////////////////////////////////////////////
// Enums
/////////////////////////////////////////////////////////////////////
%typemap(in) Enum1, ::Enum2, Space::Enum3, ::Space::Enum4 "/*in typemap for $type*/"
%typemap(in) const Enum1 &, const ::Enum2 &, const Space::Enum3 &, const ::Space::Enum4 & "/*in typemap for $type*/"
%inline %{
enum Enum1 { enum_1 };
enum Enum2 { enum_2 };
namespace Space {
enum Enum3 { enum_3 };
enum Enum4 { enum_4 };
}
%}
%inline %{
void test_enum_1a(Enum1 t, const Enum1 &tt) {}
void test_enum_1b(::Enum1 t, const ::Enum1 &tt) {}
void test_enum_2a(Enum2 t, const Enum2 &tt) {}
void test_enum_2b(::Enum2 t, const ::Enum2 &tt) {}
void test_enum_3a(Space::Enum3 t, const Space::Enum3 &tt) {}
void test_enum_3b(::Space::Enum3 t, const ::Space::Enum3 &tt) {}
namespace Space {
void test_enum_3c(Space::Enum3 t, const Space::Enum3 &tt) {}
void test_enum_3d(::Space::Enum3 t, const ::Space::Enum3 &tt) {}
void test_enum_3e(Enum3 t, const Enum3 &tt) {}
}
void test_enum_4a(Space::Enum4 t, const Space::Enum4 &tt) {}
void test_enum_4b(::Space::Enum4 t, const ::Space::Enum4 &tt) {}
namespace Space {
void test_enum_4c(Space::Enum4 t, const Space::Enum4 &tt) {}
void test_enum_4d(::Space::Enum4 t, const ::Space::Enum4 &tt) {}
void test_enum_4e(Enum4 t, const Enum4 &tt) {}
}
%}
#if 0
/////////////////////////////////////////////////////////////////////
// Enums with enum specified in typemap
/////////////////////////////////////////////////////////////////////
%typemap(in) enum Mune1, enum ::Mune2, enum Space::Mune3, enum ::Space::Mune4 "/*in typemap for $type*/"
%typemap(in) const enum Mune1 &, const enum ::Mune2 &, const enum Space::Mune3 &, const enum ::Space::Mune4 & "/*in typemap for $type*/"
%inline %{
enum Mune1 { mune_1 };
enum Mune2 { mune_2 };
namespace Space {
enum Mune3 { mune_3 };
enum Mune4 { mune_4 };
}
%}
%inline %{
void test_mune_1a(Mune1 t, const Mune1 &tt) {}
void test_mune_1b(::Mune1 t, const ::Mune1 &tt) {}
void test_mune_2a(Mune2 t, const Mune2 &tt) {}
void test_mune_2b(::Mune2 t, const ::Mune2 &tt) {}
void test_mune_3a(Space::Mune3 t, const Space::Mune3 &tt) {}
void test_mune_3b(::Space::Mune3 t, const ::Space::Mune3 &tt) {}
namespace Space {
void test_mune_3c(Space::Mune3 t, const Space::Mune3 &tt) {}
void test_mune_3d(::Space::Mune3 t, const ::Space::Mune3 &tt) {}
void test_mune_3e(Mune3 t, const Mune3 &tt) {}
}
void test_mune_4a(Space::Mune4 t, const Space::Mune4 &tt) {}
void test_mune_4b(::Space::Mune4 t, const ::Space::Mune4 &tt) {}
namespace Space {
void test_mune_4c(Space::Mune4 t, const Space::Mune4 &tt) {}
void test_mune_4d(::Space::Mune4 t, const ::Space::Mune4 &tt) {}
void test_mune_4e(Mune4 t, const Mune4 &tt) {}
}
%}
/////////////////////////////////////////////////////////////////////
// Enums with enum specified in type
/////////////////////////////////////////////////////////////////////
%typemap(in) Nemu1, ::Nemu2, Space::Nemu3, ::Space::Nemu4 "/*in typemap for $type*/"
%typemap(in) const Nemu1 &, const ::Nemu2 &, const Space::Nemu3 &, const ::Space::Nemu4 & "/*in typemap for $type*/"
%inline %{
enum Nemu1 { nemu_1 };
enum Nemu2 { nemu_2 };
namespace Space {
enum Nemu3 { nemu_3 };
enum Nemu4 { nemu_4 };
}
%}
%inline %{
void test_nemu_1a(enum Nemu1 t, const enum Nemu1 &tt) {}
void test_nemu_1b(enum ::Nemu1 t, const enum ::Nemu1 &tt) {}
void test_nemu_2a(enum Nemu2 t, const enum Nemu2 &tt) {}
void test_nemu_2b(enum ::Nemu2 t, const enum ::Nemu2 &tt) {}
void test_nemu_3a(enum Space::Nemu3 t, const enum Space::Nemu3 &tt) {}
void test_nemu_3b(enum ::Space::Nemu3 t, const enum ::Space::Nemu3 &tt) {}
namespace Space {
void test_nemu_3c(enum Space::Nemu3 t, const enum Space::Nemu3 &tt) {}
void test_nemu_3d(enum ::Space::Nemu3 t, const enum ::Space::Nemu3 &tt) {}
void test_nemu_3e(enum Nemu3 t, const enum Nemu3 &tt) {}
}
void test_nemu_4a(enum Space::Nemu4 t, const enum Space::Nemu4 &tt) {}
void test_nemu_4b(enum ::Space::Nemu4 t, const enum ::Space::Nemu4 &tt) {}
namespace Space {
void test_nemu_4c(enum Space::Nemu4 t, const enum Space::Nemu4 &tt) {}
void test_nemu_4d(enum ::Space::Nemu4 t, const enum ::Space::Nemu4 &tt) {}
void test_nemu_4e(enum Nemu4 t, const enum Nemu4 &tt) {}
}
%}
#endif

View file

@ -0,0 +1,34 @@
%module typemap_template
/* Test bug in 1.3.40 where the presence of a generic/unspecialized typemap caused the incorrect specialized typemap to be used */
%typemap(in) SWIGTYPE "/*_this_will_not_compile_SWIGTYPE_ \"$type\" */ "
%typemap(in) const SWIGTYPE & "/*_this_will_not_compile_const_SWIGTYPE_REF_\"$type\" */ "
%typemap(in) const TemplateTest1 & {$1 = (TemplateTest1<YY> *)0; /* in typemap generic for $type */}
%typemap(in) const TemplateTest1< ZZ > & {$1 = (TemplateTest1<ZZ> *)0; /* in typemap ZZ for $type */}
%typemap(in) const TemplateTest1< int > & {$1 = (TemplateTest1<int> *)0; /* in typemap int for $type */}
%inline %{
template<typename T> struct TemplateTest1 {
void setT(const TemplateTest1& t) {}
};
%}
%inline %{
struct YY {};
struct ZZ {};
%}
%template(TTYY) TemplateTest1< YY >;
%template(TTZZ) TemplateTest1< ZZ >;
%template(TTint) TemplateTest1< int >;
%inline %{
void extratest(const TemplateTest1< YY > &t,
const TemplateTest1< ZZ > &tt,
const TemplateTest1< int > &ttt)
{}
%}