aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-19 07:55:59 +0400
committerDmitry Antipov2012-07-19 07:55:59 +0400
commitd17337e501a189c1d46f758e10c6c2842cafff17 (patch)
tree152a6d615152a9fc12d40e131ebb1886d8972593 /src
parent1d29cc7da73dde538c97d029723b8a5a1be6cea1 (diff)
downloademacs-d17337e501a189c1d46f758e10c6c2842cafff17.tar.gz
emacs-d17337e501a189c1d46f758e10c6c2842cafff17.zip
New macro to iterate over all buffers, miscellaneous cleanups.
* lisp.h (all_buffers): Remove declaration. * buffer.h (all_buffers): Add declaration, with comment. (for_each_buffer): New macro. * alloc.c (Fgarbage_collect, mark_object): Use it. * buffer.c (Fkill_buffer, Fbuffer_swap_text, Fset_buffer_multibyte) (init_buffer): Likewise. * data.c (Fset_default): Likewise. * coding.c (code_conversion_restore): Remove redundant check for dead buffer. * buffer.c (Fkill_buffer): Likewise. Remove obsolete comment.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog15
-rw-r--r--src/alloc.c146
-rw-r--r--src/buffer.c12
-rw-r--r--src/buffer.h9
-rw-r--r--src/coding.c2
-rw-r--r--src/data.c2
-rw-r--r--src/lisp.h1
7 files changed, 98 insertions, 89 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5a7a981926b..73632c26bff 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,17 @@
12012-07-19 Dmitry Antipov <dmantipov@yandex.ru>
2
3 New macro to iterate over all buffers, miscellaneous cleanups.
4 * lisp.h (all_buffers): Remove declaration.
5 * buffer.h (all_buffers): Add declaration, with comment.
6 (for_each_buffer): New macro.
7 * alloc.c (Fgarbage_collect, mark_object): Use it.
8 * buffer.c (Fkill_buffer, Fbuffer_swap_text, Fset_buffer_multibyte)
9 (init_buffer): Likewise.
10 * data.c (Fset_default): Likewise.
11 * coding.c (code_conversion_restore): Remove redundant check
12 for dead buffer.
13 * buffer.c (Fkill_buffer): Likewise. Remove obsolete comment.
14
12012-07-18 Andreas Schwab <schwab@linux-m68k.org> 152012-07-18 Andreas Schwab <schwab@linux-m68k.org>
2 16
3 Fix bug that created negative-length intervals. 17 Fix bug that created negative-length intervals.
@@ -110,7 +124,6 @@
110 * gnutls.c (emacs_gnutls_handshake): Only retry if 124 * gnutls.c (emacs_gnutls_handshake): Only retry if
111 GNUTLS_E_INTERRUPTED. 125 GNUTLS_E_INTERRUPTED.
112 126
1132012-07-17 Eli Zaretskii <eliz@gnu.org>
1142012-07-17 Dmitry Antipov <dmantipov@yandex.ru> 1272012-07-17 Dmitry Antipov <dmantipov@yandex.ru>
115 128
116 Cleanup and convert miscellaneous checks to eassert. 129 Cleanup and convert miscellaneous checks to eassert.
diff --git a/src/alloc.c b/src/alloc.c
index a6980e867a7..166f5b72449 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5392,6 +5392,7 @@ See Info node `(elisp)Garbage Collection'. */)
5392 (void) 5392 (void)
5393{ 5393{
5394 register struct specbinding *bind; 5394 register struct specbinding *bind;
5395 register struct buffer *nextb;
5395 char stack_top_variable; 5396 char stack_top_variable;
5396 ptrdiff_t i; 5397 ptrdiff_t i;
5397 int message_p; 5398 int message_p;
@@ -5411,40 +5412,34 @@ See Info node `(elisp)Garbage Collection'. */)
5411 5412
5412 /* Don't keep undo information around forever. 5413 /* Don't keep undo information around forever.
5413 Do this early on, so it is no problem if the user quits. */ 5414 Do this early on, so it is no problem if the user quits. */
5414 { 5415 for_each_buffer (nextb)
5415 register struct buffer *nextb = all_buffers; 5416 {
5416 5417 /* If a buffer's undo list is Qt, that means that undo is
5417 while (nextb) 5418 turned off in that buffer. Calling truncate_undo_list on
5418 { 5419 Qt tends to return NULL, which effectively turns undo back on.
5419 /* If a buffer's undo list is Qt, that means that undo is 5420 So don't call truncate_undo_list if undo_list is Qt. */
5420 turned off in that buffer. Calling truncate_undo_list on 5421 if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name))
5421 Qt tends to return NULL, which effectively turns undo back on. 5422 && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt))
5422 So don't call truncate_undo_list if undo_list is Qt. */ 5423 truncate_undo_list (nextb);
5423 if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name)) 5424
5424 && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) 5425 /* Shrink buffer gaps, but skip indirect and dead buffers. */
5425 truncate_undo_list (nextb); 5426 if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD (name))
5426 5427 && ! nextb->text->inhibit_shrinking)
5427 /* Shrink buffer gaps, but skip indirect and dead buffers. */ 5428 {
5428 if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD (name)) 5429 /* If a buffer's gap size is more than 10% of the buffer
5429 && ! nextb->text->inhibit_shrinking) 5430 size, or larger than 2000 bytes, then shrink it
5430 { 5431 accordingly. Keep a minimum size of 20 bytes. */
5431 /* If a buffer's gap size is more than 10% of the buffer 5432 int size = min (2000, max (20, (nextb->text->z_byte / 10)));
5432 size, or larger than 2000 bytes, then shrink it
5433 accordingly. Keep a minimum size of 20 bytes. */
5434 int size = min (2000, max (20, (nextb->text->z_byte / 10)));
5435
5436 if (nextb->text->gap_size > size)
5437 {
5438 struct buffer *save_current = current_buffer;
5439 current_buffer = nextb;
5440 make_gap (-(nextb->text->gap_size - size));
5441 current_buffer = save_current;
5442 }
5443 }
5444 5433
5445 nextb = nextb->header.next.buffer; 5434 if (nextb->text->gap_size > size)
5446 } 5435 {
5447 } 5436 struct buffer *save_current = current_buffer;
5437 current_buffer = nextb;
5438 make_gap (-(nextb->text->gap_size - size));
5439 current_buffer = save_current;
5440 }
5441 }
5442 }
5448 5443
5449 t1 = current_emacs_time (); 5444 t1 = current_emacs_time ();
5450 5445
@@ -5558,48 +5553,42 @@ See Info node `(elisp)Garbage Collection'. */)
5558 Look thru every buffer's undo list 5553 Look thru every buffer's undo list
5559 for elements that update markers that were not marked, 5554 for elements that update markers that were not marked,
5560 and delete them. */ 5555 and delete them. */
5561 { 5556 for_each_buffer (nextb)
5562 register struct buffer *nextb = all_buffers; 5557 {
5563 5558 /* If a buffer's undo list is Qt, that means that undo is
5564 while (nextb) 5559 turned off in that buffer. Calling truncate_undo_list on
5565 { 5560 Qt tends to return NULL, which effectively turns undo back on.
5566 /* If a buffer's undo list is Qt, that means that undo is 5561 So don't call truncate_undo_list if undo_list is Qt. */
5567 turned off in that buffer. Calling truncate_undo_list on 5562 if (! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt))
5568 Qt tends to return NULL, which effectively turns undo back on. 5563 {
5569 So don't call truncate_undo_list if undo_list is Qt. */ 5564 Lisp_Object tail, prev;
5570 if (! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) 5565 tail = nextb->BUFFER_INTERNAL_FIELD (undo_list);
5571 { 5566 prev = Qnil;
5572 Lisp_Object tail, prev; 5567 while (CONSP (tail))
5573 tail = nextb->BUFFER_INTERNAL_FIELD (undo_list); 5568 {
5574 prev = Qnil; 5569 if (CONSP (XCAR (tail))
5575 while (CONSP (tail)) 5570 && MARKERP (XCAR (XCAR (tail)))
5576 { 5571 && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit)
5577 if (CONSP (XCAR (tail)) 5572 {
5578 && MARKERP (XCAR (XCAR (tail))) 5573 if (NILP (prev))
5579 && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit) 5574 nextb->BUFFER_INTERNAL_FIELD (undo_list) = tail = XCDR (tail);
5580 { 5575 else
5581 if (NILP (prev)) 5576 {
5582 nextb->BUFFER_INTERNAL_FIELD (undo_list) = tail = XCDR (tail); 5577 tail = XCDR (tail);
5583 else 5578 XSETCDR (prev, tail);
5584 { 5579 }
5585 tail = XCDR (tail); 5580 }
5586 XSETCDR (prev, tail); 5581 else
5587 } 5582 {
5588 } 5583 prev = tail;
5589 else 5584 tail = XCDR (tail);
5590 { 5585 }
5591 prev = tail; 5586 }
5592 tail = XCDR (tail); 5587 }
5593 } 5588 /* Now that we have stripped the elements that need not be in the
5594 } 5589 undo_list any more, we can finally mark the list. */
5595 } 5590 mark_object (nextb->BUFFER_INTERNAL_FIELD (undo_list));
5596 /* Now that we have stripped the elements that need not be in the 5591 }
5597 undo_list any more, we can finally mark the list. */
5598 mark_object (nextb->BUFFER_INTERNAL_FIELD (undo_list));
5599
5600 nextb = nextb->header.next.buffer;
5601 }
5602 }
5603 5592
5604 gc_sweep (); 5593 gc_sweep ();
5605 5594
@@ -5987,9 +5976,10 @@ mark_object (Lisp_Object arg)
5987#ifdef GC_CHECK_MARKED_OBJECTS 5976#ifdef GC_CHECK_MARKED_OBJECTS
5988 if (po != &buffer_defaults && po != &buffer_local_symbols) 5977 if (po != &buffer_defaults && po != &buffer_local_symbols)
5989 { 5978 {
5990 struct buffer *b = all_buffers; 5979 struct buffer *b;
5991 for (; b && b != po; b = b->header.next.buffer) 5980 for_each_buffer (b)
5992 ; 5981 if (b == po)
5982 break;
5993 if (b == NULL) 5983 if (b == NULL)
5994 abort (); 5984 abort ();
5995 } 5985 }
diff --git a/src/buffer.c b/src/buffer.c
index 1e1bd933f93..40370460b9f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1532,10 +1532,8 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1532 1532
1533 GCPRO1 (buffer); 1533 GCPRO1 (buffer);
1534 1534
1535 for (other = all_buffers; other; other = other->header.next.buffer) 1535 for_each_buffer (other)
1536 /* all_buffers contains dead buffers too; 1536 if (other->base_buffer == b)
1537 don't re-kill them. */
1538 if (other->base_buffer == b && !NILP (BVAR (other, name)))
1539 { 1537 {
1540 Lisp_Object buf; 1538 Lisp_Object buf;
1541 XSETBUFFER (buf, other); 1539 XSETBUFFER (buf, other);
@@ -2052,7 +2050,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2052 2050
2053 { /* This is probably harder to make work. */ 2051 { /* This is probably harder to make work. */
2054 struct buffer *other; 2052 struct buffer *other;
2055 for (other = all_buffers; other; other = other->header.next.buffer) 2053 for_each_buffer (other)
2056 if (other->base_buffer == other_buffer 2054 if (other->base_buffer == other_buffer
2057 || other->base_buffer == current_buffer) 2055 || other->base_buffer == current_buffer)
2058 error ("One of the buffers to swap has indirect buffers"); 2056 error ("One of the buffers to swap has indirect buffers");
@@ -2429,7 +2427,7 @@ current buffer is cleared. */)
2429 2427
2430 /* Copy this buffer's new multibyte status 2428 /* Copy this buffer's new multibyte status
2431 into all of its indirect buffers. */ 2429 into all of its indirect buffers. */
2432 for (other = all_buffers; other; other = other->header.next.buffer) 2430 for_each_buffer (other)
2433 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name))) 2431 if (other->base_buffer == current_buffer && !NILP (BVAR (other, name)))
2434 { 2432 {
2435 BVAR (other, enable_multibyte_characters) 2433 BVAR (other, enable_multibyte_characters)
@@ -5035,7 +5033,7 @@ init_buffer (void)
5035 Map new memory. */ 5033 Map new memory. */
5036 struct buffer *b; 5034 struct buffer *b;
5037 5035
5038 for (b = all_buffers; b; b = b->header.next.buffer) 5036 for_each_buffer (b)
5039 if (b->text->beg == NULL) 5037 if (b->text->beg == NULL)
5040 enlarge_buffer_text (b, 0); 5038 enlarge_buffer_text (b, 0);
5041 } 5039 }
diff --git a/src/buffer.h b/src/buffer.h
index 4003be5c8c4..8c596835fcc 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -857,6 +857,15 @@ struct buffer
857}; 857};
858 858
859 859
860/* Chain of all buffers, including killed ones. */
861
862extern struct buffer *all_buffers;
863
864/* Used to iterate over the chain above. */
865
866#define for_each_buffer(b) \
867 for ((b) = all_buffers; (b); (b) = (b)->header.next.buffer)
868
860/* This points to the current buffer. */ 869/* This points to the current buffer. */
861 870
862extern struct buffer *current_buffer; 871extern struct buffer *current_buffer;
diff --git a/src/coding.c b/src/coding.c
index d9fcc634b77..212eb8275fe 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7588,7 +7588,7 @@ code_conversion_restore (Lisp_Object arg)
7588 { 7588 {
7589 if (EQ (workbuf, Vcode_conversion_reused_workbuf)) 7589 if (EQ (workbuf, Vcode_conversion_reused_workbuf))
7590 reused_workbuf_in_use = 0; 7590 reused_workbuf_in_use = 0;
7591 else if (! NILP (Fbuffer_live_p (workbuf))) 7591 else
7592 Fkill_buffer (workbuf); 7592 Fkill_buffer (workbuf);
7593 } 7593 }
7594 set_buffer_internal (XBUFFER (current)); 7594 set_buffer_internal (XBUFFER (current));
diff --git a/src/data.c b/src/data.c
index 22546349677..84bd347b136 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1401,7 +1401,7 @@ for this variable. */)
1401 { 1401 {
1402 struct buffer *b; 1402 struct buffer *b;
1403 1403
1404 for (b = all_buffers; b; b = b->header.next.buffer) 1404 for_each_buffer (b)
1405 if (!PER_BUFFER_VALUE_P (b, idx)) 1405 if (!PER_BUFFER_VALUE_P (b, idx))
1406 PER_BUFFER_VALUE (b, offset) = value; 1406 PER_BUFFER_VALUE (b, offset) = value;
1407 } 1407 }
diff --git a/src/lisp.h b/src/lisp.h
index 4dd9f37ca66..bfdc4ea4c07 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2858,7 +2858,6 @@ extern Lisp_Object set_buffer_if_live (Lisp_Object);
2858extern Lisp_Object other_buffer_safely (Lisp_Object); 2858extern Lisp_Object other_buffer_safely (Lisp_Object);
2859extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string; 2859extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
2860extern Lisp_Object get_truename_buffer (Lisp_Object); 2860extern Lisp_Object get_truename_buffer (Lisp_Object);
2861extern struct buffer *all_buffers;
2862extern void init_buffer_once (void); 2861extern void init_buffer_once (void);
2863extern void init_buffer (void); 2862extern void init_buffer (void);
2864extern void syms_of_buffer (void); 2863extern void syms_of_buffer (void);