diff options
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 101 |
1 files changed, 36 insertions, 65 deletions
diff --git a/src/buffer.c b/src/buffer.c index 45d6fa36d04..37d2975c8c7 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1698,27 +1698,16 @@ record_buffer (Lisp_Object buffer) call1 (Vrun_hooks, Qbuffer_list_update_hook); } -DEFUN ("record-buffer", Frecord_buffer, Srecord_buffer, 1, 1, 0, - doc: /* Move BUFFER to the front of the buffer list. -Return BUFFER. */) - (Lisp_Object buffer) -{ - CHECK_BUFFER (buffer); - - record_buffer (buffer); - - return buffer; -} - /* Move BUFFER to the end of the buffer (a)lists. Do nothing if the - buffer is killed. For the selected frame's buffer list this moves - BUFFER to its end even if it was never shown in that frame. If - this happens we have a feature, hence `unrecord-buffer' should be - called only when BUFFER was shown in the selected frame. */ +/* Move BUFFER to the end of the buffer (a)lists. Do nothing if the + buffer is killed. For the selected frame's buffer list this moves + BUFFER to its end even if it was never shown in that frame. If + this happens we have a feature, hence `unrecord-buffer' should be + called only when BUFFER was shown in the selected frame. */ -DEFUN ("unrecord-buffer", Funrecord_buffer, Sunrecord_buffer, 1, 1, 0, - doc: /* Move BUFFER to the end of the buffer list. -Return BUFFER. */) +DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal, + 1, 1, 0, + doc: /* Move BUFFER to the end of the buffer list. */) (Lisp_Object buffer) { Lisp_Object aelt, aelt_cons, tem; @@ -1746,7 +1735,7 @@ Return BUFFER. */) if (!NILP (Vrun_hooks)) call1 (Vrun_hooks, Qbuffer_list_update_hook); - return buffer; + return Qnil; } DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, @@ -2568,13 +2557,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, Either make it bigger, or don't store any more in it. */ if (extend) { - if ((OVERLAY_COUNT_MAX - 4) / 2 < len) - memory_full (SIZE_MAX); - /* Make it work with an initial len == 0. */ - len = len * 2 + 4; - *len_ptr = len; - vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); + vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, + sizeof *vec); *vec_ptr = vec; + len = *len_ptr; } else inhibit_storing = 1; @@ -2611,13 +2597,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, { if (extend) { - if ((OVERLAY_COUNT_MAX - 4) / 2 < len) - memory_full (SIZE_MAX); - /* Make it work with an initial len == 0. */ - len = len * 2 + 4; - *len_ptr = len; - vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); + vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, + sizeof *vec); *vec_ptr = vec; + len = *len_ptr; } else inhibit_storing = 1; @@ -2708,13 +2691,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend, Either make it bigger, or don't store any more in it. */ if (extend) { - if ((OVERLAY_COUNT_MAX - 4) / 2 < len) - memory_full (SIZE_MAX); - /* Make it work with an initial len == 0. */ - len = len * 2 + 4; - *len_ptr = len; - vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); + vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, + sizeof *vec); *vec_ptr = vec; + len = *len_ptr; } else inhibit_storing = 1; @@ -2756,13 +2736,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend, { if (extend) { - if ((OVERLAY_COUNT_MAX - 4) / 2 < len) - memory_full (SIZE_MAX); - /* Make it work with an initial len == 0. */ - len = len * 2 + 4; - *len_ptr = len; - vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); + vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, + sizeof *vec); *vec_ptr = vec; + len = *len_ptr; } else inhibit_storing = 1; @@ -2944,7 +2921,7 @@ struct sortstrlist struct sortstr *buf; /* An array that expands as needed; never freed. */ ptrdiff_t size; /* Allocated length of that array. */ ptrdiff_t used; /* How much of the array is currently in use. */ - EMACS_INT bytes; /* Total length of the strings in buf. */ + ptrdiff_t bytes; /* Total length of the strings in buf. */ }; /* Buffers for storing information about the overlays touching a given @@ -2955,7 +2932,7 @@ static struct sortstrlist overlay_heads, overlay_tails; static unsigned char *overlay_str_buf; /* Allocated length of overlay_str_buf. */ -static EMACS_INT overlay_str_len; +static ptrdiff_t overlay_str_len; /* A comparison function suitable for passing to qsort. */ static int @@ -2977,17 +2954,7 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, EMACS_INT nbytes; if (ssl->used == ssl->size) - { - if (min (PTRDIFF_MAX, SIZE_MAX) / (sizeof (struct sortstr) * 2) - < ssl->size) - memory_full (SIZE_MAX); - else if (0 < ssl->size) - ssl->size *= 2; - else - ssl->size = 5; - ssl->buf = ((struct sortstr *) - xrealloc (ssl->buf, ssl->size * sizeof (struct sortstr))); - } + ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); ssl->buf[ssl->used].string = str; ssl->buf[ssl->used].string2 = str2; ssl->buf[ssl->used].size = size; @@ -3002,6 +2969,8 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, else nbytes = SBYTES (str); + if (INT_ADD_OVERFLOW (ssl->bytes, nbytes)) + memory_full (SIZE_MAX); ssl->bytes += nbytes; if (STRINGP (str2)) @@ -3014,6 +2983,8 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, else nbytes = SBYTES (str2); + if (INT_ADD_OVERFLOW (ssl->bytes, nbytes)) + memory_full (SIZE_MAX); ssl->bytes += nbytes; } } @@ -3107,14 +3078,15 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) Lisp_Object tem; EMACS_INT i; unsigned char *p; - EMACS_INT total = overlay_heads.bytes + overlay_tails.bytes; + ptrdiff_t total; + if (INT_ADD_OVERFLOW (overlay_heads.bytes, overlay_tails.bytes)) + memory_full (SIZE_MAX); + total = overlay_heads.bytes + overlay_tails.bytes; if (total > overlay_str_len) - { - overlay_str_len = total; - overlay_str_buf = (unsigned char *)xrealloc (overlay_str_buf, - total); - } + overlay_str_buf = xpalloc (overlay_str_buf, &overlay_str_len, + total - overlay_str_len, -1, 1); + p = overlay_str_buf; for (i = overlay_tails.used; --i >= 0;) { @@ -6034,8 +6006,7 @@ Functions running this hook are `get-buffer-create', defsubr (&Sother_buffer); defsubr (&Sbuffer_enable_undo); defsubr (&Skill_buffer); - defsubr (&Srecord_buffer); - defsubr (&Sunrecord_buffer); + defsubr (&Sbury_buffer_internal); defsubr (&Sset_buffer_major_mode); defsubr (&Scurrent_buffer); defsubr (&Sset_buffer); |
