Roman Yakovenko wrote:
> On 3/20/07, Mark Williams <mark image-engine.com> wrote:
>>> virtual ~event_t_wrapper(){
>>> if (this->m_pyobj) {
>>> //Py_DECREF(this->m_pyobj);
>>> this->m_pyobj = 0;
>>> }
>>> }
>>>
>> Many thanks for the solution - it appears to be
working just fine.
>> However I'm wondering why the Py_DECREF line above
is commented out?
>
> I don't remember. I think if you uncomment it the
object will be deleted twice.
>
OK. Unfortunately I'm finding that this solution does not
work in the
general case. If the Python derived class contains any
member data then
the program eventually segfaults - which is understandable
because the
instance has already been destructed at the time the virtual
member is
being called. I believe it may be the case that in many
simple cases the
solution posted works because the memory deallocated during
destructing
the class has not been overwritten.
Currently the only workaround I see is to add a
"transferOwnership"
member function which does the same reference inc/dec as the
posted
example, but must be explicitly called from within Python.
Unless, of
course, there is a way of accessing the PyObject* from
within the
wrappers constructor or somehow receiving notification when
boost::detail::initialize_wrapper() is called. The latter
would be
preferable but I do not (yet) see whether or not it is
feasible.
Thanks,
Mark
_______________________________________________
C++-sig mailing list
C++-sig python.org
http:
//mail.python.org/mailman/listinfo/c++-sig
|