Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-07-03 22:54:02


Hi Mike,

I proposed a way of addressing this in
http://groups.yahoo.com/group/boost/message/10144, but in response there was
a kind of deafening silence. In the meantime, I've been directing people at
the section titled "If you can't (afford to) copy the referent, or the
pointer
is non-const" on this page:
http://www.boost.org/libs/python/doc/pointers.html
which describes a dangerous hack to work around the problem.

I would happily make the proposed change to Boost.Python, but had been
hoping to hear more from the user community before undertaking any redesign.

Ralf Grosse-Kunstleve has been working on a set of changes that would be
closely related to the ones proposed above; I'd like to hear from Ralf on
the status of those also. Ralf?

-Dave

----- Original Message -----
From: "Mike Owen" <mikeowen_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, July 03, 2001 3:33 AM
Subject: [boost] Boost.Python: using methods on attributes of wrapped
classes

> I'm getting unexpected behaviour when using methods on attributes of BPL
> wrapped objects. For instance, if I have a wrapped class A that has
another
> wrapped class B as a member, calling the methods of the B instance in A
does
> not affect this B instance. It looks like temporaries are being
constructed
> and then destroyed when I do this. Here is a concrete example:
>
> struct Interior {
> double x;
> };
>
> struct Top {
> Interior interiorInstance;
> };
>
> #include <boost/python/class_builder.hpp>
> namespace python = boost::python;
>
> namespace {
> BOOST_PYTHON_MODULE_INIT(TestAttr) {
> try {
> python::module_builder module("TestAttr");
>
> python::class_builder<Interior> InteriorClass(module, "Interior");
> InteriorClass.def(python::constructor<>());
> InteriorClass.def_read_write(&Interior::x, "x");
>
> python::class_builder<Top> TopClass(module, "Top");
> TopClass.def(python::constructor<>());
> TopClass.def_read_write(&Top::interiorInstance, "interiorInstance");
> }
> catch(...) {
> python::handle_exception();
> }
> }
> }
>
> So the class "Top" has a member instance of "Interior". Both classes are
> exposed to python with BPL. However, when I try to set the "x" value of
> Top::Interior, it always fails. Here's the output that results from
> compiling the above and trying the experiment:
>
> HodgePodge{owen}: python
> Python 2.1 (#2, May 9 2001, 22:11:49)
> [GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> import TestAttr
> >>> a = TestAttr.Interior()
> >>> a.x
> 1.750725915200081e-313
> >>> a.x = 100
> >>> a.x
> 100.0
> >>> b = TestAttr.Top()
> >>> b.interiorInstance
> <Interior object at 0x8115c20>
> >>> b.interiorInstance.x
> 1.750725915200081e-313
> >>> b.interiorInstance.x = 100
> >>> b.interiorInstance.x
> 1.750725915200081e-313
> >>>
>
> This seems like incorrect behaviour to me, but am I wrong? How should I
be
> constructing the BPL wrap code so that I can call methods on the member
> class? Thanks!
>
> Mike.
>
> --
> "Hey...where are the sunflower seeds?" | J. Michael Owen
> o_o / |
> (") | Email:
mikeowen_at_[hidden]
> \/'\/ |
>
____(__(,_,)_______________________________________________________________
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk