#693 Generates wrong python code with -modern

open
Marcelo Matus
python (259)
5
2012-12-21
2006-06-14
Joseph Winston
No

When I use the current cvs version of swig targeting
python, I'm
having a problem with directors, %inline, and
exceptions when using
the -modern flag. An example that fails is included.
To demonstrate
the problem run:

$ make
$ python runme.py

Traceback (most recent call last):
File "runme.py", line 7, in ?
import example
File
"/home/jody/src/Tools/SWIG-CVS/Examples/python/class-exception/example.py",
line 66, in ?
class SpException(SpObject):
File
"/home/jody/src/Tools/SWIG-CVS/Examples/python/class-exception/example.py",
line 68, in SpException
for _s in [SpObject]:
__swig_setmethods__.update(_s.__swig_setmethods__)
AttributeError: type object 'SpObject' has no attribute
'__swig_setmethods__'

The problem occurs with -modern and exceptions because
when python.cxx
sees a feature:exceptionclass it sets classic to 1 and
modern to 0
even though it might have already generated classes
using classic set
to 0 and modern set to 1. A proposed patch is to not
change these
flags in feature:exceptionclass.

Index: python.cxx

RCS file: /cvsroot/swig/SWIG/Source/Modules/python.cxx,v
retrieving revision 1.205
diff -c -r1.205 python.cxx
*** python.cxx 14 Apr 2006 22:16:43 -0000 1.205
--- python.cxx 14 Jun 2006 15:41:20 -0000
***************
*** 2625,2632 ****
modern = 1;
}
if (GetFlag(n,"feature:exceptionclass")) {
! classic = 1;
! modern = 0;
}

shadow_indent = (String *) tab4;
--- 2625,2632 ----
modern = 1;
}
if (GetFlag(n,"feature:exceptionclass")) {
! // classic = 1;
! // modern = 0;
}

shadow_indent = (String *) tab4;

Discussion

  • Joseph Winston
    Joseph Winston
    2006-06-14

     
    Attachments
  • Joseph Winston
    Joseph Winston
    2006-06-14

    Logged In: YES
    user_id=398495

    I know that it is bad form to reply to your own posting, but I
    introduced a bug. Here's a better patch:

     
  • Joseph Winston
    Joseph Winston
    2006-06-14

     
    Attachments