Merge trunk (up to just after swig 2.0.5 release - rev 13009) to gsoc2008-cherylfoil

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@13017 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-04-27 18:55:37 +00:00
commit af1c6ac3c3
1811 changed files with 94580 additions and 35569 deletions

View file

@ -10,21 +10,24 @@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES = \
keywords \
kwargs_feature \
li_cdata \
li_cstring \
li_factory \
li_std_functors \
li_std_map \
li_std_multimap \
li_std_pair_lang_object \
li_std_queue \
li_std_set \
li_std_stack \
naming \
primitive_types \
std_containers \
track_objects \
track_objects_directors
ruby_keywords \
ruby_naming \
ruby_track_objects \
ruby_track_objects_directors \
std_containers
# ruby_li_std_speed
# stl_new
C_TEST_CASES += \
li_cdata \
@ -35,12 +38,10 @@ include $(srcdir)/../common.mk
# Overridden variables here
SWIGOPT += -w801 -noautorename -features autodoc=4
# Custom tests - tests with additional commandline options
ruby_naming.cpptest: SWIGOPT += -autorename
# Rules for the different types of tests
# make sure -autorename is true for the naming test
naming.cpptest: SWIGOPT = -autorename
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
@ -59,9 +60,9 @@ naming.cpptest: SWIGOPT = -autorename
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.rb appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
fi;
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) $(RUBY) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); \
fi
# Clean
%.clean:

View file

@ -1,65 +0,0 @@
%module keywords
// fix up conflicts with C++ keywords
%rename("and") Keywords::and_;
%rename("break") Keywords::break_;
%rename("case") Keywords::case_;
%rename("class") Keywords::class_;
%rename("defined?") Keywords::defined_;
%rename("do") Keywords::do_;
%rename("else") Keywords::else_;
%rename("false") Keywords::false_;
%rename("for") Keywords::for_;
%rename("if") Keywords::if_;
%rename("not") Keywords::not_;
%rename("return") Keywords::return_;
%rename("or") Keywords::or_;
%rename("true") Keywords::true_;
%rename("while") Keywords::while_;
%inline %{
class Keywords {
public:
Keywords() {}
const char* alias() { return "alias"; }
const char* and_() { return "and"; }
const char* begin() { return "begin"; }
const char* break_() { return "break"; }
const char* case_() { return "case"; }
const char* class_() { return "class"; }
const char* def() { return "def"; }
const char* defined_() { return "defined?"; }
const char* do_() { return "do"; }
const char* else_() { return "else"; }
const char* elsif() { return "elsif"; }
const char* end() { return "end"; }
const char* ensure() { return "ensure"; }
const char* false_() { return "false"; }
const char* for_() { return "for"; }
const char* if_() { return "if"; }
const char* in() { return "in"; }
const char* module() { return "module"; }
const char* next() { return "next"; }
const char* nil() { return "nil"; }
const char* not_() { return "not"; }
const char* or_() { return "or"; }
const char* redo() { return "redo"; }
const char* rescue() { return "rescue"; }
const char* retry() { return "retry"; }
const char* return_() { return "return"; }
const char* self() { return "self"; }
const char* super() { return "super"; }
const char* then() { return "then"; }
const char* true_() { return "true"; }
const char* undef() { return "undef"; }
const char* under() { return "under"; }
const char* unless() { return "unless"; }
const char* until() { return "until"; }
const char* when() { return "when"; }
const char* while_() { return "while"; }
const char* yield() { return "yield"; }
};
%}

View file

