[C++-sig] RE: class data members and boost::python::detail::init_module()
Sam Bloomquist
sam at gabrielinteractive.com
Tue Aug 19 17:21:31 CEST 2003
> "Sam Bloomquist" <sam at gabrielinteractive.com> writes:
>
> > I have an update to the question I posted earlier, shown below.
> It turns
> > out that my crash only happens when the string I am trying to
> set is longer
> > than 15 characters. Anyone have any guesses where the 15
> character limit
> > came from?
> >
> > I am currently working on moving an application from visual
> studio 6.0 to
> > visual studio .net 2003 and boost 1.29.0 to boost 1.30.0 and am
> having a few
> > problems with class data members. My c++ struct and python
> wrapper are as
> > follows:
> >
> > struct JunkObject
> > {
> > bool operator == (JunkObject& jo);
> > std::string m_sName;
> > int m_iID;
> > };
> >
> > class_<JunkObject>("JunkObject")
> > .def_readwrite("name", &JunkObject::m_sName)
> > .def_readwrite("id", &JunkObject::m_iID);
> >
> > # Then in python when I do this...
> >
> > obj = plus.JunkObject()
> > obj.id = 5
> >
> > # where "plus" is my boost python module, everthing is fine.
> But if I do...
> >
> > obj.name = "Bob went for a walk in the park."
> >
> > # my program crashes. Does anyone see something I'm missing?
> This worked
> > fine in msvs 6.0 and boost 1.29.
>
> Sam,
>
> Your example (well, if I fill in the missing details like
> BOOST_PYTHON_MODULE, etc.) works fine with the current Boost CVS and
> MSVC 6.5 for me. I bet you haven't really reduced this to a minimal
> example, have you? I'm fairly certain you'll find your bug if you do
> that. The Jamfile I used to test it was:
>
> -------
> subproject libs/python/user ;
>
> # bring in the rules for python
> SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
> include python.jam ;
>
> extension foo_ext : foo.cpp <include>../../.. ;
> boost-python-runtest foo : foo.py <pyd>foo_ext ;
> ------
>
> I placed it in a subdirectory "user" of $BOOST_ROOT/libs/python along
> with the enclosed:
>
> -------------- next part --------------
> #include <boost/python.hpp>
>
> struct JunkObject
> {
> bool operator == (JunkObject& jo);
> std::string m_sName;
> int m_iID;
> };
>
> using namespace boost::python;
> BOOST_PYTHON_MODULE(foo_ext)
> {
> class_<JunkObject>("JunkObject")
> .def_readwrite("name", &JunkObject::m_sName)
> .def_readwrite("id", &JunkObject::m_iID);
> }
>
> #include "../test/module_tail.cpp"
David,
Thanks for the help. As far as a minimal example goes, the example I gave
is directly from my code (though I've now taken out the operator ==, but it
wasn't causing any problems). For setting up my module I'm using
boost::python::detail::init_module("plus", &Setup);
where Setup is just a function that contains the wrapper class
definitions...
class_<JunkObject>("JunkObject")
.def_readwrite("name", &JunkObject::m_sName)
.def_readwrite("id", &JunkObject::m_iID);
Is this way of initializing the module still used? I can't find much in the
way of documentation on the init_module function.
Also, this problem didn't show up for me until switching to vc7, so I'm not
surprised that it works with 6.5. I do appreciate the help, though, and if
I need to change the way I'm initializing my module so that I use
BOOST_PYTHON_MODULE, that's fine.
-Sam
More information about the Cplusplus-sig
mailing list