Re: die with a reference should use overload "" operator
[p5sagit/p5-mst-13.2.git] / win32 / perllib.c
index 43d84c5..d1d942c 100644 (file)
@@ -2,31 +2,28 @@
  * "The Road goes ever on and on, down from the door where it began."
  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
 
-#ifdef __cplusplus
-}
-#  define EXTERN_C extern "C"
-#else
-#  define EXTERN_C extern
-#endif
-
 static void xs_init _((void));
 
-__declspec(dllexport) int
+DllExport int
 RunPerl(int argc, char **argv, char **env, void *iosubsystem)
 {
     int exitstatus;
     PerlInterpreter *my_perl;
-    void *pOldIOSubsystem;
 
-    pOldIOSubsystem = SetIOSubSystem(iosubsystem);
+#ifdef PERL_GLOBAL_STRUCT
+#define PERLVAR(var,type) /**/
+#define PERLVARI(var,type,init) PL_Vars.var = init;
+#define PERLVARIC(var,type,init) PL_Vars.var = init;
+#include "perlvars.h"
+#undef PERLVAR
+#undef PERLVARI
+#undef PERLVARIC
+#endif
 
     PERL_SYS_INIT(&argc,&argv);
 
@@ -35,7 +32,7 @@ RunPerl(int argc, char **argv, char **env, void *iosubsystem)
     if (!(my_perl = perl_alloc()))
        return (1);
     perl_construct( my_perl );
-    perl_destruct_level = 0;
+    PL_perl_destruct_level = 0;
 
     exitstatus = perl_parse( my_perl, xs_init, argc, argv, env);
     if (!exitstatus) {
@@ -47,52 +44,10 @@ RunPerl(int argc, char **argv, char **env, void *iosubsystem)
 
     PERL_SYS_TERM();
 
-    SetIOSubSystem(pOldIOSubsystem);
-
     return (exitstatus);
 }
 
-/* Register any extra external extensions */
-
-char *staticlinkmodules[] = {
-    "DynaLoader",
-    NULL,
-};
-
-EXTERN_C void boot_DynaLoader _((CV* cv));
-
-static
-XS(w32_GetCurrentDirectory)
-{
- dXSARGS;
- SV *sv = sv_newmortal();
- /* Make one call with zero size - return value is required size */
- DWORD len = GetCurrentDirectory((DWORD)0,NULL);
- SvUPGRADE(sv,SVt_PV);
- SvGROW(sv,len);
- SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv));
- /* 
-  * If result != 0 
-  *   then it worked, set PV valid, 
-  *   else leave it 'undef' 
-  */
- if (SvCUR(sv))
-  SvPOK_on(sv);
- EXTEND(sp,1);
- ST(0) = sv;
- XSRETURN(1);
-}
-
-static void
-xs_init()
-{
-    char *file = __FILE__;
-    dXSUB_SYS;
-    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
-    newXS("Win32::GetCurrentDirectory", w32_GetCurrentDirectory, file);
-}
-
-extern HANDLE PerlDllHandle;
+extern HANDLE w32_perldll_handle;
 
 BOOL APIENTRY
 DllMain(HANDLE hModule,                /* DLL module handle */
@@ -106,12 +61,12 @@ DllMain(HANDLE hModule,            /* DLL module handle */
     case DLL_PROCESS_ATTACH:
 /* #define DEFAULT_BINMODE */
 #ifdef DEFAULT_BINMODE
-       _setmode( _fileno( stdin  ), _O_BINARY );
-       _setmode( _fileno( stdout ), _O_BINARY );
-       _setmode( _fileno( stderr ), _O_BINARY );
-       _fmode = _O_BINARY;
+       setmode( fileno( stdin  ), O_BINARY );
+       setmode( fileno( stdout ), O_BINARY );
+       setmode( fileno( stderr ), O_BINARY );
+       _fmode = O_BINARY;
 #endif
-       PerlDllHandle = hModule;
+       w32_perldll_handle = hModule;
        break;
 
        /* The DLL is detaching from a process due to
@@ -133,3 +88,21 @@ DllMain(HANDLE hModule,             /* DLL module handle */
     }
     return TRUE;
 }
+
+/* Register any extra external extensions */
+
+char *staticlinkmodules[] = {
+    "DynaLoader",
+    NULL,
+};
+
+EXTERN_C void boot_DynaLoader _((CV* cv));
+
+static void
+xs_init()
+{
+    char *file = __FILE__;
+    dXSUB_SYS;
+    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+}
+