@ -1,18 +0,0 @@
%module li_std_functors
%include <std_vector.i>
%include <std_deque.i>
%include <std_list.i>
%include <std_set.i>
%include <std_map.i>
%include <std_functors.i>
%template(Vector ) std::vector <swig::LANGUAGE_OBJ>;
%template(Deque ) std::deque <swig::LANGUAGE_OBJ>;
%template(List ) std::list <swig::LANGUAGE_OBJ>;
%template(Set ) std::set <swig::LANGUAGE_OBJ,
swig::BinaryPredicate<> >;
%template(Map ) std::map <swig::LANGUAGE_OBJ,swig::LANGUAGE_OBJ,
swig::BinaryPredicate<> >;

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
#
# Tests for std::map and std::multimap
# Tests for std::map
#
#
#
@ -41,18 +41,9 @@ m["foo"] = "hello"
pm = Li_std_map::LanguageMap.new
m.each_key { |k| pm[k] = m[k] }
m.each_key { |k| swig_assert_equal("pm[#{k.inspect}]", "m[#{k.inspect}]", binding) }
m = Li_std_map::MmapA.new
m[0] = a1
m[0] = a2
m[0].size == 2
m.respond_to?(:each) == true
m.respond_to?(:each_key) == true
m.respond_to?(:each_value) == true
m.values_at(0)[0] == m[0]
EOF
mii = Li_std_map::Mapii.new
mii = Li_std_map::IntIntMap.new
mii[1] = 1
mii[1] = 2

View file

@ -0,0 +1,27 @@
#!/usr/bin/env ruby
#
# Tests for std::multimap
#
#
#
#
#
require 'swig_assert'
require 'li_std_multimap'
swig_assert_each_line(<<'EOF', binding)
a1 = Li_std_multimap::A.new(3)
a2 = Li_std_multimap::A.new(7)
m = Li_std_multimap::MultimapA.new
m[0] = a1
m[0] = a2
m[0].size == 2
m.respond_to?(:each) == true
m.respond_to?(:each_key) == true
m.respond_to?(:each_value) == true
m.values_at(0)[0] == m[0]
EOF

View file

@ -1,8 +0,0 @@
%module li_std_pair_lang_object
%include <std_pair.i>
namespace std {
%template(ValuePair) pair< swig::LANGUAGE_OBJ, swig::LANGUAGE_OBJ >;
}

View file

@ -1,16 +0,0 @@
/**
* @file std_queue.i
* @author gga
* @date Sun May 6 01:52:44 2007
*
* @brief test of std::queue
*
*
*/
%module li_std_queue
%include std_queue.i
%template( IntQueue ) std::queue< int >;

View file

@ -1,26 +0,0 @@
/**
* @file li_std_speed.i
* @author gga
* @date Fri May 18 18:03:15 2007
*
* @brief A speed test of the ruby stl
*
*
*/
%module li_std_speed
%include <std_list.i>
%include <std_vector.i>
%include <std_deque.i>
%include <std_set.i>
%template(RbList) std::list<swig::GC_VALUE>;
%template(RbVector) std::vector<swig::GC_VALUE>;
%template(RbDeque) std::deque<swig::GC_VALUE>;
%template(RbSet) std::set<swig::GC_VALUE>;
%template(RbFloatList) std::list<float>;
%template(RbFloatVector) std::vector<float>;
%template(RbFloatDeque) std::deque<float>;
%template(RbFloatSet) std::set<float>;

View file

@ -1,16 +0,0 @@
/**
* @file std_stack.i
* @author gga
* @date Sun May 6 01:52:44 2007
*
* @brief test of std::stack
*
*
*/
%module li_std_stack
%include std_stack.i
%template( IntStack ) std::stack< int >;

View file

@ -0,0 +1,25 @@
#!/usr/bin/env ruby
require 'swig_assert'
require 'li_std_vector_enum'
include Li_std_vector_enum
ev = EnumVector.new()
swig_assert(ev.nums[0] == 10)
swig_assert(ev.nums[1] == 20)
swig_assert(ev.nums[2] == 30)
it = ev.nums.begin
v = it.value()
swig_assert(v == 10)
it.next()
v = it.value()
swig_assert(v == 20)
expected = 10
ev.nums.each do|val|
swig_assert(val == expected)
expected += 10
end

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

