]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow control of data amount read from subprocess in one chunk
authorEli Zaretskii <eliz@gnu.org>
Sat, 21 Dec 2019 08:47:31 +0000 (10:47 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 21 Dec 2019 08:47:31 +0000 (10:47 +0200)
* src/process.c (syms_of_process) <read-process-output-max>:
New variable.
(read_process_output): Use it instead of the hard-coded
constant 4096.  (Bug#38561)
Use SAFE_ALLOCA to support large buffers for reading process
output.

* etc/NEWS: Mention 'read-process-output-max'.

etc/NEWS
src/process.c

index cf4e705a52f36f52c625c788d23adb49a03fcf37..7a7f3f204b076bd71c1a2ea15bb8b90acbc2dd30 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2724,6 +2724,14 @@ overlays.  This is only done on 'display' properties that have the
 ** 'process-contact' now takes an optional NO-BLOCK argument to allow
 not waiting for a process to be set up.
 
+---
+** New variable 'read-process-output-max' controls sub-process throughput.
+This variable determines how many bytes can be read from a sub-process
+in one read operation.  The default, 4096 bytes, was previously a
+hard-coded constant.  Setting it to a larger value might enhance
+throughput of reading from sub-processes that produces vast
+(megabytes) amounts of data in one go.
+
 +++
 ** The new user option 'quit-window-hook' is now run first when
 executing the 'quit-window' command.
index 0f82682ae5f76cc79f39b4164843417af065bf29..d6a0b30f7cbb6e5c2fb1d17508c43a9249c52564 100644 (file)
@@ -6008,7 +6008,7 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars,
    Yield number of decoded characters read,
    or -1 (setting errno) if there is a read error.
 
-   This function reads at most 4096 characters.
+   This function reads at most read_process_output_max bytes.
    If you want to read all available subprocess output,
    you must call it repeatedly until it returns zero.
 
@@ -6022,10 +6022,13 @@ read_process_output (Lisp_Object proc, int channel)
   struct Lisp_Process *p = XPROCESS (proc);
   struct coding_system *coding = proc_decode_coding_system[channel];
   int carryover = p->decoding_carryover;
-  enum { readmax = 4096 };
+  ptrdiff_t readmax = clip_to_bounds (1, read_process_output_max, PTRDIFF_MAX);
   ptrdiff_t count = SPECPDL_INDEX ();
   Lisp_Object odeactivate;
-  char chars[sizeof coding->carryover + readmax];
+  char *chars;
+
+  USE_SAFE_ALLOCA;
+  chars = SAFE_ALLOCA (sizeof coding->carryover + readmax);
 
   if (carryover)
     /* See the comment above.  */
@@ -6092,7 +6095,7 @@ read_process_output (Lisp_Object proc, int channel)
   if (nbytes <= 0)
     {
       if (nbytes < 0 || coding->mode & CODING_MODE_LAST_BLOCK)
-       return nbytes;
+       return SAFE_FREE_UNBIND_TO (count, nbytes);
       coding->mode |= CODING_MODE_LAST_BLOCK;
     }
 
@@ -6116,7 +6119,7 @@ read_process_output (Lisp_Object proc, int channel)
   /* Handling the process output should not deactivate the mark.  */
   Vdeactivate_mark = odeactivate;
 
-  unbind_to (count, Qnil);
+  SAFE_FREE_UNBIND_TO (count, Qnil);
   return nbytes;
 }
 
@@ -8442,6 +8445,12 @@ returns non-`nil'.  */);
               doc: /* Name of external socket passed to Emacs, or nil if none.  */);
   Vinternal__daemon_sockname = Qnil;
 
+  DEFVAR_INT ("read-process-output-max", read_process_output_max,
+             doc: /* Maximum number of bytes to read from subprocess in a single chunk.
+Enlarge the value only if the subprocess generates very large (megabytes)
+amounts of data in one go.  */);
+  read_process_output_max = 4096;
+
   DEFSYM (Qinternal_default_interrupt_process,
          "internal-default-interrupt-process");
   DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions");