<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Boost.Python Iterator : Segfault]]></title><description><![CDATA[<p>Hoi! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Ich habe mit Hilfe von Boost IteratorFacade einen Iterator gebastelt.<br />
Diesen möchte ich per Boost.Python in Python nutzbar machen, dazu packe ich eine entsprechende Range in ein std::pair.</p>
<p>Soweit, so gut, so sieht der Code aus:</p>
<pre><code class="language-cpp">boost::python::class_&lt;Ethon::MemoryRegionSequence&gt;(&quot;MemoryRegionIterable&quot;)
    .def(&quot;__iter__&quot;, boost::python::range(&amp;Ethon::MemoryRegionSequence::first,
      &amp;Ethon::MemoryRegionSequence::second))
  ;

  boost::python::def(&quot;MemoryRegionIterator&quot;,
    &amp;Ethon::makeMemoryRegionSequence);

  boost::python::def(&quot;makeMemoryRegionSequence&quot;,
    &amp;Ethon::makeMemoryRegionSequence);
</code></pre>
<p>wobei MemoryRegionSequence ein typedef auf das pair ist.</p>
<p>Nun bekomme ich aber immer einen Segfault, wenn der Iterator beim zweiten Element angelangt ist.<br />
Aus C++ aufgerufen funktioniert der Iterator tadellos, daran kann es also nicht liegen.</p>
<p>Ich habe mit GDB mal einen Stacktrace erzeugt:</p>
<blockquote>
<p>#0 memcpy () at ../sysdeps/x86_64/memcpy.S:399<br />
#1 0x00007ffff4ebdbd2 in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::_Rep::_M_clone(std::allocator&lt;char&gt; const&amp;, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br />
#2 0x00007ffff4ebe2ec in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) ()<br />
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br />
#3 0x00007ffff5cd0002 in boost::python::converter::as_to_python_function&lt;Ethon::MemoryRegion, boost::python::objects::class_cref_wrapper&lt;Ethon::MemoryRegion, boost::python::objects::make_instance&lt;Ethon::MemoryRegion, boost::python::objects::value_holder<a href="Ethon::MemoryRegion" rel="nofollow">Ethon::MemoryRegion</a> &gt; &gt; &gt;::convert(void const*) ()<br />
from ./Ethonmem.so<br />
#4 0x00007ffff5a63d26 in boost::python::converter::registration::to_python(void const volatile*) const<br />
() from /usr/lib/libboost_python-py27.so.1.42.0<br />
#5 0x00007ffff5cd1322 in boost::python::objects::caller_py_function_impl&lt;boost::python::detail::caller&lt;boost::python::objects::iterator_range&lt;boost::python::return_value_policy&lt;boost::python::return_by_value, boost::python::default_call_policies&gt;, Ethon::MemoryRegionIterator&gt;::next, boost::python::return_value_policy&lt;boost::python::return_by_value, boost::python::default_call_policies&gt;, boost::mpl::vector2&lt;Ethon::MemoryRegion&amp;, boost::python::objects::iterator_range&lt;boost::python::return_value_policy&lt;boost::python::return_by_value, boost::python::default_call_policies&gt;, Ethon::MemoryRegionIterator&gt;&amp;&gt; &gt; &gt;::operator()(_object*, _object*) () from ./Ethonmem.so<br />
#6 0x00007ffff5a6b71e in boost::python::objects::function::call(_object*, _object*) const ()<br />
from /usr/lib/libboost_python-py27.so.1.42.0<br />
#7 0x00007ffff5a6b978 in ?? () from /usr/lib/libboost_python-py27.so.1.42.0<br />
#8 0x00007ffff5a74c63 in boost::python::handle_exception_impl(boost::function0&lt;void&gt;) ()<br />
from /usr/lib/libboost_python-py27.so.1.42.0<br />
#9 0x00007ffff5a6ce74 in ?? () from /usr/lib/libboost_python-py27.so.1.42.0<br />
#10 0x000000000045d864 in PyObject_Call ()</p>
</blockquote>
<p>Jemand eine Idee wieso das so nicht klappt?<br />
Grüße,<br />
Ethon</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290356/boost-python-iterator-segfault</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 01:21:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290356.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 24 Jul 2011 22:01:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Boost.Python Iterator : Segfault on Sun, 24 Jul 2011 22:01:09 GMT]]></title><description><![CDATA[<p>Hoi! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Ich habe mit Hilfe von Boost IteratorFacade einen Iterator gebastelt.<br />
Diesen möchte ich per Boost.Python in Python nutzbar machen, dazu packe ich eine entsprechende Range in ein std::pair.</p>
<p>Soweit, so gut, so sieht der Code aus:</p>
<pre><code class="language-cpp">boost::python::class_&lt;Ethon::MemoryRegionSequence&gt;(&quot;MemoryRegionIterable&quot;)
    .def(&quot;__iter__&quot;, boost::python::range(&amp;Ethon::MemoryRegionSequence::first,
      &amp;Ethon::MemoryRegionSequence::second))
  ;

  boost::python::def(&quot;MemoryRegionIterator&quot;,
    &amp;Ethon::makeMemoryRegionSequence);

  boost::python::def(&quot;makeMemoryRegionSequence&quot;,
    &amp;Ethon::makeMemoryRegionSequence);
</code></pre>
<p>wobei MemoryRegionSequence ein typedef auf das pair ist.</p>
<p>Nun bekomme ich aber immer einen Segfault, wenn der Iterator beim zweiten Element angelangt ist.<br />
Aus C++ aufgerufen funktioniert der Iterator tadellos, daran kann es also nicht liegen.</p>
<p>Ich habe mit GDB mal einen Stacktrace erzeugt:</p>
<blockquote>
<p>#0 memcpy () at ../sysdeps/x86_64/memcpy.S:399<br />
#1 0x00007ffff4ebdbd2 in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::_Rep::_M_clone(std::allocator&lt;char&gt; const&amp;, unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br />
#2 0x00007ffff4ebe2ec in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;) ()<br />
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6<br />
#3 0x00007ffff5cd0002 in boost::python::converter::as_to_python_function&lt;Ethon::MemoryRegion, boost::python::objects::class_cref_wrapper&lt;Ethon::MemoryRegion, boost::python::objects::make_instance&lt;Ethon::MemoryRegion, boost::python::objects::value_holder<a href="Ethon::MemoryRegion" rel="nofollow">Ethon::MemoryRegion</a> &gt; &gt; &gt;::convert(void const*) ()<br />
from ./Ethonmem.so<br />
#4 0x00007ffff5a63d26 in boost::python::converter::registration::to_python(void const volatile*) const<br />
() from /usr/lib/libboost_python-py27.so.1.42.0<br />
#5 0x00007ffff5cd1322 in boost::python::objects::caller_py_function_impl&lt;boost::python::detail::caller&lt;boost::python::objects::iterator_range&lt;boost::python::return_value_policy&lt;boost::python::return_by_value, boost::python::default_call_policies&gt;, Ethon::MemoryRegionIterator&gt;::next, boost::python::return_value_policy&lt;boost::python::return_by_value, boost::python::default_call_policies&gt;, boost::mpl::vector2&lt;Ethon::MemoryRegion&amp;, boost::python::objects::iterator_range&lt;boost::python::return_value_policy&lt;boost::python::return_by_value, boost::python::default_call_policies&gt;, Ethon::MemoryRegionIterator&gt;&amp;&gt; &gt; &gt;::operator()(_object*, _object*) () from ./Ethonmem.so<br />
#6 0x00007ffff5a6b71e in boost::python::objects::function::call(_object*, _object*) const ()<br />
from /usr/lib/libboost_python-py27.so.1.42.0<br />
#7 0x00007ffff5a6b978 in ?? () from /usr/lib/libboost_python-py27.so.1.42.0<br />
#8 0x00007ffff5a74c63 in boost::python::handle_exception_impl(boost::function0&lt;void&gt;) ()<br />
from /usr/lib/libboost_python-py27.so.1.42.0<br />
#9 0x00007ffff5a6ce74 in ?? () from /usr/lib/libboost_python-py27.so.1.42.0<br />
#10 0x000000000045d864 in PyObject_Call ()</p>
</blockquote>
<p>Jemand eine Idee wieso das so nicht klappt?<br />
Grüße,<br />
Ethon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097401</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sun, 24 Jul 2011 22:01:09 GMT</pubDate></item></channel></rss>