@ -1,107 +0,0 @@
%module naming
%predicate predicateMethod();
%bang bangMethod();
/* This gets mapped to a constant */
%constant int constant1 = 1;
/* This gets mapped to a constant */
#define constant2 2
%immutable TestConstants::constant8;
%inline %{
/* ============ Test Constants Names ============== */
/* This gets mapped to a constant */
#define constant3 3
/* These are all singleton methods */
const int constant4[2] = {10, 20};
const int constant5 = 5;
static const int constant6 = 6;
class TestConstants {
public:
TestConstants() : constant7(7) {}
/* This gets mapped to a method */
const int constant7;
/* This gets mapped to a singleton method, but this is not legal C++ */
static const int constant8;
/* This gets mapped to a method, but this it not legal C++ */
/*const int constant9 = 9;*/
/* This gets mapped to a constant */
static const int constant10 = 10;
};
const int TestConstants::constant8 = 8;
const TestConstants * constant11[5];
/* ============ Test Enum ============== */
typedef enum {Red, Green, Blue} Colors;
/* ============ Test Method Names ============== */
class my_class {
public:
int methodOne()
{
return 1;
}
int MethodTwo()
{
return 2;
}
int Method_THREE()
{
return 3;
}
int Method44_4()
{
return 4;
}
bool predicateMethod()
{
return true;
}
bool bangMethod()
{
return true;
}
int begin()
{
return 1;
}
int end()
{
return 1;
}
};
%}
%inline
{
template <class _Type>
struct A
{
};
}
%template(A_i) A<int>;

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

@ -50,6 +50,9 @@ end
raise RuntimeError if fail != 1
# Test a number which won't fit in a 32 bit integer and is represented
# as a FIXNUM by Ruby.
raise RuntimeError if val_double(51767811298) != 51767811298
raise RuntimeError if val_double_2(1.0) != 4.0
raise RuntimeError if val_double_2(1) != 4

View file

@ -9,9 +9,9 @@
require 'swig_assert'
require 'keywords'
require 'ruby_keywords'
kw = Keywords::Keywords.new
kw = Ruby_keywords::Keywords.new
if kw.alias != 'alias' then
raise RuntimeError, 'Keyword method did not work: alias'

View file

@ -10,8 +10,8 @@
require 'benchmark'
require 'mathn'
require 'li_std_speed'
include Li_std_speed
require 'ruby_li_std_speed'
include Ruby_li_std_speed
def benchmark(f, phigh, sequences)

View file

@ -9,86 +9,86 @@
require 'swig_assert'
require 'naming'
require 'ruby_naming'
# Check class names
if not Naming
raise RuntimeError, 'Invalid module name for Naming'
if not Ruby_naming
raise RuntimeError, 'Invalid module name for Ruby_naming'
end
if not Naming::MyClass
if not Ruby_naming::MyClass
raise RuntimeError, 'Invalid class name for MyClass'
end
# Check constant names / values
if Naming::CONSTANT1 != 1
if Ruby_naming::CONSTANT1 != 1
raise RuntimeError, "Incorrect value for CONSTANT1"
end
if Naming::CONSTANT2 != 2
if Ruby_naming::CONSTANT2 != 2
raise RuntimeError, "Incorrect value for CONSTANT2"
end
# Check constant names / values
if Naming::CONSTANT3 != 3
if Ruby_naming::CONSTANT3 != 3
raise RuntimeError, "Incorrect value for CONSTANT3"
end
if not Naming::methods.include?("constant4")
if not Ruby_naming::methods.include?("constant4")
raise RuntimeError, "Incorrect mapping for constant4"
end
if not Naming::methods.include?("constant5")
if not Ruby_naming::methods.include?("constant5")
raise RuntimeError, "Incorrect mapping for constant5"
end
if not Naming::methods.include?("constant6")
if not Ruby_naming::methods.include?("constant6")
raise RuntimeError, "Incorrect mapping for constant6"
end
if not Naming::TestConstants.instance_methods.include?("constant7")
if not Ruby_naming::TestConstants.instance_methods.include?("constant7")
raise RuntimeError, "Incorrect mapping for constant7"
end
if not Naming::TestConstants.methods.include?("constant8")
if not Ruby_naming::TestConstants.methods.include?("constant8")
raise RuntimeError, "Incorrect mapping for constant8"
end
# There is no constant9 because it is illegal C++
#if not Naming::TestConstants.instance_methods.include?("constant9")
#if not Ruby_naming::TestConstants.instance_methods.include?("constant9")
# raise RuntimeError, "Incorrect mapping for constant9"
#end
if Naming::TestConstants::CONSTANT10 != 10
if Ruby_naming::TestConstants::CONSTANT10 != 10
raise RuntimeError, "Incorrect value for CONSTANT10"
end
if not Naming::methods.include?("constant11")
if not Ruby_naming::methods.include?("constant11")
raise RuntimeError, "Incorrect mapping for constant11"
end
# Check enums
if Naming::constants.include?("Color")
if Ruby_naming::constants.include?("Color")
raise RuntimeError, "Color enum should not be exposed to Ruby"
end
if Naming::Red != 0
if Ruby_naming::Red != 0
raise RuntimeError, "Incorrect value for enum RED"
end
if Naming::Green != 1
if Ruby_naming::Green != 1
raise RuntimeError, "Incorrect value for enum GREEN"
end
if Naming::Blue != 2
if Ruby_naming::Blue != 2
raise RuntimeError, "Incorrect value for enum BLUE"
end
# Check method names
my_class = Naming::MyClass.new()
my_class = Ruby_naming::MyClass.new()
if my_class.method_one != 1
raise RuntimeError, "Incorrect value for method_one"

