[C++-sig] Crash at shutdown
Niall Douglas
s_sourceforge at nedprod.com
Sat Feb 11 14:59:13 CET 2012
On 10 Feb 2012 at 21:23, Jim Bosch wrote:
> > when I execute Boost.Python export statement in C it adds some records in
> > Boost.Python and Python interpreter. When C is unloaded from memory somehow
> > these records are not being cleaned up. By the time we get to clean this records
> > C is already unloaded from memory and either Boost.Python or Python interpreter
> > corrupt the memory.
>
> I'm pretty sure there's no programmatic way to remove something from the
> registry, and to add such a feature you'd have to modify the
> Boost.Python sources and recompile the shared library. If you're
> willing to do that, that might be a way out.
I was about to say the same as Jim, except to add that this is really
another example of why BPL lacks Py_Finalize() support if I remember
correctly. BPL can set itself up, but it's a one way action - it
cannot unwind itself.
> If it's at all possible, I think the safest bet would be to refactor
> things so that everything that gets exported to Python happens within a
> separate module that would be imported by the Python scripts, so you
> only rely on Python's own dlopen calls when it involves Boost.Python
> wrappers. If that's not feasible, you might try putting the wrapper
> code in a function in a library that never gets unloaded, even if that
> function is called by some library that may be unloaded.
The other thing to try is to force an immediate exit without
unwinding the DLL list :) e.g. TerminateProcess(self). Obviously, do
this after all buffers and such have been flushed, but just before
DLL unload.
The other thing, on Windows, is to manually hack increment the DLL
reference count to ensure the DLL never gets kicked out :) This works
well for this type of situation. Sometimes when working with other
people's broken libraries it's just easiest.
BTW I agree that code which cannot shut itself down cleanly is broken
and its authors should hang their heads appropriately and treat it as
a bug to be fixed rather than a feature to be added. That said, it
can be hard to anticipate every possible shutdown use case. I've
certainly been wowed by some user reports regarding my own libraries
coming in at times.
Niall
--
Technology & Consulting Services - ned Productions Limited.
http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Company no:
472909.
More information about the Cplusplus-sig
mailing list