Boost.Python question about converters and make_getter

I have a converter registered for a boost::optional<amount_t> object. If I use it as follows, my code works just fine: boost::optional<amount_t> py_price(annotation_t& ann) { return ann.price; } class_< annotation_t > ("Annotation") .add_property("price", py_price) ; However, if I dispense with the intermediary and use make_getter, I get an exception stating that no conversion exists for optional<amount_t>: class_< annotation_t > ("Annotation") .add_property("price", make_getter(&annotation_t::price)) ; The attached file demonstrates this bug using Boost 1.40 and Python 2.6.1. I'm running it on OS X 10.6.2 with g++ 4.4.2. My steps were: g++-mp-4.4 -I/usr/include/python2.6 -I/usr/local/include/boost-1_40 -o bug.so bug.cc -L/usr/local/lib -lboost_python-xgcc44-d-1_40 -lpython -shared $ python
import bug x = bug.Annotation() x.price2 # This works just fine x.price # This causes an abort() due to terminate()
John

I think this is covered by http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/faq.html#topythoncon... ----- Original Message ---- From: John Wiegley <jwiegley@gmail.com> To: boost@lists.boost.org Sent: Fri, November 20, 2009 2:55:04 AM Subject: [boost] Boost.Python question about converters and make_getter I have a converter registered for a boost::optional<amount_t> object. If I use it as follows, my code works just fine: boost::optional<amount_t> py_price(annotation_t& ann) { return ann.price; } class_< annotation_t > ("Annotation") .add_property("price", py_price) ; However, if I dispense with the intermediary and use make_getter, I get an exception stating that no conversion exists for optional<amount_t>: class_< annotation_t > ("Annotation") .add_property("price", make_getter(&annotation_t::price)) ; The attached file demonstrates this bug using Boost 1.40 and Python 2.6.1. I'm running it on OS X 10.6.2 with g++ 4.4.2. My steps were: g++-mp-4.4 -I/usr/include/python2.6 -I/usr/local/include/boost-1_40 -o bug.so bug.cc -L/usr/local/lib -lboost_python-xgcc44-d-1_40 -lpython -shared $ python
import bug x = bug.Annotation() x.price2 # This works just fine x.price # This causes an abort() due to terminate()
John

On Nov 21, 2009, at 10:02 AM, Ralf W. Grosse-Kunstleve wrote:
I think this is covered by
http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/faq.html#topythoncon...
Thank you, that looks exactly like what I needed. John
participants (2)
-
John Wiegley
-
Ralf W. Grosse-Kunstleve