[C++-sig] python objects not is the same in separated modules

Renato Araujo renatox at gmail.com
Wed Apr 22 17:07:57 CEST 2009


Hi guys,

I found a problems with my binds when I work with separated modules.
In my function where return a c++ pointer to a object, this not return
the same python object used in setter function.
The main point here is because this works fine when all classes are
exported in the same module but when I split the module this stop
work.


Module pybase
=========================
class Base
{
    private:
        Base *_child;

    public:
        void setChild(Base *parent);
        Base* child();
        virtual ~Base();
};

class BaseWrapper : public Base, public wrapper<Base>
{
    public:
        typedef class_<BaseWrapper, noncopyable> class_type;
};

BOOST_PYTHON_MODULE(pybase)
{
    BaseWrapper::class_type foo("Base");
    foo.def("setChild", &Base::setChild);
    foo.def("child", &Base::child, return_internal_reference<>());
}


Module pyother
===================================

class Other : public Base
{
    public:
        virtual ~Other();
};

class OtherWrapper : public Other, public wrapper<Other>
{
    public:
        typedef class_<OtherWrapper, bases<Base>, noncopyable > class_type;
};

BOOST_PYTHON_MODULE(pyother)
{
    OtherWrapper::class_type other("Other");
}


Python test
==========================================

#create a class exported in module pyother
t = Other()

#create a class exported in module pybase
o = Base()

#set base child
o.setChild(t)

#get object used in previous function
c = o.child()

#compare both object this need be true
print t
print c
print t == c


this happen when I use "Other" object in "setChild" and "child"
function. when I use "Base" object works fine.

I put a small example annexed in this e-mail.


--
BR
Renato Araujo Oliveira Filho
-------------- next part --------------
A non-text attachment was scrubbed...
Name: boosttest.tar.gz
Type: application/x-gzip
Size: 2566 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090422/18573b2c/attachment-0001.bin>


More information about the Cplusplus-sig mailing list