diff options
| author | Paul Eggert | 2015-11-07 23:52:17 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-11-07 23:52:57 -0800 |
| commit | 8a8613bcf4227dfe46a694b761e9575bdf6ca2ce (patch) | |
| tree | 01d9d994b9caacc831342ef1b32e033844fc06a6 /src/lread.c | |
| parent | 6ea4ff5a362a150fb9e22eff1d8f2b87d017b7a4 (diff) | |
| download | emacs-8a8613bcf4227dfe46a694b761e9575bdf6ca2ce.tar.gz emacs-8a8613bcf4227dfe46a694b761e9575bdf6ca2ce.zip | |
Prefer xpalloc to doubling buffers by hand
* src/lread.c (grow_read_buffer): New function, which uses xpalloc.
(read1): Use it for simplicity.
* src/macros.c (store_kbd_macro_char):
* src/minibuf.c (read_minibuf_noninteractive):
* src/term.c (encode_terminal_code):
* src/xrdb.c (magic_db):
Prefer xpalloc to growing buffers by hand.
This doesn’t fix any bugs, but simplifies the code a bit.
Diffstat (limited to 'src/lread.c')
| -rw-r--r-- | src/lread.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/lread.c b/src/lread.c index 7c891f9954f..c4456f37f6d 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -2120,6 +2120,15 @@ read0 (Lisp_Object readcharfun) | |||
| 2120 | static ptrdiff_t read_buffer_size; | 2120 | static ptrdiff_t read_buffer_size; |
| 2121 | static char *read_buffer; | 2121 | static char *read_buffer; |
| 2122 | 2122 | ||
| 2123 | /* Grow the read buffer by at least MAX_MULTIBYTE_LENGTH bytes. */ | ||
| 2124 | |||
| 2125 | static void | ||
| 2126 | grow_read_buffer (void) | ||
| 2127 | { | ||
| 2128 | read_buffer = xpalloc (read_buffer, &read_buffer_size, | ||
| 2129 | MAX_MULTIBYTE_LENGTH, -1, 1); | ||
| 2130 | } | ||
| 2131 | |||
| 2123 | /* Read a \-escape sequence, assuming we already read the `\'. | 2132 | /* Read a \-escape sequence, assuming we already read the `\'. |
| 2124 | If the escape sequence forces unibyte, return eight-bit char. */ | 2133 | If the escape sequence forces unibyte, return eight-bit char. */ |
| 2125 | 2134 | ||
| @@ -2985,10 +2994,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) | |||
| 2985 | if (end - p < MAX_MULTIBYTE_LENGTH) | 2994 | if (end - p < MAX_MULTIBYTE_LENGTH) |
| 2986 | { | 2995 | { |
| 2987 | ptrdiff_t offset = p - read_buffer; | 2996 | ptrdiff_t offset = p - read_buffer; |
| 2988 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) | 2997 | grow_read_buffer (); |
| 2989 | memory_full (SIZE_MAX); | ||
| 2990 | read_buffer = xrealloc (read_buffer, read_buffer_size * 2); | ||
| 2991 | read_buffer_size *= 2; | ||
| 2992 | p = read_buffer + offset; | 2998 | p = read_buffer + offset; |
| 2993 | end = read_buffer + read_buffer_size; | 2999 | end = read_buffer + read_buffer_size; |
| 2994 | } | 3000 | } |
| @@ -3119,10 +3125,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) | |||
| 3119 | if (end - p < MAX_MULTIBYTE_LENGTH) | 3125 | if (end - p < MAX_MULTIBYTE_LENGTH) |
| 3120 | { | 3126 | { |
| 3121 | ptrdiff_t offset = p - read_buffer; | 3127 | ptrdiff_t offset = p - read_buffer; |
| 3122 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) | 3128 | grow_read_buffer (); |
| 3123 | memory_full (SIZE_MAX); | ||
| 3124 | read_buffer = xrealloc (read_buffer, read_buffer_size * 2); | ||
| 3125 | read_buffer_size *= 2; | ||
| 3126 | p = read_buffer + offset; | 3129 | p = read_buffer + offset; |
| 3127 | end = read_buffer + read_buffer_size; | 3130 | end = read_buffer + read_buffer_size; |
| 3128 | } | 3131 | } |
| @@ -3149,10 +3152,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) | |||
| 3149 | if (p == end) | 3152 | if (p == end) |
| 3150 | { | 3153 | { |
| 3151 | ptrdiff_t offset = p - read_buffer; | 3154 | ptrdiff_t offset = p - read_buffer; |
| 3152 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size) | 3155 | grow_read_buffer (); |
| 3153 | memory_full (SIZE_MAX); | ||
| 3154 | read_buffer = xrealloc (read_buffer, read_buffer_size * 2); | ||
| 3155 | read_buffer_size *= 2; | ||
| 3156 | p = read_buffer + offset; | 3156 | p = read_buffer + offset; |
| 3157 | end = read_buffer + read_buffer_size; | 3157 | end = read_buffer + read_buffer_size; |
| 3158 | } | 3158 | } |