(struct xftface_info): Delete the member xft_draw.
[bpt/emacs.git] / src / callproc.c
index 65a75d6..567fe3a 100644 (file)
@@ -75,7 +75,7 @@ extern int errno;
 #include "lisp.h"
 #include "commands.h"
 #include "buffer.h"
-#include "charset.h"
+#include "character.h"
 #include "ccl.h"
 #include "coding.h"
 #include "composite.h"
@@ -113,13 +113,13 @@ Lisp_Object Vtemp_file_name_pattern;
 
 Lisp_Object Vshell_file_name;
 
-Lisp_Object Vprocess_environment;
+Lisp_Object Vprocess_environment, Vinitial_environment;
 
 #ifdef DOS_NT
 Lisp_Object Qbuffer_file_type;
 #endif /* DOS_NT */
 
-/* True iff we are about to fork off a synchronous process or if we
+/* True if we are about to fork off a synchronous process or if we
    are waiting for it.  */
 int synch_process_alive;
 
@@ -141,6 +141,8 @@ int synch_process_retcode;
 /* Nonzero if this is termination due to exit.  */
 static int call_process_exited;
 
+EXFUN (Fgetenv_internal, 2);
+
 #ifndef VMS  /* VMS version is in vmsproc.c.  */
 
 static Lisp_Object
@@ -276,6 +278,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
     if (nargs >= 5)
       {
        int must_encode = 0;
+       Lisp_Object coding_attrs;
 
        for (i = 4; i < nargs; i++)
          CHECK_STRING (args[i]);
@@ -301,11 +304,15 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
            else
              val = Qnil;
          }
+       val = coding_inherit_eol_type (val, Qnil);
        setup_coding_system (Fcheck_coding_system (val), &argument_coding);
-       if (argument_coding.common_flags & CODING_ASCII_INCOMPATIBLE_MASK)
-         setup_coding_system (Qraw_text, &argument_coding);
-       if (argument_coding.eol_type == CODING_EOL_UNDECIDED)
-         argument_coding.eol_type = system_eol_type;
+       coding_attrs = CODING_ID_ATTRS (argument_coding.id);
+       if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs)))
+         {
+           /* We should not use an ASCII incompatible coding system.  */
+           val = raw_text_coding_system (val);
+           setup_coding_system (val, &argument_coding);
+         }
       }
   }
 
@@ -428,12 +435,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
        {
          argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
          if (CODING_REQUIRE_ENCODING (&argument_coding))
-           {
-             /* We must encode this argument.  */
-             args[i] = encode_coding_string (args[i], &argument_coding, 1);
-             if (argument_coding.type == coding_type_ccl)
-               setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);
-           }
+           /* We must encode this argument.  */
+           args[i] = encode_coding_string (&argument_coding, args[i], 1);
          new_argv[i - 3] = SDATA (args[i]);
        }
       UNGCPRO;
@@ -745,19 +748,15 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
          else
            val = Qnil;
        }
-      setup_coding_system (Fcheck_coding_system (val), &process_coding);
+      Fcheck_coding_system (val);
       /* In unibyte mode, character code conversion should not take
         place but EOL conversion should.  So, setup raw-text or one
         of the subsidiary according to the information just setup.  */
       if (NILP (current_buffer->enable_multibyte_characters)
          && !NILP (val))
-       setup_raw_text_coding_system (&process_coding);
+       val = raw_text_coding_system (val);
+      setup_coding_system (val, &process_coding);
     }
-  process_coding.src_multibyte = 0;
-  process_coding.dst_multibyte
-    = (BUFFERP (buffer)
-       ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters)
-       : ! NILP (current_buffer->enable_multibyte_characters));
 
   immediate_quit = 1;
   QUIT;
@@ -769,12 +768,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
     int carryover = 0;
     int display_on_the_fly = display_p;
     struct coding_system saved_coding;
-    int pt_orig = PT, pt_byte_orig = PT_BYTE;
-    int inserted;
 
     saved_coding = process_coding;
-    if (process_coding.composing != COMPOSITION_DISABLED)
-      coding_allocate_composition_data (&process_coding, PT);
     while (1)
       {
        /* Repeatedly read until we've filled as much as possible
@@ -807,133 +802,49 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
 
        if (!NILP (buffer))
          {
-           if (! CODING_MAY_REQUIRE_DECODING (&process_coding))
+           if (NILP (current_buffer->enable_multibyte_characters)
+               && ! CODING_MAY_REQUIRE_DECODING (&process_coding))
              insert_1_both (buf, nread, nread, 0, 1, 0);
            else
              {                 /* We have to decode the input.  */
-               int size;
-               char *decoding_buf;
-
-             repeat_decoding:
-               size = decoding_buffer_size (&process_coding, nread);
-               decoding_buf = (char *) xmalloc (size);
-
-               /* We can't use the macro CODING_REQUIRE_DETECTION
-                  because it always returns nonzero if the coding
-                  system requires EOL detection.  Here, we have to
-                  check only whether or not the coding system
-                  requires text-encoding detection.  */
-               if (process_coding.type == coding_type_undecided)
-                 {
-                   detect_coding (&process_coding, buf, nread);
-                   if (process_coding.composing != COMPOSITION_DISABLED)
-                     /* We have not yet allocated the composition
-                        data because the coding type was undecided.  */
-                     coding_allocate_composition_data (&process_coding, PT);
-                 }
-               if (process_coding.cmp_data)
-                 process_coding.cmp_data->char_offset = PT;
-
-               decode_coding (&process_coding, buf, decoding_buf,
-                              nread, size);
+               Lisp_Object curbuf;
 
+               XSETBUFFER (curbuf, current_buffer);
+               decode_coding_c_string (&process_coding, buf, nread,
+                                       curbuf);
                if (display_on_the_fly
-                   && saved_coding.type == coding_type_undecided
-                   && process_coding.type != coding_type_undecided)
+                   && CODING_REQUIRE_DETECTION (&saved_coding)
+                   && ! CODING_REQUIRE_DETECTION (&process_coding))
                  {
                    /* We have detected some coding system.  But,
                       there's a possibility that the detection was
-                      done by insufficient data.  So, we try the code
-                      detection again with more data.  */
-                   xfree (decoding_buf);
+                      done by insufficient data.  So, we give up
+                      displaying on the fly.  */
+                   if (process_coding.produced > 0)
+                     del_range_2 (process_coding.dst_pos,
+                                  process_coding.dst_pos_byte,
+                                  process_coding.dst_pos
+                                  + process_coding.produced_char,
+                                  process_coding.dst_pos_byte
+                                  + process_coding.produced, 0);
                    display_on_the_fly = 0;
                    process_coding = saved_coding;
                    carryover = nread;
                    /* This is to make the above condition always
                       fails in the future.  */
-                   saved_coding.type = coding_type_no_conversion;
+                   saved_coding.common_flags
+                     &= ~CODING_REQUIRE_DETECTION_MASK;
                    continue;
                  }
 
