A modified version of
[p5sagit/p5-mst-13.2.git] / perl.c
diff --git a/perl.c b/perl.c
index af1f27c..0c4d907 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -253,9 +253,9 @@ perl_construct(pTHXx)
        if (PERL_REVISION > 127 || PERL_VERSION > 127 || PERL_SUBVERSION > 127)
            SvGROW(PL_patchlevel, UTF8_MAXLEN*3+1);
        s = (U8*)SvPVX(PL_patchlevel);
-       s = uv_to_utf8(s, (UV)PERL_REVISION);
-       s = uv_to_utf8(s, (UV)PERL_VERSION);
-       s = uv_to_utf8(s, (UV)PERL_SUBVERSION);
+       s = uv_to_utf8(s, (UV)(ASCII_TO_NATIVE(PERL_REVISION)));
+       s = uv_to_utf8(s, (UV)(ASCII_TO_NATIVE(PERL_VERSION)));
+       s = uv_to_utf8(s, (UV)(ASCII_TO_NATIVE(PERL_SUBVERSION)));
        *s = '\0';
        SvCUR_set(PL_patchlevel, s - (U8*)SvPVX(PL_patchlevel));
        SvPOK_on(PL_patchlevel);
@@ -438,6 +438,21 @@ perl_destruct(pTHXx)
        return;
     }
 
+    /* jettison our possibly duplicated environment */
+
+#ifdef USE_ENVIRON_ARRAY
+    if (environ != PL_origenviron) {
+       I32 i;
+
+       for (i = 0; environ[i]; i++)
+           safesysfree(environ[i]);
+       /* Must use safesysfree() when working with environ. */
+       safesysfree(environ);           
+
+       environ = PL_origenviron;
+    }
+#endif
+
     /* loosen bonds of global variables */
 
     if(PL_rsfp) {
@@ -730,6 +745,7 @@ perl_destruct(pTHXx)
     Safefree(PL_op_mask);
     Safefree(PL_psig_ptr);
     Safefree(PL_psig_name);
+    Safefree(PL_bitcount);
     Safefree(PL_psig_pend);
     nuke_stacks();
     PL_hints = 0;              /* Reset hints. Should hints be per-interpreter ? */
@@ -1173,6 +1189,7 @@ print \"  \\@INC:\\n    @INC\\n\";");
            PL_tainting = TRUE;
        else {
            while (s && *s) {
+               char *d;
                while (isSPACE(*s))
                    s++;
                if (*s == '-') {
@@ -1180,11 +1197,18 @@ print \"  \\@INC:\\n    @INC\\n\";");
                    if (isSPACE(*s))
                        continue;
                }
+               d = s;
                if (!*s)
                    break;
                if (!strchr("DIMUdmw", *s))
                    Perl_croak(aTHX_ "Illegal switch in PERL5OPT: -%c", *s);
-               s = moreswitches(s);
+               while (++s && *s) {
+                   if (isSPACE(*s)) {
+                       *s++ = '\0';
+                       break;
+                   }
+               }
+               moreswitches(d);
            }
        }
     }
@@ -2112,7 +2136,7 @@ Perl_moreswitches(pTHX_ char *s)
            PL_debug = atoi(s+1);
            for (s++; isDIGIT(*s); s++) ;
        }
-       PL_debug |= 0x80000000;
+       PL_debug |= DEBUG_TOP_FLAG;
 #else
        if (ckWARN_d(WARN_DEBUGGING))
            Perl_warner(aTHX_ WARN_DEBUGGING,
@@ -3258,7 +3282,9 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
     SV *sv;
     GV* tmpgv;
     char **dup_env_base = 0;
+#ifdef NEED_ENVIRON_DUP_FOR_MODIFY
     int dup_env_count = 0;
+#endif
 
     argc--,argv++;     /* skip name of script */
     if (PL_doswitches) {
@@ -3316,7 +3342,7 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
        HV *hv;
        GvMULTI_on(PL_envgv);
        hv = GvHVn(PL_envgv);
-       hv_magic(hv, PL_envgv, 'E');
+       hv_magic(hv, Nullgv, 'E');
 #ifdef USE_ENVIRON_ARRAY
        /* Note that if the supplied env parameter is actually a copy
           of the global environ then it may now point to free'd memory
@@ -3333,12 +3359,15 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
            for (env_base = env; *env; env++) 
                dup_env_count++;
            if ((dup_env_base = (char **)
-                safemalloc( sizeof(char *) * (dup_env_count+1) ))) {
+                safesysmalloc( sizeof(char *) * (dup_env_count+1) ))) {
                char **dup_env;
                for (env = env_base, dup_env = dup_env_base;
                     *env;
-                    env++, dup_env++)
-                   *dup_env = savepv(*env);
+                    env++, dup_env++) {
+                   /* With environ one needs to use safesysmalloc(). */
+                   *dup_env = safesysmalloc(strlen(*env) + 1);
+                   (void)strcpy(*dup_env, *env);
+               }
                *dup_env = Nullch;
                env = dup_env_base;
            } /* else what? */
@@ -3354,17 +3383,15 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
            sv = newSVpv(s--,0);
            (void)hv_store(hv, *env, s - *env, sv, 0);
            *s = '=';
-#if defined(__BORLANDC__) && defined(USE_WIN32_RTL_ENV)
-           /* Sins of the RTL. See note in my_setenv(). */
-           (void)PerlEnv_putenv(savepv(*env));
-#endif
        }
+#ifdef NEED_ENVIRON_DUP_FOR_MODIFY
        if (dup_env_base) {
            char **dup_env;
            for (dup_env = dup_env_base; *dup_env; dup_env++)
-               Safefree(*dup_env);
-           Safefree(dup_env_base);
+               safesysfree(*dup_env);
+           safesysfree(dup_env_base);
        }
+#endif /* NEED_ENVIRON_DUP_FOR_MODIFY */
 #endif /* USE_ENVIRON_ARRAY */
 #ifdef DYNAMIC_ENV_FETCH
        HvNAME(hv) = savepv(ENV_HV_NAME);