[C++-sig] new to python wrapping...

Hugo van der Merwe s13361562 at bach.sun.ac.za
Mon Jan 21 22:24:43 CET 2002


Hello,

I've lately started playing with Python wrapping. Tried both SWIG and
Boost.Python, I'm thinking so far that Boost.Python's C++ and Python
specific nature will make it more ideally suited to what I want to do (I
don't care about bidnings other scripting languages).

I've got two questions so far. One is what happens with garbage
collection: if I create an instance of an object from a Python script,
then add this to e.g. a list in some other C++ class, Python won't know
it is still being used, and will try to garbage collect it?

The other is a problem I'm having with a constructor. It worked
previously, but after the latest changes in the source, I'm getting the
following (it's a pretty ugly looking constructor ;) :

C++ header:

<SNIP>
class TERRAIN_API Terrain
{
public:
    Terrain(const char* szElevationsFilename,const char*
szTextureFilename,const char* szDetailTextureFilename,float
vertexSpacing,float elevationScale,int maxNumTriangles,bool bUseBorders
= false,float offsetX = 0.0f,float offsetY = 0.0f,int numTexturesX =
0,int numTexturesY = 0);
<SNIP>

Boost.Python using wrapper:

<SNIP>
python::class_builder<Terrain> Terrain_class(this_module, "Terrain");
Terrain_class.def(python::constructor<const char*, const char*,
       const char*, float, float, int, bool, float, float, int, int>());
<SNIP>

The error I get when compiling it:

demeterwrap.cpp: In function `void initdemeterwrap(...)':
demeterwrap.cpp:87: wrong number of template arguments (11, should be 10)
/usr/include/boost/python/detail/signatures.hpp:134: provided for
`template <class A1 = struct boost::python::detail::void_t, class A2 =
struct boost::python::detail::void_t, class A3 = struct
boost::python::detail::void_t, class A4 = struct
boost::python::detail::void_t, class A5 = struct
boost::python::detail::void_t, class A6 = struct
boost::python::detail::void_t, class A7 = struct
boost::python::detail::void_t, class A8 = struct
boost::python::detail::void_t, class A9 = struct
boost::python::detail::void_t, class A10 = struct
boost::python::detail::void_t>
boost::python::constructor<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10>'
demeterwrap.cpp:87: confused by earlier errors, bailing out

I'm using a really old Boost, as it seems to be the latest one that is
packaged for Debian, and I'm lazy atm. I'll compile Boost from source if
necessary, but it seems from the Changelogs that Boost.Python hasn't had
much updates since Y2K? Maybe Boost libs used by Boost.Python have
updated, and that makes a difference? The Debian package version is 
1.21.1-1, i.e. some incarnation of 1.21, and I think Boost is currently
at 1.26 or something?

I hope this isn't something silly I've done that causes this, but I
definately count 11 parameters in the C++ constructor, as well as my
attempt at a python wrapping of it...

Any ideas?

Thanks,
Hugo van der Merwe




More information about the Cplusplus-sig mailing list