Merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@13053 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Vincent Couvert 2012-05-09 14:28:04 +00:00
commit 7444913fda
59 changed files with 955 additions and 692 deletions

View file

@ -1142,20 +1142,21 @@ R_CFLAGS=-fPIC
# need to compile .cxx files outside of R build system to make sure that
# we get -fPIC
# CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command
r: $(SRCS)
$(SWIG) -r $(SWIGOPT) $(INTERFACEPATH)
ifneq ($(SRCS),)
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) )
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null )
r_cpp: $(CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
ifneq ($(CXXSRCS),)
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) )
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )
r_clean:
rm -f *_wrap* *~ .~*

View file

@ -277,6 +277,7 @@ CPP_TEST_CASES += \
operbool \
ordering \
overload_copy \
overload_method \
overload_extend \
overload_rename \
overload_return_type \
@ -466,7 +467,6 @@ CPP_STD_TEST_CASES += \
director_string \
ignore_template_constructor \
li_std_combinations \
li_std_containers_int \
li_std_deque \
li_std_except \
li_std_map \

View file

@ -29,12 +29,12 @@ public:
void delCallback() { delete _callback; _callback = 0; }
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
int call() {
int sum = 0;
if (_callback) {
char* aa = (char*)malloc(BUFFER_SIZE_AA);
memset(aa, 9, BUFFER_SIZE_AA);
char* bb = (char*)malloc(BUFFER_SIZE_BB);
memset(bb, 13, BUFFER_SIZE_BB);
int sum = 0;
_callback->run(aa, BUFFER_SIZE_AA, bb, BUFFER_SIZE_BB);
for (int i = 0; i < BUFFER_SIZE_AA; i++)
sum += aa[i];
@ -42,8 +42,8 @@ public:
sum += bb[i];
free(aa);
free(bb);
return sum;
}
return sum;
}
};

View file

@ -36,8 +36,13 @@ namespace Bar
%include <std_string.i>
// nspace feature only supported by these languages
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
%nspace Bar::Foo;
%nspace Bar::FooBar;
#else
#warning nspace feature not yet supported in this target language
#endif
%feature("director") Bar::Foo;

View file

@ -42,6 +42,12 @@
_a = disown;
return 5;
}
int remove(A *remove)
{
delete remove;
return 5;
}
};
}

View file

