merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11627 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2009-08-17 16:29:31 +00:00
commit b6b2fce6ae
103 changed files with 893 additions and 786 deletions

View file

@ -1,16 +1,18 @@
# see top-level Makefile.in
# (see also top-level configure.in kludge)
callback
class
constants
cpointer
disown
enum
extend
funcptr
overloading
pointer
pragmas
reference
proxy
reference
simple
sync
value

View file

@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS =
SWIGOPT = -noproxy
SWIGOPT =
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \

View file

@ -1,22 +1,20 @@
<?php
# This file illustrates the low-level C++ interface
# created by SWIG. In this case, all of our C++ classes
# get converted into function calls.
# This example illustrates how member variables are wrapped.
require("example.php");
# ----- Object creation -----
print "Creating some objects:\n";
$c = new_Circle(10);
print " Created circle $c\n";
$s = new_Square(10);
print " Created square $s\n";
$c = new Circle(10);
print " Created circle\n";
$s = new Square(10);
print " Created square\n";
# ----- Access a static member -----
print "\nA total of " . nshapes() . " shapes were created\n";
print "\nA total of " . Shape::get_nshapes() . " shapes were created\n";
# ----- Member data access -----
@ -24,14 +22,14 @@ print "\nA total of " . nshapes() . " shapes were created\n";
# Note: methods in the base class Shape are used since
# x and y are defined there.
Shape_x_set($c, 20);
Shape_y_set($c, 30);
Shape_x_set($s,-10);
Shape_y_set($s,5);
$c->x = 20;
$c->y = 30;
$s->x = -10;
$s->y = 5;
print "\nHere is their current position:\n";
print " Circle = (" . Shape_x_get($c) . "," . Shape_y_get($c) . ")\n";
print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
print " Circle = ({$c->x},{$c->y})\n";
print " Square = ({$s->x},{$s->y})\n";
# ----- Call some methods -----
@ -39,18 +37,16 @@ print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
# invoke the appropriate virtual method on each object.
print "\nHere are some properties of the shapes:\n";
foreach (array($c,$s) as $o) {
print " $o\n";
print " area = " . Shape_area($o) . "\n";
print " perimeter = " . Shape_perimeter($o) . "\n";
}
print " ". get_class($o) . "\n";
print " area = {$o->area()}\n";
print " perimeter = {$o->perimeter()}\n";
}
# ----- Delete everything -----
print "\nGuess I'll clean up now\n";
# Note: this invokes the virtual destructor
#delete_Shape($c);
#delete_Shape($s);
$c = NULL;
$s = NULL;
@ -58,7 +54,7 @@ $s = NULL;
# the square.
$o = NULL;
print nshapes() . " shapes remain\n";
print Shape::get_nshapes() . " shapes remain\n";
print "Goodbye\n";
?>

View file

@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS =
SWIGOPT = -noproxy
SWIGOPT =
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \

View file

@ -17,7 +17,7 @@ Vector operator+(const Vector &a, const Vector &b) {
return r;
}
char *Vector::print() {
char *Vector::as_string() {
static char temp[512];
sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
return temp;
@ -47,4 +47,3 @@ int VectorArray::size() {
printf("VectorArray: size %d self=%p\n",maxsize,this);
return maxsize;
}

View file

@ -7,7 +7,7 @@ public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
char *as_string();
};
class VectorArray {

View file

@ -1,6 +1,10 @@
/* File : example.i */
/* This file has a few "typical" uses of C++ references. */
/* This example has nothing to do with references but the name is used by all
* the other languages so it's hard to rename to something more meaningful.
*
* Mostly it shows how to use %extend.
*/
%module example
@ -12,7 +16,7 @@ class Vector {
public:
Vector(double x, double y, double z);
~Vector();
char *print();
char *as_string();
};
/* This helper function calls an overloaded operator */
@ -41,4 +45,3 @@ public:
}
}
};

View file

