c++ - Strange behavior of add_property in Boost.Python -
i met strange behavior when using add_property
of boost.python.
here example codes, add 2 properties (read-only & read-write) wrapped class.
#include <boost/python.hpp> 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_<x>("x", init<int>() ) // note order .add_property( "val_r", &x::get_value ) // read-only first .add_property( "val_rw", &x::get_value, &x::set_value ) // read-write second ; }
and build command:
$ g++ -i/usr/include/python2.7 -shared -l/usr/local/lib -o bp.dll bp.cpp -lboost_python -lpython2.7
i'm working in cygwin x86_64, file extension .dll
. ubuntu change output extension .so
.
when importing bp
module, crashes segmentation fault. core dump file doesn't contain call stack information.
however, if change order of add_property
(as below) add read-write property first, works ok.
.add_property( "val_rw", &x::get_value, &x::set_value ) // read-write first .add_property( "val_r", &x::get_value ) // read-only second
my environment:
- cygwin x86_64
- python 2.7.10
- gcc 5.4.0
- boost: 1.60.0
btw, there's no problem in ubuntu 14.04 (64-bit) whatever add_property
order is.
why happen?
Comments
Post a Comment