Improve at exit cleanup functions

Now they are run in a defined order not based on
the order of initialization
This commit is contained in:
Kovid Goyal
2021-04-01 11:48:36 +05:30
parent 0ec7e6c36f
commit 55dc354e68
11 changed files with 70 additions and 34 deletions

View File

@@ -12,6 +12,7 @@
#undef _DARWIN_C_SOURCE
#endif
#include "data-types.h"
#include "cleanup.h"
#include "safe-wrappers.h"
#include "control-codes.h"
#include "wcwidth-std.h"
@@ -226,6 +227,10 @@ PyInit_fast_data_types(void) {
m = PyModule_Create(&module);
if (m == NULL) return NULL;
if (Py_AtExit(run_at_exit_cleanup_functions) != 0) {
PyErr_SetString(PyExc_RuntimeError, "Failed to register the atexit cleanup handler");
return NULL;
}
init_monotonic();
if (!init_logging(m)) return NULL;
@@ -237,6 +242,7 @@ PyInit_fast_data_types(void) {
if (!init_child_monitor(m)) return NULL;
if (!init_ColorProfile(m)) return NULL;
if (!init_Screen(m)) return NULL;
if (!init_glfw(m)) return NULL;
if (!init_child(m)) return NULL;
if (!init_state(m)) return NULL;
if (!init_keys(m)) return NULL;
@@ -256,7 +262,6 @@ PyInit_fast_data_types(void) {
if (!init_freetype_render_ui_text(m)) return NULL;
#endif
if (!init_fonts(m)) return NULL;
if (!init_glfw(m)) return NULL;
PyModule_AddIntConstant(m, "BOLD", BOLD_SHIFT);
PyModule_AddIntConstant(m, "ITALIC", ITALIC_SHIFT);