Merged changes from trunk up to revision 12416.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12417 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2011-01-30 05:24:00 +00:00
commit 9c796f0333
127 changed files with 2571 additions and 1771 deletions

View file

@ -1219,6 +1219,10 @@ go_clean:
DLIBPREFIX = @DLIBPREFIX@
ifeq (,$(D_VERSION))
D_VERSION = @DDEFAULTVERSION@
endif
ifeq (2,$(D_VERSION))
SWIGD = $(SWIG) -d -d2
DCOMPILER = @D2COMPILER@
@ -1229,7 +1233,7 @@ endif
ifeq (dmd,$(DCOMPILER))
# DMD is 32bit only by now
CFLAGS += -m32
DCFLAGS = -m32
endif
# ----------------------------------------------------------------
@ -1238,8 +1242,8 @@ endif
d: $(SRCS)
$(SWIGD) $(SWIGOPT) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES)
$(LDSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
$(CC) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES)
$(LDSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
# ----------------------------------------------------------------
# Build a dynamically loadable D wrapper for a C++ module
@ -1247,15 +1251,24 @@ d: $(SRCS)
d_cpp: $(SRCS)
$(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
$(CXX) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
# ----------------------------------------------------------------
# Compile D files
# ----------------------------------------------------------------
# Clear the DFLAGS environment variable for the compiler call itself
# to work around a discrepancy in argument handling between DMD and LDC.
d_compile: $(SRCS)
$(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
DFLAGS="" $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
# -----------------------------------------------------------------
# Run D example
# -----------------------------------------------------------------
d_run:
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme
# -----------------------------------------------------------------
# Clean the D examples

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -27,8 +27,16 @@ void main() {
Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline;
Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline;
Stdout( "Now the same with callback functions defined in D:" ).newline;
Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
version (LDC) {
// Currently, there is no way to specify the calling convention for
// function pointer parameters in D, but LDC does strict typechecking for
// them (which is reasonable, but not covered by the language spec yet).
// As a result, there is no way to make the code below compile with LDC at
// the moment, so just skip it.
} else {
Stdout( "Now the same with callback functions defined in D:" ).newline;
Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
}
}

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile d_run

View file

@ -0,0 +1,29 @@
/*
A test case for testing non null terminated char pointers.
*/
%module char_binary
%apply (char *STRING, size_t LENGTH) { (const char *str, size_t len) }
%inline %{
struct Test {
size_t strlen(const char *str, size_t len) {
return len;
}
};
typedef char namet[5];
namet var_namet;
typedef char* pchar;
pchar var_pchar;
%}
// Remove string handling typemaps and treat as pointer
%typemap(freearg) SWIGTYPE * ""
%apply SWIGTYPE * { char * }
%include "carrays.i"
%array_functions(char, pchar);

View file

@ -154,6 +154,7 @@ CPP_TEST_CASES += \
derived_nested \
destructor_reprotected \
director_abstract \
director_alternating \
director_basic \
director_classes \
director_classic \
@ -166,6 +167,7 @@ CPP_TEST_CASES += \
director_finalizer \
director_frob \
director_ignore \
director_keywords \
director_namespace_clash \
director_nested \
director_overload \
@ -228,9 +230,11 @@ CPP_TEST_CASES += \
li_cpointer \
li_stdint \
li_typemaps \
li_typemaps_apply \
li_windows \
long_long_apply \
memberin_extend \
member_funcptr_galore \
member_pointer \
member_template \
minherit \
@ -396,6 +400,7 @@ CPP_TEST_CASES += \
typedef_scope \
typedef_sizet \
typedef_struct \
typemap_arrays \
typemap_delete \
typemap_global_scope \
typemap_namespace \

View file

@ -55,6 +55,43 @@ public class csharp_prepost_runme {
throw new Exception("Expecting CustomInt attribute");
}
}
// Dates
{
// pre post typemap attributes example
System.DateTime dateIn = new System.DateTime(2011, 4, 13);
System.DateTime dateOut = new System.DateTime();
// Note in calls below, dateIn remains unchanged and dateOut
// is set to a new value by the C++ call
csharp_prepostNamespace.Action action = new csharp_prepostNamespace.Action(dateIn, out dateOut);
if (dateOut != dateIn)
throw new Exception("dates wrong");
dateIn = new System.DateTime(2012, 7, 14);
action.doSomething(dateIn, out dateOut);
if (dateOut != dateIn)
throw new Exception("dates wrong");
System.DateTime refDate = new System.DateTime(1999, 12, 31);
if (csharp_prepost.ImportantDate != refDate)
throw new Exception("dates wrong");
refDate = new System.DateTime(1999, 12, 31);
csharp_prepost.ImportantDate = refDate;
System.DateTime importantDate = csharp_prepost.ImportantDate;
if (importantDate != refDate)
throw new Exception("dates wrong");
System.DateTime christmasEve = new System.DateTime(2000, 12, 24);
csharp_prepost.addYears(ref christmasEve, 10);
if (christmasEve != new System.DateTime(2010, 12, 24))
throw new Exception("dates wrong");
Person person = new Person();
person.Birthday = christmasEve;
if (person.Birthday != christmasEve)
throw new Exception("dates wrong");
}
}
private static void Assert(double d1, double d2) {
if (d1 != d2)

View file

@ -12,6 +12,9 @@ public class pointer_reference_runme {
Struct ss = new Struct(20);
pointer_reference.set(ss);
if (Struct.instance.value != 20) throw new Exception("set test failed");
if (pointer_reference.overloading(1) != 111) throw new Exception("overload test 1 failed");
if (pointer_reference.overloading(ss) != 222) throw new Exception("overload test 2 failed");
}
}

View file

@ -79,7 +79,7 @@ struct PrePost2 {
// Check attributes in the typemaps
%typemap(cstype, inattributes="[CustomInt]") int val "int"
%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int "tmp_$csinput"
%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput"
%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/"
%inline %{
@ -188,5 +188,8 @@ void subtractYears(CDate *pDate, int years) {
%inline %{
CDate ImportantDate = CDate(1999, 12, 31);
struct Person {
CDate Birthday;
};
%}

View file

@ -76,6 +76,6 @@ run_testcase = \
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \
rm -rf $*; \
@if [ -d $*$(VERSIONSUFFIX) ]; then \
rm -rf $*$(VERSIONSUFFIX); \
fi

View file

@ -7,17 +7,30 @@ import d_nativepointers.SWIGTYPE_p_p_SomeClass;
import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void;
void main() {
check!(a, int*);
check!(b, float**);
check!(c, char***);
check!(d, SomeClass);
check!(e, SWIGTYPE_p_p_SomeClass);
check!(f, SWIGTYPE_p_OpaqueClass);
check!(g, void function(int**, char***));
check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
check!(a, int*);
check!(b, float**);
check!(c, char***);
check!(d, SomeClass);
check!(e, SWIGTYPE_p_p_SomeClass);
check!(f, SWIGTYPE_p_OpaqueClass);
check!(g, void function(int**, char***));
check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
{
static assert(is(int* function(int*) == typeof(&refA)));
int v = 2;
assert(*refA(&v) == 2);
}
{
static assert(is(float** function(float**) == typeof(&refB)));
float v = 1.0;
float* p = &v;
assert(**refB(&p) == 1.0);
}
}
void check(alias F, T)() {
static assert(is(T function(T) == typeof(&F)));
assert(F(null) is null);
static assert(is(T function(T) == typeof(&F)));
assert(F(null) is null);
}

View file

@ -7,17 +7,30 @@ import d_nativepointers.SWIGTYPE_p_p_SomeClass;
import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void;
void main() {
check!(a, int*);
check!(b, float**);
check!(c, char***);
check!(d, SomeClass);
check!(e, SWIGTYPE_p_p_SomeClass);
check!(f, SWIGTYPE_p_OpaqueClass);
check!(g, void function(int**, char***));
check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
check!(a, int*);
check!(b, float**);
check!(c, char***);
check!(d, SomeClass);
check!(e, SWIGTYPE_p_p_SomeClass);
check!(f, SWIGTYPE_p_OpaqueClass);
check!(g, void function(int**, char***));
check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void);
{
static assert(is(int* function(int*) == typeof(&refA)));
int v = 2;
assert(*refA(&v) == 2);
}
{
static assert(is(float** function(float**) == typeof(&refB)));
float v = 1.0;
float* p = &v;
assert(**refB(&p) == 1.0);
}
}
void check(alias F, T)() {
static assert(is(T function(T) == typeof(&F)));
assert(F(null) is null);
static assert(is(T function(T) == typeof(&F)));
assert(F(null) is null);
}

View file

@ -0,0 +1,7 @@
module director_alternating_runme;
import director_alternating.director_alternating;
void main() {
assert(getBar().id() == idFromGetBar());
}

View file

@ -0,0 +1,7 @@
module director_alternating_runme;
import director_alternating.director_alternating;
void main() {
assert(getBar().id() == idFromGetBar());
}

View file

@ -0,0 +1,89 @@
module operator_overload_runme;
import operator_overload.Op;
void main() {
// Invoke the C++ sanity check first.
Op.sanity_check();
auto a = new Op();
auto b = new Op(5);
auto c = b;
auto d = new Op(2);
auto dd = d;
// test equality
assert(a != b);
assert(b == c);
assert(a != d);
assert(d == dd);
// test <
assert(a < b);
assert(a <= b);
assert(b <= c);
assert(b >= c);
assert(b > d);
assert(b >= d);
// test +=
auto e = new Op(3);
e += d;
assert(e == b);
e -= c;
assert(e == a);
e = new Op(1);
e *= b;
assert(e == c);
e /= d;
assert(e == d);
e %= c;
assert(e == d);
// test +
auto f = new Op(1);
auto g = new Op(1);
assert(f + g == new Op(2));
assert(f - g == new Op(0));
assert(f * g == new Op(1));
assert(f / g == new Op(1));
assert(f % g == new Op(0));
// test unary operators
assert(-a == a);
assert(-b == new Op(-5));
// The unary ! operator is not overloadable in D1.
// test []
auto h = new Op(3);
assert(h[0]==3);
assert(h[1]==0);
// Generation of opIndexAssign is not supported yet.
// test ()
auto i = new Op(3);
assert(i()==3);
assert(i(1)==4);
assert(i(1,2)==6);
// test ++ and --
auto j = new Op(100);
int original = j.i;
{
Op newOp = j++;
int newInt = original++;
assert(j.i == original);
assert(newOp.i == newInt);
}
{
Op newOp = j--;
int newInt = original--;
assert(j.i == original);
assert(newOp.i == newInt);
}
// Prefix increment/decrement operators are lowered to (foo +=/-= 1) in D1,
// but the test case does not define an integer overload for operator +=
// respectively -=.
// Implicit casting is not overloadable in D1.
}

View file

@ -0,0 +1,91 @@
module operator_overload_runme;
import operator_overload.Op;
void main() {
// Invoke the C++ sanity check first.
Op.sanity_check();
auto a = new Op();
auto b = new Op(5);
auto c = b;
auto d = new Op(2);
auto dd = d;
// test equality
assert(a != b);
assert(b == c);
assert(a != d);
assert(d == dd);
// test <
assert(a < b);
assert(a <= b);
assert(b <= c);
assert(b >= c);
assert(b > d);
assert(b >= d);
// test +=
auto e = new Op(3);
e += d;
assert(e == b);
e -= c;
assert(e == a);
e = new Op(1);
e *= b;
assert(e == c);
e /= d;
assert(e == d);
e %= c;
assert(e == d);
// test +
auto f = new Op(1);
auto g = new Op(1);
assert(f + g == new Op(2));
assert(f - g == new Op(0));
assert(f * g == new Op(1));
assert(f / g == new Op(1));
assert(f % g == new Op(0));
// test unary operators
assert(-a == a);
assert(-b == new Op(-5));
// Unfortunaly, there is no way to override conversion to boolean for
// classes in D, opCast!("bool") is only used for structs.
// test []
auto h = new Op(3);
assert(h[0]==3);
assert(h[1]==0);
// Generation of opIndexAssign is not supported yet.
// test ()
auto i = new Op(3);
assert(i()==3);
assert(i(1)==4);
assert(i(1,2)==6);
// test ++ and --
auto j = new Op(100);
int original = j.i;
// The prefix increment/decrement operators are not directly overloadable in
// D2, and because the proxy classes are reference types, the lowering
// yields the same value as the postfix operators.
{
Op newOp = ++j;
int newInt = ++original;
assert(j.i == original);
assert(newOp.i == newInt);
}
{
Op newOp = --j;
int newInt = --original;
assert(j.i == original);
assert(newOp.i == newInt);
}
// Implicit casting via alias this is not supported yet.
}

View file

@ -15,4 +15,7 @@
OpaqueClass *f( OpaqueClass *value ){ return value; }
FuncA g( FuncA value ){ return value; }
FuncB* h( FuncB* value ){ return value; }
int &refA( int &value ){ return value; }
float *&refB( float *&value ){ return value; }
%}

View file

@ -0,0 +1,36 @@
// Checks if calls to a method being defined in the base class, not
// overridden in the subclass, but again overridden in a class derived from
// the first subclass are dispatched correctly.
%module(directors="1") director_alternating;
%feature("director") Foo;
%inline %{
struct Foo {
virtual ~Foo() {}
virtual int id() {
return 0;
}
};
struct Bar : Foo {};
struct Baz : Bar {
virtual int id() {
return 2;
}
};
// Note that even though the return value is of type Bar*, it really points to
// an instance of Baz (in which id() has been overridden).
Bar *getBar() {
static Baz baz;
return &baz;
}
// idFromGetBar() obviously is equivalent to getBar()->id() in C++ – this
// should be true from the target language as well.
int idFromGetBar() {
return getBar()->id();
}
%}

View file

@ -0,0 +1,13 @@
// Checks if collisions of argument names with target language keywords are
// resolved properly when directors are used (currently only »abstract« for
// C#, D and Java is checked).
%module(directors="1") director_keywords
%feature("director") Foo;
%inline %{
struct Foo {
virtual ~Foo() {}
virtual void bar(int abstract) {}
};
%}

View file

@ -0,0 +1,29 @@
%module cpp_shared_ptr
%include <boost_shared_ptr.i>
%shared_ptr(B);
%shared_ptr(C);
%inline %{
#include <stdio.h>
#include <boost/shared_ptr.hpp>
struct A {
virtual ~A() {}
};
struct B {
virtual ~B() {}
};
struct C : B, A {
virtual ~C() {}
};
struct D : C {
virtual ~D() {}
};
%}

View file

@ -10,6 +10,7 @@ c_bad_native.i:3: Error: %native declaration 'foo' is not a function.
:::::::::::::::::::::::::::::::: c_class.i :::::::::::::::::::::::::::::::::::
c_class.i:3: Warning 301: class keyword used, but not in C++ mode.
c_class.i:3: Warning 314: 'class' is a python keyword, renaming to '_class'
:::::::::::::::::::::::::::::::: c_default_error.i :::::::::::::::::::::::::::::::::::
@ -280,6 +281,11 @@ cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using
cpp_private_inherit.i:6: Warning 309: private inheritance from base 'Foo' (ignored).
cpp_private_inherit.i:9: Warning 309: protected inheritance from base 'Foo' (ignored).
:::::::::::::::::::::::::::::::: cpp_shared_ptr.i :::::::::::::::::::::::::::::::::::
cpp_shared_ptr.i:20: Warning 520: Base class 'A' of 'C' is not similarly marked as a smart pointer.
cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'C' is not similarly marked as a smart pointer.
cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'B' is not similarly marked as a smart pointer.
:::::::::::::::::::::::::::::::: cpp_template_argname.i :::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::: cpp_template_nargs.i :::::::::::::::::::::::::::::::::::

View file

@ -76,6 +76,7 @@ cpp_nobase
cpp_overload
cpp_private_defvalue
cpp_private_inherit
cpp_shared_ptr
cpp_template_argname
cpp_template_nargs
cpp_template_not
@ -98,14 +99,14 @@ for i in ${CFILES}; do
echo " Testing : ${i}.i";
echo "" >> ${LOGFILE};
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE};
${SWIG} -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
${SWIG} -python -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
done
for i in ${CPPFILES}; do
echo " Testing : ${i}.i";
echo "" >> ${LOGFILE}
echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE};
${SWIG} -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
${SWIG} -python -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1
done
echo ""