-               if (process_coding.produced > 0)
-                 insert_1_both (decoding_buf, process_coding.produced_char,
-                                process_coding.produced, 0, 1, 0);
-               xfree (decoding_buf);
-
-               if (process_coding.result == CODING_FINISH_INCONSISTENT_EOL)
-                 {
-                   Lisp_Object eol_type, coding;
-
-                   if (process_coding.eol_type == CODING_EOL_CR)
-                     {
-                       /* CRs have been replaced with LFs.  Undo
-                          that in the text inserted above.  */
-                       unsigned char *p;
-
-                       move_gap_both (PT, PT_BYTE);
-
-                       p = BYTE_POS_ADDR (pt_byte_orig);
-                       for (; p < GPT_ADDR; ++p)
-                         if (*p == '\n')
-                           *p = '\r';
-                     }
-                   else if (process_coding.eol_type == CODING_EOL_CRLF)
-                     {
-                       /* CR LFs have been replaced with LFs.  Undo
-                          that by inserting CRs in front of LFs in
-                          the text inserted above.  */
-                       EMACS_INT bytepos, old_pt, old_pt_byte, nCR;
-
-                       old_pt = PT;
-                       old_pt_byte = PT_BYTE;
-                       nCR = 0;
-
-                       for (bytepos = PT_BYTE - 1;
-                            bytepos >= pt_byte_orig;
-                            --bytepos)
-                         if (FETCH_BYTE (bytepos) == '\n')
-                           {
-                             EMACS_INT charpos = BYTE_TO_CHAR (bytepos);
-                             TEMP_SET_PT_BOTH (charpos, bytepos);
-                             insert_1_both ("\r", 1, 1, 0, 1, 0);
-                             ++nCR;
-                           }
-
-                       TEMP_SET_PT_BOTH (old_pt + nCR, old_pt_byte + nCR);
-                     }
-
-                   /* Set the coding system symbol to that for
-                      Unix-like EOL.  */
-                   eol_type = Fget (saved_coding.symbol, Qeol_type);
-                   if (VECTORP (eol_type)
-                       && ASIZE (eol_type) == 3
-                       && SYMBOLP (AREF (eol_type, CODING_EOL_LF)))
-                     coding = AREF (eol_type, CODING_EOL_LF);
-                   else
-                     coding = saved_coding.symbol;
-
-                   process_coding.symbol = coding;
-                   process_coding.eol_type = CODING_EOL_LF;
-                   process_coding.mode
-                     &= ~CODING_MODE_INHIBIT_INCONSISTENT_EOL;
-                 }
-
-               nread -= process_coding.consumed;
-               carryover = nread;
+               TEMP_SET_PT_BOTH (PT + process_coding.produced_char,
+                                 PT_BYTE + process_coding.produced);
+               carryover = process_coding.carryover_bytes;
                if (carryover > 0)
                  /* As CARRYOVER should not be that large, we had
                     better avoid overhead of bcopy.  */
-                 BCOPY_SHORT (buf + process_coding.consumed, buf,
-                              carryover);
-               if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP)
-                 {
-                   /* The decoding ended because of insufficient data
-                      area to record information about composition.
-                      We must try decoding with additional data area
-                      before reading more output for the process.  */
-                   coding_allocate_composition_data (&process_coding, PT);
-                   goto repeat_decoding;
-                 }
+                 BCOPY_SHORT (process_coding.carryover, buf,
+                              process_coding.carryover_bytes);
              }
          }
 
@@ -964,33 +875,12 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
       }
   give_up: ;
 
-    if (!NILP (buffer)
-       && process_coding.cmp_data)
-      {
-       coding_restore_composition (&process_coding, Fcurrent_buffer ());
-       coding_free_composition_data (&process_coding);
-      }
-
-    {
-      int post_read_count = SPECPDL_INDEX ();
-
-      record_unwind_protect (save_excursion_restore, save_excursion_save ());
-      inserted = PT - pt_orig;
-      TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig);
-      if (SYMBOLP (process_coding.post_read_conversion)
-         && !NILP (Ffboundp (process_coding.post_read_conversion)))
-       call1 (process_coding.post_read_conversion, make_number (inserted));
-
-      Vlast_coding_system_used = process_coding.symbol;
-
-      /* If the caller required, let the buffer inherit the
-        coding-system used to decode the process output.  */
-      if (inherit_process_coding_system)
-       call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
-              make_number (total_read));
-
-      unbind_to (post_read_count, Qnil);
-    }
+    Vlast_coding_system_used = CODING_ID_NAME (process_coding.id);
+    /* If the caller required, let the buffer inherit the
+       coding-system used to decode the process output.  */
+    if (inherit_process_coding_system)
+      call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
+              make_number (total_read));
   }
 
   /* Wait for it to terminate, unless it already has.  */
