From: Eli Zaretskii Date: Sat, 21 Dec 2019 08:47:31 +0000 (+0200) Subject: Allow control of data amount read from subprocess in one chunk X-Git-Tag: emacs-27.0.90~325 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cc78faee7d23dd0433ba537818a68cbd20fa52a3;p=emacs.git Allow control of data amount read from subprocess in one chunk * src/process.c (syms_of_process) : 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'. --- diff --git a/etc/NEWS b/etc/NEWS index cf4e705a52f..7a7f3f204b0 100644 --- 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. diff --git a/src/process.c b/src/process.c index 0f82682ae5f..d6a0b30f7cb 100644 --- a/src/process.c +++ b/src/process.c @@ -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");