Strange behavior of add_property in Boost.Python
<p>I met a strange behavior when using <code>add_property</code> of Boost.Python. </p>

<p>Here is the example codes, it simply add two properties (read-only &amp; read-write) to the wrapped class.</p>

<pre><code>#include &lt;boost/python.hpp&gt;

using namespace boost::python;

struct X {
    X( int value ) : val( value ) {}

    int get_value() const
    { return val; }

    void set_value(int value)
    { val = value; }

    int val;
};

BOOST_PYTHON_MODULE(hello) {
    class_&lt;X&gt;("X", init&lt;int&gt;() )
        // NOTE the order
        .add_property( "val_r", &amp;X::get_value )  // read-only first
        .add_property( "val_rw", &amp;X::get_value, &amp;X::set_value ) // read-write second
    ;
}
</code></pre>

<p>and the build command:</p>

<pre><code>$ g++ -I/usr/include/python2.7 -shared -L/usr/local/lib -o bp.dll bp.cpp -lboost_python -lpython2.7
</code></pre>

<p>I'm working in Cygwin x86_64, so the file extension is <code>.dll</code>. As for Ubuntu just change the output extension to <code>.so</code>.</p>

<p>When importing the <code>bp</code> module, it crashes with a <em>Segmentation fault</em>. The core dump file doesn't contain any call stack information. </p>

<p>However, if I change the order of <code>add_property</code> (as below) to add the read-write property first, it works ok.</p>

<pre><code>.add_property( "val_rw", &amp;X::get_value, &amp;X::set_value ) // read-write first
.add_property( "val_r", &amp;X::get_value )  // read-only second
</code></pre>

<p>My environment:</p>

<ul>
<li>Cygwin x86_64</li>
<li>python 2.7.10</li>
<li>gcc 5.4.0</li>
<li>boost: 1.60.0</li>
</ul>

<p>BTW, there's no problem in Ubuntu 14.04 (64-bit) whatever the <code>add_property</code> order is. </p>

<p>Why would this happen?</p>