podlators 1.07, from Russ Allbery.
[p5sagit/p5-mst-13.2.git] / win32 / perllib.c
index 857aada..87b79c0 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * "The Road goes ever on and on, down from the door where it began."
  */
-
-
+#define PERLIO_NOT_STDIO 0
 #include "EXTERN.h"
 #include "perl.h"
 
@@ -338,6 +337,10 @@ RunPerl(int argc, char **argv, char **env)
 EXTERN_C void
 set_w32_module_name(void);
 
+EXTERN_C void
+EndSockets(void);
+
+
 #ifdef __MINGW32__
 EXTERN_C               /* GCC in C++ mode mangles the name, otherwise */
 #endif
@@ -367,6 +370,17 @@ DllMain(HANDLE hModule,            /* DLL module handle */
         * process termination or call to FreeLibrary.
         */
     case DLL_PROCESS_DETACH:
+        /* As long as we use TerminateProcess()/TerminateThread() etc. for mimicing kill()
+           anything here had better be harmless if:
+            A. Not called at all.
+            B. Called after memory allocation for Heap has been forcibly removed by OS.
+            PerlIO_cleanup() was done here but fails (B).
+         */     
+       EndSockets();
+#if defined(USE_THREADS) || defined(USE_ITHREADS)
+       if (PL_curinterp)
+           FREE_THREAD_KEY;
+#endif
        break;
 
        /* The attached process creates a new thread. */