diff options
| author | Dmitry Gutov | 2024-06-11 05:36:51 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2024-06-11 05:37:45 +0300 |
| commit | d9890bb87063b402853ff0e4ea8bbfc92e5d6e00 (patch) | |
| tree | d1ffbdfd9d5e7cc3b0de682e7e5dc8affbea2803 /src | |
| parent | f33806dd6624e874d5cff3cd02ab370f518c0629 (diff) | |
| download | emacs-d9890bb87063b402853ff0e4ea8bbfc92e5d6e00.tar.gz emacs-d9890bb87063b402853ff0e4ea8bbfc92e5d6e00.zip | |
read_process_output_set_last_coding_system: Extract, reuse
* src/process.c (read_process_output_set_last_coding_system):
New function, extracted from read_and_dispose_of_process_output.
(read_and_dispose_of_process_output): Update accordingly.
(read_and_insert_process_output): Use it here instead of just
transferring carryover (bug#66020, also mentioned in bug#71452).
Diffstat (limited to 'src')
| -rw-r--r-- | src/process.c | 84 |
1 files changed, 45 insertions, 39 deletions
diff --git a/src/process.c b/src/process.c index c00eba086a2..60264d367b8 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -6345,6 +6345,48 @@ read_process_output_after_insert (struct Lisp_Process *p, Lisp_Object *old_read_ | |||
| 6345 | } | 6345 | } |
| 6346 | 6346 | ||
| 6347 | static void | 6347 | static void |
| 6348 | read_process_output_set_last_coding_system (struct Lisp_Process *p, | ||
| 6349 | struct coding_system *coding) | ||
| 6350 | { | ||
| 6351 | Vlast_coding_system_used = CODING_ID_NAME (coding->id); | ||
| 6352 | /* A new coding system might be found. */ | ||
| 6353 | if (!EQ (p->decode_coding_system, Vlast_coding_system_used)) | ||
| 6354 | { | ||
| 6355 | pset_decode_coding_system (p, Vlast_coding_system_used); | ||
| 6356 | |||
| 6357 | /* Don't call setup_coding_system for | ||
| 6358 | proc_decode_coding_system[channel] here. It is done in | ||
| 6359 | detect_coding called via decode_coding above. */ | ||
| 6360 | |||
| 6361 | /* If a coding system for encoding is not yet decided, we set | ||
| 6362 | it as the same as coding-system for decoding. | ||
| 6363 | |||
| 6364 | But, before doing that we must check if | ||
| 6365 | proc_encode_coding_system[p->outfd] surely points to a | ||
| 6366 | valid memory because p->outfd will be changed once EOF is | ||
| 6367 | sent to the process. */ | ||
| 6368 | eassert (p->outfd < FD_SETSIZE); | ||
| 6369 | if (NILP (p->encode_coding_system) && p->outfd >= 0 | ||
| 6370 | && proc_encode_coding_system[p->outfd]) | ||
| 6371 | { | ||
| 6372 | pset_encode_coding_system | ||
| 6373 | (p, coding_inherit_eol_type (Vlast_coding_system_used, Qnil)); | ||
| 6374 | setup_coding_system (p->encode_coding_system, | ||
| 6375 | proc_encode_coding_system[p->outfd]); | ||
| 6376 | } | ||
| 6377 | } | ||
| 6378 | |||
| 6379 | if (coding->carryover_bytes > 0) | ||
| 6380 | { | ||
| 6381 | if (SCHARS (p->decoding_buf) < coding->carryover_bytes) | ||
| 6382 | pset_decoding_buf (p, make_uninit_string (coding->carryover_bytes)); | ||
| 6383 | memcpy (SDATA (p->decoding_buf), coding->carryover, | ||
| 6384 | coding->carryover_bytes); | ||
| 6385 | p->decoding_carryover = coding->carryover_bytes; | ||
| 6386 | } | ||
| 6387 | } | ||
| 6388 | |||
| 6389 | static void | ||
| 6348 | read_and_insert_process_output (struct Lisp_Process *p, char *buf, | 6390 | read_and_insert_process_output (struct Lisp_Process *p, char *buf, |
| 6349 | ssize_t nread, | 6391 | ssize_t nread, |
| 6350 | struct coding_system *process_coding) | 6392 | struct coding_system *process_coding) |
| @@ -6373,7 +6415,6 @@ read_and_insert_process_output (struct Lisp_Process *p, char *buf, | |||
| 6373 | else | 6415 | else |
| 6374 | { /* We have to decode the input. */ | 6416 | { /* We have to decode the input. */ |
| 6375 | Lisp_Object curbuf; | 6417 | Lisp_Object curbuf; |
| 6376 | int carryover = 0; | ||
| 6377 | specpdl_ref count1 = SPECPDL_INDEX (); | 6418 | specpdl_ref count1 = SPECPDL_INDEX (); |
| 6378 | 6419 | ||
| 6379 | XSETBUFFER (curbuf, current_buffer); | 6420 | XSETBUFFER (curbuf, current_buffer); |
| @@ -6387,14 +6428,12 @@ read_and_insert_process_output (struct Lisp_Process *p, char *buf, | |||
| 6387 | (unsigned char *) buf, nread, curbuf); | 6428 | (unsigned char *) buf, nread, curbuf); |
| 6388 | unbind_to (count1, Qnil); | 6429 | unbind_to (count1, Qnil); |
| 6389 | 6430 | ||
| 6431 | read_process_output_set_last_coding_system (p, process_coding); | ||
| 6432 | |||
| 6390 | TEMP_SET_PT_BOTH (PT + process_coding->produced_char, | 6433 | TEMP_SET_PT_BOTH (PT + process_coding->produced_char, |
| 6391 | PT_BYTE + process_coding->produced); | 6434 | PT_BYTE + process_coding->produced); |
| 6392 | signal_after_change (PT - process_coding->produced_char, | 6435 | signal_after_change (PT - process_coding->produced_char, |
| 6393 | 0, process_coding->produced_char); | 6436 | 0, process_coding->produced_char); |
| 6394 | carryover = process_coding->carryover_bytes; | ||
| 6395 | if (carryover > 0) | ||
| 6396 | memcpy (buf, process_coding->carryover, | ||
| 6397 | process_coding->carryover_bytes); | ||
| 6398 | } | 6437 | } |
| 6399 | 6438 | ||
| 6400 | read_process_output_after_insert (p, &old_read_only, old_begv, old_zv, | 6439 | read_process_output_after_insert (p, &old_read_only, old_begv, old_zv, |
| @@ -6442,42 +6481,9 @@ read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, | |||
| 6442 | 6481 | ||
| 6443 | decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); | 6482 | decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); |
| 6444 | text = coding->dst_object; | 6483 | text = coding->dst_object; |
| 6445 | Vlast_coding_system_used = CODING_ID_NAME (coding->id); | ||
| 6446 | /* A new coding system might be found. */ | ||
| 6447 | if (!EQ (p->decode_coding_system, Vlast_coding_system_used)) | ||
| 6448 | { | ||
| 6449 | pset_decode_coding_system (p, Vlast_coding_system_used); | ||
| 6450 | 6484 | ||
| 6451 | /* Don't call setup_coding_system for | 6485 | read_process_output_set_last_coding_system (p, coding); |
| 6452 | proc_decode_coding_system[channel] here. It is done in | ||
| 6453 | detect_coding called via decode_coding above. */ | ||
| 6454 | 6486 | ||
| 6455 | /* If a coding system for encoding is not yet decided, we set | ||
| 6456 | it as the same as coding-system for decoding. | ||
| 6457 | |||
| 6458 | But, before doing that we must check if | ||
| 6459 | proc_encode_coding_system[p->outfd] surely points to a | ||
| 6460 | valid memory because p->outfd will be changed once EOF is | ||
| 6461 | sent to the process. */ | ||
| 6462 | eassert (p->outfd < FD_SETSIZE); | ||
| 6463 | if (NILP (p->encode_coding_system) && p->outfd >= 0 | ||
| 6464 | && proc_encode_coding_system[p->outfd]) | ||
| 6465 | { | ||
| 6466 | pset_encode_coding_system | ||
| 6467 | (p, coding_inherit_eol_type (Vlast_coding_system_used, Qnil)); | ||
| 6468 | setup_coding_system (p->encode_coding_system, | ||
| 6469 | proc_encode_coding_system[p->outfd]); | ||
| 6470 | } | ||
| 6471 | } | ||
| 6472 | |||
| 6473 | if (coding->carryover_bytes > 0) | ||
| 6474 | { | ||
| 6475 | if (SCHARS (p->decoding_buf) < coding->carryover_bytes) | ||
| 6476 | pset_decoding_buf (p, make_uninit_string (coding->carryover_bytes)); | ||
| 6477 | memcpy (SDATA (p->decoding_buf), coding->carryover, | ||
| 6478 | coding->carryover_bytes); | ||
| 6479 | p->decoding_carryover = coding->carryover_bytes; | ||
| 6480 | } | ||
| 6481 | if (SBYTES (text) > 0) | 6487 | if (SBYTES (text) > 0) |
| 6482 | /* FIXME: It's wrong to wrap or not based on debug-on-error, and | 6488 | /* FIXME: It's wrong to wrap or not based on debug-on-error, and |
| 6483 | sometimes it's simply wrong to wrap (e.g. when called from | 6489 | sometimes it's simply wrong to wrap (e.g. when called from |