diff --git a/.travis.yml b/.travis.yml index 47edc8bbe..9e9cd7fc7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,8 @@ matrix: env: SWIGLANG=python SWIG_FEATURES=-builtin - compiler: gcc env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 + - compiler: gcc + env: SWIGLANG=python SWIG_FEATURES=-classic - compiler: gcc env: SWIGLANG=ruby - compiler: gcc @@ -60,6 +62,9 @@ matrix: # Occasional gcc internal compiler error - compiler: gcc env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8 + # Not quite working yet + - compiler: gcc + env: SWIGLANG=python SWIG_FEATURES=-classic before_install: - date -u - uname -a diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 756b85904..0f0686e41 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -9,6 +9,13 @@ def check(got, expected, expected_builtin = None, skip = False): if expect != got: raise RuntimeError("\n" + "Expected: [" + str(expect) + "]\n" + "Got : [" + str(got) + "]") +def is_new_style_class(cls): + return hasattr(cls, "__class__") + +if not is_new_style_class(A): + # Missing static methods make this hard to test... skip if -classic is used! + exit(0) + skip = True # skip builtin check - the autodoc is missing, but it probably should not be check(A.__doc__, "Proxy of C++ A class", "::A") diff --git a/Examples/test-suite/python/cpp_static_runme.py b/Examples/test-suite/python/cpp_static_runme.py index ef8623359..eef921780 100644 --- a/Examples/test-suite/python/cpp_static_runme.py +++ b/Examples/test-suite/python/cpp_static_runme.py @@ -1,7 +1,16 @@ #!/usr/bin/evn python from cpp_static import * -StaticFunctionTest.static_func() -StaticFunctionTest.static_func_2(1) -StaticFunctionTest.static_func_3(1,2) + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + +if is_new_style_class(StaticFunctionTest): + StaticFunctionTest.static_func() + StaticFunctionTest.static_func_2(1) + StaticFunctionTest.static_func_3(1,2) +else: + StaticFunctionTest().static_func() + StaticFunctionTest().static_func_2(1) + StaticFunctionTest().static_func_3(1,2) StaticMemberTest.static_int = 10 assert StaticMemberTest.static_int == 10 diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py index f24e825ad..20adab2ff 100644 --- a/Examples/test-suite/python/default_args_runme.py +++ b/Examples/test-suite/python/default_args_runme.py @@ -1,5 +1,8 @@ # Note that this test is also used by python_default_args_runme.py hence the use of __main__ and the run function +def is_new_style_class(cls): + return hasattr(cls, "__class__") + def run(module_name): default_args = __import__(module_name) ec = default_args.EnumClass() @@ -71,13 +74,15 @@ def run(module_name): error = 0 if error: raise RuntimeError("Foo::meth ignore is not working") - if default_args.Klass.inc(100, default_args.Klass(22)).val != 122: + Klass_inc = default_args.Klass.inc if is_new_style_class(default_args.Klass) else default_args.Klass_inc + + if Klass_inc(100, default_args.Klass(22)).val != 122: raise RuntimeError("Klass::inc failed") - if default_args.Klass.inc(100).val != 99: + if Klass_inc(100).val != 99: raise RuntimeError("Klass::inc failed") - if default_args.Klass.inc().val != 0: + if Klass_inc().val != 0: raise RuntimeError("Klass::inc failed") default_args.trickyvalue1(10); default_args.trickyvalue1(10, 10) diff --git a/Examples/test-suite/python/director_abstract_runme.py b/Examples/test-suite/python/director_abstract_runme.py index 7d92d10ff..e065ba22d 100644 --- a/Examples/test-suite/python/director_abstract_runme.py +++ b/Examples/test-suite/python/director_abstract_runme.py @@ -1,5 +1,8 @@ import director_abstract +def is_new_style_class(cls): + return hasattr(cls, "__class__") + class MyFoo(director_abstract.Foo): def __init__(self): director_abstract.Foo.__init__(self) @@ -32,12 +35,14 @@ me1 = MyExample1() if director_abstract.Example1_get_color(me1, 1,2,3) != 1: raise RuntimeError +MyExample2_static = MyExample2 if is_new_style_class(MyExample2) else MyExample2(0, 0) me2 = MyExample2(1,2) -if MyExample2.get_color(me2, 1,2,3) != 2: +if MyExample2_static.get_color(me2, 1,2,3) != 2: raise RuntimeError +MyExample3_static = MyExample3 if is_new_style_class(MyExample3) else MyExample3() me3 = MyExample3() -if MyExample3.get_color(me3, 1,2,3) != 3: +if MyExample3_static.get_color(me3, 1,2,3) != 3: raise RuntimeError error = 1 diff --git a/Examples/test-suite/python/global_namespace_runme.py b/Examples/test-suite/python/global_namespace_runme.py index b64e75ca1..c627ef822 100644 --- a/Examples/test-suite/python/global_namespace_runme.py +++ b/Examples/test-suite/python/global_namespace_runme.py @@ -1,5 +1,8 @@ from global_namespace import * +def is_new_style_class(cls): + return hasattr(cls, "__class__") + k1 = Klass1() k2 = Klass2() k3 = Klass3() @@ -8,8 +11,10 @@ k5 = Klass5() k6 = Klass6() k7 = Klass7() -KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) -KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static = KlassMethods if is_new_style_class(KlassMethods) else KlassMethods() + +KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) k1 = getKlass1A() k2 = getKlass2A() @@ -19,8 +24,8 @@ k5 = getKlass5A() k6 = getKlass6A() k7 = getKlass7A() -KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) -KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) k1 = getKlass1B() k2 = getKlass2B() @@ -30,11 +35,13 @@ k5 = getKlass5B() k6 = getKlass6B() k7 = getKlass7B() -KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) -KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) -XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) -XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) +XYZMethods_static = XYZMethods if is_new_style_class(XYZMethods) else XYZMethods() +XYZMethods_static.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) +XYZMethods_static.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) -TheEnumMethods.methodA(theenum1, theenum2, theenum3) -TheEnumMethods.methodA(theenum1, theenum2, theenum3) +TheEnumMethods_static = TheEnumMethods if is_new_style_class(TheEnumMethods) else TheEnumMethods() +TheEnumMethods_static.methodA(theenum1, theenum2, theenum3) +TheEnumMethods_static.methodA(theenum1, theenum2, theenum3) diff --git a/Examples/test-suite/python/implicittest_runme.py b/Examples/test-suite/python/implicittest_runme.py index a9957bc7e..d5e6e4ef1 100644 --- a/Examples/test-suite/python/implicittest_runme.py +++ b/Examples/test-suite/python/implicittest_runme.py @@ -4,6 +4,9 @@ def check(a, b): if a != b: raise RuntimeError(str(a) + " does not equal " + str(b)) +def is_new_style_class(cls): + return hasattr(cls, "__class__") + #### Class #### # No implicit conversion @@ -39,13 +42,14 @@ check(2, A_int(1.0).get()) check(3, A_int(B()).get()) check(4, A_int("hello").get()) -check(1, A_int.sget(1)) -check(2, A_int.sget(1.0)) -check(3, A_int.sget(B())) +A_int_static = A_int if is_new_style_class(A_int) else A_int(0) +check(1, A_int_static.sget(1)) +check(2, A_int_static.sget(1.0)) +check(3, A_int_static.sget(B())) # explicit constructor: try: - check(4, A_int.sget("hello")) + check(4, A_int_static.sget("hello")) raise RuntimeError except TypeError: pass diff --git a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py index 931317615..a05432925 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py @@ -1,5 +1,8 @@ from li_boost_shared_ptr_bits import * +def is_new_style_class(cls): + return hasattr(cls, "__class__") + def check(nd): nd.i = 200 i = nd.i @@ -30,5 +33,8 @@ if sum != 66: raise "sum is wrong" ################################ -p = HiddenDestructor.create() +if is_new_style_class(HiddenDestructor): + p = HiddenDestructor.create() +else: + p = HiddenDestructor_create() diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index f967def14..0e025d546 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -17,7 +17,7 @@ class li_boost_shared_ptr_runme: self.runtest() # Expect 1 instance - the one global variable (GlobalValue) - if (li_boost_shared_ptr.Klass.getTotal_count() != 1): + if (li_boost_shared_ptr.Klass_getTotal_count() != 1): raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count()) wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count() diff --git a/Examples/test-suite/python/li_std_auto_ptr_runme.py b/Examples/test-suite/python/li_std_auto_ptr_runme.py index a29771479..d82a89f42 100644 --- a/Examples/test-suite/python/li_std_auto_ptr_runme.py +++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py @@ -2,16 +2,16 @@ from li_std_auto_ptr import * k1 = makeKlassAutoPtr("first") k2 = makeKlassAutoPtr("second") -if Klass.getTotal_count() != 2: +if Klass_getTotal_count() != 2: raise "number of objects should be 2" del k1 -if Klass.getTotal_count() != 1: +if Klass_getTotal_count() != 1: raise "number of objects should be 1" if k2.getLabel() != "second": raise "wrong object label" del k2 -if Klass.getTotal_count() != 0: +if Klass_getTotal_count() != 0: raise "no objects should be left" diff --git a/Examples/test-suite/python/li_std_containers_int_runme.py b/Examples/test-suite/python/li_std_containers_int_runme.py index 3cbbb2862..bbfa62923 100644 --- a/Examples/test-suite/python/li_std_containers_int_runme.py +++ b/Examples/test-suite/python/li_std_containers_int_runme.py @@ -7,6 +7,11 @@ def failed(a, b, msg): raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b)) def compare_sequences(a, b): + print("Comparing {} and {}\n".format(a, b)) + print(" len a: {}\n".format(a.__len__())) + print(" len b: {}\n".format(b.__len__())) + print(" len a: {}\n".format(type(a.__len__()))) + print(" len b: {}\n".format(type(b.__len__()))) if len(a) != len(b): failed(a, b, "different sizes") for i in range(len(a)): diff --git a/Examples/test-suite/python/namespace_class_runme.py b/Examples/test-suite/python/namespace_class_runme.py index d139527b7..e009f9515 100644 --- a/Examples/test-suite/python/namespace_class_runme.py +++ b/Examples/test-suite/python/namespace_class_runme.py @@ -1,5 +1,8 @@ from namespace_class import * +def is_new_style_class(cls): + return hasattr(cls, "__class__") + try: p = Private1() error = 1 @@ -18,7 +21,10 @@ except: if (error): raise RuntimeError, "Private2 is private" -EulerT3D.toFrame(1,1,1) +if is_new_style_class(EulerT3D): + EulerT3D.toFrame(1,1,1) +else: + EulerT3D().toFrame(1,1,1) b = BooT_i() b = BooT_H() @@ -33,6 +39,7 @@ f.moo(1) f = FooT_H() f.foo(Hi) -f_type = str(type(f)) -if f_type.find("'namespace_class.FooT_H'") == -1: - raise RuntimeError("Incorrect type: " + f_type) +if is_new_style_class(FooT_H): + f_type = str(type(f)) + if f_type.find("'namespace_class.FooT_H'") == -1: + raise RuntimeError("Incorrect type: " + f_type) diff --git a/Examples/test-suite/python/overload_template_fast_runme.py b/Examples/test-suite/python/overload_template_fast_runme.py index d47f7d14d..299b91db8 100644 --- a/Examples/test-suite/python/overload_template_fast_runme.py +++ b/Examples/test-suite/python/overload_template_fast_runme.py @@ -1,4 +1,8 @@ from overload_template_fast import * + +def is_new_style_class(cls): + return hasattr(cls, "__class__") + f = foo() a = maximum(3,4) @@ -140,6 +144,9 @@ if (nsoverload() != 1050): raise RuntimeError, ("nsoverload(const char *)") -A.foo(1) +if is_new_style_class(A): + A.foo(1) +else: + A_foo(1) b = B() b.foo(1) diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py index 54d7a3e00..15b0297e9 100644 --- a/Examples/test-suite/python/python_append_runme.py +++ b/Examples/test-suite/python/python_append_runme.py @@ -1,12 +1,18 @@ from python_append import * +def is_new_style_class(cls): + return hasattr(cls, "__class__") + # test not relevant for -builtin if is_python_builtin(): exit(0) t=Test() t.func() -t.static_func() +if is_new_style_class(Test): + t.static_func() +else: + Test_static_func() if grabpath() != os.path.dirname(mypath): raise RuntimeError("grabpath failed") diff --git a/Examples/test-suite/python/refcount_runme.py b/Examples/test-suite/python/refcount_runme.py index ab1803f24..ca15e04ac 100644 --- a/Examples/test-suite/python/refcount_runme.py +++ b/Examples/test-suite/python/refcount_runme.py @@ -5,7 +5,7 @@ from refcount import * a = A3() b1 = B(a) -b2 = B.create(a) +b2 = B_create(a) @@ -14,7 +14,7 @@ if a.ref_count() != 3: rca = b2.get_rca() -b3 = B.create(rca) +b3 = B_create(rca) if a.ref_count() != 5: raise RuntimeError("Count = %d" % a.ref_count()) @@ -39,7 +39,7 @@ b5 = global_create(a) if b5.ref_count() != 1: raise RuntimeError -b6 = Factory.create(a) +b6 = Factory_create(a) if b6.ref_count() != 1: raise RuntimeError diff --git a/Examples/test-suite/python/return_const_value_runme.py b/Examples/test-suite/python/return_const_value_runme.py index 516e9f5d9..932c4822c 100644 --- a/Examples/test-suite/python/return_const_value_runme.py +++ b/Examples/test-suite/python/return_const_value_runme.py @@ -1,12 +1,12 @@ import return_const_value import sys -p = return_const_value.Foo_ptr.getPtr() +p = return_const_value.Foo_ptr_getPtr() if (p.getVal() != 17): print "Runtime test1 faild. p.getVal()=", p.getVal() sys.exit(1) -p = return_const_value.Foo_ptr.getConstPtr() +p = return_const_value.Foo_ptr_getConstPtr() if (p.getVal() != 17): print "Runtime test2 faild. p.getVal()=", p.getVal() sys.exit(1) diff --git a/Examples/test-suite/python/smart_pointer_member_runme.py b/Examples/test-suite/python/smart_pointer_member_runme.py index 70e655652..2cf3686fc 100644 --- a/Examples/test-suite/python/smart_pointer_member_runme.py +++ b/Examples/test-suite/python/smart_pointer_member_runme.py @@ -1,5 +1,8 @@ from smart_pointer_member import * +def is_new_style_class(cls): + return hasattr(cls, "__class__") + f = Foo() f.y = 1 @@ -20,8 +23,9 @@ if b.x != f.x: if b.z != f.z: raise RuntimeError -if Foo.z == Bar.z: - raise RuntimeError +if is_new_style_class(Bar): # feature not supported in old style classes + if Foo.z == Bar.z: + raise RuntimeError diff --git a/Examples/test-suite/python/typemap_out_optimal_runme.py b/Examples/test-suite/python/typemap_out_optimal_runme.py index b148f2d06..95556f6bd 100644 --- a/Examples/test-suite/python/typemap_out_optimal_runme.py +++ b/Examples/test-suite/python/typemap_out_optimal_runme.py @@ -1,5 +1,5 @@ from typemap_out_optimal import * cvar.XX_debug = False -x = XX.create() +x = XX_create()