@ -1,18 +1,17 @@
<?php
# This file illustrates the manipulation of C++ references in Php.
# This uses the low-level interface. Proxy classes work differently.
# This file illustrates the manipulation of C++ references in PHP.
require "example.php";
# ----- Object creation -----
print "Creating some objects:\n";
$a = new_Vector(3,4,5);
$b = new_Vector(10,11,12);
$a = new Vector(3, 4, 5);
$b = new Vector(10, 11, 12);
print " Created a: $a " . Vector_print($a) . "\n";
print " Created b: $b " . Vector_print($b) . "\n";
print " Created a: {$a->as_string()}\n";
print " Created b: {$b->as_string()}\n";
# ----- Call an overloaded operator -----
@ -23,56 +22,28 @@ print " Created b: $b " . Vector_print($b) . "\n";
# It returns a new allocated object.
print "Adding a+b\n";
$c = addv($a,$b);
print " a+b =". Vector_print($c)."\n";
# Note: Unless we free the result, a memory leak will occur
$c = None;
$c = example::addv($a, $b);
print " a+b ={$c->as_string()}\n";
# ----- Create a vector array -----
# Note: Using the high-level interface here
print "Creating an array of vectors\n";
$va = new_VectorArray(10);
$va = new VectorArray(10);
print " va: $va size=".VectorArray_size($va)."\n";
print " va: size={$va->size()}\n";
# ----- Set some values in the array -----
# These operators copy the value of $a and $b to the vector array
VectorArray_set($va,0,$a);
VectorArray_set($va,1,$b);
VectorArray_get($va,0);
# This will work, but it will cause a memory leak!
VectorArray_set($va,2,addv($a,$b));
# The non-leaky way to do it
$c = addv($a,$b);
VectorArray_set($va,3,$c);
$c = None;
$va->set(0, $a);
$va->set(1, $b);
$va->set(2, addv($a, $b));
# Get some values from the array
print "Getting some array values\n";
for ($i = 0; $i < 5; $i++) {
print "do $i\n";
print " va($i) = ". Vector_print(VectorArray_get($va,$i)). "\n";
print " va[$i] = {$va->get($i)->as_string()}\n";
}
# Watch under resource meter to check on this
#print "Making sure we don't leak memory.\n";
#for ($i = 0; $i < 1000000; $i++) {
# $c = VectorArray_get($va,$i % 10);
#}
# ----- Clean up -----
print "Cleaning up\n";
# wants fixing FIXME
$va = None;
$a = None;
$b = None;
?>

View file

@ -0,0 +1,33 @@
%module catches
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
%}
%include <exception.i> // for throws(...) typemap
%catches(int, const char *, const ThreeException&) test_catches(int i);
%catches(int, ...) test_exception_specification(int i); // override the exception specification
%catches(...) test_catches_all(int i);
%inline %{
struct ThreeException {};
void test_catches(int i) {
if (i == 1) {
throw int(1);
} else if (i == 2) {
throw (const char *)"two";
} else if (i == 3) {
throw ThreeException();
}
}
void test_exception_specification(int i) throw(int, const char *, const ThreeException&) {
test_catches(i);
}
void test_catches_all(int i) {
test_catches(i);
}
%}

View file

