I'm withdrawing my pull request and continuing the discussion here.
I think that this is a better design than doing cleanup using
atexit. The reason is that libraries may also use
atexit, and it may be difficult to ensure the correct cleanup order for all platforms and versions of libraries (including future versions). For example, with the current design, all cleanup functions are called in one atexit handler, and they generally can't be ordered correctly with other atexit handlers.
Global object destructors are called after
exit too, so they should not call library functions that may be unsafe to call during exit.
atexit and similar techniques should still be used for things we want to clean up which the system does not clean up automatically. Of course, such cleanup functions must check if the cleanup is already done.
I tried to find places of exit in the current code:
- DoScriptMessage does exit(0); is this correct?
- Language::ReadLump does exit(0); is this correct?
- main return