[lua] fixed bug in template classes which cases template_default2 and template_specialization_defarg to fail.

Added several warning filters into the overload's test cases.
Added runtime tests for several codes.
You can now make check-lua-test-suite with no errors and only a few warnings.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10076 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Gossage 2007-10-30 06:10:04 +00:00
parent 70759b3e16
commit 0c2bbb25a3
19 changed files with 368 additions and 15 deletions

View File

@ -1,6 +1,13 @@
Version 1.3.32 (in progress)
============================
10/30/2007: mgossage
[lua] fixed bug in template classes which cases template_default2
and template_specialization_defarg to fail.
Added several warning filters into the overload's test cases.
Added runtime tests for several codes.
You can now make check-lua-test-suite with no errors and only a few warnings.
10/30/2007: olly
[guile] Fix the configure test to put GUILELINK in LIBS not LDFLAGS
(SF#1822430).

View File

@ -0,0 +1,55 @@
require("import") -- the import fn
import("overload_simple") -- import code
for k,v in pairs(overload_simple) do _G[k]=v end -- move to global
-- lua has only one numeric type, foo(int) and foo(double) are the same
-- whichever one was wrapper first will be used
assert(foo(3)=="foo:int" or foo(3)=="foo:double") -- could be either
assert(foo("hello")=="foo:char *")
f=Foo()
b=Bar()
assert(foo(f)=="foo:Foo *")
assert(foo(b)=="foo:Bar *")
v = malloc_void(32)
assert(foo(v) == "foo:void *")
s = Spam()
assert(s:foo(3) == "foo:int" or s:foo(3.0) == "foo:double") -- could be either
assert(s:foo("hello") == "foo:char *")
assert(s:foo(f) == "foo:Foo *")
assert(s:foo(b) == "foo:Bar *")
assert(s:foo(v) == "foo:void *")
assert(Spam_bar(3) == "bar:int" or Spam_bar(3.0) == "bar:double")
assert(Spam_bar("hello") == "bar:char *")
assert(Spam_bar(f) == "bar:Foo *")
assert(Spam_bar(b) == "bar:Bar *")
assert(Spam_bar(v) == "bar:void *")
-- Test constructors
s = Spam()
assert(s.type == "none")
s = Spam(3)
assert(s.type == "int" or s.type == "double")
s = Spam("hello")
assert(s.type == "char *")
s = Spam(f)
assert(s.type == "Foo *")
s = Spam(b)
assert(s.type == "Bar *")
s = Spam(v)
assert(s.type == "void *")
free_void(v)

View File

@ -0,0 +1,81 @@
require("import") -- the import fn
import("overload_template_fast") -- import code
for k,v in pairs(overload_template_fast) 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
-- whichever one was wrapper first will be used (which is int)
f = foo()
a = max(3,4)
-- mix 1
assert(mix1("hi") == 101)
assert(mix1(1.0, 1.0) == 102)
assert(mix1(1.0) == 103)
-- mix 2
assert(mix2("hi") == 101)
assert(mix2(1.0, 1.0) == 102)
assert(mix2(1.0) == 103)
-- mix 3
assert(mix3("hi") == 101)
assert(mix3(1.0, 1.0) == 102)
assert(mix3(1.0) == 103)
-- Combination 1
assert(overtparams1(100) == 10)
assert(overtparams1(100.0, 100) == 20)
-- Combination 2
assert(overtparams2(100.0, 100) == 40)
-- Combination 3
assert(overloaded() == 60)
assert(overloaded(100.0, 100) == 70)
-- Combination 4
assert(overloadedagain("hello") == 80)
assert(overloadedagain() == 90)
-- specializations
assert(specialization(10) == 202 or specialization(10.0) == 203) -- only one works
assert(specialization(10, 10) == 204 or specialization(10.0, 10.0) == 205) -- ditto
assert(specialization("hi", "hi") == 201)
-- simple specialization
xyz()
xyz_int()
xyz_double()
-- a bit of everything
assert(overload("hi") == 0)
assert(overload(1) == 10)
assert(overload(1, 1) == 20)
assert(overload(1, "hello") == 30)
k = Klass()
assert(overload(k) == 10)
assert(overload(k, k) == 20)
assert(overload(k, "hello") == 30)
-- this one is incorrect: it mactches overload(10.0, "hi") with int overload(T t, const char *c)
--print(overload(10.0, "hi"))
--assert(overload(10.0, "hi") == 40)
assert(overload() == 50)
-- everything put in a namespace
assert(nsoverload("hi") == 1000,"nsoverload()")
assert(nsoverload(1) == 1010,"nsoverload(int t)")
assert(nsoverload(1, 1) == 1020,"nsoverload(int t, const int &)")
assert(nsoverload(1, "hello") == 1030,"nsoverload(int t, const char *)")
assert(nsoverload(k) == 1010,"nsoverload(Klass t)")
assert(nsoverload(k, k) == 1020,"nsoverload(Klass t, const Klass &)")
assert(nsoverload(k, "hello") == 1030,"nsoverload(Klass t, const char *)")
-- again this one fails
--assert(nsoverload(10.0, "hi") == 1040,"nsoverload(double t, const char *)")
assert(nsoverload() == 1050,"nsoverload(const char *)")
A_foo(1)
b = B()
b:foo(1)

View File

@ -0,0 +1,81 @@
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
-- whichever one was wrapper first will be used (which is int)
f = foo()
a = max(3,4)
-- mix 1
assert(mix1("hi") == 101)
assert(mix1(1.0, 1.0) == 102)
assert(mix1(1.0) == 103)
-- mix 2
assert(mix2("hi") == 101)
assert(mix2(1.0, 1.0) == 102)
assert(mix2(1.0) == 103)
-- mix 3
assert(mix3("hi") == 101)
assert(mix3(1.0, 1.0) == 102)
assert(mix3(1.0) == 103)
-- Combination 1
assert(overtparams1(100) == 10)
assert(overtparams1(100.0, 100) == 20)
-- Combination 2
assert(overtparams2(100.0, 100) == 40)
-- Combination 3
assert(overloaded() == 60)
assert(overloaded(100.0, 100) == 70)
-- Combination 4
assert(overloadedagain("hello") == 80)
assert(overloadedagain() == 90)
-- specializations
assert(specialization(10) == 202 or specialization(10.0) == 203) -- only one works
assert(specialization(10, 10) == 204 or specialization(10.0, 10.0) == 205) -- ditto
assert(specialization("hi", "hi") == 201)
-- simple specialization
xyz()
xyz_int()
xyz_double()
-- a bit of everything
assert(overload("hi") == 0)
assert(overload(1) == 10)
assert(overload(1, 1) == 20)
assert(overload(1, "hello") == 30)
k = Klass()
assert(overload(k) == 10)
assert(overload(k, k) == 20)
assert(overload(k, "hello") == 30)
-- this one is incorrect: it mactches overload(10.0, "hi") with int overload(T t, const char *c)
--print(overload(10.0, "hi"))
--assert(overload(10.0, "hi") == 40)
assert(overload() == 50)
-- everything put in a namespace
assert(nsoverload("hi") == 1000,"nsoverload()")
assert(nsoverload(1) == 1010,"nsoverload(int t)")
assert(nsoverload(1, 1) == 1020,"nsoverload(int t, const int &)")
assert(nsoverload(1, "hello") == 1030,"nsoverload(int t, const char *)")
assert(nsoverload(k) == 1010,"nsoverload(Klass t)")
assert(nsoverload(k, k) == 1020,"nsoverload(Klass t, const Klass &)")
assert(nsoverload(k, "hello") == 1030,"nsoverload(Klass t, const char *)")
-- again this one fails
--assert(nsoverload(10.0, "hi") == 1040,"nsoverload(double t, const char *)")
assert(nsoverload() == 1050,"nsoverload(const char *)")
A_foo(1)
b = B()
b:foo(1)

View File

@ -0,0 +1,14 @@
require("import") -- the import fn
import("smart_pointer_overload") -- import code
for k,v in pairs(smart_pointer_overload) do _G[k]=v end -- move to global
f = Foo()
b = Bar(f)
assert(f:test(3) == 1)
--assert(f:test(3.5) == 2) -- won't work due to being unable to overloads
assert(f:test("hello") == 3)
assert(b:test(3) == 1)
--assert(b:test(3.5) == 2) -- won't work due to being unable to overloads
assert(b:test("hello") == 3)

View File

@ -0,0 +1,63 @@
require("import") -- the import fn
import("template_default_arg") -- import code
--for k,v in pairs(template_default_arg) do _G[k]=v end -- move to global
helloInt = template_default_arg.Hello_int()
helloInt:foo(template_default_arg.Hello_int_hi)
x = template_default_arg.X_int()
assert(x:meth(20.0, 200) == 200,"X_int test 1 failed")
assert(x:meth(20) == 20,"X_int test 2 failed")
assert(x:meth() == 0,"X_int test 3 failed")
y = template_default_arg.Y_unsigned()
assert(y:meth(20.0, 200) == 200,"Y_unsigned test 1 failed")
assert(y:meth(20) == 20,"Y_unsigned test 2 failed")
assert(y:meth() == 0,"Y_unsigned test 3 failed")
x = template_default_arg.X_longlong()
x = template_default_arg.X_longlong(20.0)
x = template_default_arg.X_longlong(20.0, 200) -- note: long longs just treated as another number
x = template_default_arg.X_int()
x = template_default_arg.X_int(20.0)
x = template_default_arg.X_int(20.0, 200)
x = template_default_arg.X_hello_unsigned()
x = template_default_arg.X_hello_unsigned(20.0)
x = template_default_arg.X_hello_unsigned(20.0, template_default_arg.Hello_int())
y = template_default_arg.Y_hello_unsigned()
y:meth(20.0, template_default_arg.Hello_int())
y:meth(template_default_arg.Hello_int())
y:meth()
fz = template_default_arg.Foo_Z_8()
x = template_default_arg.X_Foo_Z_8()
fzc = x:meth(fz)
-- Templated functions
-- plain function: int ott(Foo<int>)
assert(template_default_arg.ott(template_default_arg.Foo_int()) == 30,"ott test 1 failed")
-- %template(ott) ott<int, int>
assert(template_default_arg.ott() == 10,"ott test 2 failed")
assert(template_default_arg.ott(1) == 10,"ott test 3 failed")
assert(template_default_arg.ott(1, 1) == 10,"ott test 4 failed")
assert(template_default_arg.ott("hi") == 20,"ott test 5 failed")
assert(template_default_arg.ott("hi", 1) == 20,"ott test 6 failed")
assert(template_default_arg.ott("hi", 1, 1) == 20,"ott test 7 failed")
-- %template(ott) ott<const char *>
assert(template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") == 40,"ott test 8 failed")
assert(template_default_arg.ottstring(template_default_arg.Hello_int()) == 40,"ott test 9 failed")
-- %template(ott) ott<int>
assert(template_default_arg.ottint(template_default_arg.Hello_int(), 1) == 50,"ott test 10 failed")
assert(template_default_arg.ottint(template_default_arg.Hello_int()) == 50,"ott test 11 failed")
-- %template(ott) ott<double>
assert(template_default_arg.ott(template_default_arg.Hello_int(), 1.0) == 60,"ott test 12 failed")
assert(template_default_arg.ott(template_default_arg.Hello_int()) == 60,"ott test 13 failed")

View File

@ -8,6 +8,10 @@
%typemap(default) double y "$1=1000;";
#endif
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) test;
#endif
%warnfilter(SWIGWARN_PARSE_REDEFINED) Foo::test;

View File

@ -5,6 +5,15 @@
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fbool;
#endif
#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) bar;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Spam;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) num;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fid;
#endif
#ifndef SWIG_NO_OVERLOAD
%immutable Spam::type;

View File

@ -1,5 +1,16 @@
%module overload_template
#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) specialization;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) overload;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) space::nsoverload;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fooT;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) barT;
#endif
%{
#ifdef max
#undef max

View File

@ -1,5 +1,9 @@
%module smart_pointer_overload
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) test;
#endif
#ifndef SWIG_NO_OVERLOAD
%inline %{

View File

@ -1,6 +1,12 @@
%module template_default_arg
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) Hello; /* Ruby, wrong class name */
#ifdef SWIGLUA
// lua only has one numeric type, so most of the overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) X;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Z;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) meth;
#endif
%inline %{
template <class T>

View File

@ -1,5 +1,11 @@
%module template_extend_overload_2
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) A;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) AT;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) BT;
#endif
%inline %{
struct A

View File

@ -27,7 +27,7 @@ namespace Foo {
%typemap(javaout) Str1 * = char *;
#endif
%typemap(in) Str1 * = char *;
#if !defined(SWIGCSHARP)
#if !(defined(SWIGCSHARP) || defined(SWIGLUA))
%typemap(freearg) Str1 * = char *;
#endif
%typemap(typecheck) Str1 * = char *;

View File

@ -3,6 +3,9 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_PHP4_MULTIPLE_INHERITANCE) FooBar; // C#, Java, Php4 multiple inheritance
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah;
#endif
%inline %{
class Foo {

View File

@ -3,6 +3,9 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
SWIGWARN_PHP4_MULTIPLE_INHERITANCE) FooBar; // C#, Java, Php4 multiple inheritance
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah;
#endif
%extend Foo {
int blah(int x, int y) {

View File

@ -1,5 +1,9 @@
%module using_inherit
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Foo::test;
#endif
%inline %{
class Foo {

View File

@ -1,5 +1,9 @@
%module wrapmacro
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) SWIGMACRO_max;
#endif
/* Testing technique for wrapping macros */
%{

View File

@ -221,11 +221,8 @@ cast it to that & accept the loss of precision.
An alternative solution would be a long long struct or class
with the relevant operators.
*/
%typemap(in,checkfn="lua_isnumber") long long, unsigned long long, signed long long
%{$1 = ($type)lua_tonumber(L, $input);%}
%typemap(out) long long, unsigned long long, signed long long
%{ lua_pushnumber(L, (lua_Number) $1); SWIG_arg++;%}
%apply long {long long, signed long long, unsigned long long};
%apply const long& {const long long&, const signed long long&, const unsigned long long&};
/* It is possible to also pass a lua_State* into a function, so
void fn(int a, float b, lua_State* s) is wrappable as

View File

@ -833,11 +833,13 @@ NEW LANGUAGE NOTE:END ************************************************/
real_classname = Getattr(n, "name");
mangled_classname = Swig_name_mangle(real_classname);
// note: tcl has a static hashtable of all classes emitted, I wonder why?
/* static Hash* emitted = NewHash();
Printf(stdout,"classHandler %s\n",mangled_classname);
if (Getattr(emitted,mangled_classname)) return SWIG_NOWRAP;
Setattr(emitted,mangled_classname,"1"); */
// not sure exactly how this workswhat this works,
// but tcl has a static hashtable of all classes emitted and then only emits code for them once.
// this fixes issues in test suites: template_default2 & template_specialization
static Hash *emitted = NewHash();
if (Getattr(emitted, mangled_classname))
return SWIG_NOWRAP;
Setattr(emitted, mangled_classname, "1");
s_attr_tab = NewString("");
Printf(s_attr_tab, "static swig_lua_attribute swig_");
@ -848,9 +850,8 @@ NEW LANGUAGE NOTE:END ************************************************/
Printv(s_methods_tab, mangled_classname, "_methods[] = {\n", NIL);
// Generate normal wrappers
//return SWIG_OK;
Language::classHandler(n);
//return SWIG_OK;
SwigType *t = Copy(Getattr(n, "name"));
SwigType_add_pointer(t);
@ -888,7 +889,7 @@ NEW LANGUAGE NOTE:END ************************************************/
Delete(s_attr_tab);
// Handle inheritance
// note: with the idea of class hireachied spread over mutliple modules
// note: with the idea of class hireachied spread over multiple modules
// cf test-suite: imports.i
// it is not possible to just add the pointers to the base classes to the code
// (as sometimes these classes are not present)
@ -1009,7 +1010,7 @@ NEW LANGUAGE NOTE:END ************************************************/
* ------------------------------------------------------------ */
virtual int constructorHandler(Node *n) {
REPORT("constructorHandler", n);
// REPORT("constructorHandler", n);
current = CONSTRUCTOR;
Language::constructorHandler(n);
current = NO_CPP;