[C++-sig] c++ to python object conversion problem

Tim Blechmann tim at klingt.org
Sun Mar 4 14:37:01 CET 2007


hi roman ... thanks for your hint

i've added the wrapper code below the classes:

> > class simple: boost::noncopyable{};

class_<simple, boost::noncopyable>("simple");

> > an instance of this class (or a derived one) is allocated from python
> > and a pointer is stored in a class with a virtual function:
> >
> > class callback: boost::noncopyable
> > {
> >    virtual void overloadme(simple const &) = 0
> >    void run(void) { this->overloadme(s_); }
> >    void set(simple * s) {s_ = s;}
> >    simple * s_;
> > };
> >
> > this callback class is wrapped like it's described in the tutorial:
> >
> > class cbwrapper: callback, wrapper<callback>
> > {
> >    virtual void overloadme(simple const & s) {
> >        this->get_override("overloadme")(s);

class_<cbwrapper, boost::noncopyable>("callback")
    .def("set",  &cbwrapper::set)
    .def("overloadme", &cbwrapper::overloadme)
    ;

> I think that the problem in this line. By default Boost.Python pass copy of the
> object to the "override" function. In this case "simple" is noncopyable.
> ( I don't understand why you didn't get compile time error ).
> In my opinion you should change
>     this->get_override("...")(s)
> to
>     this->get_override( ... )( boost::ref(s) )

i tried this ... however python is crashing now:

>  0 PyFrame_New      PC=0xb7e2c81a, FP=0xb44aee68 [/usr/lib/libpython2.4.so.1.0]
   1 PyEval_EvalCodeEx PC=0xb7e79b74, FP=0xb44aeee8 [/usr/lib/libpython2.4.so.1.0]
   2 PyClassMethod_New PC=0xb7e2d81d, FP=0xb44aef48 [/usr/lib/libpython2.4.so.1.0]
   3 PyObject_Call    PC=0xb7e14a35, FP=0xb44aef68 [/usr/lib/libpython2.4.so.1.0]
   4 PyClass_IsSubclass PC=0xb7e1b05d, FP=0xb44af1b8 [/usr/lib/libpython2.4.so.1.0]
   5 PyObject_Call    PC=0xb7e14a35, FP=0xb44af1d8 [/usr/lib/libpython2.4.so.1.0]
   6 PyEval_CallObjectWithKeywords PC=0xb7e73d26, FP=0xb44af1f8 [/usr/lib/libpython2.4.so.1.0]
   7 PyEval_CallFunction PC=0xb7e94207, FP=0xb44af228 [/usr/lib/libpython2.4.so.1.0]
   8 boost::python::override::operator ()<boost::reference_wrapper<const simple> > PC=0xb66f0712, FP=0xb44af268 [/usr/include/boost/python/override.hpp#138]

> P.S. Py++ is aware of this and would generate the right from the beginning

... unfortunately, gccxml doesn't like my c++ code :/

any other hints or workarounds? 

thanks ... tim

--
tim at klingt.org    ICQ: 96771783
http://tim.klingt.org

A paranoid is a man who knows a little of what's going on.
  William S. Burroughs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070304/355f7dea/attachment.pgp>


More information about the Cplusplus-sig mailing list