[C++-sig] set python attribute from C++
David Abrahams
dave at boostpro.com
Thu Jul 17 17:55:49 CEST 2008
on Thu Jul 17 2008, Gennadiy Rozental <rogeeff-AT-gmail.com> wrote:
> Gennadiy Rozental <rogeeff <at> gmail.com> writes:
>
> Forgot to mention two critical bits of info
>
>> class PythonBase : public Base {
>> public:
> // release python object
> ~PythonBase() { bp::decref( m_object ) }
> ...
That looks like a recipe for double-deletion. When the bp::object m_object goes
out of scope, it will take care of that part.
>> 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.
>> return ptr;
>> }
>
> Gennadiy
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
More information about the Cplusplus-sig
mailing list