Re: [pygccxml-development] Parameter passing, ownership semantics
Brought to you by:
mbaas,
roman_yakovenko
From: Gustavo C. <gjc...@gm...> - 2007-02-18 22:48:33
|
On 2/18/07, Gustavo Carneiro <gjc...@gm...> wrote: > > On 2/18/07, Roman Yakovenko <rom...@gm...> wrote: > > > On 2/18/07, Gustavo Carneiro <gjc...@gm...> wrote: > > > On 2/18/07, Roman Yakovenko <rom...@gm...> wrote: > > > > I committed new function transformation: transfer ownership. The > > > documentation > > > > will come later. For usage example take a look on unittests: > > > > ( look for "transfer_ownership" ) > > > > > > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/function_transformations_tester.py?view=markup > > > > > > > > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp?view=markup > > > > > > > > Thanks! > > > > > > Unfortunately the generated code does not compile when I try to use > > that > > > feature: > > > > > > default/bindings/python/__call_policies.pypp.hpp:14:58: > > > error: boost/python/suite/indexing/iterator_range.hpp: No > > > such file or directory > > > default/bindings/python/__call_policies.pypp.hpp:172: > > > error: 'pyplusplus::call_policies::bpl::indexing' has not > > > been declared > > > default/bindings/python/__call_policies.pypp.hpp:172: > > > error: ISO C++ forbids declaration of 'iterator_range' with no type > > > default/bindings/python/__call_policies.pypp.hpp:172: > > > error: typedef name may not be a nested-name-specifier > > > default/bindings/python/__call_policies.pypp.hpp:172: > > > error: expected ';' before '<' token > > > [...etc...] > > > > > > From "boost/python/suite/indexing/iterator_range.hpp: No > > > such file or directory", does this sound like I need to get a newer > > > boost::python library or something? > > > > Something like that. Boost.Python, out of the box, comes with little > > support > > to STL containers. To make the long story short you have to install new > > indexing > > suite that comes with Py++: > > ( > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2/ > > ) > > > > Here you will find more information about new indexing suite > > http://language-binding.net/pyplusplus/documentation/containers.html. > > > > Thanks. > > After much effort to rebuilt a patched boost library, it now compiles > fine. However, the methods that are affected by the transformation > (Schedule*) are receiving some kind of name mangling: > > >>> dir(ns3.Simulator) > ['Now', 'Run', 'ScheduleDestroy_126390ccfc1f22f22289536ea47d3ecb', > 'ScheduleNow_3692da707df52052648f9d5435d958c4', > 'Schedule_fbf096d706be19b392c1e3fbcd3bf544', 'Stop', '__class__', > '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', > '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', > '__repr__', '__setattr__', '__str__', '__weakref__'] > Even with the name mangling problem, something was not right: gjc@nazgul:python$ python test-schedule.py Traceback (most recent call last): File "test-schedule.py", line 11, in <module> Simulator.Schedule_fbf096d706be19b392c1e3fbcd3bf544(t1, ev) Boost.Python.ArgumentError: Python argument types in Simulator.Schedule_fbf096d706be19b392c1e3fbcd3bf544(Time, MyEvent) did not match C++ signature: Schedule_fbf096d706be19b392c1e3fbcd3bf544(ns3::Time time, std::auto_ptr<ns3::EventImpl> event) Then I saw something I missed in the unit test, and added this code: EventImpl = mb.class_('EventImpl') EventImpl.held_type = 'std::auto_ptr< %s >' % EventImpl.decl_string (EventImpl is the type of the argument that is subject to the ownership transfer) But with the above changes the code doesn't compile (errors below). The generated source contains: bp::class_< EventImpl_wrapper, std::auto_ptr< ::ns3::EventImpl >, boost::noncopyable >( "EventImpl" ) .def( bp::init< >() ) The error comes from the ".def( bp::init< >() )" line. Manually removing the "std::auto_ptr< ::ns3::EventImpl >" part from the first line solves the compilation error. Any hints? /usr/include/boost/python/object/pointer_holder.hpp: In constructor 'boost::python::objects::pointer_holder<Pointer, Value>::pointer_holder(PyObject*) [with Pointer = std::auto_ptr<ns3::EventImpl>, Value = ns3::EventImpl]': /usr/include/boost/python/object/make_holder.hpp:83: instantiated from 'static void boost::python::objects::make_holder<0>::apply<Holder, ArgList>::execute(PyObject*) [with Holder = boost::python::objects::pointer_holder<std::auto_ptr<ns3::EventImpl>, ns3::EventImpl>, ArgList = boost::mpl::vector0<mpl_::na>]' /usr/include/boost/python/detail/make_keyword_range_fn.hpp:64: instantiated from 'boost::python::api::object boost::python::detail::make_keyword_range_constructor(const CallPolicies&, const boost::python::detail::keyword_range&, Holder*, ArgList*, Arity*) [with ArgList = boost::mpl::vector0<mpl_::na>, Arity = boost::mpl::size<boost::mpl::vector0<mpl_::na> >, Holder = boost::python::objects::pointer_holder<std::auto_ptr<ns3::EventImpl>, ns3::EventImpl>, CallPolicies = boost::python::default_call_policies]' /usr/include/boost/python/init.hpp:330: instantiated from 'void boost::python::detail::def_init_aux(ClassT&, const Signature&, NArgs, const CallPoliciesT&, const char*, const boost::python::detail::keyword_range&) [with ClassT = boost::python::class_<EventImpl_wrapper, std::auto_ptr<ns3::EventImpl>, boost::noncopyable_::noncopyable, boost::python::detail::not_specified>, CallPoliciesT = boost::python::default_call_policies, Signature = boost::mpl::vector0<mpl_::na>, NArgs = boost::mpl::size<boost::mpl::vector0<mpl_::na> >]' /usr/include/boost/python/init.hpp:399: instantiated from 'static void boost::python::detail::define_class_init_helper<0>::apply(ClassT&, const CallPoliciesT&, const Signature&, NArgs, const char*, const boost::python::detail::keyword_range&) [with ClassT = boost::python::class_<EventImpl_wrapper, std::auto_ptr<ns3::EventImpl>, boost::noncopyable_::noncopyable, boost::python::detail::not_specified>, CallPoliciesT = boost::python::default_call_policies, Signature = boost::mpl::vector0<mpl_::na>, NArgs = boost::mpl::size<boost::mpl::vector0<mpl_::na> >]' /usr/include/boost/python/init.hpp:171: instantiated from 'void boost::python::init_base<DerivedT>::visit(classT&) const [with classT = boost::python::class_<EventImpl_wrapper, std::auto_ptr<ns3::EventImpl>, boost::noncopyable_::noncopyable, boost::python::detail::not_specified>, DerivedT = 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_>]' /usr/include/boost/python/def_visitor.hpp:31: instantiated from 'static void boost::python::def_visitor_access::visit(const V&, classT&) [with V = boost::python::def_visitor<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_> >, classT = boost::python::class_<EventImpl_wrapper, std::auto_ptr<ns3::EventImpl>, boost::noncopyable_::noncopyable, boost::python::detail::not_specified>]' /usr/include/boost/python/def_visitor.hpp:67: instantiated from 'void boost::python::def_visitor<DerivedVisitor>::visit(classT&) const [with classT = boost::python::class_<EventImpl_wrapper, std::auto_ptr<ns3::EventImpl>, boost::noncopyable_::noncopyable, boost::python::detail::not_specified>, DerivedVisitor = 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_>]' /usr/include/boost/python/class.hpp:225: instantiated from 'boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, X3>::def(const boost::python::def_visitor<Derived>&) [with Derived = 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_>, W = EventImpl_wrapper, X1 = std::auto_ptr<ns3::EventImpl>, X2 = boost::noncopyable_::noncopyable, X3 = boost::python::detail::not_specified]' default/bindings/python/ns3.cpp:76: instantiated from here /usr/include/boost/python/object/pointer_holder.hpp:179: error: cannot allocate an object of abstract type 'ns3::EventImpl' ./default/ns3/event-impl.h:28: note: because the following virtual functions are pure within 'ns3::EventImpl': ./default/ns3/event-impl.h:31: note: virtual ns3::EventImpl::~EventImpl() ./default/ns3/event-impl.h:36: note: virtual void ns3::EventImpl::Notify() -- Gustavo J. A. M. Carneiro "The universe is always one step beyond logic." |