This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Storable: various core fixups: $PERL,libpth,getcwd
[perl5.git] / win32 / runperl.c
index 8cf521d..2157224 100644 (file)
@@ -1,96 +1,42 @@
-#include "EXTERN.h"
-#include "perl.h"
-
-#ifdef PERL_OBJECT
-
-#define NO_XSLOCKS
-#include "XSUB.H"
-#include "win32iop.h"
-
-#include <fcntl.h>
-#include "perlhost.h"
-
-
-char *staticlinkmodules[] = {
-    "DynaLoader",
-    NULL,
-};
-
-EXTERN_C void boot_DynaLoader _((CV* cv _CPERLarg));
-
-static void
-xs_init(CPERLarg)
-{
-    char *file = __FILE__;
-    dXSUB_SYS;
-    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
-}
-
-CPerlObj *pPerl;
-
-#undef PERL_SYS_INIT
-#define PERL_SYS_INIT(a, c)
-
-int
-main(int argc, char **argv, char **env)
-{
-    CPerlHost host;
-    int exitstatus = 1;
-#ifndef __BORLANDC__
-    /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
-     * want to free() argv after main() returns.  As luck would have it,
-     * Borland's CRT does the right thing to argv[0] already. */
-    char szModuleName[MAX_PATH];
-
-    GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
-    argv[0] = szModuleName;
+#ifdef _MSC_VER
+#include <crtdbg.h>
 #endif
 
-    if (!host.PerlCreate())
-       exit(exitstatus);
-
-    exitstatus = host.PerlParse(xs_init, argc, argv, NULL);
-
-    if (!exitstatus)
-       exitstatus = host.PerlRun();
-
-    host.PerlDestroy();
-
-    return exitstatus;
-}
-
-#else  /* PERL_OBJECT */
+#include "EXTERN.h"
+#include "perl.h"
 
 #ifdef __GNUC__
-/*
- * GNU C does not do __declspec()
- */
-#define __declspec(foo) 
 
 /* Mingw32 defaults to globing command line 
  * This is inconsistent with other Win32 ports and 
  * seems to cause trouble with passing -DXSVERSION=\"1.6\" 
- * So we turn it off like this:
+ * So we turn it off like this, but only when compiling
+ * perlmain.c: perlmainst.c is linked into the same executable
+ * as win32.c, which also does this, so we mustn't do it twice
+ * otherwise we get a multiple definition error.
  */
+#ifndef PERLDLL
 int _CRT_glob = 0;
-
 #endif
 
-
-__declspec(dllimport) int RunPerl(int argc, char **argv, char **env, void *ios);
+#endif
 
 int
 main(int argc, char **argv, char **env)
 {
-#ifndef __BORLANDC__
-    /* XXX this _may_ be a problem on some compilers (e.g. Borland) that
-     * want to free() argv after main() returns.  As luck would have it,
-     * Borland's CRT does the right thing to argv[0] already. */
-    char szModuleName[MAX_PATH];
-    GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
-    argv[0] = szModuleName;
+#ifdef _MSC_VER
+    /* Arrange for _CrtDumpMemoryLeaks() to be called automatically at program
+     * termination when built with CFG = DebugFull. */
+    int currentFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
+    currentFlag |= _CRTDBG_LEAK_CHECK_DF;
+    _CrtSetDbgFlag(currentFlag);
+
+    /* Change this -1 to the allocation number of any reported memory leaks to
+     * break on the allocation call that was leaked. */
+    _CrtSetBreakAlloc(-1L);
 #endif
-    return RunPerl(argc, argv, env, (void*)0);
+
+    return RunPerl(argc, argv, env);
 }
 
-#endif  /* PERL_OBJECT */
+