aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorEli Zaretskii2011-07-05 20:06:29 +0300
committerEli Zaretskii2011-07-05 20:06:29 +0300
commit57b3e30bb29d904180b651422ab58341debe84cb (patch)
treecb6561a3ef8100dc64654beb65c70623798839aa /src/window.c
parented94e6d7bf6751592ff3dadb2b87f03ffaab3bfa (diff)
downloademacs-57b3e30bb29d904180b651422ab58341debe84cb.tar.gz
emacs-57b3e30bb29d904180b651422ab58341debe84cb.zip
Empty the bidi cache "stack" when it->sp is zeroed.
Solves crashes due to overflow of bidi cache stack. Make sure cache is saved and restored around all temporary iterations. src/dispnew.c (buffer_posn_from_coords): Save and restore the bidi cache around display iteration. src/window.c (Fwindow_end, window_scroll_pixel_based) (displayed_window_lines, Frecenter): Save and restore the bidi cache around display iteration. src/bidi.c (bidi_unshelve_cache): Ensure we have enough space before restoring the shelved cache. (bidi_cache_ensure_space): Don't assume the required size is just one BIDI_CACHE_CHUNK away. src/xdisp.c (back_to_previous_visible_line_start, reseat_1) (init_iterator): Empty the bidi cache "stack".
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/window.c b/src/window.c
index 4dbee41c5f4..094cfcfbda3 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1162,6 +1162,7 @@ if it isn't already recorded. */)
1162 struct text_pos startp; 1162 struct text_pos startp;
1163 struct it it; 1163 struct it it;
1164 struct buffer *old_buffer = NULL; 1164 struct buffer *old_buffer = NULL;
1165 void *itdata = NULL;
1165 1166
1166 /* Cannot use Fvertical_motion because that function doesn't 1167 /* Cannot use Fvertical_motion because that function doesn't
1167 cope with variable-height lines. */ 1168 cope with variable-height lines. */
@@ -1183,11 +1184,13 @@ if it isn't already recorded. */)
1183 else 1184 else
1184 SET_TEXT_POS_FROM_MARKER (startp, w->start); 1185 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1185 1186
1187 itdata = bidi_shelve_cache ();
1186 start_display (&it, w, startp); 1188 start_display (&it, w, startp);
1187 move_it_vertically (&it, window_box_height (w)); 1189 move_it_vertically (&it, window_box_height (w));
1188 if (it.current_y < it.last_visible_y) 1190 if (it.current_y < it.last_visible_y)
1189 move_it_past_eol (&it); 1191 move_it_past_eol (&it);
1190 value = make_number (IT_CHARPOS (it)); 1192 value = make_number (IT_CHARPOS (it));
1193 bidi_unshelve_cache (itdata);
1191 1194
1192 if (old_buffer) 1195 if (old_buffer)
1193 set_buffer_internal (old_buffer); 1196 set_buffer_internal (old_buffer);
@@ -4736,6 +4739,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4736 /* True if we fiddled the window vscroll field without really scrolling. */ 4739 /* True if we fiddled the window vscroll field without really scrolling. */
4737 int vscrolled = 0; 4740 int vscrolled = 0;
4738 int x, y, rtop, rbot, rowh, vpos; 4741 int x, y, rtop, rbot, rowh, vpos;
4742 void *itdata = NULL;
4739 4743
4740 SET_TEXT_POS_FROM_MARKER (start, w->start); 4744 SET_TEXT_POS_FROM_MARKER (start, w->start);
4741 4745
@@ -4746,6 +4750,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4746 4750
4747 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos)) 4751 if (!pos_visible_p (w, PT, &x, &y, &rtop, &rbot, &rowh, &vpos))
4748 { 4752 {
4753 itdata = bidi_shelve_cache ();
4749 /* Move backward half the height of the window. Performance note: 4754 /* Move backward half the height of the window. Performance note:
4750 vmotion used here is about 10% faster, but would give wrong 4755 vmotion used here is about 10% faster, but would give wrong
4751 results for variable height lines. */ 4756 results for variable height lines. */
@@ -4766,6 +4771,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4766 } 4771 }
4767 4772
4768 start = it.current.pos; 4773 start = it.current.pos;
4774 bidi_unshelve_cache (itdata);
4769 } 4775 }
4770 else if (auto_window_vscroll_p) 4776 else if (auto_window_vscroll_p)
4771 { 4777 {
@@ -4828,6 +4834,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4828 Fset_window_vscroll (window, make_number (0), Qt); 4834 Fset_window_vscroll (window, make_number (0), Qt);
4829 } 4835 }
4830 4836
4837 itdata = bidi_shelve_cache ();
4831 /* If scroll_preserve_screen_position is non-nil, we try to set 4838 /* If scroll_preserve_screen_position is non-nil, we try to set
4832 point in the same window line as it is now, so get that line. */ 4839 point in the same window line as it is now, so get that line. */
4833 if (!NILP (Vscroll_preserve_screen_position)) 4840 if (!NILP (Vscroll_preserve_screen_position))
@@ -4906,12 +4913,16 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4906 - it.current_y + it.max_ascent + it.max_descent); 4913 - it.current_y + it.max_ascent + it.max_descent);
4907 adjust_glyphs (it.f); 4914 adjust_glyphs (it.f);
4908 } 4915 }
4909 else if (noerror)
4910 return;
4911 else if (n < 0) /* could happen with empty buffers */
4912 xsignal0 (Qbeginning_of_buffer);
4913 else 4916 else
4914 xsignal0 (Qend_of_buffer); 4917 {
4918 bidi_unshelve_cache (itdata);
4919 if (noerror)
4920 return;
4921 else if (n < 0) /* could happen with empty buffers */
4922 xsignal0 (Qbeginning_of_buffer);
4923 else
4924 xsignal0 (Qend_of_buffer);
4925 }
4915 } 4926 }
4916 else 4927 else
4917 { 4928 {
@@ -4919,10 +4930,14 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4919 /* The first line was only partially visible, make it fully 4930 /* The first line was only partially visible, make it fully
4920 visible. */ 4931 visible. */
4921 w->vscroll = 0; 4932 w->vscroll = 0;
4922 else if (noerror)
4923 return;
4924 else 4933 else
4925 xsignal0 (Qbeginning_of_buffer); 4934 {
4935 bidi_unshelve_cache (itdata);
4936 if (noerror)
4937 return;
4938 else
4939 xsignal0 (Qbeginning_of_buffer);
4940 }
4926 } 4941 }
4927 4942
4928 /* If control gets here, then we vscrolled. */ 4943 /* If control gets here, then we vscrolled. */
@@ -5066,6 +5081,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
5066 SET_PT_BOTH (charpos, bytepos); 5081 SET_PT_BOTH (charpos, bytepos);
5067 } 5082 }
5068 } 5083 }
5084 bidi_unshelve_cache (itdata);
5069} 5085}
5070 5086
5071 5087
@@ -5468,6 +5484,7 @@ displayed_window_lines (struct window *w)
5468 int height = window_box_height (w); 5484 int height = window_box_height (w);
5469 struct buffer *old_buffer; 5485 struct buffer *old_buffer;
5470 int bottom_y; 5486 int bottom_y;
5487 void *itdata = NULL;
5471 5488
5472 if (XBUFFER (w->buffer) != current_buffer) 5489 if (XBUFFER (w->buffer) != current_buffer)
5473 { 5490 {
@@ -5487,9 +5504,11 @@ displayed_window_lines (struct window *w)
5487 else 5504 else
5488 SET_TEXT_POS_FROM_MARKER (start, w->start); 5505 SET_TEXT_POS_FROM_MARKER (start, w->start);
5489 5506
5507 itdata = bidi_shelve_cache ();
5490 start_display (&it, w, start); 5508 start_display (&it, w, start);
5491 move_it_vertically (&it, height); 5509 move_it_vertically (&it, height);
5492 bottom_y = line_bottom_y (&it); 5510 bottom_y = line_bottom_y (&it);
5511 bidi_unshelve_cache (itdata);
5493 5512
5494 /* rms: On a non-window display, 5513 /* rms: On a non-window display,
5495 the value of it.vpos at the bottom of the screen 5514 the value of it.vpos at the bottom of the screen
@@ -5588,12 +5607,14 @@ and redisplay normally--don't erase and redraw the frame. */)
5588 { 5607 {
5589 struct it it; 5608 struct it it;
5590 struct text_pos pt; 5609 struct text_pos pt;
5610 void *itdata = bidi_shelve_cache ();
5591 5611
5592 SET_TEXT_POS (pt, PT, PT_BYTE); 5612 SET_TEXT_POS (pt, PT, PT_BYTE);
5593 start_display (&it, w, pt); 5613 start_display (&it, w, pt);
5594 move_it_vertically_backward (&it, window_box_height (w) / 2); 5614 move_it_vertically_backward (&it, window_box_height (w) / 2);
5595 charpos = IT_CHARPOS (it); 5615 charpos = IT_CHARPOS (it);
5596 bytepos = IT_BYTEPOS (it); 5616 bytepos = IT_BYTEPOS (it);
5617 bidi_unshelve_cache (itdata);
5597 } 5618 }
5598 else if (iarg < 0) 5619 else if (iarg < 0)
5599 { 5620 {
@@ -5602,6 +5623,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5602 int nlines = -iarg; 5623 int nlines = -iarg;
5603 int extra_line_spacing; 5624 int extra_line_spacing;
5604 int h = window_box_height (w); 5625 int h = window_box_height (w);
5626 void *itdata = bidi_shelve_cache ();
5605 5627
5606 iarg = - max (-iarg, this_scroll_margin); 5628 iarg = - max (-iarg, this_scroll_margin);
5607 5629
@@ -5639,7 +5661,10 @@ and redisplay normally--don't erase and redraw the frame. */)
5639 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing); 5661 h -= nlines * (FRAME_LINE_HEIGHT (it.f) + extra_line_spacing);
5640 } 5662 }
5641 if (h <= 0) 5663 if (h <= 0)
5642 return Qnil; 5664 {
5665 bidi_unshelve_cache (itdata);
5666 return Qnil;
5667 }
5643 5668
5644 /* Now find the new top line (starting position) of the window. */ 5669 /* Now find the new top line (starting position) of the window. */
5645 start_display (&it, w, pt); 5670 start_display (&it, w, pt);
@@ -5659,6 +5684,8 @@ and redisplay normally--don't erase and redraw the frame. */)
5659 5684
5660 charpos = IT_CHARPOS (it); 5685 charpos = IT_CHARPOS (it);
5661 bytepos = IT_BYTEPOS (it); 5686 bytepos = IT_BYTEPOS (it);
5687
5688 bidi_unshelve_cache (itdata);
5662 } 5689 }
5663 else 5690 else
5664 { 5691 {