@ -149,6 +149,18 @@ const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG;
%inline %{
// char *& tests
char *&GetCharPointerRef() {
static char str[] = CPLUSPLUS_MSG;
static char *ptr = str;
return ptr;
}
bool SetCharPointerRef(char *&str, unsigned int number) {
static char static_str[] = CPLUSPLUS_MSG;
strcpy(static_str, str);
return check(static_str, number);
}
const char *&GetConstCharPointerRef() {
static const char str[] = CPLUSPLUS_MSG;
static const char *ptr = str;

View file

@ -117,6 +117,7 @@ CPP_TEST_CASES += \
arrays_scope \
bloody_hell \
bools \
catches \
cast_operator \
casts \
char_strings \

View file

@ -0,0 +1,66 @@
using System;
using catchesNamespace;
public class runme {
static void Main() {
// test_catches()
try {
catches.test_catches(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ int exception thrown, value: 1")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_catches(2);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "two")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_catches(3);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ ThreeException const & exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
// test_exception_specification()
try {
catches.test_exception_specification(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ int exception thrown, value: 1")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_exception_specification(2);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "unknown exception")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
catches.test_exception_specification(3);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "unknown exception")
throw new ApplicationException("bad exception order: " + e.Message);
}
// test_catches_all()
try {
catches.test_catches_all(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "unknown exception")
throw new ApplicationException("bad exception order: " + e.Message);
}
}
}

View file

@ -120,15 +120,26 @@ public class char_strings_runme {
// char *& tests
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
String str = char_strings.GetCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
if (!char_strings.SetCharPointerRef(OTHERLAND_MSG + i, i))
throw new Exception("Test char pointer ref set failed, iteration " + i);
}
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
if (str != CPLUSPLUS_MSG)
throw new Exception("Test const char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
throw new Exception("Test const char pointer ref set failed, iteration " + i);
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using exception_orderNamespace;
public class runme {
static void Main() {
A a = new A();
try {
a.foo();
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E1 exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.bar();
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E2 exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.foobar();
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "postcatch unknown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.barfoo(1);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E1 exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
try {
a.barfoo(2);
throw new Exception("missed exception");
} catch (ApplicationException e) {
if (e.Message != "C++ E2 * exception thrown")
throw new ApplicationException("bad exception order: " + e.Message);
}
}
}

View file

@ -7,8 +7,8 @@ public class runme
{
int f = overload_template.foo();
f += overload_template.max(3,4);
double b = overload_template.max(3.4,5.2);
f += overload_template.maximum(3,4);
double b = overload_template.maximum(3.4,5.2);
b++; // warning suppression
// mix 1

View file

@ -32,8 +32,14 @@ bar3(foo3 x) {}
enum sad { boo, hoo = 5 };
#ifdef __cplusplus /* For Octave and g++ which compiles C test code as C++ */
extern "C" {
#endif
/* Unnamed enum instance */
enum { globalinstance1, globalinstance2, globalinstance3 = 30 } GlobalInstance;
#ifdef __cplusplus
}
#endif
/* Anonymous enum */
enum { AnonEnum1, AnonEnum2 = 100 };

View file

@ -127,15 +127,26 @@ public class char_strings_runme {
// char *& tests
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
String str = char_strings.GetCharPointerRef();
if (!str.equals(CPLUSPLUS_MSG))
throw new RuntimeException("Test char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
if (!char_strings.SetCharPointerRef(OTHERLAND_MSG + i, i))
throw new RuntimeException("Test char pointer ref set failed, iteration " + i);
}
for (i=0; i<count; i++) {
String str = char_strings.GetConstCharPointerRef();
if (!str.equals(CPLUSPLUS_MSG))
throw new RuntimeException("Test const char pointer ref get failed, iteration " + i);
}
for (i=0; i<count; i++) {
if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
throw new RuntimeException("Test const char pointer ref set failed, iteration " + i);
}
}
}

View file

@ -40,6 +40,16 @@ public class java_throws_runme {
if (!pass)
throw new RuntimeException("Test 2 failed");
// Check the exception class is used with %catches
pass = false;
try {
java_throws.catches_function(100);
}
catch (IllegalAccessException e) { pass = true; }
if (!pass)
throw new RuntimeException("Test 3 failed");
// Check newfree typemap throws attribute
try {
TestClass tc = java_throws.makeTestClass();

View file

@ -16,8 +16,8 @@ public class overload_template_runme {
public static void main(String argv[]) {
int f = overload_template.foo();
int a = overload_template.max(3,4);
double b = overload_template.max(3.4,5.2);
int a = overload_template.maximum(3,4);
double b = overload_template.maximum(3.4,5.2);
// mix 1
if (overload_template.mix1("hi") != 101)

View file

@ -32,6 +32,13 @@ public class template_methods_runme {
k.KlassTMethodBool();
b = Klass.KlassStaticTMethodBoolRenamed(true);
Klass.KlassStaticTMethodBool();
//
ComponentProperties cp = new ComponentProperties();
cp.adda("key1", "val1", "key2", 22.2);
cp.adda("key1", "val1", "key2", "val2", "key3", "val3");
cp.adda("key1", 1, "key2", 2, "key3", 3);
}
}

View file

@ -42,12 +42,16 @@ short full_of_exceptions(int num) {
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
void throw_spec_function(int value) throw (int) { throw (int)0; }
bool throw_spec_function(int value) throw (int) { throw (int)0; }
#if defined(_MSC_VER)
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
%}
%catches(int) catches_function(int value);
%inline %{
bool catches_function(int value) { throw (int)0; }
%}
// Check newfree typemap throws attribute
%newobject makeTestClass;

View file

@ -30,13 +30,13 @@ code is not functioning properly it will fail to compile.
%typemap(in) Animal ()
{
void *space_needed = malloc(HEIGHT_$1_lextype * WIDTH_$1_lextype);
$1 = space_needed;
$1 = ($1_ltype)space_needed;
}
%typemap(in) Animal[2] ()
{
void *space_needed = malloc(2 * HEIGHT_$1_lextype * WIDTH_$1_lextype);
$1 = space_needed;
$1 = ($1_ltype)space_needed;
}
%inline %{

View file

@ -1,2 +1,7 @@
%module li_math
#ifdef SWIGPHP
// PHP already provides these functions with the same names, so just kill that
// warning.
%warnfilter(SWIGWARN_PARSE_KEYWORD);
#endif
%include math.i

View file

@ -2,12 +2,12 @@ require("import") -- the import fn
import("overload_template") -- import code
for k,v in pairs(overload_template) 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,57 +0,0 @@
director_exception
MyFoo=@() subclass(Foo(),
'ping',@(self) raise(NotImplementedError("MyFoo::ping() EXCEPTION")));
MyFoo2=@() subclass(Foo(),
'ping',@(self) true);
ok = 0;
a = MyFoo();
b = launder(a);
try
b.pong();
catch
[etype,e]=raised();
if (etype=="NotImplementedError")
ok=1;
endif
end_try_catch
if (!ok)
error
endif
ok = 0;
a = MyFoo2();
b = launder(a);
try
b.pong();
catch
ok = 1;
end_try_catch
if (!ok)
error
endif
try
raise(Exception2());
catch
if (!strcmp(raised,"Exception2"))
rethrow(lasterr);
endif
end_try_catch
try
raise(Exception1());
catch
if (!strcmp(raised,"Exception1"))
rethrow(lasterr);
endif
end_try_catch

View file

@ -1,56 +0,0 @@
director_finalizer
MyFoo=@() subclass(Foo(),'__del__',@delete_MyFoo);
function delete_MyFoo(self)
self.orStatus(2);
try
Foo.__del__(self);
catch
end_try_catch
endfunction
resetStatus();
a = MyFoo();
clear a;
if (getStatus() != 3)
error
endif
resetStatus();
a = MyFoo();
launder(a);
if (getStatus() != 0)
error
endif
clear a;
if (getStatus() != 3)
error
endif
resetStatus();
a = MyFoo().__disown__();
deleteFoo(a);
if (getStatus() != 3)
error
endif
resetStatus();
a = MyFoo().__disown__();
deleteFoo(launder(a));
if (getStatus() != 3)
error
endif
resetStatus();

View file

@ -1,17 +1,2 @@
empty
printf("begin\n");
who global
printf("after load\n");
who global
#clear -g
printf("after clear\n");
who global
#clear empty
printf("after clear specific\n");
who global
printf("before shutdown\n");

View file

@ -6,40 +6,39 @@ a = A();
try
a.foo()
catch
if (!strcmp(raised(),"E1"))
error, "bad exception order"
if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E1\n"))
error("bad exception order")
endif
end_try_catch
try
a.bar()
catch
if (!strcmp(raised(),"E2"))
error, "bad exception order"
if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E2\n"))
error("bad exception order")
endif
end_try_catch
try
a.foobar()
catch
[t,e]=raised();
if (!strcmp(e.args(0),"postcatch unknown"))
error
if (!strcmp(lasterror.message, "error: postcatch unknown (SWIG_RuntimeError)\n"))
error("bad exception order")
endif
end_try_catch
try
a.barfoo(1)
catch
if (!strcmp(raised(),"E1"))
error, "bad exception order"
if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E1\n"))
error("bad exception order")
endif
end_try_catch
try
a.barfoo(2)
catch
if (!strcmp(raised(),"E2"))
error, "bad exception order"
if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E2 *\n"))
error("bad exception order")
endif
end_try_catch

View file

@ -1,7 +1,7 @@
# This is the import runtime testcase.
imports_b
imports_a
imports_b;
imports_a;
x = imports_b.B();
x.hello();

View file

@ -1,160 +1,11 @@
li_std_vector
iv = IntVector(4);
for i=0:4,
for i=0:3,
iv(i) = i;
endfor
x = average(iv);
y = average([1,2,3,4]);
a = half([10,10.5,11,11.5]);
dv = DoubleVector(10);
for i=0:10,
dv(i) = i/2.0;
endfor
halve_in_place(dv);
bv = BoolVector(4);
bv(0)= 1;
bv(1)= 0;
bv(2)= 4;
bv(3)= 0;
if (bv(0) != bv(2))
error("bad std::vector<bool> mapping")
if (x != 1.5)
error("average failed");
endif
b = B(5);
va = VecA([b,None,b,b]);
if (va(0).f(1) != 6)
error("bad std::vector<A*> mapping")
endif
if (vecAptr(va) != 6)
error("bad std::vector<A*> mapping")
endif
b.val = 7;
if (va(3).f(1) != 8)
error("bad std::vector<A*> mapping")
endif
ip = PtrInt();
ap = new_ArrInt(10);
ArrInt_setitem(ip,0,123);
ArrInt_setitem(ap,2,123);
vi = IntPtrVector((ip,ap,None));
if (ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2))
error("bad std::vector<int*> mapping")
endif
delete_ArrInt(ap);
a = halfs([10,8,4,3]);
v = IntVector();
v(0:2) = [1,2];
if (v(0) != 1 || v[1] != 2)
error("bad setslice")
endif
if (v(0:-1)(0) != 1)
error("bad getslice")
endif
if (v(0:-2).size() != 0)
error("bad getslice")
v(0:1) = [2];
if (v(0) != 2)
error("bad setslice")
endif
v(1:) = [3];
if (v(1) != 3)
error("bad setslice")
endif
v(2:) = [3]
if (v(2) != 3)
error("bad setslice")
endif
if (v(0:)(0) != v(0))
error("bad getslice")
endif
v.erase(:)
if (v.size() != 0)
error("bad getslice")
endif
v.erase(:)
if (v.size() != 0)
error("bad getslice")
endif
v = vecStr({"hello ", "world"});
if (v(0) != 'hello world')
error,"bad std::string+std::vector"
endif
pv = pyvector({1, "hello", (1,2)});
if (pv(1) != "hello")
error
endif
iv = IntVector(5);
for i=0:5,
iv(i) = i
endif
iv(1:3) = [];
if (iv(1) != 3)
error
endif
# Overloading checks
if (overloaded1(iv) != "vector<int>")
error
endif
if (overloaded1(dv) != "vector<double>")
error
endif
if (overloaded2(iv) != "vector<int>")
error
endif
if (overloaded2(dv) != "vector<double>")
error
endif
if (overloaded3(iv) != "vector<int> *")
error
endif
if (overloaded3(None) != "vector<int> *")
error
endif
if (overloaded3(100) != "int")
error
endif

View file

@ -1,5 +1,5 @@
multi_import_a
multi_import_b
multi_import_a;
multi_import_b;
x = multi_import_b.XXX();
if (x.testx() != 0)

View file

@ -1,8 +1,8 @@
overload_template
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

@ -3,7 +3,7 @@
#ifdef SWIGLUA
// lua only has one numeric type, so most of the overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) foo;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) max;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) maximum;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) specialization;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) overload;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) space::nsoverload;
@ -11,12 +11,6 @@
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) barT;
#endif
%{
#ifdef max
#undef max
#endif
%}
%inline %{
int foo() {
@ -29,15 +23,15 @@ template <class T>
}
template<class T>
T max(T a, T b) { return (a > b) ? a : b; }
T maximum(T a, T b) { return (a > b) ? a : b; }
%}
%template(foo) foo<int>;
%template(foo) foo<double>;
%template(max) max<int>;
%template(max) max<double>;
%template(maximum) maximum<int>;
%template(maximum) maximum<double>;
// Mix template overloading with plain function overload
// Mix 1

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "add_link.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "arrayptr.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "arrays_global.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "arrays_global_twodim.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "arrays.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "arrays_scope.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "casts.php";

View file

@ -0,0 +1,43 @@
<?php
require "tests.php";
require "char_strings.php";
$CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
$OTHERLAND_MSG_10 = "Little message from the safe world.10";
check::equal(GetCharHeapString(), $CPLUSPLUS_MSG, "failed GetCharHeapString");
check::equal(GetConstCharProgramCodeString(), $CPLUSPLUS_MSG, "failed GetConstCharProgramCodeString");
check::equal(GetCharStaticString(), $CPLUSPLUS_MSG, "failed GetCharStaticString");
check::equal(GetCharStaticStringFixed(), $CPLUSPLUS_MSG, "failed GetCharStaticStringFixed");
check::equal(GetConstCharStaticStringFixed(), $CPLUSPLUS_MSG, "failed GetConstCharStaticStringFixed");
check::equal(SetCharHeapString($OTHERLAND_MSG_10, 10), true, "failed GetConstCharStaticStringFixed");
check::equal(SetCharStaticString($OTHERLAND_MSG_10, 10), true, "failed SetCharStaticString");
check::equal(SetCharArrayStaticString($OTHERLAND_MSG_10, 10), true, "failed SetCharArrayStaticString");
check::equal(SetConstCharHeapString($OTHERLAND_MSG_10, 10), true, "failed SetConstCharHeapString");
check::equal(SetConstCharStaticString($OTHERLAND_MSG_10, 10), true, "failed SetConstCharStaticString");
check::equal(SetConstCharArrayStaticString($OTHERLAND_MSG_10, 10), true, "failed SetConstCharArrayStaticString");
check::equal(CharPingPong($OTHERLAND_MSG_10), $OTHERLAND_MSG_10, "failed CharPingPong");
Global_char_set($OTHERLAND_MSG_10);
check::equal(Global_char_get(), $OTHERLAND_MSG_10, "failed Global_char_get");
Global_char_array1_set($OTHERLAND_MSG_10);
check::equal(Global_char_array1_get(), $OTHERLAND_MSG_10, "failed Global_char_array1_get");
Global_char_array2_set($OTHERLAND_MSG_10);
check::equal(Global_char_array2_get(), $OTHERLAND_MSG_10, "failed Global_char_array2_get");
check::equal(Global_const_char_get(), $CPLUSPLUS_MSG, "failed Global_const_char");
check::equal(Global_const_char_array1_get(), $CPLUSPLUS_MSG, "failed Global_const_char_array1");
check::equal(Global_const_char_array2_get(), $CPLUSPLUS_MSG, "failed Global_const_char_array2");
check::equal(GetCharPointerRef(), $CPLUSPLUS_MSG, "failed GetCharPointerRef");
check::equal(SetCharPointerRef($OTHERLAND_MSG_10, 10), true, "failed SetCharPointerRef");
check::equal(GetConstCharPointerRef(), $CPLUSPLUS_MSG, "failed GetConstCharPointerRef");
check::equal(SetConstCharPointerRef($OTHERLAND_MSG_10, 10), true, "failed SetConstCharPointerRef");
check::done();
?>

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "class_ignore.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "conversion_namespace.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "conversion.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "cpp_static.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "director_nested.php";

View file

@ -4,7 +4,7 @@ require "tests.php";
require "director_string.php";
// No new functions
check::functions(array(a_get_first,a_call_get_first,a_string_length,a_process_text,a_call_process_func,stringvector_size,stringvector_is_empty,stringvector_clear,stringvector_push,stringvector_pop));
check::functions(array(a_get_first,a_call_get_first,a_string_length,a_process_text,a_call_process_func,stringvector_size,stringvector_is_empty,stringvector_clear,stringvector_push,stringvector_pop,stringvector_capacity,stringvector_reserve));
// No new classes
check::classes(array(A,StringVector));
// now new vars

View file

@ -1,14 +1,12 @@
<?php
// Sample test file
require "tests.php";
require "enum_scope_template.php";
check::classes(array("enum_scope_template", "TreeInt"));
check::functions("chops");
check::equal(0,TreeInt_Oak,"0==TreeInt_Oak");
check::equal(1,TreeInt_Fir,"0==TreeInt_Fir");
check::equal(2,TreeInt_Cedar,"0==TreeInt_Cedar");
check::equal(1,TreeInt_Fir,"1==TreeInt_Fir");
check::equal(2,TreeInt_Cedar,"2==TreeInt_Cedar");
check::equal(TreeInt_Oak,chops(TreeInt_Oak),"TreeInt_Oak==chops(TreeInt_Oak)");
check::equal(TreeInt_Fir,chops(TreeInt_Fir),"TreeInt_Fir==chops(TreeInt_Fir)");
check::equal(TreeInt_Cedar,chops(TreeInt_Cedar),"TreeInt_Cedar==chops(TreeInt_Cedar)");

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "evil_diamond_ns.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "evil_diamond_prop.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "evil_diamond.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "extend_template_ns.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "extend_template.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "grouping.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "ignore_parameter.php";

View file

@ -1,14 +1,15 @@
<?php
// Sample test file
require "tests.php";
require "li_carrays.php";
// No new functions
// Check functions.
check::functions(array(new_intarray,delete_intarray,intarray_getitem,intarray_setitem));
// No new classes
check::classes(array(doubleArray));
// now new vars
// 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());
$d = new doubleArray(10);

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "li_std_string.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "newobject1.php";

View file

@ -0,0 +1,15 @@
<?php
require "tests.php";
require "pointer_reference.php";
$s = pointer_reference::get();
check::equal($s->value, 10, "pointer_reference::get() failed");
$ss = new Struct(20);
pointer_reference::set($ss);
$i = Struct::instance();
check::equal($i->value, 20, "pointer_reference::set() failed");
check::done();
?>

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "prefix.php";

View file

@ -0,0 +1,25 @@
<?php
require "tests.php";
require "primitive_ref.php";
check::equal(ref_over(3), 3, "ref_over failed");
check::equal(ref_int(3), 3, "ref_int failed");
check::equal(ref_uint(3), 3, "ref_uint failed");
check::equal(ref_short(3), 3, "ref_short failed");
check::equal(ref_ushort(3), 3, "ref_ushort failed");
check::equal(ref_long(3), 3, "ref_long failed");
check::equal(ref_ulong(3), 3, "ref_ulong failed");
check::equal(ref_schar(3), 3, "ref_schar failed");
check::equal(ref_uchar(3), 3, "ref_uchar failed");
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::done();
?>

View file

@ -1,15 +1,14 @@
<?php
// Sample test file
require "tests.php";
require "rename_scope.php";
check::classes(array("rename_scope","Interface_UP","Interface_BP","Natural_UP","Natural_BP","Bucket"));
check::classmethods("Interface_UP",array("__construct"));
check::classmethods("Interface_BP",array("__construct"));
check::classmethods("Natural_UP",array("__construct","rtest"));
check::classmethods("Natural_BP",array("__construct","rtest"));
check::classmethods("Interface_UP",array("__construct","__set","__isset","__get"));
check::classmethods("Interface_BP",array("__construct","__set","__isset","__get"));
check::classmethods("Natural_UP",array("__construct","__set","__isset","__get","rtest"));
check::classmethods("Natural_BP",array("__construct","__set","__isset","__get","rtest"));
check::classparent("Natural_UP","Interface_UP");
check::classparent("Natural_BP","Interface_BP");

View file

@ -1,12 +1,11 @@
<?php
// Sample test file
require "tests.php";
require "smart_pointer_rename.php";
check::classes(array("Foo","Bar"));
check::classmethods("foo",array("foo","ftest1","ftest2"));
check::classmethods("bar",array("__deref__","bar","test","ftest1","ftest2"));
check::classmethods("foo",array("ftest1","ftest2","__set","__isset","__get","__construct"));
check::classmethods("bar",array("__deref__","test","ftest1","ftest2","__set","__isset","__get","__construct"));
$foo=new foo();
check::classname("foo",$foo);
$bar=new bar($foo);

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "sym.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "template_arg_typename.php";

View file

@ -1,5 +1,4 @@
<?php
// Sample test file
require "tests.php";
require "valuewrapper_base.php";
@ -7,7 +6,7 @@ require "valuewrapper_base.php";
check::classes(array("valuewrapper_base","Base","Interface_BP"));
check::functions("make_interface_bp");
$ibp=make_interface_bp();
$ibp=valuewrapper_base::make_interface_bp();
check::classname("interface_bp",$ibp);
check::done();

View file

@ -1,20 +1,23 @@
%module php_namewarn_rename
#ifdef SWIGPHP
%warnfilter(SWIGWARN_PARSE_KEYWORD) Empty();
// FIXME: this doesn't work for me:
%warnfilter(SWIGWARN_PARSE_KEYWORD) stdClass;
%warnfilter(SWIGWARN_PARSE_KEYWORD) Hello::empty();
#endif
%inline %{
void Empty() {};
void Empty() {}
class stdClass
class stdClass
{
};
struct Hello
struct Hello
{
void empty() {}
void empty() {}
};
%}

View file

@ -139,13 +139,13 @@ endif
# Clean: remove the generated .py file
%.clean:
@rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
@rm -f $*.py;
@#We only remove the _runme3.py if it is generated by 2to3 from a _runme.py.
@if [ -f $(py2_runme) ]; then rm -f $(py3_runme) $(py3_runme).bak; fi
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile python_clean
rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py
cvsignore:
@echo '*wrap* *.pyc *.so *.dll *.exp *.lib'
@ -168,3 +168,4 @@ hugemod:
$(MAKE) hugemod_b.cpptest
sh -c "time $(PYTHON) $(hugemod_runme)"
sh -c "time $(PYTHON) $(hugemod_runme)"

View file

@ -1,8 +1,8 @@
from overload_template 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

@ -7,7 +7,7 @@
enum Polarization { UnaryPolarization, BinaryPolarization };
template <Polarization P>
struct Interface
struct Interface_
{
};
}
@ -15,9 +15,9 @@
namespace oss
{
// Interface
%template(Interface_UP) Interface<UnaryPolarization>;
%template(Interface_BP) Interface<BinaryPolarization>;
// Interface_
%template(Interface_UP) Interface_<UnaryPolarization>;
%template(Interface_BP) Interface_<BinaryPolarization>;
}
%inline
@ -27,7 +27,7 @@ namespace oss
namespace interfaces
{
template <Polarization P>
struct Natural : Interface<P>
struct Natural : Interface_<P>
{
int test(void) { return 1; }
};

View file

@ -98,6 +98,13 @@ sv[1] = Li_std_vector::Struct.new
EOF
bv = BoolVector.new(2)
[true, false, true, true].each { |i| bv.push(i) }
0.upto(bv.size-1) { |i| bv[i] = !bv[i] }
bv_check = [true, true, false, true, false, false]
for i in 0..bv.size-1 do
swig_assert(bv_check[i] == bv[i], binding, "bv[#{i}]")
end
swig_assert_each_line(<<'EOF', binding)
lv = LanguageVector.new

View file

@ -13,5 +13,5 @@ require 'overload_template'
f = Overload_template.foo()
a = Overload_template.max(3,4)
b = Overload_template.max(3.4,5.2)
a = Overload_template.maximum(3,4)
b = Overload_template.maximum(3.4,5.2)

View file

@ -12,14 +12,14 @@
enum Polarization { UnaryPolarization, BinaryPolarization };
template <Polarization P>
struct Interface
struct Interface_
{
};
namespace modules
{
template <class traits, class base = Interface<traits::pmode> >
template <class traits, class base = Interface_<traits::pmode> >
// *** problem here ****
struct Module : base
{
@ -35,7 +35,7 @@
namespace oss
{
%template(Interface_UP) Interface<UnaryPolarization>;
%template(Interface_UP) Interface_<UnaryPolarization>;
namespace modules
{
%template(Module_etraits) Module<etraits>;

View file

@ -6,7 +6,7 @@
enum Polarization { UnaryPolarization, BinaryPolarization };
template <Polarization P>
struct Interface
struct Interface_
{
};
@ -21,8 +21,8 @@
namespace oss
{
%template(Interface_UP) Interface<UnaryPolarization>;
%template(Module_UPIUP) Module<UnaryPolarization,Interface<UnaryPolarization> >;
%template(Interface_UP) Interface_<UnaryPolarization>;
%template(Module_UPIUP) Module<UnaryPolarization,Interface_<UnaryPolarization> >;
}
%inline %{
@ -31,18 +31,18 @@ namespace oss
namespace hello
{
struct HInterface1 :
Interface<oss::UnaryPolarization> // this works (with fullns qualification)
Interface_<oss::UnaryPolarization> // this works (with fullns qualification)
{
};
struct HInterface2 :
Interface<UnaryPolarization> // this doesn't work
Interface_<UnaryPolarization> // this doesn't work
{
};
struct HModule1 : Module<UnaryPolarization, Interface<UnaryPolarization> > {
struct HModule1 : Module<UnaryPolarization, Interface_<UnaryPolarization> > {
};
}
}
%}
%}

View file

@ -9,7 +9,7 @@
enum Polarization { UnaryPolarization, BinaryPolarization };
template <Polarization P>
struct Interface
struct Interface_
{
};
@ -25,7 +25,7 @@
typedef Traits traits;
static const Polarization P = traits::pmode;
void get(Interface<P> arg) { }; // Here P is only replace by traits::pmode
void get(Interface_<P> arg) { }; // Here P is only replace by traits::pmode
};
}
@ -34,6 +34,6 @@
namespace oss
{
%template(Interface_UP) Interface<UnaryPolarization>;
%template(Interface_UP) Interface_<UnaryPolarization>;
%template(Module_UP) Module<etraits>;
}

View file

@ -5,6 +5,8 @@
%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve1<float>();
%warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve3<float>();
%include <std_string.i>
///////////////////
%ignore convolve1<float>(float a);
@ -76,3 +78,23 @@ struct Klass {
%template(KlassTMethodBool) Klass::tmethod<bool>;
%template(KlassStaticTMethodBool) Klass::statictmethod<bool>;
////////////////////////////////////////////////////////////////////////////
%inline %{
class ComponentProperties{
public:
ComponentProperties() {}
~ComponentProperties() {}
template <typename T1> void adda(std::string key, T1 val) {}
template <typename T1, typename T2> void adda(std::string key1, T1 val1, std::string key2, T2 val2) {}
template <typename T1, typename T2, typename T3> void adda(std::string key1, T1 val1, std::string key2, T2 val2, std::string key3, T3 val3) {}
};
%}
%extend ComponentProperties {
%template(adda) adda<std::string, double>;
%template(adda) adda<std::string, std::string, std::string>; // ERROR OCCURS HERE
%template(adda) adda<int, int, int>;
}

View file

@ -8,13 +8,13 @@
};
template <class ArgType, class ResType>
struct Function
struct Function_
{
char *test() { return (char *) "test"; }
};
template <class AF, class RF>
struct ArithFunction : Function<AF, RF>
struct ArithFunction : Function_<AF, RF>
{
};
@ -40,7 +40,7 @@
};
template <class AF, class RF>
class Class : public ArithFunction< typename traits<AF, RF>::arg_type,
class Class_ : public ArithFunction< typename traits<AF, RF>::arg_type,
typename traits<AF, RF>::res_type >
{
};
@ -49,7 +49,7 @@
typename traits<AF, RF>::base
make_Class()
{
return Class<AF, RF>();
return Class_<AF, RF>();
}
@ -58,9 +58,9 @@
%{
namespace hello {
template struct Function <Double, Double>;
template struct Function_ <Double, Double>;
template struct ArithFunction <Double, Double>;
template class Class <Double, Double>;
template class Class_ <Double, Double>;
}
%}
@ -69,9 +69,9 @@
// This complains only when using a namespace
//
%template() traits<Double,Double>;
%template(Function_DD) Function <Double, Double>;
%template(Function_DD) Function_ <Double, Double>;
%template(ArithFunction_DD) ArithFunction <Double, Double>;
%template(Class_DD) Class <Double, Double>;
%template(Class_DD) Class_ <Double, Double>;
%template(make_Class_DD) make_Class <Double, Double>;
}

View file

@ -10,9 +10,9 @@
};
template <Polarization P>
struct Interface : Base
struct Interface_ : Base
{
Interface(const Base& b) { };
Interface_(const Base& b) { };
};
template <class Result>
@ -23,6 +23,6 @@
namespace oss
{
// Interface
%template(Interface_BP) Interface<BinaryPolarization>;
%template(make_Interface_BP) make<Interface<BinaryPolarization> >;
%template(Interface_BP) Interface_<BinaryPolarization>;
%template(make_Interface_BP) make<Interface_<BinaryPolarization> >;
}