diff options
| author | Stefan Monnier | 2012-03-25 16:37:21 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-03-25 16:37:21 -0400 |
| commit | 699c782b7668c44d0fa4446331b0590a6d5dac82 (patch) | |
| tree | 5dcce364741d0761920a3d274b0fc8aba4103d45 /src/buffer.c | |
| parent | 98fb480ee31bf74cf554044f60f21df16566dd7f (diff) | |
| parent | e99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff) | |
| download | emacs-699c782b7668c44d0fa4446331b0590a6d5dac82.tar.gz emacs-699c782b7668c44d0fa4446331b0590a6d5dac82.zip | |
Merge from trunkpending
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 284 |
1 files changed, 128 insertions, 156 deletions
diff --git a/src/buffer.c b/src/buffer.c index e2f34d629e9..1fea19b0d65 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Buffer manipulation primitives for GNU Emacs. | 1 | /* Buffer manipulation primitives for GNU Emacs. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1989, 1993-1995, 1997-2011 Free Software Foundation, Inc. | 3 | Copyright (C) 1985-1989, 1993-1995, 1997-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is part of GNU Emacs. | 5 | This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -152,7 +152,7 @@ Lisp_Object Qmodification_hooks; | |||
| 152 | Lisp_Object Qinsert_in_front_hooks; | 152 | Lisp_Object Qinsert_in_front_hooks; |
| 153 | Lisp_Object Qinsert_behind_hooks; | 153 | Lisp_Object Qinsert_behind_hooks; |
| 154 | 154 | ||
| 155 | static void alloc_buffer_text (struct buffer *, size_t); | 155 | static void alloc_buffer_text (struct buffer *, ptrdiff_t); |
| 156 | static void free_buffer_text (struct buffer *b); | 156 | static void free_buffer_text (struct buffer *b); |
| 157 | static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); | 157 | static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); |
| 158 | static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); | 158 | static void modify_overlay (struct buffer *, EMACS_INT, EMACS_INT); |
| @@ -272,7 +272,11 @@ See also `find-buffer-visiting'. */) | |||
| 272 | call the corresponding file handler. */ | 272 | call the corresponding file handler. */ |
| 273 | handler = Ffind_file_name_handler (filename, Qget_file_buffer); | 273 | handler = Ffind_file_name_handler (filename, Qget_file_buffer); |
| 274 | if (!NILP (handler)) | 274 | if (!NILP (handler)) |
| 275 | return call2 (handler, Qget_file_buffer, filename); | 275 | { |
| 276 | Lisp_Object handled_buf = call2 (handler, Qget_file_buffer, | ||
| 277 | filename); | ||
| 278 | return BUFFERP (handled_buf) ? handled_buf : Qnil; | ||
| 279 | } | ||
| 276 | 280 | ||
| 277 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) | 281 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) |
| 278 | { | 282 | { |
| @@ -361,6 +365,7 @@ even if it is dead. The return value is never nil. */) | |||
| 361 | BUF_END_UNCHANGED (b) = 0; | 365 | BUF_END_UNCHANGED (b) = 0; |
| 362 | BUF_BEG_UNCHANGED (b) = 0; | 366 | BUF_BEG_UNCHANGED (b) = 0; |
| 363 | *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'. */ | 367 | *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'. */ |
| 368 | b->text->inhibit_shrinking = 0; | ||
| 364 | 369 | ||
| 365 | b->newline_cache = 0; | 370 | b->newline_cache = 0; |
| 366 | b->width_run_cache = 0; | 371 | b->width_run_cache = 0; |
| @@ -723,7 +728,7 @@ reset_buffer (register struct buffer *b) | |||
| 723 | b->prevent_redisplay_optimizations_p = 1; | 728 | b->prevent_redisplay_optimizations_p = 1; |
| 724 | BVAR (b, backed_up) = Qnil; | 729 | BVAR (b, backed_up) = Qnil; |
| 725 | BUF_AUTOSAVE_MODIFF (b) = 0; | 730 | BUF_AUTOSAVE_MODIFF (b) = 0; |
| 726 | b->auto_save_failure_time = -1; | 731 | b->auto_save_failure_time = 0; |
| 727 | BVAR (b, auto_save_file_name) = Qnil; | 732 | BVAR (b, auto_save_file_name) = Qnil; |
| 728 | BVAR (b, read_only) = Qnil; | 733 | BVAR (b, read_only) = Qnil; |
| 729 | b->overlays_before = NULL; | 734 | b->overlays_before = NULL; |
| @@ -1021,7 +1026,10 @@ buffer_lisp_local_variables (struct buffer *buf) | |||
| 1021 | if (buf != current_buffer) | 1026 | if (buf != current_buffer) |
| 1022 | val = XCDR (elt); | 1027 | val = XCDR (elt); |
| 1023 | 1028 | ||
| 1024 | result = Fcons (Fcons (XCAR (elt), val), result); | 1029 | result = Fcons (EQ (val, Qunbound) |
| 1030 | ? XCAR (elt) | ||
| 1031 | : Fcons (XCAR (elt), val), | ||
| 1032 | result); | ||
| 1025 | } | 1033 | } |
| 1026 | 1034 | ||
| 1027 | return result; | 1035 | return result; |
| @@ -1063,9 +1071,12 @@ No argument or nil as argument means use current buffer as BUFFER. */) | |||
| 1063 | idx = PER_BUFFER_IDX (offset); | 1071 | idx = PER_BUFFER_IDX (offset); |
| 1064 | if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) | 1072 | if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) |
| 1065 | && SYMBOLP (PER_BUFFER_SYMBOL (offset))) | 1073 | && SYMBOLP (PER_BUFFER_SYMBOL (offset))) |
| 1066 | result = Fcons (Fcons (PER_BUFFER_SYMBOL (offset), | 1074 | { |
| 1067 | PER_BUFFER_VALUE (buf, offset)), | 1075 | Lisp_Object sym = PER_BUFFER_SYMBOL (offset); |
| 1068 | result); | 1076 | Lisp_Object val = PER_BUFFER_VALUE (buf, offset); |
| 1077 | result = Fcons (EQ (val, Qunbound) ? sym : Fcons (sym, val), | ||
| 1078 | result); | ||
| 1079 | } | ||
| 1069 | } | 1080 | } |
| 1070 | } | 1081 | } |
| 1071 | 1082 | ||
| @@ -1525,7 +1536,13 @@ with SIGHUP. */) | |||
| 1525 | UNGCPRO; | 1536 | UNGCPRO; |
| 1526 | } | 1537 | } |
| 1527 | 1538 | ||
| 1528 | /* Make this buffer not be current. | 1539 | /* Run replace_buffer_in_windows before making another buffer current |
| 1540 | since set-window-buffer-start-and-point will refuse to make another | ||
| 1541 | buffer current if the selected window does not show the current | ||
| 1542 | buffer. (Bug#10114) */ | ||
| 1543 | replace_buffer_in_windows (buffer); | ||
| 1544 | |||
| 1545 | /* Make this buffer not be current. | ||
| 1529 | In the process, notice if this is the sole visible buffer | 1546 | In the process, notice if this is the sole visible buffer |
| 1530 | and give up if so. */ | 1547 | and give up if so. */ |
| 1531 | if (b == current_buffer) | 1548 | if (b == current_buffer) |
| @@ -1565,7 +1582,6 @@ with SIGHUP. */) | |||
| 1565 | 1582 | ||
| 1566 | /* These may run Lisp code and into infinite loops (if someone | 1583 | /* These may run Lisp code and into infinite loops (if someone |
| 1567 | insisted on circular lists) so allow quitting here. */ | 1584 | insisted on circular lists) so allow quitting here. */ |
| 1568 | replace_buffer_in_windows (buffer); | ||
| 1569 | frames_discard_buffer (buffer); | 1585 | frames_discard_buffer (buffer); |
| 1570 | 1586 | ||
| 1571 | clear_charpos_cache (b); | 1587 | clear_charpos_cache (b); |
| @@ -1625,7 +1641,7 @@ with SIGHUP. */) | |||
| 1625 | 1641 | ||
| 1626 | /* Reset the local variables, so that this buffer's local values | 1642 | /* Reset the local variables, so that this buffer's local values |
| 1627 | won't be protected from GC. They would be protected | 1643 | won't be protected from GC. They would be protected |
| 1628 | if they happened to remain encached in their symbols. | 1644 | if they happened to remain cached in their symbols. |
| 1629 | This gets rid of them for certain. */ | 1645 | This gets rid of them for certain. */ |
| 1630 | swap_out_buffer_local_variables (b); | 1646 | swap_out_buffer_local_variables (b); |
| 1631 | reset_buffer_local_variables (b, 1); | 1647 | reset_buffer_local_variables (b, 1); |
| @@ -1697,27 +1713,16 @@ record_buffer (Lisp_Object buffer) | |||
| 1697 | call1 (Vrun_hooks, Qbuffer_list_update_hook); | 1713 | call1 (Vrun_hooks, Qbuffer_list_update_hook); |
| 1698 | } | 1714 | } |
| 1699 | 1715 | ||
| 1700 | DEFUN ("record-buffer", Frecord_buffer, Srecord_buffer, 1, 1, 0, | ||
| 1701 | doc: /* Move BUFFER to the front of the buffer list. | ||
| 1702 | Return BUFFER. */) | ||
| 1703 | (Lisp_Object buffer) | ||
| 1704 | { | ||
| 1705 | CHECK_BUFFER (buffer); | ||
| 1706 | |||
| 1707 | record_buffer (buffer); | ||
| 1708 | |||
| 1709 | return buffer; | ||
| 1710 | } | ||
| 1711 | 1716 | ||
| 1712 | /* Move BUFFER to the end of the buffer (a)lists. Do nothing if the | 1717 | /* Move BUFFER to the end of the buffer (a)lists. Do nothing if the |
| 1713 | buffer is killed. For the selected frame's buffer list this moves | 1718 | buffer is killed. For the selected frame's buffer list this moves |
| 1714 | BUFFER to its end even if it was never shown in that frame. If | 1719 | BUFFER to its end even if it was never shown in that frame. If |
| 1715 | this happens we have a feature, hence `unrecord-buffer' should be | 1720 | this happens we have a feature, hence `bury-buffer-internal' should be |
| 1716 | called only when BUFFER was shown in the selected frame. */ | 1721 | called only when BUFFER was shown in the selected frame. */ |
| 1717 | 1722 | ||
| 1718 | DEFUN ("unrecord-buffer", Funrecord_buffer, Sunrecord_buffer, 1, 1, 0, | 1723 | DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal, |
| 1719 | doc: /* Move BUFFER to the end of the buffer list. | 1724 | 1, 1, 0, |
| 1720 | Return BUFFER. */) | 1725 | doc: /* Move BUFFER to the end of the buffer list. */) |
| 1721 | (Lisp_Object buffer) | 1726 | (Lisp_Object buffer) |
| 1722 | { | 1727 | { |
| 1723 | Lisp_Object aelt, aelt_cons, tem; | 1728 | Lisp_Object aelt, aelt_cons, tem; |
| @@ -1745,7 +1750,7 @@ Return BUFFER. */) | |||
| 1745 | if (!NILP (Vrun_hooks)) | 1750 | if (!NILP (Vrun_hooks)) |
| 1746 | call1 (Vrun_hooks, Qbuffer_list_update_hook); | 1751 | call1 (Vrun_hooks, Qbuffer_list_update_hook); |
| 1747 | 1752 | ||
| 1748 | return buffer; | 1753 | return Qnil; |
| 1749 | } | 1754 | } |
| 1750 | 1755 | ||
| 1751 | DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, | 1756 | DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, |
| @@ -2491,7 +2496,7 @@ swap_out_buffer_local_variables (struct buffer *b) | |||
| 2491 | Lisp_Object sym = XCAR (XCAR (alist)); | 2496 | Lisp_Object sym = XCAR (XCAR (alist)); |
| 2492 | eassert (XSYMBOL (sym)->redirect == SYMBOL_LOCALIZED); | 2497 | eassert (XSYMBOL (sym)->redirect == SYMBOL_LOCALIZED); |
| 2493 | /* Need not do anything if some other buffer's binding is | 2498 | /* Need not do anything if some other buffer's binding is |
| 2494 | now encached. */ | 2499 | now cached. */ |
| 2495 | if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer)) | 2500 | if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer)) |
| 2496 | { | 2501 | { |
| 2497 | /* Symbol is set up for this buffer's old local value: | 2502 | /* Symbol is set up for this buffer's old local value: |
| @@ -2567,13 +2572,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, | |||
| 2567 | Either make it bigger, or don't store any more in it. */ | 2572 | Either make it bigger, or don't store any more in it. */ |
| 2568 | if (extend) | 2573 | if (extend) |
| 2569 | { | 2574 | { |
| 2570 | if ((OVERLAY_COUNT_MAX - 4) / 2 < len) | 2575 | vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, |
| 2571 | memory_full (SIZE_MAX); | 2576 | sizeof *vec); |
| 2572 | /* Make it work with an initial len == 0. */ | ||
| 2573 | len = len * 2 + 4; | ||
| 2574 | *len_ptr = len; | ||
| 2575 | vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); | ||
| 2576 | *vec_ptr = vec; | 2577 | *vec_ptr = vec; |
| 2578 | len = *len_ptr; | ||
| 2577 | } | 2579 | } |
| 2578 | else | 2580 | else |
| 2579 | inhibit_storing = 1; | 2581 | inhibit_storing = 1; |
| @@ -2610,13 +2612,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, | |||
| 2610 | { | 2612 | { |
| 2611 | if (extend) | 2613 | if (extend) |
| 2612 | { | 2614 | { |
| 2613 | if ((OVERLAY_COUNT_MAX - 4) / 2 < len) | 2615 | vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, |
| 2614 | memory_full (SIZE_MAX); | 2616 | sizeof *vec); |
| 2615 | /* Make it work with an initial len == 0. */ | ||
| 2616 | len = len * 2 + 4; | ||
| 2617 | *len_ptr = len; | ||
| 2618 | vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); | ||
| 2619 | *vec_ptr = vec; | 2617 | *vec_ptr = vec; |
| 2618 | len = *len_ptr; | ||
| 2620 | } | 2619 | } |
| 2621 | else | 2620 | else |
| 2622 | inhibit_storing = 1; | 2621 | inhibit_storing = 1; |
| @@ -2707,13 +2706,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend, | |||
| 2707 | Either make it bigger, or don't store any more in it. */ | 2706 | Either make it bigger, or don't store any more in it. */ |
| 2708 | if (extend) | 2707 | if (extend) |
| 2709 | { | 2708 | { |
| 2710 | if ((OVERLAY_COUNT_MAX - 4) / 2 < len) | 2709 | vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, |
| 2711 | memory_full (SIZE_MAX); | 2710 | sizeof *vec); |
| 2712 | /* Make it work with an initial len == 0. */ | ||
| 2713 | len = len * 2 + 4; | ||
| 2714 | *len_ptr = len; | ||
| 2715 | vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); | ||
| 2716 | *vec_ptr = vec; | 2711 | *vec_ptr = vec; |
| 2712 | len = *len_ptr; | ||
| 2717 | } | 2713 | } |
| 2718 | else | 2714 | else |
| 2719 | inhibit_storing = 1; | 2715 | inhibit_storing = 1; |
| @@ -2755,13 +2751,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend, | |||
| 2755 | { | 2751 | { |
| 2756 | if (extend) | 2752 | if (extend) |
| 2757 | { | 2753 | { |
| 2758 | if ((OVERLAY_COUNT_MAX - 4) / 2 < len) | 2754 | vec = xpalloc (vec, len_ptr, 1, OVERLAY_COUNT_MAX, |
| 2759 | memory_full (SIZE_MAX); | 2755 | sizeof *vec); |
| 2760 | /* Make it work with an initial len == 0. */ | ||
| 2761 | len = len * 2 + 4; | ||
| 2762 | *len_ptr = len; | ||
| 2763 | vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); | ||
| 2764 | *vec_ptr = vec; | 2756 | *vec_ptr = vec; |
| 2757 | len = *len_ptr; | ||
| 2765 | } | 2758 | } |
| 2766 | else | 2759 | else |
| 2767 | inhibit_storing = 1; | 2760 | inhibit_storing = 1; |
| @@ -2871,6 +2864,12 @@ compare_overlays (const void *v1, const void *v2) | |||
| 2871 | return s1->beg < s2->beg ? -1 : 1; | 2864 | return s1->beg < s2->beg ? -1 : 1; |
| 2872 | if (s1->end != s2->end) | 2865 | if (s1->end != s2->end) |
| 2873 | return s2->end < s1->end ? -1 : 1; | 2866 | return s2->end < s1->end ? -1 : 1; |
| 2867 | /* Avoid the non-determinism of qsort by choosing an arbitrary ordering | ||
| 2868 | between "equal" overlays. The result can still change between | ||
| 2869 | invocations of Emacs, but it won't change in the middle of | ||
| 2870 | `find_field' (bug#6830). */ | ||
| 2871 | if (XHASH (s1->overlay) != XHASH (s2->overlay)) | ||
| 2872 | return XHASH (s1->overlay) < XHASH (s2->overlay) ? -1 : 1; | ||
| 2874 | return 0; | 2873 | return 0; |
| 2875 | } | 2874 | } |
| 2876 | 2875 | ||
| @@ -2943,7 +2942,7 @@ struct sortstrlist | |||
| 2943 | struct sortstr *buf; /* An array that expands as needed; never freed. */ | 2942 | struct sortstr *buf; /* An array that expands as needed; never freed. */ |
| 2944 | ptrdiff_t size; /* Allocated length of that array. */ | 2943 | ptrdiff_t size; /* Allocated length of that array. */ |
| 2945 | ptrdiff_t used; /* How much of the array is currently in use. */ | 2944 | ptrdiff_t used; /* How much of the array is currently in use. */ |
| 2946 | EMACS_INT bytes; /* Total length of the strings in buf. */ | 2945 | ptrdiff_t bytes; /* Total length of the strings in buf. */ |
| 2947 | }; | 2946 | }; |
| 2948 | 2947 | ||
| 2949 | /* Buffers for storing information about the overlays touching a given | 2948 | /* Buffers for storing information about the overlays touching a given |
| @@ -2954,7 +2953,7 @@ static struct sortstrlist overlay_heads, overlay_tails; | |||
| 2954 | static unsigned char *overlay_str_buf; | 2953 | static unsigned char *overlay_str_buf; |
| 2955 | 2954 | ||
| 2956 | /* Allocated length of overlay_str_buf. */ | 2955 | /* Allocated length of overlay_str_buf. */ |
| 2957 | static EMACS_INT overlay_str_len; | 2956 | static ptrdiff_t overlay_str_len; |
| 2958 | 2957 | ||
| 2959 | /* A comparison function suitable for passing to qsort. */ | 2958 | /* A comparison function suitable for passing to qsort. */ |
| 2960 | static int | 2959 | static int |
| @@ -2976,17 +2975,7 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, | |||
| 2976 | EMACS_INT nbytes; | 2975 | EMACS_INT nbytes; |
| 2977 | 2976 | ||
| 2978 | if (ssl->used == ssl->size) | 2977 | if (ssl->used == ssl->size) |
| 2979 | { | 2978 | ssl->buf = xpalloc (ssl->buf, &ssl->size, 5, -1, sizeof *ssl->buf); |
| 2980 | if (min (PTRDIFF_MAX, SIZE_MAX) / (sizeof (struct sortstr) * 2) | ||
| 2981 | < ssl->size) | ||
| 2982 | memory_full (SIZE_MAX); | ||
| 2983 | else if (0 < ssl->size) | ||
| 2984 | ssl->size *= 2; | ||
| 2985 | else | ||
| 2986 | ssl->size = 5; | ||
| 2987 | ssl->buf = ((struct sortstr *) | ||
| 2988 | xrealloc (ssl->buf, ssl->size * sizeof (struct sortstr))); | ||
| 2989 | } | ||
| 2990 | ssl->buf[ssl->used].string = str; | 2979 | ssl->buf[ssl->used].string = str; |
| 2991 | ssl->buf[ssl->used].string2 = str2; | 2980 | ssl->buf[ssl->used].string2 = str2; |
| 2992 | ssl->buf[ssl->used].size = size; | 2981 | ssl->buf[ssl->used].size = size; |
| @@ -3001,6 +2990,8 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, | |||
| 3001 | else | 2990 | else |
| 3002 | nbytes = SBYTES (str); | 2991 | nbytes = SBYTES (str); |
| 3003 | 2992 | ||
| 2993 | if (INT_ADD_OVERFLOW (ssl->bytes, nbytes)) | ||
| 2994 | memory_full (SIZE_MAX); | ||
| 3004 | ssl->bytes += nbytes; | 2995 | ssl->bytes += nbytes; |
| 3005 | 2996 | ||
| 3006 | if (STRINGP (str2)) | 2997 | if (STRINGP (str2)) |
| @@ -3013,6 +3004,8 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, | |||
| 3013 | else | 3004 | else |
| 3014 | nbytes = SBYTES (str2); | 3005 | nbytes = SBYTES (str2); |
| 3015 | 3006 | ||
| 3007 | if (INT_ADD_OVERFLOW (ssl->bytes, nbytes)) | ||
| 3008 | memory_full (SIZE_MAX); | ||
| 3016 | ssl->bytes += nbytes; | 3009 | ssl->bytes += nbytes; |
| 3017 | } | 3010 | } |
| 3018 | } | 3011 | } |
| @@ -3106,14 +3099,15 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) | |||
| 3106 | Lisp_Object tem; | 3099 | Lisp_Object tem; |
| 3107 | EMACS_INT i; | 3100 | EMACS_INT i; |
| 3108 | unsigned char *p; | 3101 | unsigned char *p; |
| 3109 | EMACS_INT total = overlay_heads.bytes + overlay_tails.bytes; | 3102 | ptrdiff_t total; |
| 3110 | 3103 | ||
| 3104 | if (INT_ADD_OVERFLOW (overlay_heads.bytes, overlay_tails.bytes)) | ||
| 3105 | memory_full (SIZE_MAX); | ||
| 3106 | total = overlay_heads.bytes + overlay_tails.bytes; | ||
| 3111 | if (total > overlay_str_len) | 3107 | if (total > overlay_str_len) |
| 3112 | { | 3108 | overlay_str_buf = xpalloc (overlay_str_buf, &overlay_str_len, |
| 3113 | overlay_str_len = total; | 3109 | total - overlay_str_len, -1, 1); |
| 3114 | overlay_str_buf = (unsigned char *)xrealloc (overlay_str_buf, | 3110 | |
| 3115 | total); | ||
| 3116 | } | ||
| 3117 | p = overlay_str_buf; | 3111 | p = overlay_str_buf; |
| 3118 | for (i = overlay_tails.used; --i >= 0;) | 3112 | for (i = overlay_tails.used; --i >= 0;) |
| 3119 | { | 3113 | { |
| @@ -4427,7 +4421,7 @@ static int mmap_fd_1; | |||
| 4427 | 4421 | ||
| 4428 | static int mmap_page_size; | 4422 | static int mmap_page_size; |
| 4429 | 4423 | ||
| 4430 | /* 1 means mmap has been intialized. */ | 4424 | /* 1 means mmap has been initialized. */ |
| 4431 | 4425 | ||
| 4432 | static int mmap_initialized_p; | 4426 | static int mmap_initialized_p; |
| 4433 | 4427 | ||
| @@ -4458,7 +4452,7 @@ static int mmap_initialized_p; | |||
| 4458 | is currently mapped. Used to prevent overwriting an existing | 4452 | is currently mapped. Used to prevent overwriting an existing |
| 4459 | memory mapping. | 4453 | memory mapping. |
| 4460 | 4454 | ||
| 4461 | Default is to conservativly assume the address range is occupied by | 4455 | Default is to conservatively assume the address range is occupied by |
| 4462 | something else. This can be overridden by system configuration | 4456 | something else. This can be overridden by system configuration |
| 4463 | files if system-specific means to determine this exists. */ | 4457 | files if system-specific means to determine this exists. */ |
| 4464 | 4458 | ||
| @@ -4466,24 +4460,40 @@ static int mmap_initialized_p; | |||
| 4466 | #define MMAP_ALLOCATED_P(start, end) 1 | 4460 | #define MMAP_ALLOCATED_P(start, end) 1 |
| 4467 | #endif | 4461 | #endif |
| 4468 | 4462 | ||
| 4469 | /* Function prototypes. */ | 4463 | /* Perform necessary initializations for the use of mmap. */ |
| 4470 | 4464 | ||
| 4471 | static int mmap_free_1 (struct mmap_region *); | 4465 | static void |
| 4472 | static int mmap_enlarge (struct mmap_region *, int); | 4466 | mmap_init (void) |
| 4473 | static struct mmap_region *mmap_find (POINTER_TYPE *, POINTER_TYPE *); | 4467 | { |
| 4474 | static POINTER_TYPE *mmap_alloc (POINTER_TYPE **, size_t); | 4468 | #if MAP_ANON == 0 |
| 4475 | static POINTER_TYPE *mmap_realloc (POINTER_TYPE **, size_t); | 4469 | /* The value of mmap_fd is initially 0 in temacs, and -1 |
| 4476 | static void mmap_free (POINTER_TYPE **ptr); | 4470 | in a dumped Emacs. */ |
| 4477 | static void mmap_init (void); | 4471 | if (mmap_fd <= 0) |
| 4472 | { | ||
| 4473 | /* No anonymous mmap -- we need the file descriptor. */ | ||
| 4474 | mmap_fd = open ("/dev/zero", O_RDONLY); | ||
| 4475 | if (mmap_fd == -1) | ||
| 4476 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); | ||
| 4477 | } | ||
| 4478 | #endif /* MAP_ANON == 0 */ | ||
| 4479 | |||
| 4480 | if (mmap_initialized_p) | ||
| 4481 | return; | ||
| 4482 | mmap_initialized_p = 1; | ||
| 4478 | 4483 | ||
| 4484 | #if MAP_ANON != 0 | ||
| 4485 | mmap_fd = -1; | ||
| 4486 | #endif | ||
| 4487 | |||
| 4488 | mmap_page_size = getpagesize (); | ||
| 4489 | } | ||
| 4479 | 4490 | ||
| 4480 | /* Return a region overlapping address range START...END, or null if | 4491 | /* Return a region overlapping address range START...END, or null if |
| 4481 | none. END is not including, i.e. the last byte in the range | 4492 | none. END is not including, i.e. the last byte in the range |
| 4482 | is at END - 1. */ | 4493 | is at END - 1. */ |
| 4483 | 4494 | ||
| 4484 | static struct mmap_region * | 4495 | static struct mmap_region * |
| 4485 | mmap_find (start, end) | 4496 | mmap_find (POINTER_TYPE *start, POINTER_TYPE *end) |
| 4486 | POINTER_TYPE *start, *end; | ||
| 4487 | { | 4497 | { |
| 4488 | struct mmap_region *r; | 4498 | struct mmap_region *r; |
| 4489 | char *s = (char *) start, *e = (char *) end; | 4499 | char *s = (char *) start, *e = (char *) end; |
| @@ -4512,8 +4522,7 @@ mmap_find (start, end) | |||
| 4512 | the region. Value is non-zero if successful. */ | 4522 | the region. Value is non-zero if successful. */ |
| 4513 | 4523 | ||
| 4514 | static int | 4524 | static int |
| 4515 | mmap_free_1 (r) | 4525 | mmap_free_1 (struct mmap_region *r) |
| 4516 | struct mmap_region *r; | ||
| 4517 | { | 4526 | { |
| 4518 | if (r->next) | 4527 | if (r->next) |
| 4519 | r->next->prev = r->prev; | 4528 | r->next->prev = r->prev; |
| @@ -4536,9 +4545,7 @@ mmap_free_1 (r) | |||
| 4536 | Value is non-zero if successful. */ | 4545 | Value is non-zero if successful. */ |
| 4537 | 4546 | ||
| 4538 | static int | 4547 | static int |
| 4539 | mmap_enlarge (r, npages) | 4548 | mmap_enlarge (struct mmap_region *r, int npages) |
| 4540 | struct mmap_region *r; | ||
| 4541 | int npages; | ||
| 4542 | { | 4549 | { |
| 4543 | char *region_end = (char *) r + r->nbytes_mapped; | 4550 | char *region_end = (char *) r + r->nbytes_mapped; |
| 4544 | size_t nbytes; | 4551 | size_t nbytes; |
| @@ -4602,8 +4609,7 @@ mmap_enlarge (r, npages) | |||
| 4602 | when Emacs starts. */ | 4609 | when Emacs starts. */ |
| 4603 | 4610 | ||
| 4604 | void | 4611 | void |
| 4605 | mmap_set_vars (restore_p) | 4612 | mmap_set_vars (int restore_p) |
| 4606 | int restore_p; | ||
| 4607 | { | 4613 | { |
| 4608 | struct mmap_region *r; | 4614 | struct mmap_region *r; |
| 4609 | 4615 | ||
| @@ -4636,9 +4642,7 @@ mmap_set_vars (restore_p) | |||
| 4636 | return null. */ | 4642 | return null. */ |
| 4637 | 4643 | ||
| 4638 | static POINTER_TYPE * | 4644 | static POINTER_TYPE * |
| 4639 | mmap_alloc (var, nbytes) | 4645 | mmap_alloc (POINTER_TYPE **var, size_t nbytes) |
| 4640 | POINTER_TYPE **var; | ||
| 4641 | size_t nbytes; | ||
| 4642 | { | 4646 | { |
| 4643 | void *p; | 4647 | void *p; |
| 4644 | size_t map; | 4648 | size_t map; |
| @@ -4675,15 +4679,29 @@ mmap_alloc (var, nbytes) | |||
| 4675 | } | 4679 | } |
| 4676 | 4680 | ||
| 4677 | 4681 | ||
| 4682 | /* Free a block of relocatable storage whose data is pointed to by | ||
| 4683 | PTR. Store 0 in *PTR to show there's no block allocated. */ | ||
| 4684 | |||
| 4685 | static void | ||
| 4686 | mmap_free (POINTER_TYPE **var) | ||
| 4687 | { | ||
| 4688 | mmap_init (); | ||
| 4689 | |||
| 4690 | if (*var) | ||
| 4691 | { | ||
| 4692 | mmap_free_1 (MMAP_REGION (*var)); | ||
| 4693 | *var = NULL; | ||
| 4694 | } | ||
| 4695 | } | ||
| 4696 | |||
| 4697 | |||
| 4678 | /* Given a pointer at address VAR to data allocated with mmap_alloc, | 4698 | /* Given a pointer at address VAR to data allocated with mmap_alloc, |
| 4679 | resize it to size NBYTES. Change *VAR to reflect the new block, | 4699 | resize it to size NBYTES. Change *VAR to reflect the new block, |
| 4680 | and return this value. If more memory cannot be allocated, then | 4700 | and return this value. If more memory cannot be allocated, then |
| 4681 | leave *VAR unchanged, and return null. */ | 4701 | leave *VAR unchanged, and return null. */ |
| 4682 | 4702 | ||
| 4683 | static POINTER_TYPE * | 4703 | static POINTER_TYPE * |
| 4684 | mmap_realloc (var, nbytes) | 4704 | mmap_realloc (POINTER_TYPE **var, size_t nbytes) |
| 4685 | POINTER_TYPE **var; | ||
| 4686 | size_t nbytes; | ||
| 4687 | { | 4705 | { |
| 4688 | POINTER_TYPE *result; | 4706 | POINTER_TYPE *result; |
| 4689 | 4707 | ||
| @@ -4753,51 +4771,6 @@ mmap_realloc (var, nbytes) | |||
| 4753 | } | 4771 | } |
| 4754 | 4772 | ||
| 4755 | 4773 | ||
| 4756 | /* Free a block of relocatable storage whose data is pointed to by | ||
| 4757 | PTR. Store 0 in *PTR to show there's no block allocated. */ | ||
| 4758 | |||
| 4759 | static void | ||
| 4760 | mmap_free (var) | ||
| 4761 | POINTER_TYPE **var; | ||
| 4762 | { | ||
| 4763 | mmap_init (); | ||
| 4764 | |||
| 4765 | if (*var) | ||
| 4766 | { | ||
| 4767 | mmap_free_1 (MMAP_REGION (*var)); | ||
| 4768 | *var = NULL; | ||
| 4769 | } | ||
| 4770 | } | ||
| 4771 | |||
| 4772 | |||
| 4773 | /* Perform necessary intializations for the use of mmap. */ | ||
| 4774 | |||
| 4775 | static void | ||
| 4776 | mmap_init () | ||
| 4777 | { | ||
| 4778 | #if MAP_ANON == 0 | ||
| 4779 | /* The value of mmap_fd is initially 0 in temacs, and -1 | ||
| 4780 | in a dumped Emacs. */ | ||
| 4781 | if (mmap_fd <= 0) | ||
| 4782 | { | ||
| 4783 | /* No anonymous mmap -- we need the file descriptor. */ | ||
| 4784 | mmap_fd = open ("/dev/zero", O_RDONLY); | ||
| 4785 | if (mmap_fd == -1) | ||
| 4786 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); | ||
| 4787 | } | ||
| 4788 | #endif /* MAP_ANON == 0 */ | ||
| 4789 | |||
| 4790 | if (mmap_initialized_p) | ||
| 4791 | return; | ||
| 4792 | mmap_initialized_p = 1; | ||
| 4793 | |||
| 4794 | #if MAP_ANON != 0 | ||
| 4795 | mmap_fd = -1; | ||
| 4796 | #endif | ||
| 4797 | |||
| 4798 | mmap_page_size = getpagesize (); | ||
| 4799 | } | ||
| 4800 | |||
| 4801 | #endif /* USE_MMAP_FOR_BUFFERS */ | 4774 | #endif /* USE_MMAP_FOR_BUFFERS */ |
| 4802 | 4775 | ||
| 4803 | 4776 | ||
| @@ -4816,7 +4789,7 @@ extern void r_alloc_free (POINTER_TYPE **ptr); | |||
| 4816 | /* Allocate NBYTES bytes for buffer B's text buffer. */ | 4789 | /* Allocate NBYTES bytes for buffer B's text buffer. */ |
| 4817 | 4790 | ||
| 4818 | static void | 4791 | static void |
| 4819 | alloc_buffer_text (struct buffer *b, size_t nbytes) | 4792 | alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) |
| 4820 | { | 4793 | { |
| 4821 | POINTER_TYPE *p; | 4794 | POINTER_TYPE *p; |
| 4822 | 4795 | ||
| @@ -4846,8 +4819,8 @@ void | |||
| 4846 | enlarge_buffer_text (struct buffer *b, EMACS_INT delta) | 4819 | enlarge_buffer_text (struct buffer *b, EMACS_INT delta) |
| 4847 | { | 4820 | { |
| 4848 | POINTER_TYPE *p; | 4821 | POINTER_TYPE *p; |
| 4849 | size_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 | 4822 | ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 |
| 4850 | + delta); | 4823 | + delta); |
| 4851 | BLOCK_INPUT; | 4824 | BLOCK_INPUT; |
| 4852 | #if defined USE_MMAP_FOR_BUFFERS | 4825 | #if defined USE_MMAP_FOR_BUFFERS |
| 4853 | p = mmap_realloc ((POINTER_TYPE **) &b->text->beg, nbytes); | 4826 | p = mmap_realloc ((POINTER_TYPE **) &b->text->beg, nbytes); |
| @@ -4946,7 +4919,7 @@ init_buffer_once (void) | |||
| 4946 | BVAR (&buffer_defaults, truncate_lines) = Qnil; | 4919 | BVAR (&buffer_defaults, truncate_lines) = Qnil; |
| 4947 | BVAR (&buffer_defaults, word_wrap) = Qnil; | 4920 | BVAR (&buffer_defaults, word_wrap) = Qnil; |
| 4948 | BVAR (&buffer_defaults, ctl_arrow) = Qt; | 4921 | BVAR (&buffer_defaults, ctl_arrow) = Qt; |
| 4949 | BVAR (&buffer_defaults, bidi_display_reordering) = Qnil; | 4922 | BVAR (&buffer_defaults, bidi_display_reordering) = Qt; |
| 4950 | BVAR (&buffer_defaults, bidi_paragraph_direction) = Qnil; | 4923 | BVAR (&buffer_defaults, bidi_paragraph_direction) = Qnil; |
| 4951 | BVAR (&buffer_defaults, cursor_type) = Qt; | 4924 | BVAR (&buffer_defaults, cursor_type) = Qt; |
| 4952 | BVAR (&buffer_defaults, extra_line_spacing) = Qnil; | 4925 | BVAR (&buffer_defaults, extra_line_spacing) = Qnil; |
| @@ -5496,9 +5469,7 @@ file I/O and the behavior of various editing commands. | |||
| 5496 | 5469 | ||
| 5497 | This variable is buffer-local but you cannot set it directly; | 5470 | This variable is buffer-local but you cannot set it directly; |
| 5498 | use the function `set-buffer-multibyte' to change a buffer's representation. | 5471 | use the function `set-buffer-multibyte' to change a buffer's representation. |
| 5499 | Changing its default value with `setq-default' is supported. | 5472 | See also Info node `(elisp)Text Representations'. */); |
| 5500 | See also variable `default-enable-multibyte-characters' and Info node | ||
| 5501 | `(elisp)Text Representations'. */); | ||
| 5502 | XSYMBOL (intern_c_string ("enable-multibyte-characters"))->constant = 1; | 5473 | XSYMBOL (intern_c_string ("enable-multibyte-characters"))->constant = 1; |
| 5503 | 5474 | ||
| 5504 | DEFVAR_PER_BUFFER ("buffer-file-coding-system", | 5475 | DEFVAR_PER_BUFFER ("buffer-file-coding-system", |
| @@ -5541,7 +5512,9 @@ Instead, give each line of text just one screen line. | |||
| 5541 | 5512 | ||
| 5542 | Note that this is overridden by the variable | 5513 | Note that this is overridden by the variable |
| 5543 | `truncate-partial-width-windows' if that variable is non-nil | 5514 | `truncate-partial-width-windows' if that variable is non-nil |
| 5544 | and this buffer is not full-frame width. */); | 5515 | and this buffer is not full-frame width. |
| 5516 | |||
| 5517 | Minibuffers set this variable to nil. */); | ||
| 5545 | 5518 | ||
| 5546 | DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer, word_wrap), Qnil, | 5519 | DEFVAR_PER_BUFFER ("word-wrap", &BVAR (current_buffer, word_wrap), Qnil, |
| 5547 | doc: /* *Non-nil means to use word-wrapping for continuation lines. | 5520 | doc: /* *Non-nil means to use word-wrapping for continuation lines. |
| @@ -6029,7 +6002,7 @@ The function `kill-all-local-variables' runs this before doing anything else. * | |||
| 6029 | doc: /* Hook run when the buffer list changes. | 6002 | doc: /* Hook run when the buffer list changes. |
| 6030 | Functions running this hook are `get-buffer-create', | 6003 | Functions running this hook are `get-buffer-create', |
| 6031 | `make-indirect-buffer', `rename-buffer', `kill-buffer', | 6004 | `make-indirect-buffer', `rename-buffer', `kill-buffer', |
| 6032 | `record-buffer' and `unrecord-buffer'. */); | 6005 | and `bury-buffer-internal'. */); |
| 6033 | Vbuffer_list_update_hook = Qnil; | 6006 | Vbuffer_list_update_hook = Qnil; |
| 6034 | DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook"); | 6007 | DEFSYM (Qbuffer_list_update_hook, "buffer-list-update-hook"); |
| 6035 | 6008 | ||
| @@ -6054,8 +6027,7 @@ Functions running this hook are `get-buffer-create', | |||
| 6054 | defsubr (&Sother_buffer); | 6027 | defsubr (&Sother_buffer); |
| 6055 | defsubr (&Sbuffer_enable_undo); | 6028 | defsubr (&Sbuffer_enable_undo); |
| 6056 | defsubr (&Skill_buffer); | 6029 | defsubr (&Skill_buffer); |
| 6057 | defsubr (&Srecord_buffer); | 6030 | defsubr (&Sbury_buffer_internal); |
| 6058 | defsubr (&Sunrecord_buffer); | ||
| 6059 | defsubr (&Sset_buffer_major_mode); | 6031 | defsubr (&Sset_buffer_major_mode); |
| 6060 | defsubr (&Scurrent_buffer); | 6032 | defsubr (&Scurrent_buffer); |
| 6061 | defsubr (&Sset_buffer); | 6033 | defsubr (&Sset_buffer); |