Subject: [Boost-bugs] [Boost C++ Libraries] #6203: boost::python::api::object constructor failure
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-12-03 11:38:21
#6203: boost::python::api::object constructor failure
-----------------------------------------------+----------------------------
Reporter: Johan RÃ¥de <johan.rade@â¦> | Owner: rwgk
Type: Bugs | Status: new
Milestone: To Be Determined | Component: Python
Version: Boost 1.48.0 | Severity: Problem
Keywords: |
-----------------------------------------------+----------------------------
Here is the C++ code for a Python extension module and a Python script
that calls the module.
Expected behavior when you run the script:
{{{
The script runs and produces the output "Hello, I'm Y!"
}}}
Observed behavior (with Boost 1.48.0, Python 2.7.2, MSVS 2010):
{{{
The script fails with the error message:
Traceback (most recent call last):
File "../TestHello/TestHello.py", line 12, in <module>
y = Hello.create('Y')
TypeError: No to_python (by-value) converter found for C++ type: class Y
Press any key to continue . . .
}}}
I have also attached a zip file with the code as a solution for MSVS 2010
and Python Tools for Visual Studio.
Hello.cpp:
{{{
#include <string>
#include <exception>
#include <boost/noncopyable.hpp>
#include <boost/python.hpp>
using std::string;
using boost::noncopyable;
using boost::python::class_;
using boost::python::def;
class X : noncopyable {
public:
string hello() const { return "Hello, I'm X!"; }
};
class Y : noncopyable {
public:
string hello() const { return "Hello, I'm Y!"; }
};
class Z : noncopyable {
public:
string hello() const { return "Hello, I'm Z!"; }
};
PyObject* create(char c)
{
if(c == 'X')
return boost::python::api::object(new X).ptr();
else if(c == 'Y')
return boost::python::api::object(new Y).ptr();
else if(c == 'Z')
return boost::python::api::object(new Z).ptr();
else
throw std::exception("The function argument must be 'X', 'Y' or
'Z'.");
}
BOOST_PYTHON_MODULE(Hello)
{
class_<X, noncopyable>("X").def("hello", &X::hello);
class_<Y, noncopyable>("Y").def("hello", &Y::hello);
class_<Z, noncopyable>("Z").def("hello", &Z::hello);
def("create", &create);
}
}}}
Test.py:
{{{
import Hello
y = Hello.create('Y')
print(y.hello())
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6203> 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:50:07 UTC