aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c68
1 files changed, 52 insertions, 16 deletions
diff --git a/src/buffer.c b/src/buffer.c
index cc0899676de..a12c80ec0b0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -44,6 +44,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
44#include "keymap.h" 44#include "keymap.h"
45#include "frame.h" 45#include "frame.h"
46#include "xwidget.h" 46#include "xwidget.h"
47#include "pdumper.h"
47 48
48#ifdef WINDOWSNT 49#ifdef WINDOWSNT
49#include "w32heap.h" /* for mmap_* */ 50#include "w32heap.h" /* for mmap_* */
@@ -529,6 +530,8 @@ even if it is dead. The return value is never nil. */)
529 /* No one shows us now. */ 530 /* No one shows us now. */
530 b->window_count = 0; 531 b->window_count = 0;
531 532
533 memset (&b->local_flags, 0, sizeof (b->local_flags));
534
532 BUF_GAP_SIZE (b) = 20; 535 BUF_GAP_SIZE (b) = 20;
533 block_input (); 536 block_input ();
534 /* We allocate extra 1-byte at the tail and keep it always '\0' for 537 /* We allocate extra 1-byte at the tail and keep it always '\0' for
@@ -781,6 +784,8 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
781 /* Always -1 for an indirect buffer. */ 784 /* Always -1 for an indirect buffer. */
782 b->window_count = -1; 785 b->window_count = -1;
783 786
787 memset (&b->local_flags, 0, sizeof (b->local_flags));
788
784 b->pt = b->base_buffer->pt; 789 b->pt = b->base_buffer->pt;
785 b->begv = b->base_buffer->begv; 790 b->begv = b->base_buffer->begv;
786 b->zv = b->base_buffer->zv; 791 b->zv = b->base_buffer->zv;
@@ -5001,24 +5006,37 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5001void 5006void
5002enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) 5007enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5003{ 5008{
5004 void *p;
5005 ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1
5006 + delta);
5007 block_input (); 5009 block_input ();
5010 void *p;
5011 unsigned char *old_beg = b->text->beg;
5012 ptrdiff_t old_nbytes =
5013 BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1;
5014 ptrdiff_t new_nbytes = old_nbytes + delta;
5015
5016 if (pdumper_object_p (old_beg))
5017 b->text->beg = NULL;
5018 else
5019 old_beg = NULL;
5020
5008#if defined USE_MMAP_FOR_BUFFERS 5021#if defined USE_MMAP_FOR_BUFFERS
5009 p = mmap_realloc ((void **) &b->text->beg, nbytes); 5022 p = mmap_realloc ((void **) &b->text->beg, new_nbytes);
5010#elif defined REL_ALLOC 5023#elif defined REL_ALLOC
5011 p = r_re_alloc ((void **) &b->text->beg, nbytes); 5024 p = r_re_alloc ((void **) &b->text->beg, new_nbytes);
5012#else 5025#else
5013 p = xrealloc (b->text->beg, nbytes); 5026 p = xrealloc (b->text->beg, new_nbytes);
5014#endif 5027#endif
5015 5028
5016 if (p == NULL) 5029 if (p == NULL)
5017 { 5030 {
5031 if (old_beg)
5032 b->text->beg = old_beg;
5018 unblock_input (); 5033 unblock_input ();
5019 memory_full (nbytes); 5034 memory_full (new_nbytes);
5020 } 5035 }
5021 5036
5037 if (old_beg)
5038 memcpy (p, old_beg, min (old_nbytes, new_nbytes));
5039
5022 BUF_BEG_ADDR (b) = p; 5040 BUF_BEG_ADDR (b) = p;
5023 unblock_input (); 5041 unblock_input ();
5024} 5042}
@@ -5031,13 +5049,16 @@ free_buffer_text (struct buffer *b)
5031{ 5049{
5032 block_input (); 5050 block_input ();
5033 5051
5052 if (!pdumper_object_p (b->text->beg))
5053 {
5034#if defined USE_MMAP_FOR_BUFFERS 5054#if defined USE_MMAP_FOR_BUFFERS
5035 mmap_free ((void **) &b->text->beg); 5055 mmap_free ((void **) &b->text->beg);
5036#elif defined REL_ALLOC 5056#elif defined REL_ALLOC
5037 r_alloc_free ((void **) &b->text->beg); 5057 r_alloc_free ((void **) &b->text->beg);
5038#else 5058#else
5039 xfree (b->text->beg); 5059 xfree (b->text->beg);
5040#endif 5060#endif
5061 }
5041 5062
5042 BUF_BEG_ADDR (b) = NULL; 5063 BUF_BEG_ADDR (b) = NULL;
5043 unblock_input (); 5064 unblock_input ();
@@ -5048,14 +5069,25 @@ free_buffer_text (struct buffer *b)
5048/*********************************************************************** 5069/***********************************************************************
5049 Initialization 5070 Initialization
5050 ***********************************************************************/ 5071 ***********************************************************************/
5051
5052void 5072void
5053init_buffer_once (void) 5073init_buffer_once (void)
5054{ 5074{
5075 /* TODO: clean up the buffer-local machinery. Right now,
5076 we have:
5077
5078 buffer_defaults: default values of buffer-locals
5079 buffer_local_flags: metadata
5080 buffer_permanent_local_flags: metadata
5081 buffer_local_symbols: metadata
5082
5083 There must be a simpler way to store the metadata.
5084 */
5085
5055 int idx; 5086 int idx;
5056 5087
5057 /* Items flagged permanent get an explicit permanent-local property 5088 /* Items flagged permanent get an explicit permanent-local property
5058 added in bindings.el, for clarity. */ 5089 added in bindings.el, for clarity. */
5090 PDUMPER_REMEMBER_SCALAR (buffer_permanent_local_flags);
5059 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags); 5091 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags);
5060 5092
5061 /* 0 means not a lisp var, -1 means always local, else mask. */ 5093 /* 0 means not a lisp var, -1 means always local, else mask. */
@@ -5144,10 +5176,15 @@ init_buffer_once (void)
5144 XSETFASTINT (BVAR (&buffer_local_flags, extra_line_spacing), idx); ++idx; 5176 XSETFASTINT (BVAR (&buffer_local_flags, extra_line_spacing), idx); ++idx;
5145 XSETFASTINT (BVAR (&buffer_local_flags, cursor_in_non_selected_windows), idx); ++idx; 5177 XSETFASTINT (BVAR (&buffer_local_flags, cursor_in_non_selected_windows), idx); ++idx;
5146 5178
5179 /* buffer_local_flags contains no pointers, so it's safe to treat it
5180 as a blob for pdumper. */
5181 PDUMPER_REMEMBER_SCALAR (buffer_local_flags);
5182
5147 /* Need more room? */ 5183 /* Need more room? */
5148 if (idx >= MAX_PER_BUFFER_VARS) 5184 if (idx >= MAX_PER_BUFFER_VARS)
5149 emacs_abort (); 5185 emacs_abort ();
5150 last_per_buffer_idx = idx; 5186 last_per_buffer_idx = idx;
5187 PDUMPER_REMEMBER_SCALAR (last_per_buffer_idx);
5151 5188
5152 /* Make sure all markable slots in buffer_defaults 5189 /* Make sure all markable slots in buffer_defaults
5153 are initialized reasonably, so mark_buffer won't choke. */ 5190 are initialized reasonably, so mark_buffer won't choke. */
@@ -5242,7 +5279,9 @@ init_buffer_once (void)
5242 5279
5243 Vbuffer_alist = Qnil; 5280 Vbuffer_alist = Qnil;
5244 current_buffer = 0; 5281 current_buffer = 0;
5282 pdumper_remember_lv_ptr_raw (&current_buffer, Lisp_Vectorlike);
5245 all_buffers = 0; 5283 all_buffers = 0;
5284 pdumper_remember_lv_ptr_raw (&all_buffers, Lisp_Vectorlike);
5246 5285
5247 QSFundamental = build_pure_c_string ("Fundamental"); 5286 QSFundamental = build_pure_c_string ("Fundamental");
5248 5287
@@ -5266,12 +5305,12 @@ init_buffer_once (void)
5266} 5305}
5267 5306
5268void 5307void
5269init_buffer (int initialized) 5308init_buffer (void)
5270{ 5309{
5271 Lisp_Object temp; 5310 Lisp_Object temp;
5272 5311
5273#ifdef USE_MMAP_FOR_BUFFERS 5312#ifdef USE_MMAP_FOR_BUFFERS
5274 if (initialized) 5313 if (dumped_with_unexec_p ())
5275 { 5314 {
5276 struct buffer *b; 5315 struct buffer *b;
5277 5316
@@ -5312,9 +5351,6 @@ init_buffer (int initialized)
5312 eassert (b->text->beg != NULL); 5351 eassert (b->text->beg != NULL);
5313 } 5352 }
5314 } 5353 }
5315#else /* not USE_MMAP_FOR_BUFFERS */
5316 /* Avoid compiler warnings. */
5317 (void) initialized;
5318#endif /* USE_MMAP_FOR_BUFFERS */ 5354#endif /* USE_MMAP_FOR_BUFFERS */
5319 5355
5320 AUTO_STRING (scratch, "*scratch*"); 5356 AUTO_STRING (scratch, "*scratch*");