[C++-sig] Re: class data members

David Abrahams dave at boost-consulting.com
Mon Aug 18 22:24:53 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 --------------
An embedded and charset-unspecified text was scrubbed...
Name: foo.cpp
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030818/d5a52478/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.py
Type: application/octet-stream
Size: 499 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20030818/d5a52478/attachment.obj>
-------------- next part --------------

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


More information about the Cplusplus-sig mailing list