Duplicate environment for JPL so that JDK 1.2/1.3 don't get upset.
Jarkko Hietaniemi [Wed, 14 Feb 2001 03:14:14 +0000 (03:14 +0000)]
p4raw-id: //depot/perl@8803

perl.c
perl.h

diff --git a/perl.c b/perl.c
index 0f0bb55..af1f27c 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -3257,6 +3257,8 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
     char *s;
     SV *sv;
     GV* tmpgv;
+    char **dup_env_base = 0;
+    int dup_env_count = 0;
 
     argc--,argv++;     /* skip name of script */
     if (PL_doswitches) {
@@ -3325,6 +3327,23 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
            env = environ;
        if (env != environ)
            environ[0] = Nullch;
+#ifdef NEED_ENVIRON_DUP_FOR_MODIFY
+       {
+           char **env_base;
+           for (env_base = env; *env; env++) 
+               dup_env_count++;
+           if ((dup_env_base = (char **)
+                safemalloc( 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);
+               *dup_env = Nullch;
+               env = dup_env_base;
+           } /* else what? */
+       }
+#endif /* NEED_ENVIRON_DUP_FOR_MODIFY */
        for (; *env; env++) {
            if (!(s = strchr(*env,'=')))
                continue;
@@ -3340,7 +3359,13 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
            (void)PerlEnv_putenv(savepv(*env));
 #endif
        }
-#endif
+       if (dup_env_base) {
+           char **dup_env;
+           for (dup_env = dup_env_base; *dup_env; dup_env++)
+               Safefree(*dup_env);
+           Safefree(dup_env_base);
+       }
+#endif /* USE_ENVIRON_ARRAY */
 #ifdef DYNAMIC_ENV_FETCH
        HvNAME(hv) = savepv(ENV_HV_NAME);
 #endif
diff --git a/perl.h b/perl.h
index 8953c6a..c92e4db 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -1692,6 +1692,13 @@ typedef struct ptr_tbl PTR_TBL_t;
 #  define USE_ENVIRON_ARRAY
 #endif
 
+#ifdef JPL
+    /* E.g. JPL needs to operate on a copy of the real environment.
+     * JDK 1.2 and 1.3 seem to get upset if the original environment
+     * is diddled with. */
+#   define NEED_ENVIRON_DUP_FOR_MODIFY
+#endif
+
 #ifndef PERL_SYS_INIT3
 #  define PERL_SYS_INIT3(argvp,argcp,envp) PERL_SYS_INIT(argvp,argcp)
 #endif