[C++-sig] set python attribute from C++
Gennadiy Rozental
rogeeff at gmail.com
Thu Jul 17 18:19:05 CEST 2008
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.
Gennadiy
More information about the Cplusplus-sig
mailing list