From 7363e4326dad151703ebc92f46b4ad2fe8e58238 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 7 Feb 2010 20:24:30 +0000 Subject: [PATCH] Fix for LXT/LXT2 output using MinGW. When using MinGW, routines registered via atexit() inside a DLL are only called when the DLL is detached. If not detached manually, DLLs are automatically detached *after* all remaining open files are closed. This meant that by the time the LXT or LXT2 close_dumpfile routine was called, the dump file handle was no longer valid, so any remaining output was lost. This patch fixes the problem by manually detaching the VPI modules. (cherry picked from commit 4818db887eb1ab550069bb4cde34b0d2ad695a89) --- vvp/main.cc | 8 +++++++- vvp/vpi_modules.cc | 8 -------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/vvp/main.cc b/vvp/main.cc index a452fcd33..4f436589a 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -450,12 +450,18 @@ int main(int argc, char*argv[]) modpath_delete(); vpi_handle_delete(); udp_defns_delete(); - load_module_delete(); island_delete(); signal_pool_delete(); vvp_net_pool_delete(); ufunc_pool_delete(); #endif +/* + * Unload the VPI modules. This is essential for MinGW, to ensure + * dump files are flushed before the main process terminates, as + * the DLL termination code is called after all remaining open + * files are automatically closed. +*/ + load_module_delete(); return vvp_return_value; } diff --git a/vvp/vpi_modules.cc b/vvp/vpi_modules.cc index 7997ff24b..7e509a19b 100644 --- a/vvp/vpi_modules.cc +++ b/vvp/vpi_modules.cc @@ -20,18 +20,14 @@ # include "config.h" # include "vpi_priv.h" # include "ivl_dlfcn.h" -#ifdef CHECK_WITH_VALGRIND # include "vvp_cleanup.h" -#endif # include # include # include # include -#ifdef CHECK_WITH_VALGRIND static ivl_dll_t*dll_list = 0; static unsigned dll_list_cnt = 0; -#endif typedef void (*vlog_startup_routines_t)(void); @@ -55,7 +51,6 @@ unsigned vpip_module_path_cnt = 0 #endif ; -#ifdef CHECK_WITH_VALGRIND void load_module_delete(void) { for (unsigned idx = 0; idx < dll_list_cnt; idx += 1) { @@ -65,7 +60,6 @@ void load_module_delete(void) dll_list = 0; dll_list_cnt = 0; } -#endif void vpip_load_module(const char*name) { @@ -162,12 +156,10 @@ void vpip_load_module(const char*name) return; } -#ifdef CHECK_WITH_VALGRIND /* Add the dll to the list so it can be closed when we are done. */ dll_list_cnt += 1; dll_list = (ivl_dll_t*)realloc(dll_list, dll_list_cnt*sizeof(ivl_dll_t)); dll_list[dll_list_cnt-1] = dll; -#endif vpi_mode_flag = VPI_MODE_REGISTER; vlog_startup_routines_t*routines = (vlog_startup_routines_t*)table;