Subject: [Boost-bugs] [Boost C++ Libraries] #1952: The operation static_cast<std::string>(boost::python::extract<std::string>(...)) crashes Python. Seems to create reference counting problem.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-05-27 14:42:27
#1952: The operation
static_cast<std::string>(boost::python::extract<std::string>(...)) crashes
Python. Seems to create reference counting problem.
--------------------------------------------------------------------+-------
Reporter: Konstantin Aslanidi <konstantin.aslanidi_at_[hidden]> | Owner: dave
Type: Bugs | Status: new
Milestone: Boost 1.36.0 | Component: Python
Version: Boost 1.35.0 | Severity: Showstopper
Keywords: python extract |
--------------------------------------------------------------------+-------
I submit boost::python based python extension code that crashes Python
interpreter when used as described below. I attach Visual Studio .NET
project files.
C:\KDocuments\Variance Swap Validation 2\VarSw2\Debug>python
ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
Python 2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vrsw2
>>> p=vrsw2.VarSwapTest()
>>> p.set(((1,2),(3,4)))
<crash here>
The C++ extension code:
#include <string>
#include <fstream>
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
using namespace boost::python;
class VarSwapTest
{
private:
class Impl
{
private:
std::ofstream theFile;
public:
Impl()
: theFile("VarSwapTestEcho.txt")
{}
void set( object& input )
{
object o=input.attr("__str__")();
extract<std::string> ex(o);
if( ex.check() )
theFile<<(static_cast<std::string>(ex()))<<std::endl;
else
theFile<<"failed to extract
string"<<std::endl;
}
};
private:
boost::shared_ptr<Impl> theImpl;
public:
VarSwapTest() : theImpl(new Impl()) {}
void set( object input )
{
theImpl->set(input);
}
};
BOOST_PYTHON_MODULE(vrsw2)
{
class_<VarSwapTest>("VarSwapTest")
.def("set",&VarSwapTest::set)
;
}
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1952>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC