[cable] CableSwig: Python wrappers don't wrap public member data

Steven Levitt slevitt at siac.com
Wed Sep 10 12:31:37 EDT 2003


I hope this is the appropriate list to which to post questions regarding
CableSwig. Please re-direct me if I'm mistaken.

I've built CableSwig on Windows using Cygwin and well on HP-UX 11 using gcc
3.2 (after a struggle with the default build options.)

I've created a simple test based on a C++ struct with a single, public
integer data member. When I try to generate a Python wrapper for this
struct, the wrapper does not include any code for accessing the data
member.  According to the basic SWIG documentation, SWIG-generated wrappers
should wrap all public data members by default.  I don't understand what is
different about cswig.

Here is the struct I am wrapping, followed by the CABLE configuration file,
and the commands I am using to generate the wrapper.

Test.hpp:
#if !defined(Test_hpp)
#define Test_hpp

struct Test
{
      int anIntegerValue ;
} ;

#endif

TestConfig.cpp:
#include "Test.hpp"

#ifdef CABLE_CONFIGURATION
namespace _cable_
{
    const char* const group="Test";
    namespace wrappers
    {
            // List class wrappers as typedefs.
            // Name of typedef will be wrapped name.
            typedef ::Test Test ;
    }
}
// Additional code to ensure implicit instantiation of
// class templates that are to be wrapped.
#endif

Makefile:
GCCXML=../CableSwigBuild/bin/gccxml
CSWIG=../CableSwigBuild/bin/cswig
ACC=/opt/aCC/bin/aCC
PYTHONPATH=/data/dbk/tools/python/2.3
PYTHONINCLUDE=$(PYTHONPATH)/include/python2.3
PYTHONLIBPATH=$(PYTHONPATH)/lib
PYTHONLIB=python2.3

all : _Test.sl Test.py

Test.xml : TestConfig.cpp Test.hpp
      $(GCCXML) -I. -DCABLE_CONFIGURATION TestConfig.cpp -fxml=Test.xml
-fxml-start=_cable_

Test.py Test_wrap.cxx : Test.xml
      $(CSWIG) -c++ -python Test.xml

_Test.sl : Test.cpp Test_wrap.cxx
      $(ACC) -g -b +z -Dstd= -I. -I$(PYTHONINCLUDE)  Test.cpp Test_wrap.cxx
-o _Test.sl -L$(PYTHONLIBPATH) -l$(PYTHONLIB)

Here is what happens when I try to use the generated wrapper in Python:
>>> import Test
>>> x = Test.Test()
>>> x.anIntegerValue
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "Test.py", line 34, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, Test, name)
  File "Test.py", line 19, in _swig_getattr
    raise AttributeError,name
AttributeError: anIntegerValue

I've grepped the generated Test_wrap.cxx, and there is no reference
anywhere to Test::anIntegerValue.




-----------------------------------------
This message and its attachments may contain  privileged and confidential information.  If you are not the intended recipient(s), you are prohibited from printing, forwarding, saving or copying this email.  If you have received this e-mail in error, please immediately notify the sender and delete this e-mail and its attachments from your computer.




More information about the cable mailing list