Jump to content
  • Advertisement
Sign in to follow this  
Genjix

boost::python and registering exceptions

This topic is 4782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!