[C++-sig] std::string crush
Vladimir Ignatov
vignatov at colorpilot.com
Fri May 28 13:59:28 CEST 2004
Hello!
I am just start learning Boost.Python and faced a strange problem. I need
to push some binary data from Python to C++ module. std::string look like a
natural way to do it. Unfortunately I can't get this simple stuff working.
After several invokes, TestStr() raise the "RuntimeError: unidentifiable C++
exception" which I think is actually a crush (access violation or so). Here
is the snippets from my code:
-Py-----------------------
import dx8
for i in range( 40 ):
dx8.TestStr( "a"*96 )
-C++-----------------------
void TestStr( std::string s )
{
char buf[ 512 ];
::memcpy( buf, s.data(), 96 );
}
BOOST_PYTHON_MODULE(dx8cpp)
{
def( "TestStr", &TestStr );
}
---------------
The looping in this example is essential. Say, after 4 iteration function
still work, but 40 iterations kills for shure. If I replace std::string to
const char* , like:
void TestStr( const char* s )
{
char buf[ 512 ];
::memcpy( buf, s, 96 );
}
then problem disappears. Any suggestions are welcomed.
My system is Win2000 + Python 2.3 + VS.NET (VC 7.0) + Boost 1.31.0
Vladimir Ignatov
More information about the Cplusplus-sig
mailing list