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

Tim Blechmann tim at klingt.org
Sun Mar 4 15:48:25 CET 2007


hi roman,

i just figured out, that it was a simple python threading issue, because
the c++ thread hasn't been synchronized with python.
after guarding the calls to the override object by a
PyGILState_Ensure()/Release() pair, it works flawless!

cheers ... tim

On Sun, 2007-03-04 at 16:21 +0200, Roman Yakovenko wrote:
> On 3/4/07, Tim Blechmann <tim at klingt.org> wrote:
> > 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)
> 
> A problem could also be here, you have to set call policies:
> http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies
> 
> Also, creating small and **complete** is much better way to get help.
> 
--
tim at klingt.org    ICQ: 96771783
http://tim.klingt.org

Life is really simple, but we insist on making it complicated.
  Confucius
-------------- 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/e1616dd9/attachment.pgp>


More information about the Cplusplus-sig mailing list