[C++-sig] set python attribute from C++

David Abrahams dave at boostpro.com
Thu Jul 17 18:30:51 CEST 2008


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.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com



More information about the Cplusplus-sig mailing list