View file

@ -2,6 +2,14 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME);
#if defined(SWIGGO) && defined(SWIGGO_GCCGO)
%{
#ifdef __GNUC__
#include <cxxabi.h>
#endif
%}
#endif
%include "exception.i"
%{
@ -23,6 +31,18 @@
SWIG_exception_fail(SWIG_RuntimeError,"postcatch unknown");
}
}
#elif defined(SWIGGO) && defined(SWIGGO_GCCGO)
%exception %{
try {
$action
#ifdef __GNUC__
} catch (__cxxabiv1::__foreign_exception&) {
throw;
#endif
} catch(...) {
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
}
%}
#else
%exception {
try {

View file

@ -0,0 +1,25 @@
package main
import . "./char_binary"
func main() {
t := NewTest()
if t.Strlen("hile") != 4 {
print(t.Strlen("hile"))
panic("bad multi-arg typemap")
}
if t.Strlen("hil\000") != 4 {
panic("bad multi-arg typemap")
}
// creating a raw char*
pc := New_pchar(5)
Pchar_setitem(pc, 0, 'h')
Pchar_setitem(pc, 1, 'o')
Pchar_setitem(pc, 2, 'l')
Pchar_setitem(pc, 3, 'a')
Pchar_setitem(pc, 4, 0)
Delete_pchar(pc)
}

View file

@ -10,7 +10,7 @@ SCM test_create()
newobj = new A();
type = SWIG_TypeQuery("A *");
result = SWIG_NewPointerObj(result, type, 1);
result = SWIG_NewPointerObj(newobj, type, 1);
return result;
#undef FUNC_NAME

View file

@ -0,0 +1,24 @@
import char_binary.*;
public class char_binary_runme {
static {
try {
System.loadLibrary("char_binary");
} 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[]) {
Test t = new Test();
byte[] hile = "hile".getBytes();
byte[] hil0 = "hil\0".getBytes();
if (t.strlen(hile) != 4)
throw new RuntimeException("bad multi-arg typemap");
if (t.strlen(hil0) != 4)
throw new RuntimeException("bad multi-arg typemap");
}
}

View file

@ -19,5 +19,8 @@ public class pointer_reference_runme {
Struct ss = new Struct(20);
pointer_reference.set(ss);
if (Struct.getInstance().getValue() != 20) throw new RuntimeException("set test failed");
if (pointer_reference.overloading(1) != 111) throw new RuntimeException("overload test 1 failed");
if (pointer_reference.overloading(ss) != 222) throw new RuntimeException("overload test 2 failed");
}
}

View file

@ -30,7 +30,7 @@ public class rname_runme {
throw new RuntimeException("base.newname");
RenamedDerived derived = new RenamedDerived();
derived.func(base, base, base);
derived.Xfunc(base, base, base);
if (!derived.newname(10.0).equals("Derived"))
throw new RuntimeException("derived.newname");
}

View file

@ -0,0 +1,19 @@
import typemap_arrays.*;
public class typemap_arrays_runme {
static {
try {
System.loadLibrary("typemap_arrays");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) {
if (typemap_arrays.sumA(null) != 60)
throw new RuntimeException("Sum is wrong");
}
}

View file

@ -19,7 +19,9 @@ public class wallkw_runme {
throw new RuntimeException("delegate keyword fail");
if (!wallkw._pass().equals("pass"))
throw new RuntimeException("pass keyword fail");
if (!wallkw.C_alias().equals("alias"))
if (!wallkw._alias().equals("alias"))
throw new RuntimeException("alias keyword fail");
if (!wallkw.C_rescue().equals("rescue"))
throw new RuntimeException("rescue keyword fail");
}
}

View file

@ -0,0 +1,46 @@
%module li_typemaps_apply
// Test %apply to global primitive type references/pointers to make sure the return types are still okay... mainly for the strongly typed languages.
%include "typemaps.i"
#if !defined(SWIGJAVA) // Needs asymmetric type marshalling support for this testcase to work
%define TMAPS(PRIMTYPE, NAME)
%apply PRIMTYPE *INPUT { PRIMTYPE * }
%apply PRIMTYPE &INPUT { PRIMTYPE & }
%inline %{
PRIMTYPE *input_ptr_##NAME(PRIMTYPE *v) { static PRIMTYPE stat; stat = *v; return &stat; }
PRIMTYPE &input_ref_##NAME(PRIMTYPE &v) { static PRIMTYPE stat; stat = v; return stat; }
%}
%apply PRIMTYPE *OUTPUT { PRIMTYPE * }
%apply PRIMTYPE &OUTPUT { PRIMTYPE & }
%inline %{
PRIMTYPE *output_ptr_##NAME(PRIMTYPE x, PRIMTYPE *v) { static PRIMTYPE stat; stat = x; *v = x; return &stat; }
PRIMTYPE &output_ref_##NAME(PRIMTYPE x, PRIMTYPE &v) { static PRIMTYPE stat; stat = x; v = x; return stat; }
%}
%apply PRIMTYPE *INOUT { PRIMTYPE * }
%apply PRIMTYPE &INOUT { PRIMTYPE & }
%inline %{
PRIMTYPE *inout_ptr_##NAME(PRIMTYPE *v) { static PRIMTYPE stat; stat = *v; *v = *v; return &stat; }
PRIMTYPE &inout_ref_##NAME(PRIMTYPE &v) { static PRIMTYPE stat; stat = v; v = v; return stat; }
%}
%enddef
TMAPS(bool, bool)
TMAPS(int, int)
TMAPS(short, short)
TMAPS(long, long)
TMAPS(unsigned int, uint)
TMAPS(unsigned short, ushort)
TMAPS(unsigned long, ulong)
TMAPS(unsigned char, uchar)
TMAPS(signed char, schar)
TMAPS(float, float)
TMAPS(double, double)
TMAPS(long long, longlong)
TMAPS(unsigned long long, ulonglong)
#endif

View file

@ -9,3 +9,5 @@ ss = pointer_reference.Struct(20);
pointer_reference.set(ss);
assert(pointer_reference.Struct_instance.value == 20)
assert(pointer_reference.overloading(1) == 111)
assert(pointer_reference.overloading(ss) == 222)

View file

@ -0,0 +1,83 @@
%module member_funcptr_galore
%inline %{
namespace FunkSpace {
struct Funktions {
int addByValue(const int &a, int b) { return a+b; }
int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; }
int & addByReference(const int &a, int b) { static int val; val = a+b; return val; }
};
}
template <typename T> struct Thing {};
namespace Space {
class Shape {
public:
double x, y;
double *z;
void move(double dx, double dy);
virtual double area(Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int));
virtual double abc(Thing<short> ts, Thing< const Space::Shape * > tda[]);
};
}
extern double do_op(Space::Shape *s, double (Space::Shape::*m)(void));
/* Functions that return member pointers */
extern double (Space::Shape::*areapt())(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
extern double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * > tda[]);
/* Global variables that are member pointers */
extern double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
extern double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]);
%}
%{
void Space::Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
double do_op(Space::Shape *s, double (Space::Shape::*m)(void)) {
return (s->*m)();
}
double (Space::Shape::*areapt(Space::Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)))(Space::Shape &, int & (FunkSpace::Funktions::*d)(const int &, int)) {
return &Space::Shape::area;
}
double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * >[]) {
return &Space::Shape::abc;
}
/* Member pointer variables */
double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
%}
/* Some constants */
%constant double (Space::Shape::*AREAPT)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
%constant double (Space::Shape::*PERIMPT)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
%constant double (Space::Shape::*NULLPT)(void) = 0;
%inline %{
int call1(int (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
int call2(int * (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return *(f.*d)(a, b); }
int call3(int & (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
%}
%constant int (FunkSpace::Funktions::*ADD_BY_VALUE)(const int &, int) = &FunkSpace::Funktions::addByValue;
%constant int * (FunkSpace::Funktions::*ADD_BY_POINTER)(const int &, int) = &FunkSpace::Funktions::addByPointer;
%constant int & (FunkSpace::Funktions::*ADD_BY_REFERENCE)(const int &, int) = &FunkSpace::Funktions::addByReference;
%inline %{
// parameter that is a member pointer containing a function ptr, urgh :)
int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; }
int unreal2(double (Space::Shape::*memptr)(Thing<short>)) { return 0; }
%}

View file

@ -1,402 +0,0 @@
primitive_types
var_init();
# assigning globals calls
cvar.var_bool = sct_bool;
cvar.var_schar = sct_schar;
cvar.var_uchar = sct_uchar;
cvar.var_int = sct_int;
cvar.var_uint = sct_uint;
cvar.var_short = sct_short;
cvar.var_ushort = sct_ushort;
cvar.var_long = sct_long;
cvar.var_ulong = sct_ulong;
cvar.var_llong = sct_llong;
cvar.var_ullong = sct_ullong;
cvar.var_char = sct_char;
cvar.var_pchar = sct_pchar;
cvar.var_pcharc = sct_pcharc;
cvar.var_pint = sct_pint;
cvar.var_sizet = sct_sizet;
cvar.var_hello = sct_hello;
cvar.var_myint = sct_myint;
cvar.var_namet = def_namet;
cvar.var_parami = sct_parami;
cvar.var_paramd = sct_paramd;
cvar.var_paramc = sct_paramc;
v_check();
function octerror(name, val, cte)
name, val, cte
error
endfunction
if cvar.var_bool != cct_bool:
octerror("bool", cvar.var_bool, cct_bool)
endif
if cvar.var_schar != cct_schar:
octerror("schar", cvar.var_schar, cct_schar)
endif
if cvar.var_uchar != cct_uchar:
octerror("uchar", cvar.var_uchar, cct_uchar)
endif
if cvar.var_int != cct_int:
octerror("int", cvar.var_int, cct_int)
endif
if cvar.var_uint != cct_uint:
octerror("uint", cvar.var_uint, cct_uint)
endif
if cvar.var_short != cct_short:
octerror("short", cvar.var_short, cct_short)
endif
if cvar.var_ushort != cct_ushort:
octerror("ushort", cvar.var_ushort, cct_ushort)
endif
if cvar.var_long != cct_long:
octerror("long", cvar.var_long, cct_long)
endif
if cvar.var_ulong != cct_ulong:
octerror("ulong", cvar.var_ulong, cct_ulong)
endif
if cvar.var_llong != cct_llong:
octerror("llong", cvar.var_llong, cct_llong)
endif
if cvar.var_ullong != cct_ullong:
octerror("ullong", cvar.var_ullong, cct_ullong)
endif
if cvar.var_char != cct_char:
octerror("char", cvar.var_char, cct_char)
endif
if cvar.var_pchar != cct_pchar:
octerror("pchar", cvar.var_pchar, cct_pchar)
endif
if cvar.var_pcharc != cct_pcharc:
octerror("pchar", cvar.var_pcharc, cct_pcharc)
endif
if cvar.var_pint != cct_pint:
octerror("pint", cvar.var_pint, cct_pint)
endif
if cvar.var_sizet != cct_sizet:
octerror("sizet", cvar.var_sizet, cct_sizet)
endif
if cvar.var_hello != cct_hello:
octerror("hello", cvar.var_hello, cct_hello)
endif
if cvar.var_myint != cct_myint:
octerror("myint", cvar.var_myint, cct_myint)
endif
if cvar.var_namet != def_namet:
octerror("name", cvar.var_namet, def_namet)
endif
function OctTest()
self=subclass(TestDirector);
self.ident=@(self,x) x;
self.vval_bool=@(self, x) self.ident(x);
self.vval_schar=@(self, x) self.ident(x);
self.vval_uchar=@(self, x) self.ident(x);
self.vval_int=@(self, x) self.ident(x);
self.vval_uint=@(self, x) self.ident(x);
self.vval_short=@(self, x) self.ident(x);
self.vval_ushort=@(self, x) self.ident(x);
self.vval_long=@(self, x) self.ident(x);
self.vval_ulong=@(self, x) self.ident(x);
self.vval_llong=@(self, x) self.ident(x);
self.vval_ullong=@(self, x) self.ident(x);
self.vval_float=@(self, x) self.ident(x);
self.vval_double=@(self, x) self.ident(x);
self.vval_char=@(self, x) self.ident(x);
self.vval_pchar=@(self, x) self.ident(x);
self.vval_pcharc=@(self, x) self.ident(x);
self.vval_pint=@(self, x) self.ident(x);
self.vval_sizet=@(self, x) self.ident(x);
self.vval_hello=@(self, x) self.ident(x);
self.vval_myint=@(self, x) self.ident(x);
self.vref_bool=@(self, x) self.ident(x);
self.vref_schar=@(self, x) self.ident(x);
self.vref_uchar=@(self, x) self.ident(x);
self.vref_int=@(self, x) self.ident(x);
self.vref_uint=@(self, x) self.ident(x);
self.vref_short=@(self, x) self.ident(x);
self.vref_ushort=@(self, x) self.ident(x);
self.vref_long=@(self, x) self.ident(x);
self.vref_ulong=@(self, x) self.ident(x);
self.vref_llong=@(self, x) self.ident(x);
self.vref_ullong=@(self, x) self.ident(x);
self.vref_float=@(self, x) self.ident(x);
self.vref_double=@(self, x) self.ident(x);
self.vref_char=@(self, x) self.ident(x);
self.vref_pchar=@(self, x) self.ident(x);
self.vref_pcharc=@(self, x) self.ident(x);
self.vref_pint=@(self, x) self.ident(x);
self.vref_sizet=@(self, x) self.ident(x);
self.vref_hello=@(self, x) self.ident(x);
self.vref_myint=@(self, x) self.ident(x);
endfunction
t = Test();
p = OctTest();
# internal call check
if (t.c_check() != p.c_check())
error, "bad director"
endif
p.var_bool = p.stc_bool;
p.var_schar = p.stc_schar;
p.var_uchar = p.stc_uchar;
p.var_int = p.stc_int;
p.var_uint = p.stc_uint;
p.var_short = p.stc_short;
p.var_ushort = p.stc_ushort;
p.var_long = p.stc_long;
p.var_ulong = p.stc_ulong;
p.var_llong = p.stc_llong;
p.var_ullong = p.stc_ullong;
p.var_char = p.stc_char;
p.var_pchar = sct_pchar;
p.var_pcharc = sct_pcharc;
p.var_pint = sct_pint;
p.var_sizet = sct_sizet;
p.var_hello = sct_hello;
p.var_myint = sct_myint;
p.var_namet = def_namet;
p.var_parami = sct_parami;
p.var_paramd = sct_paramd;
p.var_paramc = sct_paramc;
p.v_check();
t.var_bool = t.stc_bool;
t.var_schar = t.stc_schar;
t.var_uchar = t.stc_uchar;
t.var_int = t.stc_int;
t.var_uint = t.stc_uint;
t.var_short = t.stc_short;
t.var_ushort = t.stc_ushort;
t.var_long = t.stc_long;
t.var_ulong = t.stc_ulong;
t.var_llong = t.stc_llong;
t.var_ullong = t.stc_ullong;
t.var_char = t.stc_char;
t.var_pchar = sct_pchar;
t.var_pcharc = sct_pcharc;
t.var_pint = sct_pint;
t.var_sizet = sct_sizet;
t.var_hello = sct_hello;
t.var_myint = sct_myint;
t.var_namet = def_namet;
t.var_parami = sct_parami;
t.var_paramd = sct_paramd;
t.var_paramc = sct_paramc;
t.v_check();
# this value contains a '0' char!
if (def_namet != 'ho\0la')
error
endif
t.var_namet = def_namet;
if (t.var_namet != def_namet)
error
endif
t.var_namet = 'holac';
if (t.var_namet != 'holac')
error
endif
t.var_namet = 'hol';
if (t.var_namet != 'hol')
error
endif
if (t.strlen('hile') != 4)
error
endif
if (t.strlen('hil\0') != 4)
error
endif
cvar.var_char = '\0';
if (cvar.var_char != '\0')
error
endif
cvar.var_char = 0;
if (cvar.var_char != '\0')
error
endif
cvar.var_namet = '\0';
if (cvar.var_namet != '')
error
endif
cvar.var_namet = '';
if (cvar.var_namet != '')
error, "bad char empty case"
endif
cvar.var_pchar = None;
if (cvar.var_pchar != None)
error, "bad None case"
endif
cvar.var_pchar = '';
if (cvar.var_pchar != '')
error
endif
cvar.var_pcharc = None;
if (cvar.var_pcharc != None)
error
endif
cvar.var_pcharc = '';
if (cvar.var_pcharc != '')
error
endif
#
# creating a raw char*
#
pc = new_pchar(5);
pchar_setitem(pc, 0, 'h');
pchar_setitem(pc, 1, 'o');
pchar_setitem(pc, 2, 'l');
pchar_setitem(pc, 3, 'a');
pchar_setitem(pc, 4, 0);
if (t.strlen(pc) != 4)
error
endif
cvar.var_pchar = pc;
if (cvar.var_pchar != "hola")
error
endif
cvar.var_namet = pc;
if (cvar.var_namet != "hola")
error
endif
delete_pchar(pc);
#
# Now when things should fail
#
try
error = 0;
a = t.var_uchar;
t.var_uchar = 10000;
err = 1;
catch
if (a != t.var_uchar)
err = 1;
endif
end_try_catch
if (err)
error
endif
try
err = 0;
a = t.var_char;
t.var_char = '23';
err = 1;
catch
if (a != t.var_char)
error = 1
endif
end_try_catch
if (err)
error
endif
try
err = 0
a = t.var_uint
t.var_uint = -1
err = 1;
catch
if a != t.var_uint:
err = 1;
endif
end_try_catch
if (err)
error
endif
#
#
try
err = 0;
a = t.var_namet;
t.var_namet = '123456';
err = 1;
catch
if (a != t.var_namet)
err = 1;
endif
end_try_catch
if (err)
error
endif
#
#
#
t2 = p.vtest(t);
if (t.var_namet != t2.var_namet)
error
endif
if (cvar.fixsize != 'ho\0la\0\0\0')
error
endif
cvar.fixsize = 'ho';
if (cvar.fixsize != 'ho\0\0\0\0\0\0')
error
endif
f = Foo(3);
f1 = fptr_val(f);
f2 = fptr_ref(f);
if (f1._a != f2._a)
error
endif
v = char_foo(1,3);
if (v !=3)
error
endif
s = char_foo(1,"hello");
if (s !="hello")
error
endif
v = SetPos(1,3);
if (v !=4)
error
endif

View file

@ -79,6 +79,12 @@ see bottom for a set of possible tests
%}
#endif
#ifdef SWIGD
// Due to the way operator overloading is implemented in D1 and D2, the prefix
// increment/decrement operators (D1) resp. the postfix ones (D2) are ignored.
%warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS, SWIGWARN_IGNORE_OPERATOR_MINUSMINUS);
#endif
%rename(IntCast) operator int();
%rename(DoubleCast) operator double();

View file

@ -1,6 +1,6 @@
%module operator_overload_break
#if defined(SWIGPYTHON)
#if defined(SWIGPYTHON) || defined(SWIGD)
%warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS);
#endif

View file

@ -0,0 +1,32 @@
use strict;
use warnings;
use Test::More tests => 7;
BEGIN { use_ok('char_binary') }
require_ok('char_binary');
my $t = char_binary::Test->new();
is($t->strlen('hile'), 4, "string typemap");
is($t->strlen("hil\0"), 4, "string typemap");
#
# creating a raw char*
#
my $pc = char_binary::new_pchar(5);
char_binary::pchar_setitem($pc, 0, 'h');
char_binary::pchar_setitem($pc, 1, 'o');
char_binary::pchar_setitem($pc, 2, 'l');
char_binary::pchar_setitem($pc, 3, 'a');
char_binary::pchar_setitem($pc, 4, 0);
is($t->strlen($pc), 4, "string typemap");
$char_binary::var_pchar = $pc;
is($char_binary::var_pchar, "hola", "pointer case");
$char_binary::var_namet = $pc;
is($char_binary::var_namet, "hola", "pointer case");
char_binary::delete_pchar($pc);

View file

@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 54;
use Test::More tests => 51;
BEGIN { use_ok('primitive_types') }
require_ok('primitive_types');
@ -179,11 +179,6 @@ $t->{var_namet} = 'hol';
is($t->{var_namet}, 'hol', "namet");
is($t->strlen('hile'), 4, "string typemap");
is($t->strlen("hil\0"), 4, "string typemap");
$primitive_types::var_char = "\0";
is($primitive_types::var_char, "\0", "char '0' case");
@ -220,8 +215,6 @@ primitive_types::pchar_setitem($pc, 3, 'a');
primitive_types::pchar_setitem($pc, 4, 0);
is($t->strlen($pc), 4, "string typemap");
$primitive_types::var_pchar = $pc;
is($primitive_types::var_pchar, "hola", "pointer case");

View file

@ -11,5 +11,8 @@ pointer_reference::set($ss);
$i = Struct::instance();
check::equal($i->value, 20, "pointer_reference::set() failed");
check::equal(pointer_reference::overloading(1), 111, "overload test 1 failed");
check::equal(pointer_reference::overloading($ss), 222, "overload test 2 failed");
check::done();
?>

View file

@ -35,6 +35,12 @@ void set(Struct *const& s) {
Struct *const& get() {
return Struct::pInstance;
}
int overloading(int i) {
return 111;
}
int overloading(Struct *const& s) {
return 222;
}
%}
%{

View file

@ -355,8 +355,6 @@ macro(size_t, pfx, sizet)
%enddef
%apply (char *STRING, int LENGTH) { (const char *str, size_t len) }
%inline {
struct Foo
{
@ -464,15 +462,8 @@ macro(size_t, pfx, sizet)
%test_prim_types_ovr(ovr_decl, ovr)
size_t strlen(const char *str, size_t len)
{
return len;
}
static const double stc_double;
static const double stc_float;
};
struct TestDirector

View file

@ -0,0 +1,36 @@
from char_binary import *
t = Test()
if t.strlen('hile') != 4:
print t.strlen('hile')
raise RuntimeError, "bad multi-arg typemap"
if t.strlen('hil\0') != 4:
raise RuntimeError, "bad multi-arg typemap"
#
# creating a raw char*
#
pc = new_pchar(5)
pchar_setitem(pc, 0, 'h')
pchar_setitem(pc, 1, 'o')
pchar_setitem(pc, 2, 'l')
pchar_setitem(pc, 3, 'a')
pchar_setitem(pc, 4, 0)
if t.strlen(pc) != 4:
raise RuntimeError, "bad multi-arg typemap"
cvar.var_pchar = pc
if cvar.var_pchar != "hola":
print cvar.var_pchar
raise RuntimeError, "bad pointer case"
cvar.var_namet = pc
#if cvar.var_namet != "hola\0":
if cvar.var_namet != "hola":
raise RuntimeError, "bad pointer case"
delete_pchar(pc)

View file

@ -0,0 +1,5 @@
from director_alternating import *
id = getBar().id()
if id != idFromGetBar():
raise RuntimeError, "Got wrong id: " + str(id)

View file

@ -0,0 +1,16 @@
import pointer_reference
s = pointer_reference.get()
if s.value != 10:
raise RuntimeError, "get test failed"
ss = pointer_reference.Struct(20)
pointer_reference.set(ss)
if pointer_reference.cvar.Struct_instance.value != 20:
raise RuntimeError, "set test failed"
if pointer_reference.overloading(1) != 111:
raise RuntimeError, "overload test 1 failed"
if pointer_reference.overloading(ss) != 222:
raise RuntimeError, "overload test 2 failed"

View file

@ -188,14 +188,6 @@ if t.var_namet != 'hol':
raise RuntimeError
if t.strlen('hile') != 4:
print t.strlen('hile')
raise RuntimeError, "bad string typemap"
if t.strlen('hil\0') != 4:
raise RuntimeError, "bad string typemap"
cvar.var_char = '\0'
if cvar.var_char != '\0':
raise RuntimeError, "bad char '0' case"
@ -244,9 +236,6 @@ pchar_setitem(pc, 3, 'a')
pchar_setitem(pc, 4, 0)
if t.strlen(pc) != 4:
raise RuntimeError, "bad string typemap"
cvar.var_pchar = pc
if cvar.var_pchar != "hola":
print cvar.var_pchar

View file

@ -0,0 +1,5 @@
from typemap_arrays import *
if sumA(None) != 60:
raise RuntimeError, "Sum is wrong"

View file

@ -15,19 +15,14 @@
%rename(foo_u) *::foo(unsigned);
/* Rename classes in a class hierarchy */
%rename (RenamedBase) Base;
%rename (RenamedDerived) Derived;
%rename (RenamedBase) Space::Base;
%rename (RenamedDerived) Space::Derived;
/* Rename base class method applies to derived classes too */#
%rename (newname) Base::oldname(double d) const;
%rename (newname) Space::Base::oldname(double d) const;
/* Rename derived class method only */
#ifndef SWIGGO
%rename (func) Derived::fn(Base baseValue, Base* basePtr, Base& baseRef);
#else
/* func is a keyword in Go. */
%rename (Xfunc) Derived::fn(Base baseValue, Base* basePtr, Base& baseRef);
#endif
%rename (Xfunc) Space::Derived::fn(Base baseValue, Base* basePtr, Base& baseRef);
%inline %{
class Bar {
@ -43,20 +38,22 @@ char *foo(double) { return (char *) "foo-double"; }
char *foo(short) { return (char *) "foo-short"; }
char *foo(unsigned) { return (char *) "foo-unsigned"; }
namespace Space {
class Base {
public:
Base(){};
virtual ~Base(){};
void fn(Base baseValue, Base* basePtr, Base& baseRef){}
virtual const char * oldname(double d) const { return (char*) "Base"; }
virtual const char * oldname(double d) const { return "Base"; }
};
class Derived : public Base {
public:
Derived(){}
~Derived(){}
void fn(Base baseValue, Base* basePtr, Base& baseRef){}
virtual const char * oldname(double d) const { return (char*) "Derived"; }
virtual const char * oldname(double d) const { return "Derived"; }
};
}
%}

0
Examples/test-suite/threads_exception.i Executable file → Normal file
View file

View file

@ -0,0 +1,30 @@
%module typemap_arrays
// Test that previously non-working array typemaps special variables are working
%typemap(in) SWIGTYPE[ANY] {
_should_not_be_used_and_will_not_compile_
}
// Check $basemangle expands to _p_int and $basetype expands to int *
%typemap(in) int *nums[3] (int *temp[3]) {
$basetype var1$basemangle = new int(10);
$basetype var2$basemangle = new int(20);
$basetype var3$basemangle = new int(30);
temp[0] = var1_p_int;
temp[1] = var2_p_int;
temp[2] = var3_p_int;
$1 = temp;
}
%inline %{
int sumA(int *nums[3]) {
int sum = 0;
for (int i=0; i<3; ++i) {
int *p = nums[i];
if (p)
sum += *p;
}
return sum;
}
%}

View file

@ -3,14 +3,23 @@
%inline %{
class Foo {
protected:
int x;
int blah(int xx) { return xx; }
int x;
int blah(int xx) { return xx; }
virtual int vmethod(int xx) { return xx; }
};
class FooBar : public Foo {
public:
using Foo::blah;
using Foo::x;
using Foo::blah;
using Foo::x;
using Foo::vmethod;
};
class FooBaz : public Foo {
protected:
using Foo::blah;
using Foo::x;
using Foo::vmethod;
};
%}

View file

@ -5,12 +5,14 @@
%warnfilter(SWIGWARN_PARSE_KEYWORD) clone; // 'clone' is a php keyword, renamed as 'c_clone'
%warnfilter(SWIGWARN_PARSE_KEYWORD) delegate; // 'delegate' is a C# keyword, renaming to '_delegate'
%warnfilter(SWIGWARN_PARSE_KEYWORD) pass; // 'pass' is a python keyword, renaming to '_pass'
%warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a ruby keyword, renaming to 'C_alias'
%warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a D keyword, renaming to '_alias'
%warnfilter(SWIGWARN_PARSE_KEYWORD) rescue; // 'rescue' is a ruby keyword, renaming to 'C_rescue'
%inline %{
const char * clone() { return "clone"; }
const char * delegate() { return "delegate"; }
const char * pass() { return "pass"; }
const char * alias() { return "alias"; }
const char * rescue() { return "rescue"; }
%}