aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorEli Zaretskii2019-12-21 10:47:31 +0200
committerEli Zaretskii2019-12-21 10:47:31 +0200
commitcc78faee7d23dd0433ba537818a68cbd20fa52a3 (patch)
tree88f370cc83f7e2bead825886035af7e2905535b5 /src/process.c
parent0f7e3430bba031a6c5f45e0afe2ddcac197603cf (diff)
downloademacs-cc78faee7d23dd0433ba537818a68cbd20fa52a3.tar.gz
emacs-cc78faee7d23dd0433ba537818a68cbd20fa52a3.zip
Allow control of data amount read from subprocess in one chunk
* 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'.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c19
1 files changed, 14 insertions, 5 deletions
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,
6008 Yield number of decoded characters read, 6008 Yield number of decoded characters read,
6009 or -1 (setting errno) if there is a read error. 6009 or -1 (setting errno) if there is a read error.
6010 6010
6011 This function reads at most 4096 characters. 6011 This function reads at most read_process_output_max bytes.
6012 If you want to read all available subprocess output, 6012 If you want to read all available subprocess output,
6013 you must call it repeatedly until it returns zero. 6013 you must call it repeatedly until it returns zero.
6014 6014
@@ -6022,10 +6022,13 @@ read_process_output (Lisp_Object proc, int channel)
6022 struct Lisp_Process *p = XPROCESS (proc); 6022 struct Lisp_Process *p = XPROCESS (proc);
6023 struct coding_system *coding = proc_decode_coding_system[channel]; 6023 struct coding_system *coding = proc_decode_coding_system[channel];
6024 int carryover = p->decoding_carryover; 6024 int carryover = p->decoding_carryover;
6025 enum { readmax = 4096 }; 6025 ptrdiff_t readmax = clip_to_bounds (1, read_process_output_max, PTRDIFF_MAX);
6026 ptrdiff_t count = SPECPDL_INDEX (); 6026 ptrdiff_t count = SPECPDL_INDEX ();
6027 Lisp_Object odeactivate; 6027 Lisp_Object odeactivate;
6028 char chars[sizeof coding->carryover + readmax]; 6028 char *chars;
6029
6030 USE_SAFE_ALLOCA;
6031 chars = SAFE_ALLOCA (sizeof coding->carryover + readmax);
6029 6032
6030 if (carryover) 6033 if (carryover)
6031 /* See the comment above. */ 6034 /* See the comment above. */
@@ -6092,7 +6095,7 @@ read_process_output (Lisp_Object proc, int channel)
6092 if (nbytes <= 0) 6095 if (nbytes <= 0)
6093 { 6096 {
6094 if (nbytes < 0 || coding->mode & CODING_MODE_LAST_BLOCK) 6097 if (nbytes < 0 || coding->mode & CODING_MODE_LAST_BLOCK)
6095 return nbytes; 6098 return SAFE_FREE_UNBIND_TO (count, nbytes);
6096 coding->mode |= CODING_MODE_LAST_BLOCK; 6099 coding->mode |= CODING_MODE_LAST_BLOCK;
6097 } 6100 }
6098 6101
@@ -6116,7 +6119,7 @@ read_process_output (Lisp_Object proc, int channel)
6116 /* Handling the process output should not deactivate the mark. */ 6119 /* Handling the process output should not deactivate the mark. */
6117 Vdeactivate_mark = odeactivate; 6120 Vdeactivate_mark = odeactivate;
6118 6121
6119 unbind_to (count, Qnil); 6122 SAFE_FREE_UNBIND_TO (count, Qnil);
6120 return nbytes; 6123 return nbytes;
6121} 6124}
6122 6125
@@ -8442,6 +8445,12 @@ returns non-`nil'. */);
8442 doc: /* Name of external socket passed to Emacs, or nil if none. */); 8445 doc: /* Name of external socket passed to Emacs, or nil if none. */);
8443 Vinternal__daemon_sockname = Qnil; 8446 Vinternal__daemon_sockname = Qnil;
8444 8447
8448 DEFVAR_INT ("read-process-output-max", read_process_output_max,
8449 doc: /* Maximum number of bytes to read from subprocess in a single chunk.
8450Enlarge the value only if the subprocess generates very large (megabytes)
8451amounts of data in one go. */);
8452 read_process_output_max = 4096;
8453
8445 DEFSYM (Qinternal_default_interrupt_process, 8454 DEFSYM (Qinternal_default_interrupt_process,
8446 "internal-default-interrupt-process"); 8455 "internal-default-interrupt-process");
8447 DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); 8456 DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions");