[C++-sig] boost::python std::vector< std::string > crash

John Reid j.reid at mail.cryst.bbk.ac.uk
Thu Jun 22 12:39:15 CEST 2006


Hi,

I'm using boost/python/suite/indexing/vector_indexing_suite.hpp from the 
cvs_head version of boost python on MSVC 8. I'm getting a runtime 
assertion failure when appending to a vector of strings.



I define a module with a vector of strings with the following code:

#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>

#include <vector>

using namespace boost;
using namespace boost::python;
using namespace std;

typedef vector< string > string_vec;

BOOST_PYTHON_MODULE( _bptest )
{
	/**
	A vector of strings.
	*/
	class_< string_vec >( "StringVec" )
		.def( vector_indexing_suite< string_vec >() )
		;
}



I use this python code:

import sys

print 'Importing bptest'
_path_to_module = 
'../bin/Bio/Biopsy/_bptest.pyd/vc-8_0/debug/threading-multi'
sys.path.append( _path_to_module )
import _bptest

print 'Creating string vec'
strings = _bptest.StringVec()

print 'Appending string'
strings.append( 'a' )




and it crashes in "strings.append( 'a' )"



There seems to be very little in the documenation about how std::strings 
are handled. They seem to work fine when used outside containers. Also 
containers of user-defined classes (as in the vector indexing example, 
struct X) and containers of doubles, ints, etc.. seem to work fine.

What am I missing here?



Eventually I want to use a C++ method that accepts a
const std::vector< std::string > &
as an argument. The FAQ it suggests there are two methods to do this: 
vector_indexing and also using custom rvalue converters. Unfortunately 
this documentation seems rather out of date. The instructions to log in 
to cvs to see the example code don't appear to work. I did manage to 
find the code but it is not clear how it could help me.


Any help would be much appreciated.

Thanks,
John.



P.S. here is the stack trace:
 > 
_biopsy.pyd!boost::python::detail::value_destroyer<0>::execute<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > >(const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > * 
p="")  Line 34	C++
 
_biopsy.pyd!boost::python::detail::destroy_referent_impl<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const >(void * p=0x0021fbc8, const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
(void)* __formal=0x00000000)  Line 95 + 0x9 bytes	C++
 
_biopsy.pyd!boost::python::detail::destroy_referent<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const &>(void * p=0x0021fbc8, const 
std::basic_string<char,std::char_traits<char>,std::allocator<char> > & 
(void)* __formal=0x00000000)  Line 101 + 0xb bytes	C++
 
_biopsy.pyd!boost::python::converter::rvalue_from_python_data<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const 
&>::~rvalue_from_python_data<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const &>()  Line 135 + 0xe bytes	C++
 
_biopsy.pyd!boost::python::converter::arg_rvalue_from_python<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const 
&>::~arg_rvalue_from_python<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const &>()  + 0xf bytes	C++
 
_biopsy.pyd!boost::python::arg_from_python<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const 
&>::~arg_from_python<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > const &>()  + 0xf bytes	C++
  	_biopsy.pyd!boost::python::detail::caller_arity<2>::impl<void 
(__cdecl*)(std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > > > 
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > 
const 
&),boost::python::default_call_policies,boost::mpl::vector3<void,std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > > > 
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > 
const &> >::operator()(_object * args_=0x009d58a0, _object * 
__formal=0x00000000)  Line 201 + 0x2a bytes	C++
 
_biopsy.pyd!boost::python::objects::caller_py_function_impl<boost::python::detail::caller<void 
(__cdecl*)(std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > > > 
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > 
const 
&),boost::python::default_call_policies,boost::mpl::vector3<void,std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
 > > > 
&,std::basic_string<char,std::char_traits<char>,std::allocator<char> > 
const &> > >::operator()(_object * args=0x009d58a0, _object * 
kw=0x00000000)  Line 39	C++





More information about the Cplusplus-sig mailing list