@ -45,6 +45,11 @@ public class java_lib_various_runme {
if ( !langs[i].equals(newLangs[i]) )
throw new RuntimeException("Languages verify failed " + i + " " + langs[i] + "|" + newLangs[i]);
// STRING_ARRAY null
java_lib_various.setLanguages(null);
if (java_lib_various.getLanguages() != null)
throw new RuntimeException("languages should be null");
// STRING_RET test
{
String stringOutArray[] = { "" };

View file

@ -12,3 +12,9 @@ for x=0,100 do
b:acquire(a)
end
collectgarbage() -- this will double delete unless the memory is managed properly
a=disown.A()
a:__disown()
b:remove(a)
a=nil
collectgarbage() -- this will double delete unless the manual disown call worked

View file

@ -0,0 +1,16 @@
require("import") -- the import fn
import("li_factory") -- import code
-- moving to global
for k,v in pairs(li_factory) do _G[k]=v end
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
circle = Geometry_create(Geometry_CIRCLE)
r = circle:radius()
assert(r == 1.5)
point = Geometry_create(Geometry_POINT)
w = point:width()
assert(w == 1.0)

View file

@ -103,5 +103,7 @@ struct GlobalClass {
void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {}
%}
#else
#warning nspace feature not yet supported in this target language
#endif

View file

@ -49,5 +49,7 @@ namespace Outer {
const Outer::Inner2::Color& col2c) {}
}
#else
#warning nspace feature not yet supported in this target language
#endif

View file

@ -127,7 +127,7 @@ public:
class Baz5 {
public:
Array<octave_idx_type> __dims__() const {
Array<octave_idx_type> c(2,1);
Array<octave_idx_type> c(dim_vector(2,1));
c(0) = 3;
c(1) = 4;
return c;
@ -137,7 +137,7 @@ public:
class Baz6 {
public:
Array<octave_idx_type> __dims__() const {
Array<octave_idx_type> c(1,2);
Array<octave_idx_type> c(dim_vector(1,2));
c(0) = 3;
c(1) = 4;
return c;

View file

@ -1,5 +1,11 @@
%module operator_pointer_ref
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4996) // 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
#endif
%}
%rename(AsCharStarRef) operator char*&;
%inline %{

View file

@ -0,0 +1,20 @@
/* This test confirms the fix to sourceforge bug #3478922 for R */
%module overload_method
%inline %{
class Base
{
public:
Base() : x(42) {}
int method() const { return x; }
void overloaded_method(int aArg) { x = aArg; }
int overloaded_method() const { return x; }
private:
int x;
};
%}

View file

@ -1,99 +1,74 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 631;
use Test::More tests => 415;
BEGIN { use_ok('li_typemaps') }
require_ok('li_typemaps');
my @tests = qw(
in inr
out outr
inout inoutr
);
sub should_pass { my($type, @values) = @_;
# verify that each value passes cleanly
for my $test (@tests) {
my $name = "${test}_${type}";
my $func = li_typemaps->can($name);
for my $val (@values) {
my $rv = eval { $func->($val) };
is($rv, $val, "$name $val");
sub batch { my($type, @values) = @_;
# this is a little ugly because I'm trying to be clever and save my
# wrists from hammering out all these tests.
for my $val (@values) {
for my $tst (qw(
in inr
out outr
inout inoutr
)) {
my $func = $tst . '_' . $type;
is(eval { li_typemaps->can($func)->($val) }, $val, "$func $val");
if($@) {
my $err = $@;
$err =~ s/^/#\$\@# /mg;
print $err;
}
}
}
}
sub should_fail { my($type, @values) = @_;
# verify that all values trigger runtime errors
for my $test (@tests) {
my $name = "${test}_${type}";
my $func = li_typemaps->can($name);
for my $val (@values) {
my $rv = eval { $func->($val) };
like($@, qr/\b(?:Overflow|Type)Error\b/, "overflow $name $val");
}
}
}
batch('bool', '', 1);
# let's assume we're at least on a 32 bit machine
batch('int', -0x80000000, -1, 0, 1, 12, 0x7fffffff);
# long could be bigger, but it's at least this big
batch('long', -0x80000000, -1, 0, 1, 12, 0x7fffffff);
batch('short', -0x8000, -1, 0, 1, 12, 0x7fff);
batch('uint', 0, 1, 12, 0xffffffff);
batch('ushort', 0, 1, 12, 0xffff);
batch('ulong', 0, 1, 12, 0xffffffff);
batch('uchar', 0, 1, 12, 0xff);
batch('schar', -0x80, 0, 1, 12, 0x7f);
sub pad { my($t, $s, $f) = @_;
my $nbytes = length pack $t, 0;
return unpack $t, $s . ($f x ($nbytes - 1));
{
use Math::BigInt qw();
# the pack dance is to get plain old NVs out of the
# Math::BigInt objects.
my $inf = unpack 'd', pack 'd', Math::BigInt->binf();
my $nan = unpack 'd', pack 'd', Math::BigInt->bnan();
batch('float',
-(2 - 2 ** -23) * 2 ** 127,
-1, -2 ** -149, 0, 2 ** -149, 1,
(2 - 2 ** -23) * 2 ** 127,
$nan);
{ local $TODO = "float typemaps don't pass infinity";
# it seems as though SWIG is unwilling to pass infinity around
# because that value always fails bounds checking. I think that
# is a bug.
batch('float', $inf);
}
batch('double',
-(2 - 2 ** -53) ** 1023,
-1, -2 ** -1074, 0, 2 ** 1074,
(2 - 2 ** -53) ** 1023,
$nan, $inf);
}
# some edge case values:
my $nan = unpack 'f>', "\x7f\xc0\x00\x00";
my $inf = unpack 'f>', "\x7f\x80\x00\x00";
my $char_min = pad 'c', "\x80";
my $char_max = pad 'c', "\x7f";
my $char_umax = pad 'C', "\xff";
my $short_min = pad 's!>', "\x80", "\x00";
my $short_max = pad 's!>', "\x7f", "\xff";
my $short_umax = pad 'S!>', "\xff", "\xff";
my $int_min = pad 'i!>', "\x80", "\x00";
my $int_max = pad 'i!>', "\x7f", "\xff";
my $int_umax = pad 'I!>', "\xff", "\xff";
my $long_min = pad 'l!>', "\x80", "\x00";
my $long_max = pad 'l!>', "\x7f", "\xff";
my $long_umax = pad 'L!>', "\xff", "\xff";
should_pass('bool', '', 1);
should_pass('int', $int_min, -1, 0, 1, 12, $int_max);
should_fail('int', $int_min - 1000, $int_max + 1000, $inf, $nan);
should_pass('long', $long_min, -1, 0, 1, 12, $long_max);
should_fail('long', $long_min - 8000, $long_max + 8000, $inf, $nan);
should_pass('short', $short_min, -1, 0, 1, 12, $short_max);
should_fail('short', $short_min - 1, $short_max + 1, $inf, $nan);
should_pass('uint', 0, 1, 12, $int_umax);
should_fail('uint', -1, $int_umax + 1000, $inf, $nan);
should_pass('ushort', 0, 1, 12, $short_umax);
should_fail('ushort', -1, $short_umax + 1, $inf, $nan);
should_pass('ulong', 0, 1, 12, $long_umax);
should_fail('ulong', -1, $long_umax + 8000, $inf, $nan);
should_pass('uchar', 0, 1, 12, $char_umax);
should_fail('uchar', -1, $char_umax + 1, $inf, $nan);
should_pass('schar', $char_min, -1, 0, 1, 12, $char_max);
should_fail('schar', $char_min - 1, $char_max + 1, $inf, $nan);
should_pass('float', -1, 0, 1, $nan);
TODO: {
local $TODO = "typemaps don't allow float infinity";
should_pass('float', -$inf, $inf);
}
should_pass('double', -$inf, -1, 0, 1, $inf, $nan);
should_pass('longlong', -1, 0, 1, 12);
should_fail('longlong', $inf, $nan);
should_pass('ulonglong', 0, 1, 12);
should_fail('ulonglong', -1, $inf, $nan);
batch('longlong', -1, 0, 1, 12);
batch('ulonglong', 0, 1, 12);
SKIP: {
my $llong_min = eval { pad 'q>', "\x80", "\x00" };
my $llong_max = eval { pad 'q>', "\x7f", "\xff" };
my $llong_umax = eval { pad 'Q>', "\xff", "\xff" };
skip 'not a 64 bit perl', 6 * 6 unless defined $llong_min;
should_pass('longlong', $llong_min, $llong_max);
should_fail('longlong', $llong_min - 8000, $llong_max + 8000);
should_pass('ulonglong', $llong_umax);
should_fail('ulonglong', $llong_umax + 8000);
my $a = "8000000000000000";
my $b = "7fffffffffffffff";
my $c = "ffffffffffffffff";
skip "not a 64bit Perl", 18 unless eval { pack 'q', 1 };
batch('longlong', -hex($a), hex($b));
batch('ulonglong', hex($c));
}
my($foo, $int) = li_typemaps::out_foo(10);
@ -104,3 +79,4 @@ is($int, 20);
my($a, $b) = li_typemaps::inoutr_int2(13, 31);
is($a, 13);
is($b, 31);

View file

@ -46,6 +46,7 @@ CPP_TEST_CASES += \
li_cwstring \
li_factory \
li_implicit \
li_std_containers_int \
li_std_map_member \
li_std_multimap \
li_std_pair_extra \

View file

@ -2,7 +2,7 @@ from autodoc import *
def check(got, expected):
if expected != got:
raise RuntimeError("\n" + "Expected: [" + expected + "]\n" + "Got : [" + got + "]")
raise RuntimeError("\n" + "Expected: [" + str(expected) + "]\n" + "Got : [" + str(got) + "]")
check(A.__doc__, "Proxy of C++ A class")
check(A.funk.__doc__, "just a string")

View file

@ -8,8 +8,9 @@ if d.bar() != 2:
raise RuntimeError
if bar_getter(b) != 1:
raise RuntimeError
if bar_getter(d) != 2:
raise RuntimeError
# Fix reverted in rev 12953
#if bar_getter(d) != 2:
# raise RuntimeError
b = BaseDefaultInt()
d = DerivedDefaultInt()
@ -22,7 +23,8 @@ if d2.bar2() != 4:
raise RuntimeError
if bar2_getter(b) != 3:
raise RuntimeError
if bar2_getter(d) != 4:
raise RuntimeError
if bar2_getter(d2) != 4:
raise RuntimeError
# Fix reverted in rev 12953
#if bar2_getter(d) != 4:
# raise RuntimeError
#if bar2_getter(d2) != 4:
# raise RuntimeError

View file

@ -26,7 +26,7 @@ except threads_exception.Exc,e:
if e.code != 42:
raise RuntimeError
if e.msg != "Hosed":
raise RuntimeError
raise RuntimeError, "bad... msg: %s" % e.msg
for i in range(1,4):
try:

View file

@ -10,8 +10,13 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
C_TEST_CASES = r_copy_struct r_legacy
CPP_TEST_CASES = r_double_delete r_overload_array
C_TEST_CASES += \
r_copy_struct \
r_legacy
CPP_TEST_CASES += \
r_double_delete \
r_overload_array
include $(srcdir)/../common.mk

View file

@ -0,0 +1,13 @@
source("unittest.R")
dyn.load(paste("overload_method", .Platform$dynlib.ext, sep=""))
source("overload_method.R")
cacheMetaData(1)
b <- Base()
Base_method(b)
Base_overloaded_method(b)
Base_overloaded_method(b, 43)
Base_overloaded_method(b)
b$method()
b$overloaded_method()

View file

@ -97,7 +97,7 @@
RCPtr<A> _a;
};
class B* global_create(A* a)
struct B* global_create(A* a)
{
return new B(a);
}

View file

@ -5,6 +5,12 @@
%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'NewName' due to Go name ('NewName') conflict with 'Name' */
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4996) // 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.
#endif
%}
%ignore Name::operator=;
%inline %{

View file

@ -21,16 +21,16 @@ namespace Space {
C method(C c, D d, E e) { return c; }
// Use typedef with classname qualifiers
Bar(bool, Bar::C c, Bar::D d, Bar::E e) {}
Bar::C method_1(Bar::C c, Bar::D d, Bar::E e) { return c; }
Bar(bool, typename Bar::C c, typename Bar::D d, typename Bar::E e) {}
typename Bar::C method_1(typename Bar::C c, typename Bar::D d, typename Bar::E e) { return c; }
// Use typedef with classname and full template parameter qualifiers
Bar(bool, bool, Bar<CC, DD, EE>::C c, Bar<CC, DD, EE>::D d, Bar<CC, DD, EE>::E e) {}
Bar<CC, DD, EE>::C method_2(Bar<CC, DD, EE>::C c, Bar<CC, DD, EE>::D d, Bar<CC, DD, EE>::E e) { return c; }
Bar(bool, bool, typename Bar<CC, DD, EE>::C c, typename Bar<CC, DD, EE>::D d, typename Bar<CC, DD, EE>::E e) {}
typename Bar<CC, DD, EE>::C method_2(typename Bar<CC, DD, EE>::C c, typename Bar<CC, DD, EE>::D d, typename Bar<CC, DD, EE>::E e) { return c; }
// Use typedef with namespace and classname and full template parameter qualifiers
Bar(bool, bool, bool, Space::Bar<CC, DD, EE>::C c, Space::Bar<CC, DD, EE>::D d, Space::Bar<CC, DD, EE>::E e) {}
Space::Bar<CC, DD, EE>::C method_3(Space::Bar<CC, DD, EE>::C c, Space::Bar<CC, DD, EE>::D d, Space::Bar<CC, DD, EE>::E e) { return c; }
Bar(bool, bool, bool, typename Space::Bar<CC, DD, EE>::C c, typename Space::Bar<CC, DD, EE>::D d, typename Space::Bar<CC, DD, EE>::E e) {}
typename Space::Bar<CC, DD, EE>::C method_3(typename Space::Bar<CC, DD, EE>::C c, typename Space::Bar<CC, DD, EE>::D d, typename Space::Bar<CC, DD, EE>::E e) { return c; }
};
template<typename TT = SomeType> class Foo {
public:
@ -43,15 +43,15 @@ namespace Space {
// Use typedef with classname qualifiers
Foo(const T &, T t) {}
Foo::T method_A(Foo::T t) { return t; }
typename Foo::T method_A(typename Foo::T t) { return t; }
// Use typedef with classname and full template parameter qualifiers
Foo(const Foo<TT>::T &, const Foo<TT>::T &, Foo<TT>::T t) {}
Foo<TT>::T method_B(Foo<TT>::T t) { return t; }
Foo(const typename Foo<TT>::T &, const typename Foo<TT>::T &, typename Foo<TT>::T t) {}
typename Foo<TT>::T method_B(typename Foo<TT>::T t) { return t; }
// Use typedef with namespace and classname and full template parameter qualifiers
Foo(const Foo<TT>::T &, const Foo<TT>::T &, const Foo<TT>::T &, Foo<TT>::T t) {}
Foo<TT>::T method_C(Foo<TT>::T t) { return t; }
Foo(const typename Foo<TT>::T &, const typename Foo<TT>::T &, const typename Foo<TT>::T &, typename Foo<TT>::T t) {}
typename Foo<TT>::T method_C(typename Foo<TT>::T t) { return t; }
};
template<typename T = int> class ATemplate {};

View file

@ -24,8 +24,8 @@ template<class Key, class T> class Multimap {
class const_iterator {};
// test usage of a typedef of a nested class in a template
Standard::Pair<iterator,iterator> equal_range_1(const key_type& kt1) {}
Standard::Pair<const_iterator,const_iterator> equal_range_2(const key_type& kt2) const {}
Standard::Pair<iterator,iterator> equal_range_1(const key_type& kt1) { return Standard::Pair<iterator,iterator>(); }
Standard::Pair<const_iterator,const_iterator> equal_range_2(const key_type& kt2) const { return Standard::Pair<const_iterator,const_iterator>(); }
};
}
%}

View file

@ -3,6 +3,7 @@
%typemap(in) Integer1
{
$1 = 0;
/* do nothing */
}
@ -13,6 +14,7 @@
%typemap(in) Integer2
{
$1 = 0;
/* do nothing */
}

View file

@ -45,10 +45,18 @@ B_t make_b() {
%inline %{
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _Foo {
enum { NONAME1, NONAME2 } enumvar;
int foovar;
void (*fptr)(int);
} Foo;
#ifdef __cplusplus
}
#endif
%}

View file

@ -58,17 +58,17 @@ void foo2(Foo<short> f, const Foo<short>& ff) {}
// Test obscure bug where named typemaps where not being applied when symbol name contained a number
%typemap(out) double "_typemap_for_double_no_compile_"
%typemap(out) double ABC::meth "$1 = 0.0;"
%typemap(out) double ABC::m1 "$1 = 0.0;"
%typemap(out) double ABC::_x2 "$1 = 0.0;"
%typemap(out) double ABC::y_ "$1 = 0.0;"
%typemap(out) double ABC::_3 "$1 = 0.0;"
%typemap(out) double ABCD::meth "$1 = 0.0;"
%typemap(out) double ABCD::m1 "$1 = 0.0;"
%typemap(out) double ABCD::_x2 "$1 = 0.0;"
%typemap(out) double ABCD::y_ "$1 = 0.0;"
%typemap(out) double ABCD::_3 "$1 = 0.0;"
%inline %{
struct ABC {
double meth() {}
double m1() {}
double _x2() {}
double y_() {}
double _3() {}
struct ABCD {
double meth() { return 0.0; }
double m1() { return 0.0; }
double _x2() { return 0.0; }
double y_() { return 0.0; }
double _3() { return 0.0; }
};
%}