[C++-sig] boost_1.30_2 => boost_1.32.0 / Python2.2.3 => Python2.4.0

Knight, Steve Steve.Knight at kbcfp.com
Tue Feb 1 18:37:02 CET 2005


Hello, 

Hope you can help but I'm upgrading both Python and boost and have run
into a specific problem.   I have tried searching the archives for clues
but haven't found anything,   I apologise if I'm duplicating.

So the problem is that I can't seem to wrap virtual functions in 1.32.
To start from the beginning I have a class that I'm trying to register
Python callbacks for so that when the C++ generates event messages it
does so and calls back into Python code.   I had this working before
with something along the lines of the following (dummy class is used in
place of the real underlying library class I'm trying to wrap):

		struct dummy {
		    virtual void onMsg(int* arg1, int& arg2) = 0;
		};

		struct MsgCallbackWrapper : dummy
		{
		    PyObject* self;

		    MsgCallbackWrapper(PyObject* self_)
		       : dummy(), self(self_) {}

		    void onMsg(int* listener, int& msg) {
		        try {
		            object o(msg);
		            call_method<void, object>(self, "onMsg",
boost::ref(o));
		        }
		        catch (...) {
		            // There's not a lot you can do here because
we probably
		            // don't want to make our thread abort
		            PyErr_Print();
		        }
		    }
		};


		BOOST_PYTHON_MODULE(test_boost)
		{
		    class_<dummy, boost::noncopyable,
boost::shared_ptr<MsgCallbackWrapper> >("MsgCallback")
		        .def("onMsg" , &dummy::onMsg);
		}

So, I can build for python2.2 and boost 1.30.2 and do the following:

Python 2.2.3 (#3, Sep  9 2003, 15:56:36)
[GCC 3.2.2] on sunos5
>>> import test_boost
>>>

So, then I rebuild for Python2.4/boost_1_32_0 and try to do the same:

ActivePython 2.4 Build 243 (ActiveState Corp.) based on
Python 2.4 (#1, Nov 30 2004, 10:31:14) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import test_boost
Segmentation Fault (core dumped)

Seems to me that perhaps what I'm doing isn't supported under
boost_1_32_0 but trying other example code for wrapping virtual
functions seems to end in the same results.  I also tried using the CVS
head, at which point my code stops compiling, so making me think this
this is something I'm doing wrong.   However I can't decode the 

Using gdb I get a stack trace (below).  Frame #1 looks suspicious to me
in that MsgCallbackWrapper => dummy conversion would indeed be a
downcast but I don't really know what I'm talking about so I'll leave my
analysis of the situation at that!

Does anyone have any idea what the problem could be and what I've
missed?

Thanks in advance,

Steve

	#0  0xfe5e7c38 in
std::iterator_traits<std::_List_iterator<boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > > const&, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >*> >::difference_type
std::__distance<std::_List_iterator<boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > > const&, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >*>
>(std::_List_iterator<boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > > const&, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >*>,
std::_List_iterator<boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > > const&, boost::list_edge<unsigned,
boost::property<boost::edge_index_t, unsigned,
boost::property<boost::(anonymous namespace)::edge_cast_t, void*
(*)(void*), boost::no_property> > >*>, std::input_iterator_tag) ()
	   from
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/lib/libboost_python-gcc-1
_32.so
	#1  0xfe6eff20 in void
boost::python::objects::register_conversion<MsgCallbackWrapper,
dummy>(bool, MsgCallbackWrapper*, dummy*) (is_downcast=false)
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/inheritance.hpp:122
	#2  0xfe6ef934 in void
boost::python::objects::register_base_of<MsgCallbackWrapper>::operator()
<dummy>(dummy*) const (this=0xffbee18f)
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/class_metadata.hpp:56
	#3  0xfe6ef3f4 in void
boost::mpl::aux::for_each_impl<false>::execute<boost::mpl::aux::sel_iter
<dummy, 0>, boost::mpl::aux::sel_iter<dummy, 1>,
boost::add_pointer<mpl_::arg<-1> >,
boost::python::objects::register_base_of<MsgCallbackWrapper>
>(boost::mpl::aux::sel_iter<dummy, 0>*, boost::mpl::aux::sel_iter<dummy,
1>*, boost::add_pointer<mpl_::arg<-1> >*,
boost::python::objects::register_base_of<MsgCallbackWrapper>) (f={<No
data fields>})
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
mpl/for_each.hpp:73
	#4  0xfe6eebb4 in void
boost::mpl::for_each<boost::mpl::single_view<dummy>,
boost::add_pointer<mpl_::arg<-1> >,
boost::python::objects::register_base_of<MsgCallbackWrapper>
>(boost::python::objects::register_base_of<MsgCallbackWrapper>,
boost::mpl::single_view<dummy>*, boost::add_pointer<mpl_::arg<-1> >*) (
	    f={<No data fields>})
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
mpl/for_each.hpp:96
	#5  0xfe6ee424 in void
boost::python::objects::register_shared_ptr_from_python_and_casts<MsgCal
lbackWrapper, boost::mpl::single_view<dummy> >(MsgCallbackWrapper*,
boost::mpl::single_view<dummy>) ()
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/class_metadata.hpp:88
	#6  0xfe6ee014 in void
boost::python::objects::class_metadata<dummy,
boost::noncopyable_::noncopyable, boost::shared_ptr<MsgCallbackWrapper>,
boost::python::detail::not_specified>::maybe_register_callback_class<dum
my>(dummy*, mpl_::bool_<true>) ()
	---Type <return> to continue, or q <return> to quit---
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/class_metadata.hpp:259
	#7  0xfe6edd10 in void
boost::python::objects::class_metadata<dummy,
boost::noncopyable_::noncopyable, boost::shared_ptr<MsgCallbackWrapper>,
boost::python::detail::not_specified>::register_aux2<dummy,
mpl_::bool_<true> >(dummy*, mpl_::bool_<true>) ()
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/class_metadata.hpp:216
	#8  0xfe6edac8 in boost::python::objects::class_metadata<dummy,
boost::noncopyable_::noncopyable, boost::shared_ptr<MsgCallbackWrapper>,
boost::python::detail::not_specified>::register_aux(void*) ()
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/class_metadata.hpp:208
	#9  0xfe6ed804 in boost::python::objects::class_metadata<dummy,
boost::noncopyable_::noncopyable, boost::shared_ptr<MsgCallbackWrapper>,
boost::python::detail::not_specified>::register_() ()
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/object/class_metadata.hpp:195
	#10 0xfe6ed560 in void boost::python::class_<dummy,
boost::noncopyable_::noncopyable, boost::shared_ptr<MsgCallbackWrapper>,
boost::python::detail::not_specified>::initialize<boost::python::init<mp
l_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_,
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_,
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_>
>(boost::python::init<mpl_::void_, mpl_::void_, mpl_::void_,
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_,
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_,
mpl_::void_, mpl_::void_> const&) (this=0xffbee560,
	    i=@0xffbee4d0)
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/class.hpp:453
	#11 0xfe6ed3a4 in boost::python::class_<dummy,
boost::noncopyable_::noncopyable, boost::shared_ptr<MsgCallbackWrapper>,
boost::python::detail::not_specified>::class_(char const*, char const*)
(this=0xffbee560,
	    name=0xfe7961c0 "MsgCallback", doc=0x0)
	    at
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/include/boost-1_32/boost/
python/class.hpp:586
	#12 0xfe6ecfd4 in init_module_test_boost() () at
test_boost.cpp:39
	#13 0xfe5ecb74 in
boost::detail::function::void_function_obj_invoker0<void (*)(),
void>::invoke(boost::detail::function::any_pointer) ()
	   from
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/lib/libboost_python-gcc-1
_32.so
	#14 0xfe5ebefc in
boost::python::handle_exception_impl(boost::function0<void,
std::allocator<boost::function_base> >) ()
	   from
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/lib/libboost_python-gcc-1
_32.so
	#15 0xfe5ec990 in boost::python::detail::init_module(char
const*, void (*)())
	    ()
	   from
/proj/cbtech/pkgs/sunos-5.8-sun4u/boost-1.32.0/lib/libboost_python-gcc-1
_32.so


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050201/6239a78e/attachment.htm>


More information about the Cplusplus-sig mailing list