Boost.Python Iterator : Segfault



  • Hoi! 😉

    Ich habe mit Hilfe von Boost IteratorFacade einen Iterator gebastelt.
    Diesen möchte ich per Boost.Python in Python nutzbar machen, dazu packe ich eine entsprechende Range in ein std::pair.

    Soweit, so gut, so sieht der Code aus:

    boost::python::class_<Ethon::MemoryRegionSequence>("MemoryRegionIterable")
        .def("__iter__", boost::python::range(&Ethon::MemoryRegionSequence::first,
          &Ethon::MemoryRegionSequence::second))
      ;
    
      boost::python::def("MemoryRegionIterator",
        &Ethon::makeMemoryRegionSequence);
    
      boost::python::def("makeMemoryRegionSequence",
        &Ethon::makeMemoryRegionSequence);
    

    wobei MemoryRegionSequence ein typedef auf das pair ist.

    Nun bekomme ich aber immer einen Segfault, wenn der Iterator beim zweiten Element angelangt ist.
    Aus C++ aufgerufen funktioniert der Iterator tadellos, daran kann es also nicht liegen.

    Ich habe mit GDB mal einen Stacktrace erzeugt:

    #0 memcpy () at ../sysdeps/x86_64/memcpy.S:399
    #1 0x00007ffff4ebdbd2 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_M_clone(std::allocator<char> const&, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
    #2 0x00007ffff4ebe2ec in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
    from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
    #3 0x00007ffff5cd0002 in boost::python::converter::as_to_python_function<Ethon::MemoryRegion, boost::python::objects::class_cref_wrapper<Ethon::MemoryRegion, boost::python::objects::make_instance<Ethon::MemoryRegion, boost::python::objects::value_holderEthon::MemoryRegion > > >::convert(void const*) ()
    from ./Ethonmem.so
    #4 0x00007ffff5a63d26 in boost::python::converter::registration::to_python(void const volatile*) const
    () from /usr/lib/libboost_python-py27.so.1.42.0
    #5 0x00007ffff5cd1322 in boost::python::objects::caller_py_function_impl<boost::python::detail::caller<boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, Ethon::MemoryRegionIterator>::next, boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, boost::mpl::vector2<Ethon::MemoryRegion&, boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, Ethon::MemoryRegionIterator>&> > >::operator()(_object*, _object*) () from ./Ethonmem.so
    #6 0x00007ffff5a6b71e in boost::python::objects::function::call(_object*, _object*) const ()
    from /usr/lib/libboost_python-py27.so.1.42.0
    #7 0x00007ffff5a6b978 in ?? () from /usr/lib/libboost_python-py27.so.1.42.0
    #8 0x00007ffff5a74c63 in boost::python::handle_exception_impl(boost::function0<void>) ()
    from /usr/lib/libboost_python-py27.so.1.42.0
    #9 0x00007ffff5a6ce74 in ?? () from /usr/lib/libboost_python-py27.so.1.42.0
    #10 0x000000000045d864 in PyObject_Call ()

    Jemand eine Idee wieso das so nicht klappt?
    Grüße,
    Ethon


Anmelden zum Antworten