diff options
| author | Alan Mackenzie | 2020-01-22 19:50:30 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2020-01-22 19:50:30 +0000 |
| commit | 224e8d146485ce178086549d41fa8359dcc0e03e (patch) | |
| tree | 215a967ed0052f48141782da45afadea6ef19d9d /src | |
| parent | d02f2a793e8ee974198f88d966c4a87df3fba104 (diff) | |
| download | emacs-224e8d146485ce178086549d41fa8359dcc0e03e.tar.gz emacs-224e8d146485ce178086549d41fa8359dcc0e03e.zip | |
Make call_process call signal_after_change. This fixes bug #38691.
Now, functions such as call-proess-region invoke after-change-functions
correctly.
* src/callproc.c (call_process): Call prepare_to_modify_buffer in a single
place, no longer delegating the task to insert_1_both, etc. Call
signal_after_change in each of two code branches, such that
before-change-functions and after-change-functions are always called in
balanced pairs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/callproc.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/callproc.c b/src/callproc.c index 52b89504205..6bd4ae22f63 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -746,6 +746,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, | |||
| 746 | int carryover = 0; | 746 | int carryover = 0; |
| 747 | bool display_on_the_fly = display_p; | 747 | bool display_on_the_fly = display_p; |
| 748 | struct coding_system saved_coding = process_coding; | 748 | struct coding_system saved_coding = process_coding; |
| 749 | ptrdiff_t prepared_pos = 0; /* prepare_to_modify_buffer was last | ||
| 750 | called here. */ | ||
| 749 | 751 | ||
| 750 | while (1) | 752 | while (1) |
| 751 | { | 753 | { |
| @@ -773,6 +775,33 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, | |||
| 773 | if (display_on_the_fly) | 775 | if (display_on_the_fly) |
| 774 | break; | 776 | break; |
| 775 | } | 777 | } |
| 778 | /* CHANGE FUNCTIONS | ||
| 779 | For each iteration of the enclosing while (1) loop which | ||
| 780 | yields data (i.e. nread > 0), before- and | ||
| 781 | after-change-functions are each invoked exactly once. | ||
| 782 | This is done directly from the current function only, by | ||
| 783 | calling prepare_to_modify_buffer and signal_after_change. | ||
| 784 | It is not done here by directing another function such as | ||
| 785 | insert_1_both to call them. The call to | ||
| 786 | prepare_to_modify_buffer follows this comment, and there | ||
| 787 | is one call to signal_after_change in each of the | ||
| 788 | branches of the next `else if'. | ||
| 789 | |||
| 790 | Exceptionally, the insertion into the buffer is aborted | ||
| 791 | at the call to del_range_2 ~45 lines further down, this | ||
| 792 | function removing the newly inserted data. At this stage | ||
| 793 | prepare_to_modify_buffer has been called, but | ||
| 794 | signal_after_change hasn't. A continue statement | ||
| 795 | restarts the enclosing while (1) loop. A second, | ||
| 796 | unwanted, call to `prepare_to_modify_buffer' is inhibited | ||
| 797 | by the test perpared_pos < PT. The data are inserted | ||
| 798 | again, and this time signal_after_change gets called, | ||
| 799 | balancing the previous call to prepare_to_modify_buffer. */ | ||
| 800 | if ((prepared_pos < PT) && nread) | ||
| 801 | { | ||
| 802 | prepare_to_modify_buffer (PT, PT, NULL); | ||
| 803 | prepared_pos = PT; | ||
| 804 | } | ||
| 776 | 805 | ||
| 777 | /* Now NREAD is the total amount of data in the buffer. */ | 806 | /* Now NREAD is the total amount of data in the buffer. */ |
| 778 | 807 | ||
| @@ -780,15 +809,16 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, | |||
| 780 | ; | 809 | ; |
| 781 | else if (NILP (BVAR (current_buffer, enable_multibyte_characters)) | 810 | else if (NILP (BVAR (current_buffer, enable_multibyte_characters)) |
| 782 | && ! CODING_MAY_REQUIRE_DECODING (&process_coding)) | 811 | && ! CODING_MAY_REQUIRE_DECODING (&process_coding)) |
| 783 | insert_1_both (buf, nread, nread, 0, 1, 0); | 812 | { |
| 813 | insert_1_both (buf, nread, nread, 0, 0, 0); | ||
| 814 | signal_after_change (PT, 0, nread); | ||
| 815 | } | ||
| 784 | else | 816 | else |
| 785 | { /* We have to decode the input. */ | 817 | { /* We have to decode the input. */ |
| 786 | Lisp_Object curbuf; | 818 | Lisp_Object curbuf; |
| 787 | ptrdiff_t count1 = SPECPDL_INDEX (); | 819 | ptrdiff_t count1 = SPECPDL_INDEX (); |
| 788 | 820 | ||
| 789 | XSETBUFFER (curbuf, current_buffer); | 821 | XSETBUFFER (curbuf, current_buffer); |
| 790 | /* FIXME: Call signal_after_change! */ | ||
| 791 | prepare_to_modify_buffer (PT, PT, NULL); | ||
| 792 | /* We cannot allow after-change-functions be run | 822 | /* We cannot allow after-change-functions be run |
| 793 | during decoding, because that might modify the | 823 | during decoding, because that might modify the |
| 794 | buffer, while we rely on process_coding.produced to | 824 | buffer, while we rely on process_coding.produced to |
| @@ -824,6 +854,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, | |||
| 824 | 854 | ||
| 825 | TEMP_SET_PT_BOTH (PT + process_coding.produced_char, | 855 | TEMP_SET_PT_BOTH (PT + process_coding.produced_char, |
| 826 | PT_BYTE + process_coding.produced); | 856 | PT_BYTE + process_coding.produced); |
| 857 | signal_after_change (PT, 0, process_coding.produced_char); | ||
| 827 | carryover = process_coding.carryover_bytes; | 858 | carryover = process_coding.carryover_bytes; |
| 828 | if (carryover > 0) | 859 | if (carryover > 0) |
| 829 | memcpy (buf, process_coding.carryover, | 860 | memcpy (buf, process_coding.carryover, |