diff options
Diffstat (limited to 'src/callproc.c')
| -rw-r--r-- | src/callproc.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/callproc.c b/src/callproc.c index 6027ccdda9f..fe198b0770a 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -218,9 +218,10 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 218 | int fd[2]; | 218 | int fd[2]; |
| 219 | int filefd; | 219 | int filefd; |
| 220 | register int pid; | 220 | register int pid; |
| 221 | char buf[16384]; | 221 | #define CALLPROC_BUFFER_SIZE_MIN (16 * 1024) |
| 222 | char *bufptr = buf; | 222 | #define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN) |
| 223 | int bufsize = sizeof buf; | 223 | char buf[CALLPROC_BUFFER_SIZE_MAX]; |
| 224 | int bufsize = CALLPROC_BUFFER_SIZE_MIN; | ||
| 224 | int count = SPECPDL_INDEX (); | 225 | int count = SPECPDL_INDEX (); |
| 225 | 226 | ||
| 226 | register const unsigned char **new_argv | 227 | register const unsigned char **new_argv |
| @@ -765,7 +766,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 765 | nread = carryover; | 766 | nread = carryover; |
| 766 | while (nread < bufsize - 1024) | 767 | while (nread < bufsize - 1024) |
| 767 | { | 768 | { |
| 768 | int this_read = emacs_read (fd[0], bufptr + nread, | 769 | int this_read = emacs_read (fd[0], buf + nread, |
| 769 | bufsize - nread); | 770 | bufsize - nread); |
| 770 | 771 | ||
| 771 | if (this_read < 0) | 772 | if (this_read < 0) |
| @@ -790,7 +791,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 790 | if (!NILP (buffer)) | 791 | if (!NILP (buffer)) |
| 791 | { | 792 | { |
| 792 | if (! CODING_MAY_REQUIRE_DECODING (&process_coding)) | 793 | if (! CODING_MAY_REQUIRE_DECODING (&process_coding)) |
| 793 | insert_1_both (bufptr, nread, nread, 0, 1, 0); | 794 | insert_1_both (buf, nread, nread, 0, 1, 0); |
| 794 | else | 795 | else |
| 795 | { /* We have to decode the input. */ | 796 | { /* We have to decode the input. */ |
| 796 | int size; | 797 | int size; |
| @@ -807,7 +808,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 807 | requires text-encoding detection. */ | 808 | requires text-encoding detection. */ |
| 808 | if (process_coding.type == coding_type_undecided) | 809 | if (process_coding.type == coding_type_undecided) |
| 809 | { | 810 | { |
| 810 | detect_coding (&process_coding, bufptr, nread); | 811 | detect_coding (&process_coding, buf, nread); |
| 811 | if (process_coding.composing != COMPOSITION_DISABLED) | 812 | if (process_coding.composing != COMPOSITION_DISABLED) |
| 812 | /* We have not yet allocated the composition | 813 | /* We have not yet allocated the composition |
| 813 | data because the coding type was undecided. */ | 814 | data because the coding type was undecided. */ |
| @@ -816,7 +817,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 816 | if (process_coding.cmp_data) | 817 | if (process_coding.cmp_data) |
| 817 | process_coding.cmp_data->char_offset = PT; | 818 | process_coding.cmp_data->char_offset = PT; |
| 818 | 819 | ||
| 819 | decode_coding (&process_coding, bufptr, decoding_buf, | 820 | decode_coding (&process_coding, buf, decoding_buf, |
| 820 | nread, size); | 821 | nread, size); |
| 821 | 822 | ||
| 822 | if (display_on_the_fly | 823 | if (display_on_the_fly |
| @@ -905,7 +906,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 905 | if (carryover > 0) | 906 | if (carryover > 0) |
| 906 | /* As CARRYOVER should not be that large, we had | 907 | /* As CARRYOVER should not be that large, we had |
| 907 | better avoid overhead of bcopy. */ | 908 | better avoid overhead of bcopy. */ |
| 908 | BCOPY_SHORT (bufptr + process_coding.consumed, bufptr, | 909 | BCOPY_SHORT (buf + process_coding.consumed, buf, |
| 909 | carryover); | 910 | carryover); |
| 910 | if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP) | 911 | if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP) |
| 911 | { | 912 | { |
| @@ -922,17 +923,13 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) | |||
| 922 | if (process_coding.mode & CODING_MODE_LAST_BLOCK) | 923 | if (process_coding.mode & CODING_MODE_LAST_BLOCK) |
| 923 | break; | 924 | break; |
| 924 | 925 | ||
| 926 | #if (CALLPROC_BUFFER_SIZE_MIN != CALLPROC_BUFFER_SIZE_MAX) | ||
| 925 | /* Make the buffer bigger as we continue to read more data, | 927 | /* Make the buffer bigger as we continue to read more data, |
| 926 | but not past 64k. */ | 928 | but not past CALLPROC_BUFFER_SIZE_MAX. */ |
| 927 | if (bufsize < 64 * 1024 && total_read > 32 * bufsize) | 929 | if (bufsize < CALLPROC_BUFFER_SIZE_MAX && total_read > 32 * bufsize) |
| 928 | { | 930 | if ((bufsize *= 2) > CALLPROC_BUFFER_SIZE_MAX) |
| 929 | char *tempptr; | 931 | bufsize = CALLPROC_BUFFER_SIZE_MAX; |
| 930 | bufsize *= 2; | 932 | #endif |
| 931 | |||
| 932 | tempptr = (char *) alloca (bufsize); | ||
| 933 | bcopy (bufptr, tempptr, bufsize / 2); | ||
| 934 | bufptr = tempptr; | ||
| 935 | } | ||
| 936 | 933 | ||
| 937 | if (display_p) | 934 | if (display_p) |
| 938 | { | 935 | { |