aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c154
1 files changed, 62 insertions, 92 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 328963be78c..81c537b9c6a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -146,7 +146,7 @@ static Lisp_Object Qoverlayp;
146 146
147Lisp_Object Qpriority, Qbefore_string, Qafter_string; 147Lisp_Object Qpriority, Qbefore_string, Qafter_string;
148 148
149static Lisp_Object Qclone_number, Qevaporate; 149static Lisp_Object Qevaporate;
150 150
151Lisp_Object Qmodification_hooks; 151Lisp_Object Qmodification_hooks;
152Lisp_Object Qinsert_in_front_hooks; 152Lisp_Object Qinsert_in_front_hooks;
@@ -361,6 +361,7 @@ even if it is dead. The return value is never nil. */)
361 BUF_END_UNCHANGED (b) = 0; 361 BUF_END_UNCHANGED (b) = 0;
362 BUF_BEG_UNCHANGED (b) = 0; 362 BUF_BEG_UNCHANGED (b) = 0;
363 *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'. */ 363 *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'. */
364 b->text->inhibit_shrinking = 0;
364 365
365 b->newline_cache = 0; 366 b->newline_cache = 0;
366 b->width_run_cache = 0; 367 b->width_run_cache = 0;
@@ -471,8 +472,8 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to)
471 472
472 /* buffer-local Lisp variables start at `undo_list', 473 /* buffer-local Lisp variables start at `undo_list',
473 tho only the ones from `name' on are GC'd normally. */ 474 tho only the ones from `name' on are GC'd normally. */
474 for (offset = PER_BUFFER_VAR_OFFSET (undo_list); 475 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
475 offset < sizeof *to; 476 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
476 offset += sizeof (Lisp_Object)) 477 offset += sizeof (Lisp_Object))
477 { 478 {
478 Lisp_Object obj; 479 Lisp_Object obj;
@@ -830,8 +831,8 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too)
830 831
831 /* buffer-local Lisp variables start at `undo_list', 832 /* buffer-local Lisp variables start at `undo_list',
832 tho only the ones from `name' on are GC'd normally. */ 833 tho only the ones from `name' on are GC'd normally. */
833 for (offset = PER_BUFFER_VAR_OFFSET (undo_list); 834 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
834 offset < sizeof *b; 835 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
835 offset += sizeof (Lisp_Object)) 836 offset += sizeof (Lisp_Object))
836 { 837 {
837 int idx = PER_BUFFER_IDX (offset); 838 int idx = PER_BUFFER_IDX (offset);
@@ -1055,8 +1056,8 @@ No argument or nil as argument means use current buffer as BUFFER. */)
1055 1056
1056 /* buffer-local Lisp variables start at `undo_list', 1057 /* buffer-local Lisp variables start at `undo_list',
1057 tho only the ones from `name' on are GC'd normally. */ 1058 tho only the ones from `name' on are GC'd normally. */
1058 for (offset = PER_BUFFER_VAR_OFFSET (undo_list); 1059 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
1059 offset < sizeof (struct buffer); 1060 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
1060 /* sizeof EMACS_INT == sizeof Lisp_Object */ 1061 /* sizeof EMACS_INT == sizeof Lisp_Object */
1061 offset += (sizeof (EMACS_INT))) 1062 offset += (sizeof (EMACS_INT)))
1062 { 1063 {
@@ -2900,13 +2901,10 @@ sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2900 overlays that are limited to some other window. */ 2901 overlays that are limited to some other window. */
2901 if (w) 2902 if (w)
2902 { 2903 {
2903 Lisp_Object window, clone_number; 2904 Lisp_Object window;
2904 2905
2905 window = Foverlay_get (overlay, Qwindow); 2906 window = Foverlay_get (overlay, Qwindow);
2906 clone_number = Foverlay_get (overlay, Qclone_number); 2907 if (WINDOWP (window) && XWINDOW (window) != w)
2907 if (WINDOWP (window) && XWINDOW (window) != w
2908 && (! NUMBERP (clone_number)
2909 || XFASTINT (clone_number) != XFASTINT (w->clone_number)))
2910 continue; 2908 continue;
2911 } 2909 }
2912 2910
@@ -3035,7 +3033,7 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
3035EMACS_INT 3033EMACS_INT
3036overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr) 3034overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3037{ 3035{
3038 Lisp_Object overlay, window, clone_number, str; 3036 Lisp_Object overlay, window, str;
3039 struct Lisp_Overlay *ov; 3037 struct Lisp_Overlay *ov;
3040 EMACS_INT startpos, endpos; 3038 EMACS_INT startpos, endpos;
3041 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 3039 int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
@@ -3054,12 +3052,8 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3054 if (endpos != pos && startpos != pos) 3052 if (endpos != pos && startpos != pos)
3055 continue; 3053 continue;
3056 window = Foverlay_get (overlay, Qwindow); 3054 window = Foverlay_get (overlay, Qwindow);
3057 clone_number = Foverlay_get (overlay, Qclone_number); 3055 if (WINDOWP (window) && XWINDOW (window) != w)
3058 if (WINDOWP (window) && XWINDOW (window) != w
3059 && (! NUMBERP (clone_number)
3060 || XFASTINT (clone_number) != XFASTINT (w->clone_number)))
3061 continue; 3056 continue;
3062
3063 if (startpos == pos 3057 if (startpos == pos
3064 && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str))) 3058 && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
3065 record_overlay_string (&overlay_heads, str, 3059 record_overlay_string (&overlay_heads, str,
@@ -3086,10 +3080,7 @@ overlay_strings (EMACS_INT pos, struct window *w, unsigned char **pstr)
3086 if (endpos != pos && startpos != pos) 3080 if (endpos != pos && startpos != pos)
3087 continue; 3081 continue;
3088 window = Foverlay_get (overlay, Qwindow); 3082 window = Foverlay_get (overlay, Qwindow);
3089 clone_number = Foverlay_get (overlay, Qclone_number); 3083 if (WINDOWP (window) && XWINDOW (window) != w)
3090 if (WINDOWP (window) && XWINDOW (window) != w
3091 && (! NUMBERP (clone_number)
3092 || XFASTINT (clone_number) != XFASTINT (w->clone_number)))
3093 continue; 3084 continue;
3094 if (startpos == pos 3085 if (startpos == pos
3095 && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str))) 3086 && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
@@ -4066,7 +4057,8 @@ DEFUN ("overlay-get", Foverlay_get, Soverlay_get, 2, 2, 0,
4066} 4057}
4067 4058
4068DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0, 4059DEFUN ("overlay-put", Foverlay_put, Soverlay_put, 3, 3, 0,
4069 doc: /* Set one property of overlay OVERLAY: give property PROP value VALUE. */) 4060 doc: /* Set one property of overlay OVERLAY: give property PROP value VALUE.
4061VALUE will be returned.*/)
4070 (Lisp_Object overlay, Lisp_Object prop, Lisp_Object value) 4062 (Lisp_Object overlay, Lisp_Object prop, Lisp_Object value)
4071{ 4063{
4072 Lisp_Object tail, buffer; 4064 Lisp_Object tail, buffer;
@@ -4475,24 +4467,40 @@ static int mmap_initialized_p;
4475#define MMAP_ALLOCATED_P(start, end) 1 4467#define MMAP_ALLOCATED_P(start, end) 1
4476#endif 4468#endif
4477 4469
4478/* Function prototypes. */ 4470/* Perform necessary intializations for the use of mmap. */
4479 4471
4480static int mmap_free_1 (struct mmap_region *); 4472static void
4481static int mmap_enlarge (struct mmap_region *, int); 4473mmap_init (void)
4482static struct mmap_region *mmap_find (POINTER_TYPE *, POINTER_TYPE *); 4474{
4483static POINTER_TYPE *mmap_alloc (POINTER_TYPE **, size_t); 4475#if MAP_ANON == 0
4484static POINTER_TYPE *mmap_realloc (POINTER_TYPE **, size_t); 4476 /* The value of mmap_fd is initially 0 in temacs, and -1
4485static void mmap_free (POINTER_TYPE **ptr); 4477 in a dumped Emacs. */
4486static void mmap_init (void); 4478 if (mmap_fd <= 0)
4479 {
4480 /* No anonymous mmap -- we need the file descriptor. */
4481 mmap_fd = open ("/dev/zero", O_RDONLY);
4482 if (mmap_fd == -1)
4483 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno));
4484 }
4485#endif /* MAP_ANON == 0 */
4487 4486
4487 if (mmap_initialized_p)
4488 return;
4489 mmap_initialized_p = 1;
4490
4491#if MAP_ANON != 0
4492 mmap_fd = -1;
4493#endif
4494
4495 mmap_page_size = getpagesize ();
4496}
4488 4497
4489/* Return a region overlapping address range START...END, or null if 4498/* Return a region overlapping address range START...END, or null if
4490 none. END is not including, i.e. the last byte in the range 4499 none. END is not including, i.e. the last byte in the range
4491 is at END - 1. */ 4500 is at END - 1. */
4492 4501
4493static struct mmap_region * 4502static struct mmap_region *
4494mmap_find (start, end) 4503mmap_find (POINTER_TYPE *start, POINTER_TYPE *end)
4495 POINTER_TYPE *start, *end;
4496{ 4504{
4497 struct mmap_region *r; 4505 struct mmap_region *r;
4498 char *s = (char *) start, *e = (char *) end; 4506 char *s = (char *) start, *e = (char *) end;
@@ -4521,8 +4529,7 @@ mmap_find (start, end)
4521 the region. Value is non-zero if successful. */ 4529 the region. Value is non-zero if successful. */
4522 4530
4523static int 4531static int
4524mmap_free_1 (r) 4532mmap_free_1 (struct mmap_region *r)
4525 struct mmap_region *r;
4526{ 4533{
4527 if (r->next) 4534 if (r->next)
4528 r->next->prev = r->prev; 4535 r->next->prev = r->prev;
@@ -4545,9 +4552,7 @@ mmap_free_1 (r)
4545 Value is non-zero if successful. */ 4552 Value is non-zero if successful. */
4546 4553
4547static int 4554static int
4548mmap_enlarge (r, npages) 4555mmap_enlarge (struct mmap_region *r, int npages)
4549 struct mmap_region *r;
4550 int npages;
4551{ 4556{
4552 char *region_end = (char *) r + r->nbytes_mapped; 4557 char *region_end = (char *) r + r->nbytes_mapped;
4553 size_t nbytes; 4558 size_t nbytes;
@@ -4611,8 +4616,7 @@ mmap_enlarge (r, npages)
4611 when Emacs starts. */ 4616 when Emacs starts. */
4612 4617
4613void 4618void
4614mmap_set_vars (restore_p) 4619mmap_set_vars (int restore_p)
4615 int restore_p;
4616{ 4620{
4617 struct mmap_region *r; 4621 struct mmap_region *r;
4618 4622
@@ -4645,9 +4649,7 @@ mmap_set_vars (restore_p)
4645 return null. */ 4649 return null. */
4646 4650
4647static POINTER_TYPE * 4651static POINTER_TYPE *
4648mmap_alloc (var, nbytes) 4652mmap_alloc (POINTER_TYPE **var, size_t nbytes)
4649 POINTER_TYPE **var;
4650 size_t nbytes;
4651{ 4653{
4652 void *p; 4654 void *p;
4653 size_t map; 4655 size_t map;
@@ -4684,15 +4686,29 @@ mmap_alloc (var, nbytes)
4684} 4686}
4685 4687
4686 4688
4689/* Free a block of relocatable storage whose data is pointed to by
4690 PTR. Store 0 in *PTR to show there's no block allocated. */
4691
4692static void
4693mmap_free (POINTER_TYPE **var)
4694{
4695 mmap_init ();
4696
4697 if (*var)
4698 {
4699 mmap_free_1 (MMAP_REGION (*var));
4700 *var = NULL;
4701 }
4702}
4703
4704
4687/* Given a pointer at address VAR to data allocated with mmap_alloc, 4705/* Given a pointer at address VAR to data allocated with mmap_alloc,
4688 resize it to size NBYTES. Change *VAR to reflect the new block, 4706 resize it to size NBYTES. Change *VAR to reflect the new block,
4689 and return this value. If more memory cannot be allocated, then 4707 and return this value. If more memory cannot be allocated, then
4690 leave *VAR unchanged, and return null. */ 4708 leave *VAR unchanged, and return null. */
4691 4709
4692static POINTER_TYPE * 4710static POINTER_TYPE *
4693mmap_realloc (var, nbytes) 4711mmap_realloc (POINTER_TYPE **var, size_t nbytes)
4694 POINTER_TYPE **var;
4695 size_t nbytes;
4696{ 4712{
4697 POINTER_TYPE *result; 4713 POINTER_TYPE *result;
4698 4714
@@ -4762,51 +4778,6 @@ mmap_realloc (var, nbytes)
4762} 4778}
4763 4779
4764 4780
4765/* Free a block of relocatable storage whose data is pointed to by
4766 PTR. Store 0 in *PTR to show there's no block allocated. */
4767
4768static void
4769mmap_free (var)
4770 POINTER_TYPE **var;
4771{
4772 mmap_init ();
4773
4774 if (*var)
4775 {
4776 mmap_free_1 (MMAP_REGION (*var));
4777 *var = NULL;
4778 }
4779}
4780
4781
4782/* Perform necessary intializations for the use of mmap. */
4783
4784static void
4785mmap_init ()
4786{
4787#if MAP_ANON == 0
4788 /* The value of mmap_fd is initially 0 in temacs, and -1
4789 in a dumped Emacs. */
4790 if (mmap_fd <= 0)
4791 {
4792 /* No anonymous mmap -- we need the file descriptor. */
4793 mmap_fd = open ("/dev/zero", O_RDONLY);
4794 if (mmap_fd == -1)
4795 fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno));
4796 }
4797#endif /* MAP_ANON == 0 */
4798
4799 if (mmap_initialized_p)
4800 return;
4801 mmap_initialized_p = 1;
4802
4803#if MAP_ANON != 0
4804 mmap_fd = -1;
4805#endif
4806
4807 mmap_page_size = getpagesize ();
4808}
4809
4810#endif /* USE_MMAP_FOR_BUFFERS */ 4781#endif /* USE_MMAP_FOR_BUFFERS */
4811 4782
4812 4783
@@ -5229,7 +5200,6 @@ syms_of_buffer (void)
5229 DEFSYM (Qinsert_behind_hooks, "insert-behind-hooks"); 5200 DEFSYM (Qinsert_behind_hooks, "insert-behind-hooks");
5230 DEFSYM (Qget_file_buffer, "get-file-buffer"); 5201 DEFSYM (Qget_file_buffer, "get-file-buffer");
5231 DEFSYM (Qpriority, "priority"); 5202 DEFSYM (Qpriority, "priority");
5232 DEFSYM (Qclone_number, "clone-number");
5233 DEFSYM (Qbefore_string, "before-string"); 5203 DEFSYM (Qbefore_string, "before-string");
5234 DEFSYM (Qafter_string, "after-string"); 5204 DEFSYM (Qafter_string, "after-string");
5235 DEFSYM (Qfirst_change_hook, "first-change-hook"); 5205 DEFSYM (Qfirst_change_hook, "first-change-hook");