[C++-sig] Segfaults in object deallocation
Niall Douglas
s_sourceforge at nedprod.com
Sat Mar 23 04:02:58 CET 2013
On 22 Mar 2013 at 14:33, Alex Leach wrote:
> So, in Environment's destructor, which I thought was a no-op, FastMutex's
> destructor is also being called. Now, that's a bit of a bummer. As far as
> I can tell (I'm still very new to C++; coming from Python), unlike how I
> hacked the initialiser list, I can't do any work either side of the
> chained base class destructor calls.
Separate C++ objects from their python wrappers. Have C++ objects
held by shared_ptr.
Have a custom deleter on shared_ptr invoke a virtual
int_PythonIsAboutToDelete() function before it actually calls delete.
You see as soon as destruction begins, all virtual functions cease to
work, so you need a predestructor stage.
Do your pre destruction cleanup like destroying mutexs in that
virtual function. Or indeed anything which can throw exceptions,
because destructors are (soon to be) noexcept.
Hope that helps,
Niall
--
Any opinions or advice expressed here do NOT reflect those
of my employer BlackBerry Inc.
Work Portfolio: http://careers.stackoverflow.com/nialldouglas/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SMime.p7s
Type: application/x-pkcs7-signature
Size: 6061 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20130322/c1186558/attachment.bin>
More information about the Cplusplus-sig
mailing list