Boost logo

Boost :

From: Mike Owen (mikeowen_at_[hidden])
Date: 2001-07-03 02:33:23

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 {
    try {
      python::module_builder module("TestAttr");

      python::class_builder<Interior> InteriorClass(module, "Interior");
      InteriorClass.def_read_write(&Interior::x, "x");

      python::class_builder<Top> TopClass(module, "Top");
      TopClass.def_read_write(&Top::interiorInstance, "interiorInstance");
    catch(...) {

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
>>> a.x = 100
>>> a.x
>>> b = TestAttr.Top()
>>> b.interiorInstance
<Interior object at 0x8115c20>
>>> b.interiorInstance.x
>>> b.interiorInstance.x = 100
>>> b.interiorInstance.x

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!


 "Hey...where are the sunflower seeds?" |       J. Michael Owen         
        o_o /                           |       
        (")                             |       Email:  mikeowen_at_[hidden]
       \/'\/                            |

Boost list run by bdawes at, gregod at, cpdaniel at, john at