Merge branch 'python-options-rationalise'

* python-options-rationalise:
  Hard-wire -noproxydel on
  Hard-wire -modern and -modernargs on
  Drop support for Python classic classes
This commit is contained in:
William S Fulton 2018-10-12 07:13:12 +01:00
commit edfbbab8e2
22 changed files with 157 additions and 432 deletions

View file

@ -222,11 +222,6 @@ matrix:
env: SWIGLANG=python SWIG_FEATURES=-O PY3=3 VER=3.7 env: SWIGLANG=python SWIG_FEATURES=-O PY3=3 VER=3.7
sudo: required sudo: required
dist: trusty dist: trusty
- compiler: gcc
os: linux
env: SWIGLANG=python SWIG_FEATURES=-classic
sudo: required
dist: trusty
- compiler: gcc - compiler: gcc
os: linux os: linux
env: SWIGLANG=r env: SWIGLANG=r

View file

@ -6313,9 +6313,7 @@ SWIG is able to support Python 3.x. The wrapper code generated by
SWIG can be compiled with both Python 2.x or 3.x. Further more, by SWIG can be compiled with both Python 2.x or 3.x. Further more, by
passing the <tt>-py3</tt> command line option to SWIG, wrapper code passing the <tt>-py3</tt> command line option to SWIG, wrapper code
with some Python 3 specific features can be generated (see below with some Python 3 specific features can be generated (see below
subsections for details of these features). The <tt>-py3</tt> option also subsections for details of these features).
disables some incompatible features for Python 3, such as
<tt>-classic</tt>.
<p> <p>
There is a list of known-to-be-broken features in Python 3: There is a list of known-to-be-broken features in Python 3:

View file

@ -59,15 +59,15 @@
*/ */
/* /*
Now, the EmptyError doesn't appear in a throw declaration, and hence Python classes that are used as exceptions need to be subclasses of the
we need to 'mark' it as an exception class. In python, classes that "Exception" class, and so SWIG needs to know which wrapped classes may be
are used as exception are 'special', and need to be wrapped as used in this way. You can explicitly tell SWIG this by using
'classic' ones. %exceptionclass. SWIG will implicitly set this feature for classes which
appear in a throw declaration, but it's not a problem to explicitly
This is a python issue, and if you don't mark the class, you will mark such classes as well.
see 'interesting' behaviours at the python side.
This is a Python requirement - if you fail to mark such classes with
%exceptionclass you may see 'interesting' behaviour on the Python side.
*/ */
%exceptionclass EmptyError; %exceptionclass EmptyError;
%exceptionclass FullError; %exceptionclass FullError;

View file

@ -10,10 +10,6 @@ print " Finished importing pkg2.foo"
var2 = pkg2.foo.Pkg2_Foo() var2 = pkg2.foo.Pkg2_Foo()
classname = str(type(var2)) classname = str(type(var2))
# Check for an old-style class if swig was run in -classic mode
if classname == "<type 'instance'>":
classname = str(var2.__class__)
if classname.find("pkg2.foo.Pkg2_Foo") == -1: if classname.find("pkg2.foo.Pkg2_Foo") == -1:
raise RuntimeError("failed type checking: " + classname) raise RuntimeError("failed type checking: " + classname)
print " Successfully created object pkg2.foo.Pkg2_Foo" print " Successfully created object pkg2.foo.Pkg2_Foo"

View file

@ -9,10 +9,6 @@ print " Finished importing pkg1.pkg2.foo"
var2 = pkg1.pkg2.foo.Pkg2_Foo() var2 = pkg1.pkg2.foo.Pkg2_Foo()
classname = str(type(var2)) classname = str(type(var2))
# Check for an old-style class if swig was run in -classic mode
if classname == "<type 'instance'>":
classname = str(var2.__class__)
if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1: if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1:
raise RuntimeError("failed type checking: " + classname) raise RuntimeError("failed type checking: " + classname)
print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo"

View file

@ -10,9 +10,6 @@ def check(got, expected, expected_builtin=None, skip=False):
expect = expected_builtin expect = expected_builtin
comment_verifier.check(got, expect) comment_verifier.check(got, expect)
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def is_fastproxy(): def is_fastproxy():
fastproxy = True fastproxy = True
try: try:
@ -21,11 +18,6 @@ def is_fastproxy():
fastproxy = False fastproxy = False
return fastproxy return fastproxy
if not is_new_style_class(A):
# Missing static methods make this hard to test... skip if -classic is
# used!
sys.exit(0)
if is_fastproxy(): if is_fastproxy():
# Detect when -fastproxy is specified and skip test as it changes the function names making it # Detect when -fastproxy is specified and skip test as it changes the function names making it
# hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved # hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved

View file

@ -2,17 +2,9 @@
from cpp_static import * from cpp_static import *
def is_new_style_class(cls): StaticFunctionTest.static_func()
return hasattr(cls, "__class__") StaticFunctionTest.static_func_2(1)
StaticFunctionTest.static_func_3(1, 2)
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)
if is_python_builtin(): if is_python_builtin():
if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99") if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99")

View file

@ -2,10 +2,6 @@
# the use of __main__ and the run function # the use of __main__ and the run function
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def run(module_name): def run(module_name):
default_args = __import__(module_name) default_args = __import__(module_name)
ec = default_args.EnumClass() ec = default_args.EnumClass()
@ -101,10 +97,7 @@ def run(module_name):
if error: if error:
raise RuntimeError("Foo::meth ignore is not working") raise RuntimeError("Foo::meth ignore is not working")
if is_new_style_class(default_args.Klass): Klass_inc = default_args.Klass.inc
Klass_inc = default_args.Klass.inc
else:
Klass_inc = default_args.Klass_inc
if Klass_inc(100, default_args.Klass(22)).val != 122: if Klass_inc(100, default_args.Klass(22)).val != 122:
raise RuntimeError("Klass::inc failed") raise RuntimeError("Klass::inc failed")

View file

@ -1,10 +1,6 @@
import director_abstract import director_abstract
def is_new_style_class(cls):
return hasattr(cls, "__class__")
class MyFoo(director_abstract.Foo): class MyFoo(director_abstract.Foo):
def __init__(self): def __init__(self):
@ -44,20 +40,12 @@ me1 = MyExample1()
if director_abstract.Example1_get_color(me1, 1, 2, 3) != 1: if director_abstract.Example1_get_color(me1, 1, 2, 3) != 1:
raise RuntimeError raise RuntimeError
if is_new_style_class(MyExample2):
MyExample2_static = MyExample2
else:
MyExample2_static = MyExample2(0, 0)
me2 = MyExample2(1, 2) me2 = MyExample2(1, 2)
if MyExample2_static.get_color(me2, 1, 2, 3) != 2: if MyExample2.get_color(me2, 1, 2, 3) != 2:
raise RuntimeError raise RuntimeError
if is_new_style_class(MyExample3):
MyExample3_static = MyExample3
else:
MyExample3_static = MyExample3()
me3 = MyExample3() me3 = MyExample3()
if MyExample3_static.get_color(me3, 1, 2, 3) != 3: if MyExample3.get_color(me3, 1, 2, 3) != 3:
raise RuntimeError raise RuntimeError
error = 1 error = 1

View file

@ -1,9 +1,6 @@
from global_namespace import * from global_namespace import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
k1 = Klass1() k1 = Klass1()
k2 = Klass2() k2 = Klass2()
k3 = Klass3() k3 = Klass3()
@ -12,12 +9,8 @@ k5 = Klass5()
k6 = Klass6() k6 = Klass6()
k7 = Klass7() k7 = Klass7()
if is_new_style_class(KlassMethods): KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static = KlassMethods KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
else:
KlassMethods_static = KlassMethods()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1A() k1 = getKlass1A()
k2 = getKlass2A() k2 = getKlass2A()
@ -27,8 +20,8 @@ k5 = getKlass5A()
k6 = getKlass6A() k6 = getKlass6A()
k7 = getKlass7A() k7 = getKlass7A()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1B() k1 = getKlass1B()
k2 = getKlass2B() k2 = getKlass2B()
@ -38,21 +31,11 @@ k5 = getKlass5B()
k6 = getKlass6B() k6 = getKlass6B()
k7 = getKlass7B() k7 = getKlass7B()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7) KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7) KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
if is_new_style_class(XYZMethods): XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods_static = XYZMethods XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
else:
XYZMethods_static = XYZMethods()
XYZMethods_static.methodA(
XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods_static.methodB(
XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
if is_new_style_class(TheEnumMethods): TheEnumMethods.methodA(theenum1, theenum2, theenum3)
TheEnumMethods_static = TheEnumMethods TheEnumMethods.methodA(theenum1, theenum2, theenum3)
else:
TheEnumMethods_static = TheEnumMethods()
TheEnumMethods_static.methodA(theenum1, theenum2, theenum3)
TheEnumMethods_static.methodA(theenum1, theenum2, theenum3)

View file

@ -6,9 +6,6 @@ def check(a, b):
raise RuntimeError(str(a) + " does not equal " + str(b)) raise RuntimeError(str(a) + " does not equal " + str(b))
def is_new_style_class(cls):
return hasattr(cls, "__class__")
#### Class #### #### Class ####
# No implicit conversion # No implicit conversion
@ -45,17 +42,13 @@ check(2, A_int(1.0).get())
check(3, A_int(B()).get()) check(3, A_int(B()).get())
check(4, A_int("hello").get()) check(4, A_int("hello").get())
if is_new_style_class(A_int): check(1, A_int.sget(1))
A_int_static = A_int check(2, A_int.sget(1.0))
else: check(3, A_int.sget(B()))
A_int_static = 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: # explicit constructor:
try: try:
check(4, A_int_static.sget("hello")) check(4, A_int.sget("hello"))
raise RuntimeError raise RuntimeError
except TypeError: except TypeError:
pass pass

View file

@ -1,10 +1,6 @@
from li_boost_shared_ptr_bits import * from li_boost_shared_ptr_bits import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def check(nd): def check(nd):
nd.i = 200 nd.i = 200
i = nd.i i = nd.i
@ -35,7 +31,4 @@ if sum != 66:
raise "sum is wrong" raise "sum is wrong"
################################ ################################
if is_new_style_class(HiddenDestructor): p = HiddenDestructor.create()
p = HiddenDestructor.create()
else:
p = HiddenDestructor_create()

View file

@ -1,9 +1,5 @@
from namespace_class import * from namespace_class import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
try: try:
p = Private1() p = Private1()
error = 1 error = 1
@ -22,10 +18,7 @@ except:
if (error): if (error):
raise RuntimeError, "Private2 is private" raise RuntimeError, "Private2 is private"
if is_new_style_class(EulerT3D): EulerT3D.toFrame(1, 1, 1)
EulerT3D.toFrame(1, 1, 1)
else:
EulerT3D().toFrame(1, 1, 1)
b = BooT_i() b = BooT_i()
b = BooT_H() b = BooT_H()
@ -40,7 +33,6 @@ f.moo(1)
f = FooT_H() f = FooT_H()
f.foo(Hi) f.foo(Hi)
if is_new_style_class(FooT_H): f_type = str(type(f))
f_type = str(type(f)) if f_type.find("'namespace_class.FooT_H'") == -1:
if f_type.find("'namespace_class.FooT_H'") == -1: raise RuntimeError("Incorrect type: " + f_type)
raise RuntimeError("Incorrect type: " + f_type)

View file

@ -1,9 +1,5 @@
from overload_template_fast import * from overload_template_fast import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
f = foo() f = foo()
a = maximum(3, 4) a = maximum(3, 4)
@ -145,9 +141,6 @@ if (nsoverload() != 1050):
raise RuntimeError, ("nsoverload(const char *)") raise RuntimeError, ("nsoverload(const char *)")
if is_new_style_class(A): A.foo(1)
A.foo(1)
else:
A_foo(1)
b = B() b = B()
b.foo(1) b.foo(1)

View file

@ -1,19 +1,13 @@
from python_append import * from python_append import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
# test not relevant for -builtin # test not relevant for -builtin
if is_python_builtin(): if is_python_builtin():
exit(0) exit(0)
t = Test() t = Test()
t.funk() t.funk()
if is_new_style_class(Test): t.static_func()
t.static_func()
else:
Test_static_func()
if grabpath() != os.path.dirname(mypath): if grabpath() != os.path.dirname(mypath):
raise RuntimeError("grabpath failed") raise RuntimeError("grabpath failed")

View file

@ -9,7 +9,7 @@ def check(got, expected):
raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list)) raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list))
# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options # When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options
# such as -O, -builtin, -classic produce different initial indentation. # such as -O and -builtin may produce different initial indentation.
check(inspect.getdoc(DocStrings.docstring1), check(inspect.getdoc(DocStrings.docstring1),
" line 1\n" " line 1\n"

View file

@ -3,17 +3,11 @@ import python_pickle
import pickle import pickle
import sys import sys
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def check(p): def check(p):
msg = p.msg msg = p.msg
if msg != "hi there": if msg != "hi there":
raise RuntimeError("Bad, got: " + msg) raise RuntimeError("Bad, got: " + msg)
if not is_new_style_class(python_pickle.PickleMe):
sys.exit(0)
python_pickle.cvar.debug = False python_pickle.cvar.debug = False
p = python_pickle.PickleMe("hi there") p = python_pickle.PickleMe("hi there")

View file

@ -6,9 +6,6 @@ def check_unorderable_types(exception):
# raise RuntimeError("A TypeError 'unorderable types' exception was expected"), None, sys.exc_info()[2] # raise RuntimeError("A TypeError 'unorderable types' exception was expected"), None, sys.exc_info()[2]
pass # Exception message seems to vary from one version of Python to another pass # Exception message seems to vary from one version of Python to another
def is_new_style_class(cls):
return hasattr(cls, "__class__")
base1 = python_richcompare.BaseClass(1) base1 = python_richcompare.BaseClass(1)
base2 = python_richcompare.BaseClass(2) base2 = python_richcompare.BaseClass(2)
base3 = python_richcompare.BaseClass(3) base3 = python_richcompare.BaseClass(3)
@ -103,39 +100,37 @@ if not (a2 <= b2):
# Check inequalities to other objects # Check inequalities to other objects
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
if is_new_style_class(python_richcompare.BaseClass): if sys.version_info[0:2] < (3, 0):
# Skip testing -classic option if (base1 < 42):
if sys.version_info[0:2] < (3, 0): raise RuntimeError("Comparing class to incompatible type, < returned True")
if (base1 < 42): if (base1 <= 42):
raise RuntimeError("Comparing class to incompatible type, < returned True") raise RuntimeError("Comparing class to incompatible type, <= returned True")
if (base1 <= 42): if not (base1 > 42):
raise RuntimeError("Comparing class to incompatible type, <= returned True") raise RuntimeError("Comparing class to incompatible type, > returned False")
if not (base1 > 42): if not (base1 >= 42):
raise RuntimeError("Comparing class to incompatible type, > returned False") raise RuntimeError("Comparing class to incompatible type, >= returned False")
if not (base1 >= 42): else:
raise RuntimeError("Comparing class to incompatible type, >= returned False") # Python 3 throws: TypeError: unorderable types
else: try:
# Python 3 throws: TypeError: unorderable types res = base1 < 42
try: raise RuntimeError("Failed to throw")
res = base1 < 42 except TypeError,e:
raise RuntimeError("Failed to throw") check_unorderable_types(e)
except TypeError,e: try:
check_unorderable_types(e) res = base1 <= 42
try: raise RuntimeError("Failed to throw")
res = base1 <= 42 except TypeError,e:
raise RuntimeError("Failed to throw") check_unorderable_types(e)
except TypeError,e: try:
check_unorderable_types(e) res = base1 > 42
try: raise RuntimeError("Failed to throw")
res = base1 > 42 except TypeError,e:
raise RuntimeError("Failed to throw") check_unorderable_types(e)
except TypeError,e: try:
check_unorderable_types(e) res = base1 >= 42
try: raise RuntimeError("Failed to throw")
res = base1 >= 42 except TypeError,e:
raise RuntimeError("Failed to throw") check_unorderable_types(e)
except TypeError,e:
check_unorderable_types(e)
# Check inequalities used for ordering # Check inequalities used for ordering
#------------------------------------------------------------------------- #-------------------------------------------------------------------------

View file

@ -1,9 +1,6 @@
from smart_pointer_member import * from smart_pointer_member import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
f = Foo() f = Foo()
f.y = 1 f.y = 1
@ -24,6 +21,5 @@ if b.x != f.x:
if b.z != f.z: if b.z != f.z:
raise RuntimeError raise RuntimeError
if is_new_style_class(Bar): # feature not supported in old style classes if Foo.z == Bar.z:
if Foo.z == Bar.z: raise RuntimeError
raise RuntimeError

View file

@ -29,8 +29,6 @@
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
and works for modern (-modern) and plain python.
*/ */

View file

@ -41,9 +41,6 @@ The implementation is based on this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
and works for modern (-modern) and plain python. We do not use __slots__,
so, it works with old python versions.
*/ */
#define %pythonnondynamic %feature("python:nondynamic", "1") #define %pythonnondynamic %feature("python:nondynamic", "1")

View file

@ -65,8 +65,6 @@ static String *methods;
static String *class_name; static String *class_name;
static String *shadow_indent = 0; static String *shadow_indent = 0;
static int in_class = 0; static int in_class = 0;
static int classic = 0;
static int modern = 0;
static int new_repr = 1; static int new_repr = 1;
static int no_header_file = 0; static int no_header_file = 0;
static int max_bases = 0; static int max_bases = 0;
@ -91,13 +89,11 @@ static int nobuildnone = 0;
static int safecstrings = 0; static int safecstrings = 0;
static int dirvtable = 0; static int dirvtable = 0;
static int doxygen = 0; static int doxygen = 0;
static int proxydel = 1;
static int fastunpack = 0; static int fastunpack = 0;
static int fastproxy = 0; static int fastproxy = 0;
static int fastquery = 0; static int fastquery = 0;
static int fastinit = 0; static int fastinit = 0;
static int olddefs = 0; static int olddefs = 0;
static int modernargs = 0;
static int aliasobj0 = 0; static int aliasobj0 = 0;
static int castmode = 0; static int castmode = 0;
static int extranative = 0; static int extranative = 0;
@ -123,7 +119,6 @@ Python Options (available with -python)\n\
-buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\ -buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\
-builtin - Create new python built-in types, rather than proxy classes, for better performance\n\ -builtin - Create new python built-in types, rather than proxy classes, for better performance\n\
-castmode - Enable the casting mode, which allows implicit cast between types in python\n\ -castmode - Enable the casting mode, which allows implicit cast between types in python\n\
-classic - Use classic classes only\n\
-classptr - Generate shadow 'ClassPtr' as in older swig versions\n\ -classptr - Generate shadow 'ClassPtr' as in older swig versions\n\
-cppcast - Enable C++ casting operators (default) \n\ -cppcast - Enable C++ casting operators (default) \n\
-dirvtable - Generate a pseudo virtual table for directors for faster dispatch \n\ -dirvtable - Generate a pseudo virtual table for directors for faster dispatch \n\
@ -137,9 +132,7 @@ Python Options (available with -python)\n\
-fastquery - Use fast query mechanism for types \n\ -fastquery - Use fast query mechanism for types \n\
-globals <name> - Set <name> used to access C global variable [default: 'cvar']\n\ -globals <name> - Set <name> used to access C global variable [default: 'cvar']\n\
-interface <lib>- Set the lib name to <lib>\n\ -interface <lib>- Set the lib name to <lib>\n\
-keyword - Use keyword arguments\n\ -keyword - Use keyword arguments\n";
-modern - Use modern python features only, without compatibility code\n\
-modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n";
static const char *usage2 = "\ static const char *usage2 = "\
-newrepr - Use more informative version of __repr__ in proxy classes (default) \n\ -newrepr - Use more informative version of __repr__ in proxy classes (default) \n\
-newvwm - New value wrapper mode, use only when everything else fails \n\ -newvwm - New value wrapper mode, use only when everything else fails \n\
@ -154,14 +147,11 @@ static const char *usage2 = "\
-nofastunpack - Use traditional UnpackTuple method to parse the argument functions (default) \n\ -nofastunpack - Use traditional UnpackTuple method to parse the argument functions (default) \n\
-nofastproxy - Use traditional proxy mechanism for member methods (default) \n\ -nofastproxy - Use traditional proxy mechanism for member methods (default) \n\
-nofastquery - Use traditional query mechanism for types (default) \n\ -nofastquery - Use traditional query mechanism for types (default) \n\
-noh - Don't generate the output header file\n\ -noh - Don't generate the output header file\n";
-nomodern - Don't use modern python features which are not backwards compatible \n\
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n";
static const char *usage3 = "\ static const char *usage3 = "\
-noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\ -noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\
-nooutputtuple - Use a PyList for appending output values (default) \n\ -nooutputtuple - Use a PyList for appending output values (default) \n\
-noproxy - Don't generate proxy classes \n\ -noproxy - Don't generate proxy classes \n\
-noproxydel - Don't generate the redundant __del__ method \n\
-noproxyimport - Don't insert proxy import statements derived from the %import directive \n\ -noproxyimport - Don't insert proxy import statements derived from the %import directive \n\
-nortti - Disable the use of the native C++ RTTI with directors\n\ -nortti - Disable the use of the native C++ RTTI with directors\n\
-nosafecstrings - Avoid extra strings copies when possible (default)\n\ -nosafecstrings - Avoid extra strings copies when possible (default)\n\
@ -169,14 +159,13 @@ static const char *usage3 = "\
-olddefs - Keep the old method definitions even when using fastproxy\n\ -olddefs - Keep the old method definitions even when using fastproxy\n\
-oldrepr - Use shorter and old version of __repr__ in proxy classes\n\ -oldrepr - Use shorter and old version of __repr__ in proxy classes\n\
-outputtuple - Use a PyTuple for outputs instead of a PyList (use carefully with legacy interfaces) \n\ -outputtuple - Use a PyTuple for outputs instead of a PyList (use carefully with legacy interfaces) \n\
-proxydel - Generate a __del__ method even though it is now redundant (default) \n\
-py3 - Generate code with Python 3 specific features and syntax\n\ -py3 - Generate code with Python 3 specific features and syntax\n\
-relativeimport - Use relative python imports \n\ -relativeimport - Use relative python imports \n\
-safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\ -safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\
-threads - Add thread support for all the interface\n\ -threads - Add thread support for all the interface\n\
-O - Enable the following optimization options: \n\ -O - Enable the following optimization options: \n\
-modern -fastdispatch -nosafecstrings -fvirtual -noproxydel \n\ -fastdispatch -nosafecstrings -fvirtual\n\
-fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone \n\ -fastproxy -fastinit -fastunpack -fastquery -nobuildnone\n\
\n"; \n";
static String *getSlot(Node *n = NULL, const char *key = NULL, String *default_slot = NULL) { static String *getSlot(Node *n = NULL, const char *key = NULL, String *default_slot = NULL) {
@ -392,11 +381,6 @@ public:
use_kw = 1; use_kw = 1;
SWIG_cparse_set_compact_default_args(1); SWIG_cparse_set_compact_default_args(1);
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i], "-classic") == 0) {
classic = 1;
modernargs = 0;
modern = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-cppcast") == 0) { } else if (strcmp(argv[i], "-cppcast") == 0) {
cppcast = 1; cppcast = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
@ -491,33 +475,11 @@ public:
} else if (strcmp(argv[i], "-noextranative") == 0) { } else if (strcmp(argv[i], "-noextranative") == 0) {
extranative = 0; extranative = 0;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i], "-modernargs") == 0) {
modernargs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nomodernargs") == 0) {
modernargs = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-aliasobj0") == 0) { } else if (strcmp(argv[i], "-aliasobj0") == 0) {
aliasobj0 = 1; aliasobj0 = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noaliasobj0") == 0) { } else if (strcmp(argv[i], "-noaliasobj0") == 0) {
aliasobj0 = 0; aliasobj0 = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-proxydel") == 0) {
proxydel = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noproxydel") == 0) {
proxydel = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-modern") == 0) {
classic = 0;
modern = 1;
modernargs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nomodern") == 0) {
modern = 0;
modernargs = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noh") == 0) { } else if (strcmp(argv[i], "-noh") == 0) {
no_header_file = 1; no_header_file = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
@ -527,18 +489,14 @@ public:
no_header_file = 1; no_header_file = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i], "-O") == 0) { } else if (strcmp(argv[i], "-O") == 0) {
classic = 0;
modern = 1;
safecstrings = 0; safecstrings = 0;
buildnone = 0; buildnone = 0;
nobuildnone = 1; nobuildnone = 1;
classptr = 0; classptr = 0;
proxydel = 0;
fastunpack = 1; fastunpack = 1;
fastproxy = 1; fastproxy = 1;
fastinit = 1; fastinit = 1;
fastquery = 1; fastquery = 1;
modernargs = 1;
Wrapper_fast_dispatch_mode_set(1); Wrapper_fast_dispatch_mode_set(1);
Wrapper_virtual_elimination_mode_set(1); Wrapper_virtual_elimination_mode_set(1);
Swig_mark_arg(i); Swig_mark_arg(i);
@ -557,16 +515,21 @@ public:
} else if (strcmp(argv[i], "-relativeimport") == 0) { } else if (strcmp(argv[i], "-relativeimport") == 0) {
relativeimport = 1; relativeimport = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i], "-modern") == 0 ||
strcmp(argv[i], "-modernargs") == 0 ||
strcmp(argv[i], "-noproxydel") == 0) {
Printf(stderr, "Option %s is now always on.\n", argv[i]);
} else if (strcmp(argv[i], "-classic") == 0 ||
strcmp(argv[i], "-nomodern") == 0 ||
strcmp(argv[i], "-nomodernargs") == 0 ||
strcmp(argv[i], "-proxydel") == 0) {
Printf(stderr, "*** %s is no longer supported.\n", argv[i]);
SWIG_exit(EXIT_FAILURE);
} }
} }
} }
if (py3) {
/* force disable features that not compatible with Python 3.x */
classic = 0;
}
if (cppcast) { if (cppcast) {
Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
} }
@ -745,10 +708,6 @@ public:
Printf(f_runtime, "#define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS\n"); Printf(f_runtime, "#define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS\n");
} }
if (classic) {
Printf(f_runtime, "#define SWIG_PYTHON_CLASSIC\n");
}
if (builtin) { if (builtin) {
Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n"); Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n");
} }
@ -893,8 +852,6 @@ public:
Printf(f_shadow, "_swig_new_instance_method = %s.SWIG_PyInstanceMethod_New\n", module); Printf(f_shadow, "_swig_new_instance_method = %s.SWIG_PyInstanceMethod_New\n", module);
} }
/* if (!modern) */
/* always needed, a class can be forced to be no-modern, such as an exception */
{ {
// Python-2.2 object hack // Python-2.2 object hack
Printv(f_shadow, Printv(f_shadow,
@ -911,15 +868,7 @@ public:
tab4, "if not static:\n", tab4, "if not static:\n",
#endif #endif
NIL); NIL);
if (!classic) { Printv(f_shadow, tab4, tab4, "object.__setattr__(self, name, value)\n", NIL);
if (!modern)
Printv(f_shadow, tab4, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, tab4, "object.__setattr__(self, name, value)\n", NIL);
if (!modern)
Printv(f_shadow, tab4, tab4, "else:\n", tab4, NIL);
}
if (classic || !modern)
Printv(f_shadow, tab4, tab4, "self.__dict__[name] = value\n", NIL);
Printv(f_shadow, Printv(f_shadow,
tab4, "else:\n", tab4, "else:\n",
tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
@ -936,58 +885,49 @@ public:
"\n", "def _swig_repr(self):\n", "\n", "def _swig_repr(self):\n",
tab4, "try:\n", tab8, "strthis = \"proxy of \" + self.this.__repr__()\n", tab4, "try:\n", tab8, "strthis = \"proxy of \" + self.this.__repr__()\n",
tab4, "except __builtin__.Exception:\n", tab8, "strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); tab4, "except __builtin__.Exception:\n", tab8, "strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
if (!classic && !modern) {
Printv(f_shadow,
"try:\n",
tab4, "_object = object\n", tab4, "_newclass = 1\n",
"except __builtin__.Exception:\n",
tab4, "class _object:\n", tab8, "pass\n", tab4, "_newclass = 0\n\n", NIL);
}
} }
if (modern) {
Printv(f_shadow, "\n", Printv(f_shadow, "\n",
"def _swig_setattr_nondynamic_instance_variable(set):\n", "def _swig_setattr_nondynamic_instance_variable(set):\n",
tab4, "def set_instance_attr(self, name, value):\n", tab4, "def set_instance_attr(self, name, value):\n",
#ifdef USE_THISOWN #ifdef USE_THISOWN
tab4, tab4, "if name in (\"this\", \"thisown\"):\n", tab4, tab4, "if name in (\"this\", \"thisown\"):\n",
tab4, tab4, tab4, "set(self, name, value)\n", tab4, tab4, tab4, "set(self, name, value)\n",
#else #else
tab4, tab4, "if name == \"thisown\":\n", tab4, tab4, "if name == \"thisown\":\n",
tab4, tab4, tab4, "self.this.own(value)\n", tab4, tab4, tab4, "self.this.own(value)\n",
tab4, tab4, "elif name == \"this\":\n", tab4, tab4, "elif name == \"this\":\n",
tab4, tab4, tab4, "set(self, name, value)\n", tab4, tab4, tab4, "set(self, name, value)\n",
#endif #endif
tab4, tab4, "elif hasattr(self, name) and isinstance(getattr(type(self), name), property):\n", tab4, tab4, "elif hasattr(self, name) and isinstance(getattr(type(self), name), property):\n",
tab4, tab4, tab4, "set(self, name, value)\n", tab4, tab4, tab4, "set(self, name, value)\n",
tab4, tab4, "else:\n", tab4, tab4, "else:\n",
tab4, tab4, tab4, "raise AttributeError(\"You cannot add instance attributes to %s\" % self)\n", tab4, tab4, tab4, "raise AttributeError(\"You cannot add instance attributes to %s\" % self)\n",
tab4, "return set_instance_attr\n\n", NIL); tab4, "return set_instance_attr\n\n", NIL);
Printv(f_shadow, "\n", Printv(f_shadow, "\n",
"def _swig_setattr_nondynamic_class_variable(set):\n", "def _swig_setattr_nondynamic_class_variable(set):\n",
tab4, "def set_class_attr(cls, name, value):\n", tab4, "def set_class_attr(cls, name, value):\n",
tab4, tab4, "if hasattr(cls, name) and not isinstance(getattr(cls, name), property):\n", tab4, tab4, "if hasattr(cls, name) and not isinstance(getattr(cls, name), property):\n",
tab4, tab4, tab4, "set(cls, name, value)\n", tab4, tab4, tab4, "set(cls, name, value)\n",
tab4, tab4, "else:\n", tab4, tab4, "else:\n",
tab4, tab4, tab4, "raise AttributeError(\"You cannot add class attributes to %s\" % cls)\n", tab4, tab4, tab4, "raise AttributeError(\"You cannot add class attributes to %s\" % cls)\n",
tab4, "return set_class_attr\n\n", NIL); tab4, "return set_class_attr\n\n", NIL);
Printv(f_shadow, "\n", Printv(f_shadow, "\n",
"def _swig_add_metaclass(metaclass):\n", "def _swig_add_metaclass(metaclass):\n",
tab4, "\"\"\"Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass\"\"\"\n", tab4, "\"\"\"Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass\"\"\"\n",
tab4, "def wrapper(cls):\n", tab4, "def wrapper(cls):\n",
tab4, tab4, "return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())\n", tab4, tab4, "return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())\n",
tab4, "return wrapper\n\n", NIL); tab4, "return wrapper\n\n", NIL);
Printv(f_shadow, "\n", Printv(f_shadow, "\n",
"class _SwigNonDynamicMeta(type):\n", "class _SwigNonDynamicMeta(type):\n",
tab4, "\"\"\"Meta class to enforce nondynamic attributes (no new attributes) for a class\"\"\"\n", tab4, "\"\"\"Meta class to enforce nondynamic attributes (no new attributes) for a class\"\"\"\n",
tab4, "__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)\n", tab4, "__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)\n",
"\n", NIL); "\n", NIL);
Printv(f_shadow, "\n", NIL); Printv(f_shadow, "\n", NIL);
}
if (directorsEnabled()) { if (directorsEnabled()) {
Printv(f_shadow, "import weakref\n\n", NIL); Printv(f_shadow, "import weakref\n\n", NIL);
@ -1057,9 +997,6 @@ public:
if (shadow) { if (shadow) {
Swig_banner_target_lang(f_shadow_py, "#"); Swig_banner_target_lang(f_shadow_py, "#");
if (!modern && !classic) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
if (Len(f_shadow_begin) > 0) if (Len(f_shadow_begin) > 0)
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL); Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
if (Len(f_shadow_after_begin) > 0) if (Len(f_shadow_after_begin) > 0)
@ -2860,7 +2797,7 @@ public:
over_varargs = true; over_varargs = true;
} }
int funpack = modernargs && fastunpack && !varargs && !over_varargs && !allow_kwargs; int funpack = fastunpack && !varargs && !over_varargs && !allow_kwargs;
int noargs = funpack && (tuple_required == 0 && tuple_arguments == 0); int noargs = funpack && (tuple_required == 0 && tuple_arguments == 0);
int onearg = funpack && (tuple_required == 1 && tuple_arguments == 1); int onearg = funpack && (tuple_required == 1 && tuple_arguments == 1);
@ -3007,7 +2944,7 @@ public:
if (builtin && !funpack && in_class && tuple_arguments == 0) { if (builtin && !funpack && in_class && tuple_arguments == 0) {
Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, \"%s takes no arguments\");\n", iname); Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, \"%s takes no arguments\");\n", iname);
} else if (use_parse || allow_kwargs || !modernargs) { } else if (use_parse || allow_kwargs) {
Printf(parse_args, ":%s\"", iname); Printf(parse_args, ":%s\"", iname);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
funpack = 0; funpack = 0;
@ -3677,14 +3614,10 @@ public:
Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname); Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname);
Printf(f_wrappers, tab2 "PyObject *module;\n", tm); Printf(f_wrappers, tab2 "PyObject *module;\n", tm);
Printf(f_wrappers, tab2 "PyObject *d;\n"); Printf(f_wrappers, tab2 "PyObject *d;\n");
if (modernargs) { if (fastunpack) {
if (fastunpack) { Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args,(char *)\"swigconstant\", 1, 1,&module)) return NULL;\n");
Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args,(char *)\"swigconstant\", 1, 1,&module)) return NULL;\n");
} else {
Printf(f_wrappers, tab2 "if (!PyArg_UnpackTuple(args,(char *)\"swigconstant\", 1, 1,&module)) return NULL;\n");
}
} else { } else {
Printf(f_wrappers, tab2 "if (!PyArg_ParseTuple(args,(char *)\"O:swigconstant\", &module)) return NULL;\n"); Printf(f_wrappers, tab2 "if (!PyArg_UnpackTuple(args,(char *)\"swigconstant\", 1, 1,&module)) return NULL;\n");
} }
Printf(f_wrappers, tab2 "d = PyModule_GetDict(module);\n"); Printf(f_wrappers, tab2 "d = PyModule_GetDict(module);\n");
Printf(f_wrappers, tab2 "if (!d) return NULL;\n"); Printf(f_wrappers, tab2 "if (!d) return NULL;\n");
@ -4020,7 +3953,7 @@ public:
String *mname = SwigType_manglestr(rname); String *mname = SwigType_manglestr(rname);
String *pmname = SwigType_manglestr(pname); String *pmname = SwigType_manglestr(pname);
String *templ = NewStringf("SwigPyBuiltin_%s", mname); String *templ = NewStringf("SwigPyBuiltin_%s", mname);
int funpack = modernargs && fastunpack; int funpack = fastunpack;
static String *tp_new = NewString("PyType_GenericNew"); static String *tp_new = NewString("PyType_GenericNew");
Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL); Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL);
@ -4433,8 +4366,6 @@ public:
} }
virtual int classHandler(Node *n) { virtual int classHandler(Node *n) {
int oldclassic = classic;
int oldmodern = modern;
File *f_shadow_file = f_shadow; File *f_shadow_file = f_shadow;
Node *base_node = NULL; Node *base_node = NULL;
@ -4444,19 +4375,6 @@ public:
have_constructor = 0; have_constructor = 0;
have_repr = 0; have_repr = 0;
if (GetFlag(n, "feature:classic")) {
classic = 1;
modern = 0;
}
if (GetFlag(n, "feature:modern")) {
classic = 0;
modern = 1;
}
if (GetFlag(n, "feature:exceptionclass")) {
classic = 1;
modern = 0;
}
class_name = Getattr(n, "sym:name"); class_name = Getattr(n, "sym:name");
real_classname = Getattr(n, "name"); real_classname = Getattr(n, "name");
@ -4532,7 +4450,7 @@ public:
Delete(rname); Delete(rname);
} }
} else { } else {
if (modern && !py3) { if (!py3) {
if (GetFlag(n, "feature:python:nondynamic")) if (GetFlag(n, "feature:python:nondynamic"))
Printv(f_shadow, "@_swig_add_metaclass(_SwigNonDynamicMeta)\n", NIL); Printv(f_shadow, "@_swig_add_metaclass(_SwigNonDynamicMeta)\n", NIL);
} }
@ -4541,13 +4459,12 @@ public:
if (Len(base_class)) { if (Len(base_class)) {
Printf(f_shadow, "(%s)", base_class); Printf(f_shadow, "(%s)", base_class);
} else { } else {
if (!classic) {
Printf(f_shadow, modern ? "(object" : "(_object");
Printf(f_shadow, modern && py3 && GetFlag(n, "feature:python:nondynamic") ? ", metaclass=_SwigNonDynamicMeta" : "", ")");
Printf(f_shadow, ")");
}
if (GetFlag(n, "feature:exceptionclass")) { if (GetFlag(n, "feature:exceptionclass")) {
Printf(f_shadow, "(Exception)"); Printf(f_shadow, "(Exception)");
} else {
Printf(f_shadow, "(object");
Printf(f_shadow, py3 && GetFlag(n, "feature:python:nondynamic") ? ", metaclass=_SwigNonDynamicMeta" : "", ")");
Printf(f_shadow, ")");
} }
} }
@ -4560,30 +4477,10 @@ public:
Printv(f_shadow, tab4, str, "\n\n", NIL); Printv(f_shadow, tab4, str, "\n\n", NIL);
} }
if (!modern) { Printv(f_shadow, tab4, "thisown = property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); /* Add static attribute */
if (Len(base_class)) { if (GetFlag(n, "feature:python:nondynamic")) {
Printv(f_shadow, tab4, "for _s in [", base_class, "]:\n", tab8, "__swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))\n", NIL); Printv(f_shadow_file, tab4, "__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n", NIL);
}
if (!GetFlag(n, "feature:python:nondynamic")) {
Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL);
} else {
Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL);
}
Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL);
if (Len(base_class)) {
Printv(f_shadow, tab4, "for _s in [", base_class, "]:\n", tab8, "__swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))\n", NIL);
}
Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL);
} else {
Printv(f_shadow, tab4, "thisown = property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
/* Add static attribute */
if (GetFlag(n, "feature:python:nondynamic")) {
Printv(f_shadow_file, tab4, "__setattr__ = _swig_setattr_nondynamic_instance_variable(object.__setattr__)\n", NIL);
}
} }
} }
} }
@ -4634,14 +4531,10 @@ public:
} else { } else {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
Printv(f_wrappers, " PyObject *obj;\n", NIL); Printv(f_wrappers, " PyObject *obj;\n", NIL);
if (modernargs) { if (fastunpack) {
if (fastunpack) { Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char *)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char *)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
} else {
Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char *)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
}
} else { } else {
Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char *)\"O:swigregister\", &obj)) return NULL;\n", NIL); Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char *)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
} }
Printv(f_wrappers, Printv(f_wrappers,
@ -4691,15 +4584,10 @@ public:
/* Now the Ptr class */ /* Now the Ptr class */
if (classptr) { if (classptr) {
Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL);
if (!modern) { Printv(f_shadow_file,
Printv(f_shadow_file, tab8, "try:\n", tab8, tab4, "self.this.append(this)\n",
tab8, "try:\n", tab8, tab4, "self.this.append(this)\n", tab8, "except __builtin__.Exception:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n", NIL);
tab8, "except __builtin__.Exception:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n", NIL);
} else {
Printv(f_shadow_file,
tab8, "try:\n", tab8, tab4, "self.this.append(this)\n",
tab8, "except __builtin__.Exception:\n", tab8, tab4, "self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n", NIL);
}
} }
Printf(f_shadow_file, "\n"); Printf(f_shadow_file, "\n");
@ -4718,9 +4606,6 @@ public:
Clear(builtin_methods); Clear(builtin_methods);
} }
classic = oldclassic;
modern = oldmodern;
/* Restore shadow file back to original version */ /* Restore shadow file back to original version */
Delete(f_shadow); Delete(f_shadow);
f_shadow = f_shadow_file; f_shadow = f_shadow_file;
@ -4867,7 +4752,7 @@ public:
String *fullname = Swig_name_member(NSPACE_TODO, class_name, symname); String *fullname = Swig_name_member(NSPACE_TODO, class_name, symname);
String *wname = Swig_name_wrapper(fullname); String *wname = Swig_name_wrapper(fullname);
Setattr(class_members, symname, n); Setattr(class_members, symname, n);
int funpack = modernargs && fastunpack && !Getattr(n, "sym:overloaded"); int funpack = fastunpack && !Getattr(n, "sym:overloaded");
String *pyflags = NewString("METH_STATIC|"); String *pyflags = NewString("METH_STATIC|");
int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2; int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2;
if (funpack && argcount == 0) if (funpack && argcount == 0)
@ -4913,17 +4798,8 @@ public:
} }
Printv(f_shadow, tab4, symname, " = staticmethod(", symname, ")\n", NIL); Printv(f_shadow, tab4, symname, " = staticmethod(", symname, ")\n", NIL);
} else { } else {
if (!classic) { Printv(f_shadow, tab4, symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
if (!modern) ")\n", NIL);
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
")\n", NIL);
}
if (classic || !modern) {
if (!classic)
Printv(f_shadow, tab4, "else:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
}
} }
} }
return SWIG_OK; return SWIG_OK;
@ -5104,9 +4980,6 @@ public:
} else { } else {
Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL); Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL);
if (!have_pythonprepend(n) && !have_pythonappend(n)) { if (!have_pythonprepend(n) && !have_pythonappend(n)) {
if (proxydel) {
Printv(f_shadow, tab4, "def __del__(self):\n", tab8, "return None\n", NIL);
}
return SWIG_OK; return SWIG_OK;
} }
Printv(f_shadow, tab4, "def __del__(self):\n", NIL); Printv(f_shadow, tab4, "def __del__(self):\n", NIL);
@ -5147,20 +5020,10 @@ public:
String *setname = Swig_name_set(NSPACE_TODO, mname); String *setname = Swig_name_set(NSPACE_TODO, mname);
String *getname = Swig_name_get(NSPACE_TODO, mname); String *getname = Swig_name_get(NSPACE_TODO, mname);
int assignable = is_assignable(n); int assignable = is_assignable(n);
if (!modern) { Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL);
if (assignable) { if (assignable)
Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL); Printv(f_shadow, ", ", module, ".", setname, NIL);
} Printv(f_shadow, ")\n", NIL);
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
}
if (!classic) {
if (!modern)
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL);
if (assignable)
Printv(f_shadow, ", ", module, ".", setname, NIL);
Printv(f_shadow, ")\n", NIL);
}
Delete(mname); Delete(mname);
Delete(setname); Delete(setname);
Delete(getname); Delete(getname);
@ -5206,7 +5069,7 @@ public:
DelWrapper(f); DelWrapper(f);
int assignable = is_assignable(n); int assignable = is_assignable(n);
if (assignable) { if (assignable) {
int funpack = modernargs && fastunpack; int funpack = fastunpack;
Wrapper *f = NewWrapper(); Wrapper *f = NewWrapper();
Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
Wrapper_add_local(f, "res", "int res"); Wrapper_add_local(f, "res", "int res");
@ -5221,15 +5084,7 @@ public:
add_method(setname, wrapsetname, 0, 0, funpack, 1, 1); add_method(setname, wrapsetname, 0, 0, funpack, 1, 1);
DelWrapper(f); DelWrapper(f);
} }
if (!modern && !builtin) { if (!builtin) {
if (assignable) {
Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
}
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
}
if (!classic && !builtin) {
if (!modern)
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL); Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL);
if (assignable) if (assignable)
Printv(f_shadow, ", ", module, ".", setname, NIL); Printv(f_shadow, ", ", module, ".", setname, NIL);
@ -5680,34 +5535,26 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Append(w->code, "PyObject *method = swig_get_method(swig_method_index, swig_method_name);\n"); Append(w->code, "PyObject *method = swig_get_method(swig_method_index, swig_method_name);\n");
if (Len(parse_args) > 0) { if (Len(parse_args) > 0) {
if (use_parse || !modernargs) { if (use_parse) {
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", Swig_cresult_name(), parse_args, arglist); Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", Swig_cresult_name(), parse_args, arglist);
} else { } else {
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunctionObjArgs(method %s, NULL);\n", Swig_cresult_name(), arglist); Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunctionObjArgs(method %s, NULL);\n", Swig_cresult_name(), arglist);
} }
} else { } else {
if (modernargs) { Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n");
Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n"); Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_Call(method, (PyObject *) args, NULL);\n", Swig_cresult_name());
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_Call(method, (PyObject *) args, NULL);\n", Swig_cresult_name());
} else {
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallFunction(method, NULL, NULL);\n", Swig_cresult_name());
}
} }
Append(w->code, "#else\n"); Append(w->code, "#else\n");
if (Len(parse_args) > 0) { if (Len(parse_args) > 0) {
if (use_parse || !modernargs) { if (use_parse) {
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", Swig_cresult_name(), pyname, parse_args, arglist); Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", Swig_cresult_name(), pyname, parse_args, arglist);
} else { } else {
Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname); Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", Swig_cresult_name(), arglist); Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", Swig_cresult_name(), arglist);
} }
} else { } else {
if (!modernargs) { Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", Swig_cresult_name(), pyname); Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n", Swig_cresult_name());
} else {
Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
Printf(w->code, "swig::SwigVar_PyObject %s = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n", Swig_cresult_name());
}
} }
Append(w->code, "#endif\n"); Append(w->code, "#endif\n");