View file

@ -9,9 +9,9 @@
require 'swig_assert'
require 'track_objects_directors'
require 'ruby_track_objects_directors'
class MyFoo < Track_objects_directors::Foo
class MyFoo < Ruby_track_objects_directors::Foo
def ping
"MyFoo::ping()"
end
@ -22,12 +22,12 @@ a = MyFoo.new
raise RuntimeError if a.ping != "MyFoo::ping()"
raise RuntimeError if a.pong != "Foo::pong();MyFoo::ping()"
b = Track_objects_directors::Foo.new
b = Ruby_track_objects_directors::Foo.new
raise RuntimeError if b.ping != "Foo::ping()"
raise RuntimeError if b.pong != "Foo::pong();Foo::ping()"
container = Track_objects_directors::Container.new
container = Ruby_track_objects_directors::Container.new
foo = MyFoo.new
container.set_foo(foo)

View file

@ -9,7 +9,7 @@
require 'swig_assert'
require 'track_objects'
require 'ruby_track_objects'
def test_same_ruby_object(foo1, foo2)
if not foo1.equal?(foo2)
@ -23,12 +23,12 @@ def test_same_cpp_object(foo1, foo2)
end
end
bar = Track_objects::Bar.new
foo1 = Track_objects::Foo.new()
bar = Ruby_track_objects::Bar.new
foo1 = Ruby_track_objects::Foo.new()
bar.set_unowned_foo(foo1)
# test_simple_identity
foo2 = Track_objects::Foo.new()
foo2 = Ruby_track_objects::Foo.new()
foo3 = foo2
test_same_ruby_object(foo2, foo3)
@ -48,8 +48,8 @@ test_same_ruby_object(foo5, foo6)
test_same_cpp_object(foo5, foo6)
# test_new_foo_identity
foo7 = Track_objects::Bar.get_new_foo()
foo8 = Track_objects::Bar.get_new_foo()
foo7 = Ruby_track_objects::Bar.get_new_foo()
foo8 = Ruby_track_objects::Bar.get_new_foo()
if foo7.equal?(foo8)
raise "Ruby objects should be different."
@ -60,7 +60,7 @@ if foo7.cpp_equal(foo8)
end
# test_set_owned_identity
foo9 = Track_objects::Foo.new
foo9 = Ruby_track_objects::Foo.new
bar.set_owned_foo(foo9)
foo10 = bar.get_owned_foo()
@ -69,7 +69,7 @@ test_same_cpp_object(foo9, foo10)
# test_set_owned_identity2
begin
foo11 = Track_objects::Foo.new
foo11 = Ruby_track_objects::Foo.new
bar.set_owned_foo(foo11)
foo11 = nil
end
@ -90,20 +90,20 @@ test_same_ruby_object(foo13, foo14)
test_same_cpp_object(foo13, foo14)
# Now create the factory
factory = Track_objects::Factory.new
factory = Ruby_track_objects::Factory.new
# Create itemA which is really an itemB
itemA = factory.createItem
# Check class
if itemA.class != Track_objects::ItemA
if itemA.class != Ruby_track_objects::ItemA
raise RuntimeError, 'Item should have an ItemA class'
end
# Now downcast
itemB = Track_objects.downcast(itemA)
itemB = Ruby_track_objects.downcast(itemA)
if itemB.class != Track_objects::ItemB
if itemB.class != Ruby_track_objects::ItemB
raise RuntimeError, 'Item should have an ItemB class'
end