@@ -1245,8 +1135,6 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
 {
   char **env;
   char *pwd_var;
-  char *term_var;
-  char *display_var;
 #ifdef WINDOWSNT
   int cpid;
   HANDLE handles[3];
@@ -1275,9 +1163,10 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
 
   /* Note that use of alloca is always safe here.  It's obvious for systems
      that do not have true vfork or that have true (stack) alloca.
-     If using vfork and C_ALLOCA it is safe because that changes
-     the superior's static variables as if the superior had done alloca
-     and will be cleaned up in the usual way.  */
+     If using vfork and C_ALLOCA (when Emacs used to include
+     src/alloca.c) it is safe because that changes the superior's
+     static variables as if the superior had done alloca and will be
+     cleaned up in the usual way. */
   {
     register char *temp;
     register int i;
@@ -1327,53 +1216,45 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
     register char **new_env;
     char **p, **q;
     register int new_length;
-    Lisp_Object local = selected_frame; /* get_frame_param (XFRAME (Fframe_with_environment (selected_frame)), */
-/*                                          Qenvironment); */
-
-    Lisp_Object term;
-    Lisp_Object display;
+    Lisp_Object display = Qnil;
     
     new_length = 0;
 
     for (tem = Vprocess_environment;
          CONSP (tem) && STRINGP (XCAR (tem));
          tem = XCDR (tem))
-      new_length++;
-
-#if 0    
-    for (tem = local;
-        CONSP (tem) && STRINGP (XCAR (tem));
-        tem = XCDR (tem))
-      new_length++;
-#endif
-
-    /* Add TERM and DISPLAY from the frame local values. */
-    term = get_frame_param (XFRAME (local), Qterm_environment_variable);
-    if (! NILP (term))
-      new_length++;
+      {
+       if (strncmp (SDATA (XCAR (tem)), "DISPLAY", 7) == 0
+           && (SDATA (XCAR (tem)) [7] == '\0'
+               || SDATA (XCAR (tem)) [7] == '='))
+         /* DISPLAY is specified in process-environment.  */
+         display = Qt;
+       new_length++;
+      }
 
-    display = get_frame_param (XFRAME (local), Qdisplay_environment_variable);
-    if (! NILP (display))
-      new_length++;
+    /* If not provided yet, use the frame's DISPLAY.  */
+    if (NILP (display))
+      {
+       Lisp_Object tmp = Fframe_parameter (selected_frame, Qdisplay);
+       if (!STRINGP (tmp) && CONSP (Vinitial_environment))
+         /* If still not found, Look for DISPLAY in Vinitial_environment.  */
+         tmp = Fgetenv_internal (build_string ("DISPLAY"),
+                                 Vinitial_environment);
+       if (STRINGP (tmp))
+         {
+           display = tmp;
+           new_length++;
+         }
+      }
 
     /* new_length + 2 to include PWD and terminating 0.  */
     env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
-
     /* If we have a PWD envvar, pass one down,
        but with corrected value.  */
     if (egetenv ("PWD"))
       *new_env++ = pwd_var;
  
-    if (! NILP (term))
-      {
-       int vlen = strlen ("TERM=") + strlen (SDATA (term)) + 1;
-       char *vdata = (char *) alloca (vlen);
-       strcpy (vdata, "TERM=");
-       strcat (vdata, SDATA (term));
-       new_env = add_env (env, new_env, vdata);
-      }
-
-    if (! NILP (display))
+    if (STRINGP (display))
       {
        int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1;
        char *vdata = (char *) alloca (vlen);
@@ -1386,21 +1267,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
     for (tem = Vprocess_environment;
         CONSP (tem) && STRINGP (XCAR (tem));
         tem = XCDR (tem))
-      {
-       if ((strcmp (SDATA (XCAR (tem)), "TERM") != 0)
-           && (strcmp (SDATA (XCAR (tem)), "DISPLAY") != 0))
-         new_env = add_env (env, new_env, SDATA (XCAR (tem)));
-      }
-
-  
-#if 0    
-    /* Local part of environment.  */
-    for (tem = local;
-         CONSP (tem) && STRINGP (XCAR (tem));
-         tem = XCDR (tem))
       new_env = add_env (env, new_env, SDATA (XCAR (tem)));
-#endif
-    
+
     *new_env = 0;
 
     /* Remove variable names without values.  */
@@ -1408,7 +1276,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
     while (*p != 0)
       {
         while (*q != 0 && strchr (*q, '=') == NULL)
-          *q++;
+          q++;
         *p = *q++;
         if (*p != 0)
           p++;
@@ -1529,129 +1397,74 @@ relocate_fd (fd, minfd)
 }
 
 static int
-getenv_internal (var, varlen, value, valuelen, frame)
+getenv_internal_1 (var, varlen, value, valuelen, env)
      char *var;
      int varlen;
      char **value;
      int *valuelen;
-     Lisp_Object frame;
+     Lisp_Object env;
 {
-  Lisp_Object scan;
-  Lisp_Object term;
-  Lisp_Object display;
-  
-
-  if (NILP (frame))
+  for (; CONSP (env); env = XCDR (env))
     {
-      /* Try to find VAR in Vprocess_environment first.  */
-      for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
-        {
-          Lisp_Object entry = XCAR (scan);
-          if (STRINGP (entry)
-              && SBYTES (entry) >= varlen
+      Lisp_Object entry = XCAR (env);
+      if (STRINGP (entry)
+         && SBYTES (entry) >= varlen
 #ifdef WINDOWSNT
-              /* NT environment variables are case insensitive.  */
-              && ! strnicmp (SDATA (entry), var, varlen)
+         /* NT environment variables are case insensitive.  */
+         && ! strnicmp (SDATA (entry), var, varlen)
 #else  /* not WINDOWSNT */
-              && ! bcmp (SDATA (entry), var, varlen)
+         && ! bcmp (SDATA (entry), var, varlen)
 #endif /* not WINDOWSNT */
-              )
-            {
-              if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
-                {
-                  *value = (char *) SDATA (entry) + (varlen + 1);
-                  *valuelen = SBYTES (entry) - (varlen + 1);
-                  return 1;
-                }
-              else if (SBYTES (entry) == varlen)
-                {
-                  /* Lone variable names in Vprocess_environment mean that
-                     variable should be removed from the environment. */
-                  return 0;
-                }
-            }
-        }
-      frame = selected_frame;
+         )
+       {
+         if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
+           {
+             *value = (char *) SDATA (entry) + (varlen + 1);
+             *valuelen = SBYTES (entry) - (varlen + 1);
+             return 1;
+           }
+         else if (SBYTES (entry) == varlen)
+           {
+             /* Lone variable names in Vprocess_environment mean that
+                variable should be removed from the environment. */
+             *value = NULL;
+             return 1;
+           }
+       }
     }
+  return 0;
+}
 
-  /* For TERM and DISPLAY first try to get the values from the frame. */
-  term = get_frame_param (XFRAME (frame), Qterm_environment_variable);
-  if (strcmp (var, "TERM") == 0)
-    if (! NILP (term))
-      {
-         *value    = (char *) SDATA (term);
-         *valuelen = SBYTES (term);
-         return 1;
-      }
-  display = get_frame_param (XFRAME (frame), Qdisplay_environment_variable);
-  if (strcmp (var, "DISPLAY") == 0)
-    if (! NILP (display))
-      {
-         *value    = (char *) SDATA (display);
-         *valuelen = SBYTES (display);
-         return 1;
-      }
-
-  {
-    /* Try to find VAR in Vprocess_environment.  */
-    for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
-      {
-       Lisp_Object entry = XCAR (scan);
-       if (STRINGP (entry)
-           && SBYTES (entry) >= varlen
-#ifdef WINDOWSNT
-           /* NT environment variables are case insensitive.  */
-           && ! strnicmp (SDATA (entry), var, varlen)
-#else  /* not WINDOWSNT */
-           && ! bcmp (SDATA (entry), var, varlen)
-#endif /* not WINDOWSNT */
-           )
-         {
-           if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
-             {
-               *value = (char *) SDATA (entry) + (varlen + 1);
-               *valuelen = SBYTES (entry) - (varlen + 1);
-               return 1;
-             }
-           else if (SBYTES (entry) == varlen)
-             {
-               /* Lone variable names in Vprocess_environment mean that
-                  variable should be removed from the environment. */
-               return 0;
-             }
-         }
-      }
-  }
-
-#if 0
-  /* Find the environment in which to search the variable. */
-  CHECK_FRAME (frame);
-  frame = Fframe_with_environment (frame);
+static int
+getenv_internal (var, varlen, value, valuelen, frame)
+     char *var;
+     int varlen;
+     char **value;
+     int *valuelen;
+     Lisp_Object frame;
+{
+  /* Try to find VAR in Vprocess_environment first.  */
+  if (getenv_internal_1 (var, varlen, value, valuelen,
+                        Vprocess_environment))
+    return *value ? 1 : 0;
 
-  for (scan = get_frame_param (XFRAME (frame), Qenvironment);
-       CONSP (scan);
-       scan = XCDR (scan))
+  /* For DISPLAY try to get the values from the frame or the initial env.  */
+  if (strcmp (var, "DISPLAY") == 0)
     {
-      Lisp_Object entry;
-
-      entry = XCAR (scan);
-      if (STRINGP (entry)
-          && SBYTES (entry) > varlen
-          && SREF (entry, varlen) == '='
-#ifdef WINDOWSNT
-          /* NT environment variables are case insensitive.  */
-          && ! strnicmp (SDATA (entry), var, varlen)
-#else  /* not WINDOWSNT */
-          && ! bcmp (SDATA (entry), var, varlen)
-#endif /* not WINDOWSNT */
-          )
+      Lisp_Object display
+       = Fframe_parameter (NILP (frame) ? selected_frame : frame, Qdisplay);
+      if (STRINGP (display))
        {
-         *value    = (char *) SDATA (entry) + (varlen + 1);
-         *valuelen = SBYTES (entry) - (varlen + 1);
+         *value    = (char *) SDATA (display);
+         *valuelen = SBYTES (display);
          return 1;
        }
+      /* If still not found, Look for DISPLAY in Vinitial_environment.  */
+      if (getenv_internal_1 (var, varlen, value, valuelen,
+                            Vinitial_environment))
+       return *value ? 1 : 0;
     }
-#endif
+
   return 0;
 }
 
@@ -1664,18 +1477,28 @@ This function searches `process-environment' for VARIABLE.  If it is
 not found there, then it continues the search in the environment list
 of the selected frame.
 
-If optional parameter FRAME is non-nil, then this function will ignore
-`process-environment' and will simply look up the variable in that
-frame's environment.  */)
-     (variable, frame)
-     Lisp_Object variable, frame;
+If optional parameter ENV is a list, then search this list instead of
+`process-environment', and return t when encountering a negative entry.
+
+If it is a frame, then this function will ignore `process-environment' and
+will simply look up the variable in that frame's environment.  */)
+     (variable, env)
+     Lisp_Object variable, env;
 {
   char *value;
   int valuelen;
 
   CHECK_STRING (variable);
-  if (getenv_internal (SDATA (variable), SBYTES (variable),
-                      &value, &valuelen, frame))
+  if (CONSP (env))
+    {
+      if (getenv_internal_1 (SDATA (variable), SBYTES (variable),
+                            &value, &valuelen, env))
+       return value ? make_string (value, valuelen) : Qt;
+      else
+       return Qnil;
+    }
+  else if (getenv_internal (SDATA (variable), SBYTES (variable),
+                           &value, &valuelen, env))
     return make_string (value, valuelen);
   else
     return Qnil;
@@ -1833,7 +1656,6 @@ void
 set_initial_environment ()
 {
   register char **envp;
-  Lisp_Object env = Vprocess_environment;
 #ifndef CANNOT_DUMP
   if (initialized)
 #endif
@@ -1841,7 +1663,9 @@ set_initial_environment ()
       for (envp = environ; *envp; envp++)
        Vprocess_environment = Fcons (build_string (*envp),
                                      Vprocess_environment);
-      store_frame_param (SELECTED_FRAME(), Qenvironment, Vprocess_environment);
+      /* Ideally, the `copy' shouldn't be necessary, but it seems it's frequent
+        to use `delete' and friends on process-environment.  */
+      Vinitial_environment = Fcopy_sequence (Vprocess_environment);
     }
 }
 
@@ -1901,6 +1725,12 @@ If this variable is nil, then Emacs is unable to use a shared directory.  */);
 This is used by `call-process-region'.  */);
   /* This variable is initialized in init_callproc.  */
 
+  DEFVAR_LISP ("initial-environment", &Vinitial_environment,
+              doc: /* List of environment variables inherited from the parent process.
+Each element should be a string of the form ENVVARNAME=VALUE.
+The elements must normally be decoded (using `locale-coding-system') for use.  */);
+  Vinitial_environment = Qnil;
+
   DEFVAR_LISP ("process-environment", &Vprocess_environment,
               doc: /* List of overridden environment variables for subprocesses to inherit.
 Each element should be a string of the form ENVVARNAME=VALUE.