From 8ccad4327e0305d3a27119307ddf76af3419708d Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Tue, 11 Jun 2024 05:54:57 +0300 Subject: [PATCH] fast-read-process-output: Make safer * src/process.c (read_process_output): Move the call to 'read_and_insert_process_output' from here. (read_and_dispose_of_process_output): To here (bug#66020). So that any Lisp code invoked through modification hook from the former function also benefit from safety guards like running_asynch_code, saved match data, inhibit_quot, etc. (cherry picked from commit bac8a70f454d022d8352200d85eacd27017d4f12) --- src/process.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/process.c b/src/process.c index 60264d367b8..b6ec114e2b3 100644 --- a/src/process.c +++ b/src/process.c @@ -6263,10 +6263,7 @@ read_process_output (Lisp_Object proc, int channel) friends don't expect current-buffer to be changed from under them. */ record_unwind_current_buffer (); - if (fast_read_process_output && EQ (p->filter, Qinternal_default_process_filter)) - read_and_insert_process_output (p, chars, nbytes, coding); - else - read_and_dispose_of_process_output (p, chars, nbytes, coding); + read_and_dispose_of_process_output (p, chars, nbytes, coding); /* Handling the process output should not deactivate the mark. */ Vdeactivate_mark = odeactivate; @@ -6479,19 +6476,27 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, save the match data in a special nonrecursive fashion. */ running_asynch_code = 1; - decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); - text = coding->dst_object; + if (fast_read_process_output && EQ (p->filter, Qinternal_default_process_filter)) + { + read_and_insert_process_output (p, chars, nbytes, coding); + } + else + { + decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); + text = coding->dst_object; - read_process_output_set_last_coding_system (p, coding); + read_process_output_set_last_coding_system (p, coding); - if (SBYTES (text) > 0) - /* FIXME: It's wrong to wrap or not based on debug-on-error, and - sometimes it's simply wrong to wrap (e.g. when called from - accept-process-output). */ - internal_condition_case_1 (read_process_output_call, - list3 (outstream, make_lisp_proc (p), text), - !NILP (Vdebug_on_error) ? Qnil : Qerror, - read_process_output_error_handler); + if (SBYTES (text) > 0) + /* FIXME: It's wrong to wrap or not based on debug-on-error, and + sometimes it's simply wrong to wrap (e.g. when called from + accept-process-output). */ + internal_condition_case_1 (read_process_output_call, + list3 (outstream, make_lisp_proc (p), text), + !NILP (Vdebug_on_error) ? Qnil : Qerror, + read_process_output_error_handler); + + } /* If we saved the match data nonrecursively, restore it now. */ restore_search_regs (); -- 2.39.2