From: Abhinandan J. <ja...@he...> - 2007-09-30 21:01:17
|
William Thanks for the prompt response. Here is a small example that illustrates the problem. A.h file ======== class AA { }; B.h file ======== #include "A.h" class BB : public AA { }; B.i file ======== %module B_py // using 1 causes %import to used, while 0 enables %include #if 1 %import "A.h" #else %include "A.h" #endif %include "B.h" ---------------- end of file contents ---------------- Generate swig wrappers using swig -c++ -python B.i twice: once with #if 1 in B.i as is (to use %import) and next with it changed to #if 0 (to use %include). Do a diff between the B_py.py files generated. The first one contains the line class BB(_object): etc. while the second one contains (correctly) the line class BB(AA): etc. I believe the first case (with #if 1) should also be generating the latter output for the BB proxy inheritance. Without this, there is no way for the BB proxy class to get to superclass AA's methods. I am using swig 1.3.31. Thanks Abhi On Sun, Sep 30, 2007 at 07:53:18PM +0100, William S Fulton wrote: > Abhinandan Jain wrote: > > I an having trouble getting Python proxy classes to work when using > > the %import directive. I have a C++ class X and another Y derived from > > X. I am using SWIG to build an extension for class X using an X.i > > file. In Y.i, if I use the > > > > %include X.i > > > > directive, then the resulting Python proxy class Y shows up as derived > > from class X's Python proxy class. However this also leads to > > duplicate wrapper code for some methods being generated as well. My > > understanding is that the correct way to avoid this is to use instead > > the > > > > %import X.i > > > > directive in Y.i. This does indeed get rid of the duplicative > > code. However, the Y's Python proxy class no longer inherits from X's > > Python proxy class, but instead simply from the 'object' class. This > > means that I am no longer able to access any of X's methods from an > > instance of Y in Python. > > > > I suspect that I am either not using the %import directive correctly > > or am misunderstanding its purpose. Any help/advise on this problem > > would be much appreciated. > > > > Thanks in advance. I am using pretty recent version of SWIG from the > > repository. > > > > You aren't doing anything wrong from what you have described. Have you > looked carefully at the warnings? SWIG usually warns if it hasn't parsed > the base class. > > What is happening sounds a bit odd and possibly you have another > %include "X.i" somewhere... you should never mix %import and %include of > the same file. You'll need to cut the code down to a small example in > order for us to help any further. If you are using the SVN version of > SWIG, do you get the same problem using the latest release (1.3.31)? > > William > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user -- Abhinandan Jain, Ph.D. Dynamics and Real-Time Simulation (DARTS) Lab Mobilty and Robotic Systems Section Jet Propulsion Laboratory 4800 Oak Grove Drive, Pasadena, CA 91109 (818)-354-3412 (818)-393-5007 (fax) |