[C++-sig] set python attribute from C++
Gennadiy Rozental
rogeeff at gmail.com
Thu Jul 17 20:08:13 CEST 2008
David Abrahams <dave <at> boostpro.com> writes:
> on Thu Jul 17 2008, Gennadiy Rozental <rogeeff-AT-gmail.com> wrote:
>
> > David Abrahams <dave <at> boostpro.com> writes:
> >> >> Base*
> >> >> PythonFactory::create(...)
> >> >> {
> >> >> bp::object obj = m_py_type();
> >> >> PythonBase* ptr = bp::extract<PythonBase*>( obj );
> >> >>
> >> >> ptr->init( obj );
> >> >
> >> > // make sure python object is not destroyed once we leave
> >> > // this scope
> >> > bp::incref( obj );
> >>
> >> Oh, well in that case, it adds nothing. You may as well leave
> >> the incref/decref out.
> >
> > No. I can't (or at least it does not work for me). Without it
> > python object is destroyed immediately once we leave create
> > function scope and ptr become dangling pointer.
>
> Then m_object is a raw pointer and not a bp::object as you've
> described in your code examples.
Hmm. You right. I do not need it anymore.
I used to need it because init method above was invoked later - after we left
create function. Not anymore. I removed both incref/decref and everything works
fine.
Thanks
Gennadiy
More information about the Cplusplus-sig
mailing list