Sign in to follow this  
Genjix

boost::python and registering exceptions

Recommended Posts

Genjix    100
#include "xml.h"

#include <boost/python.hpp>
using namespace boost::python;

void TranslatorNodoc(Xml::NoDocument const &nd)
{
	PyErr_SetString(PyExc_UserWarning , nd.What());
}
void TranslatorNoattr(Xml::NoAttribute const &na)
{
	PyErr_SetString(PyExc_UserWarning , na.What());
}

BOOST_PYTHON_MODULE(xml)
{
	// ...
	register_exception_translator<Xml::NoDocument>(TranslatorNodoc);
}



If I comment out register_exception_translator it compiles fine... what am I doing wrong? Thanks genjix@amir ~/tmp/xml/xml $ make g++ -shared xml.cpp xmlexception.cpp tinyxml/tinyxml.cpp tinyxml/tinystr.cpp tinyxml/tinyxmlparser.cpp tinyxml/tinyxmlerror.cpp xmldocument.cpp xmlelement.cpp -I/usr/include/python2.3 -lboost_python -o xml.so /usr/include/boost/bind.hpp: In member function `R boost::_bi::list3<A1, A2, A3>::operator()(boost::_bi::type<R>, F, A&) [with R = bool, F = boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>, A = boost::_bi::list2<const boost::python::detail::exception_handler&, const boost::function0<void, std::allocator<boost::function_base> >&>, A1 = boost::arg<1>, A2 = boost::arg<2>, A3 = boost::_bi::value<void (*)(const Xml::NoDocument&)>]': /usr/include/boost/bind/bind_template.hpp:45: instantiated from `typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&) [with A1 = const boost::python::detail::exception_handler, A2 = const boost::function0<void, std::allocator<boost::function_base> >, R = bool, F = boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>, L = boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(const Xml::NoDocument&)> >]' /usr/include/boost/function/function_template.hpp:111: instantiated from `static R boost::detail::function::function_obj_invoker2<FunctionObj, R, T0, T1>::invoke(boost::detail::function::any_pointer, T0, T1) [with FunctionObj = boost::_bi::bind_t<bool, boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>, boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(const Xml::NoDocument&)> > >, R = bool, T0 = const boost::python::detail::exception_handler&, T1 = const boost::function0<void, std::allocator<boost::function_base> >&]' /usr/include/boost/function/function_template.hpp:476: instantiated from `void boost::function2<R, T0, T1, Allocator>::assign_to(FunctionObj, boost::detail::function::function_obj_tag) [with FunctionObj = boost::_bi::bind_t<bool, boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>, boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(const Xml::NoDocument&)> > >, R = bool, T0 = const boost::python::detail::exception_handler&, T1 = const boost::function0<void, std::allocator<boost::function_base> >&, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:427: instantiated from `void boost::function2<R, T0, T1, Allocator>::assign_to(Functor) [with Functor = boost::_bi::bind_t<bool, boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>, boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(const Xml::NoDocument&)> > >, R = bool, T0 = const boost::python::detail::exception_handler&, T1 = const boost::function0<void, std::allocator<boost::function_base> >&, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:289: instantiated from `boost::function2<R, T0, T1, Allocator>::function2(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<bool, boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>, boost::_bi::list3<boost::arg<1>, boost::arg<2>, boost::_bi::value<void (*)(const Xml::NoDocument&)> > >, R = bool, T0 = const boost::python::detail::exception_handler&, T1 = const boost::function0<void, std::allocator<boost::function_base> >&, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/python/exception_translator.hpp:21: instantiated from `void boost::python::register_exception_translator(const Translate&, boost::type<Target>*) [with ExceptionType = Xml::NoDocument, Translate = void ()(const Xml::NoDocument&)]' xml.cpp:45: instantiated from here /usr/include/boost/bind.hpp:303: error: no match for call to `(boost::python::detail::translate_exception<Xml::NoDocument, void ()(const Xml::NoDocument&)>) (const boost::python::detail::exception_handler&, const boost::function0<void, std::allocator<boost::function_base> >&, void (*&)(const Xml::NoDocument&))' /usr/include/boost/python/detail/translate_exception.hpp:33: note: candidates are: bool boost::python::detail::translate_exception<ExceptionType, Translate>::operator()(const boost::python::detail::exception_handler&, const boost::function0<void, std::allocator<boost::function_base> >&, typename boost::call_traits<T2>::param_type) const [with ExceptionType = Xml::NoDocument, Translate = void ()(const Xml::NoDocument&)] make: *** [target] Error 1 genjix@amir ~/tmp/xml/xml $

Share this post


Link to post
Share on other sites
SiCrane    11839
Try putting an & in front of TranslatorNodoc when calling register_exception_translator<>(). i.e.:

register_exception_translator<Xml::NoDocument>(TranslatorNodoc);


gcc's type deduction can go a little crazy if it's trying to instantiate the function with a function type instead of a function pointer type.

Share this post


Link to post
Share on other sites
Genjix    100
oh... lol, what a simple fix, don't know why I didn't figure that out :p

Thank you so very much for your help SiCrane, you don't know how much empty space, spit and bytes I tried with this XD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this