View file

@ -1,29 +0,0 @@
%module stl_new
%include <std_vector.i>
%include <std_deque.i>
%include <std_list.i>
%include <std_set.i>
%include <std_map.i>
%template(Vector ) std::vector <swig::LANGUAGE_OBJ>;
%template(Deque ) std::deque <swig::LANGUAGE_OBJ>;
%template(List ) std::list <swig::LANGUAGE_OBJ>;
%template(Set ) std::set <swig::LANGUAGE_OBJ,
swig::BinaryPredicate<> >;
%template(Map ) std::map <swig::LANGUAGE_OBJ,swig::LANGUAGE_OBJ,
swig::BinaryPredicate<> >;
// %inline %{
// namespace swig {
// void nth_element(swig::Iterator_T< _Iter>& first,
// swig::Iterator_T< _Iter>& nth,
// swig::Iterator_T< _Iter>& last,
// const swig::BinaryPredicate<>& comp = swig::BinaryPredicate<>())
// {
// std::nth_element( first, nth, last, comp);
// }
// }
// %}

View file

@ -1,125 +0,0 @@
%module track_objects
%include typemaps.i
%trackobjects Foo;
%newobject Bar::get_new_foo;
%typemap(in, numinputs=0) Foo** foo (Foo *temp) {
/* %typemap(in, numinputs=0) Foo** foo */
$1 = &temp;
}
%typemap(argout) Foo** foo {
/* %typemap(argout) Foo** foo */
$result = SWIG_NewPointerObj((void *) *$1, $*1_descriptor, 0);
}
%apply SWIGTYPE *DISOWN {Foo* ownedFoo};
%trackobjects ItemA;
%trackobjects ItemB;
%inline %{
class Foo
{
public:
Foo() {}
~Foo() {}
/* Helper method that can be called from Ruby that checks
that two Ruby objects are pointing to the same underlying
C++ object */
bool cpp_equal(const Foo* other)
{
return (this == other);
}
/* Just a simple method to call on Foo*/
const char* say_hello()
{
return "Hello";
}
};
class Bar
{
private:
Foo* owned_;
Foo* unowned_;
public:
Bar(): owned_(new Foo), unowned_(0)
{
}
~Bar()
{
delete owned_;
}
/* Test that track objects works with %newobject */
static Foo* get_new_foo()
{
return new Foo;
}
/* Test the same foo Ruby object is created each time */
Foo* get_owned_foo()
{
return owned_;
}
/* Test that track objects works with argout parameters.*/
void get_owned_foo_by_argument(Foo** foo)
{
*foo = owned_;
}
/* Test that track objects works with the DISOWN typemap.*/
void set_owned_foo(Foo* ownedFoo)
{
delete owned_;
owned_ = ownedFoo;
}
Foo* get_unowned_foo()
{
return unowned_;
}
void set_unowned_foo(Foo* foo)
{
unowned_ = foo;
}
};
class ItemA
{
};
class ItemB: public ItemA
{
public:
};
ItemB* downcast(ItemA* item)
{
return static_cast<ItemB*>(item);
}
class Factory
{
public:
Factory() {}
ItemA* createItem()
{
return new ItemB;
}
};
%}

View file

@ -1,44 +0,0 @@
%module(directors="1") track_objects_directors
%{
#include <string>
%}
%include "std_string.i";
%feature("director") Foo;
%trackobjects;
%inline %{
class Foo {
public:
Foo() {}
virtual ~Foo() {}
virtual std::string ping()
{
return "Foo::ping()";
}
virtual std::string pong()
{
return "Foo::pong();" + ping();
}
};
class Container {
Foo* foo_;
public:
Foo* get_foo()
{
return foo_;
}
void set_foo(Foo *foo)
{
foo_ = foo;
}
};
%}