Fossil SCM
unloadTcl is only needed on Win32, not for Win64 or any other platform.
Commit
0013d9ccb6595fd6ff120d548d976daede4a4626
Parent
1a30da30db0b238…
2 files changed
+2
-2
+10
-19
+2
-2
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -346,20 +346,20 @@ | ||
| 346 | 346 | /* |
| 347 | 347 | ** atexit() handler which frees up "some" of the resources |
| 348 | 348 | ** used by fossil. |
| 349 | 349 | */ |
| 350 | 350 | static void fossil_atexit(void) { |
| 351 | -#if defined(_WIN32) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) | |
| 351 | +#if defined(_WIN32) && !defined(_WIN64) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) | |
| 352 | 352 | /* |
| 353 | 353 | ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash |
| 354 | 354 | ** when exiting while a stubs-enabled Tcl is still loaded. This is due to |
| 355 | 355 | ** a bug in MinGW, see: |
| 356 | 356 | ** |
| 357 | 357 | ** http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724 |
| 358 | 358 | ** |
| 359 | 359 | ** The workaround is to manually unload the loaded Tcl library prior to |
| 360 | - ** exiting the process. | |
| 360 | + ** exiting the process. Win64 is not affected. | |
| 361 | 361 | */ |
| 362 | 362 | unloadTcl(g.interp, &g.tcl); |
| 363 | 363 | #endif |
| 364 | 364 | #ifdef FOSSIL_ENABLE_JSON |
| 365 | 365 | cson_value_free(g.json.gc.v); |
| 366 | 366 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -346,20 +346,20 @@ | |
| 346 | /* |
| 347 | ** atexit() handler which frees up "some" of the resources |
| 348 | ** used by fossil. |
| 349 | */ |
| 350 | static void fossil_atexit(void) { |
| 351 | #if defined(_WIN32) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) |
| 352 | /* |
| 353 | ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash |
| 354 | ** when exiting while a stubs-enabled Tcl is still loaded. This is due to |
| 355 | ** a bug in MinGW, see: |
| 356 | ** |
| 357 | ** http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724 |
| 358 | ** |
| 359 | ** The workaround is to manually unload the loaded Tcl library prior to |
| 360 | ** exiting the process. |
| 361 | */ |
| 362 | unloadTcl(g.interp, &g.tcl); |
| 363 | #endif |
| 364 | #ifdef FOSSIL_ENABLE_JSON |
| 365 | cson_value_free(g.json.gc.v); |
| 366 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -346,20 +346,20 @@ | |
| 346 | /* |
| 347 | ** atexit() handler which frees up "some" of the resources |
| 348 | ** used by fossil. |
| 349 | */ |
| 350 | static void fossil_atexit(void) { |
| 351 | #if defined(_WIN32) && !defined(_WIN64) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) |
| 352 | /* |
| 353 | ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash |
| 354 | ** when exiting while a stubs-enabled Tcl is still loaded. This is due to |
| 355 | ** a bug in MinGW, see: |
| 356 | ** |
| 357 | ** http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724 |
| 358 | ** |
| 359 | ** The workaround is to manually unload the loaded Tcl library prior to |
| 360 | ** exiting the process. Win64 is not affected. |
| 361 | */ |
| 362 | unloadTcl(g.interp, &g.tcl); |
| 363 | #endif |
| 364 | #ifdef FOSSIL_ENABLE_JSON |
| 365 | cson_value_free(g.json.gc.v); |
| 366 |
+10
-19
| --- src/th_tcl.c | ||
| +++ src/th_tcl.c | ||
| @@ -868,49 +868,35 @@ | ||
| 868 | 868 | return TH_ERROR; |
| 869 | 869 | } |
| 870 | 870 | return TH_OK; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | +#if defined(_WIN32) && !defined(_WIN64) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) | |
| 873 | 874 | /* |
| 874 | 875 | ** Finalizes and unloads the previously loaded Tcl library, if applicable. |
| 875 | 876 | */ |
| 876 | 877 | int unloadTcl( |
| 877 | 878 | Th_Interp *interp, |
| 878 | 879 | void *pContext |
| 879 | 880 | ){ |
| 880 | 881 | struct TclContext *tclContext = (struct TclContext *)pContext; |
| 881 | 882 | Tcl_Interp *tclInterp; |
| 882 | - tcl_FinalizeProc *xFinalize; | |
| 883 | -#if defined(USE_TCL_STUBS) | |
| 884 | 883 | void *library; |
| 885 | -#endif /* defined(USE_TCL_STUBS) */ | |
| 886 | 884 | |
| 887 | 885 | if ( !tclContext ){ |
| 888 | 886 | Th_ErrorMessage(interp, |
| 889 | 887 | "invalid Tcl context", (const char *)"", 0); |
| 890 | 888 | return TH_ERROR; |
| 891 | 889 | } |
| 892 | 890 | /* |
| 893 | - ** Grab the Tcl_Finalize function pointer prior to deleting the Tcl | |
| 894 | - ** interpreter because the memory backing the Tcl stubs table will | |
| 895 | - ** be going away. | |
| 896 | - */ | |
| 897 | - xFinalize = tclContext->xFinalize; | |
| 898 | - /* | |
| 899 | 891 | ** If the Tcl interpreter has been created, formally delete it now. |
| 900 | 892 | */ |
| 901 | 893 | tclInterp = tclContext->interp; |
| 902 | 894 | if ( tclInterp ){ |
| 903 | 895 | Tcl_DeleteInterp(tclInterp); |
| 904 | - tclContext->interp = tclInterp = 0; | |
| 905 | - } | |
| 906 | - /* | |
| 907 | - ** If the Tcl library is not finalized prior to unloading it, a deadlock | |
| 908 | - ** can occur in some circumstances (i.e. the [clock] thread is running). | |
| 909 | - */ | |
| 910 | - if( xFinalize ) xFinalize(); | |
| 911 | -#if defined(USE_TCL_STUBS) | |
| 896 | + tclContext->interp = 0; | |
| 897 | + } | |
| 912 | 898 | /* |
| 913 | 899 | ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash |
| 914 | 900 | ** when exiting while a stubs-enabled Tcl is still loaded. This is due to |
| 915 | 901 | ** a bug in MinGW, see: |
| 916 | 902 | ** |
| @@ -919,16 +905,21 @@ | ||
| 919 | 905 | ** The workaround is to manually unload the loaded Tcl library prior to |
| 920 | 906 | ** exiting the process. |
| 921 | 907 | */ |
| 922 | 908 | library = tclContext->library; |
| 923 | 909 | if( library ){ |
| 910 | + /* | |
| 911 | + ** If the Tcl library is not finalized prior to unloading it, a deadlock | |
| 912 | + ** can occur in some circumstances (i.e. the [clock] thread is running). | |
| 913 | + */ | |
| 914 | + tclContext->xFinalize(); | |
| 924 | 915 | dlclose(library); |
| 925 | - tclContext->library = library = 0; | |
| 916 | + tclContext->library = 0; | |
| 926 | 917 | } |
| 927 | -#endif /* defined(USE_TCL_STUBS) */ | |
| 928 | 918 | return TH_OK; |
| 929 | 919 | } |
| 920 | +#endif | |
| 930 | 921 | |
| 931 | 922 | /* |
| 932 | 923 | ** Register the Tcl language commands with interpreter interp. |
| 933 | 924 | ** Usually this is called soon after interpreter creation. |
| 934 | 925 | */ |
| 935 | 926 |
| --- src/th_tcl.c | |
| +++ src/th_tcl.c | |
| @@ -868,49 +868,35 @@ | |
| 868 | return TH_ERROR; |
| 869 | } |
| 870 | return TH_OK; |
| 871 | } |
| 872 | |
| 873 | /* |
| 874 | ** Finalizes and unloads the previously loaded Tcl library, if applicable. |
| 875 | */ |
| 876 | int unloadTcl( |
| 877 | Th_Interp *interp, |
| 878 | void *pContext |
| 879 | ){ |
| 880 | struct TclContext *tclContext = (struct TclContext *)pContext; |
| 881 | Tcl_Interp *tclInterp; |
| 882 | tcl_FinalizeProc *xFinalize; |
| 883 | #if defined(USE_TCL_STUBS) |
| 884 | void *library; |
| 885 | #endif /* defined(USE_TCL_STUBS) */ |
| 886 | |
| 887 | if ( !tclContext ){ |
| 888 | Th_ErrorMessage(interp, |
| 889 | "invalid Tcl context", (const char *)"", 0); |
| 890 | return TH_ERROR; |
| 891 | } |
| 892 | /* |
| 893 | ** Grab the Tcl_Finalize function pointer prior to deleting the Tcl |
| 894 | ** interpreter because the memory backing the Tcl stubs table will |
| 895 | ** be going away. |
| 896 | */ |
| 897 | xFinalize = tclContext->xFinalize; |
| 898 | /* |
| 899 | ** If the Tcl interpreter has been created, formally delete it now. |
| 900 | */ |
| 901 | tclInterp = tclContext->interp; |
| 902 | if ( tclInterp ){ |
| 903 | Tcl_DeleteInterp(tclInterp); |
| 904 | tclContext->interp = tclInterp = 0; |
| 905 | } |
| 906 | /* |
| 907 | ** If the Tcl library is not finalized prior to unloading it, a deadlock |
| 908 | ** can occur in some circumstances (i.e. the [clock] thread is running). |
| 909 | */ |
| 910 | if( xFinalize ) xFinalize(); |
| 911 | #if defined(USE_TCL_STUBS) |
| 912 | /* |
| 913 | ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash |
| 914 | ** when exiting while a stubs-enabled Tcl is still loaded. This is due to |
| 915 | ** a bug in MinGW, see: |
| 916 | ** |
| @@ -919,16 +905,21 @@ | |
| 919 | ** The workaround is to manually unload the loaded Tcl library prior to |
| 920 | ** exiting the process. |
| 921 | */ |
| 922 | library = tclContext->library; |
| 923 | if( library ){ |
| 924 | dlclose(library); |
| 925 | tclContext->library = library = 0; |
| 926 | } |
| 927 | #endif /* defined(USE_TCL_STUBS) */ |
| 928 | return TH_OK; |
| 929 | } |
| 930 | |
| 931 | /* |
| 932 | ** Register the Tcl language commands with interpreter interp. |
| 933 | ** Usually this is called soon after interpreter creation. |
| 934 | */ |
| 935 |
| --- src/th_tcl.c | |
| +++ src/th_tcl.c | |
| @@ -868,49 +868,35 @@ | |
| 868 | return TH_ERROR; |
| 869 | } |
| 870 | return TH_OK; |
| 871 | } |
| 872 | |
| 873 | #if defined(_WIN32) && !defined(_WIN64) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) |
| 874 | /* |
| 875 | ** Finalizes and unloads the previously loaded Tcl library, if applicable. |
| 876 | */ |
| 877 | int unloadTcl( |
| 878 | Th_Interp *interp, |
| 879 | void *pContext |
| 880 | ){ |
| 881 | struct TclContext *tclContext = (struct TclContext *)pContext; |
| 882 | Tcl_Interp *tclInterp; |
| 883 | void *library; |
| 884 | |
| 885 | if ( !tclContext ){ |
| 886 | Th_ErrorMessage(interp, |
| 887 | "invalid Tcl context", (const char *)"", 0); |
| 888 | return TH_ERROR; |
| 889 | } |
| 890 | /* |
| 891 | ** If the Tcl interpreter has been created, formally delete it now. |
| 892 | */ |
| 893 | tclInterp = tclContext->interp; |
| 894 | if ( tclInterp ){ |
| 895 | Tcl_DeleteInterp(tclInterp); |
| 896 | tclContext->interp = 0; |
| 897 | } |
| 898 | /* |
| 899 | ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash |
| 900 | ** when exiting while a stubs-enabled Tcl is still loaded. This is due to |
| 901 | ** a bug in MinGW, see: |
| 902 | ** |
| @@ -919,16 +905,21 @@ | |
| 905 | ** The workaround is to manually unload the loaded Tcl library prior to |
| 906 | ** exiting the process. |
| 907 | */ |
| 908 | library = tclContext->library; |
| 909 | if( library ){ |
| 910 | /* |
| 911 | ** If the Tcl library is not finalized prior to unloading it, a deadlock |
| 912 | ** can occur in some circumstances (i.e. the [clock] thread is running). |
| 913 | */ |
| 914 | tclContext->xFinalize(); |
| 915 | dlclose(library); |
| 916 | tclContext->library = 0; |
| 917 | } |
| 918 | return TH_OK; |
| 919 | } |
| 920 | #endif |
| 921 | |
| 922 | /* |
| 923 | ** Register the Tcl language commands with interpreter interp. |
| 924 | ** Usually this is called soon after interpreter creation. |
| 925 | */ |
| 926 |