Simplify and avoid signal-handling races.
[bpt/emacs.git] / src / fringe.c
index 90c0978..d788503 100644 (file)
@@ -1,7 +1,5 @@
 /* Fringe handling (split from xdisp.c).
-   Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997,
-                 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-                 2006, 2007, 2008, 2009, 2010, 2011, 2012  Free Software Foundation, Inc.
+   Copyright (C) 1985-1988, 1993-1995, 1997-2012  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -20,41 +18,24 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <stdio.h>
-#include <setjmp.h>
 
 #include "lisp.h"
 #include "frame.h"
 #include "window.h"
 #include "dispextern.h"
+#include "character.h"
 #include "buffer.h"
 #include "blockinput.h"
 #include "termhooks.h"
 
 #ifdef HAVE_WINDOW_SYSTEM
 
-extern Lisp_Object Qfringe;
-extern Lisp_Object Qtop, Qbottom, Qcenter;
-extern Lisp_Object Qup, Qdown, Qleft, Qright;
-
-/* Non-nil means that newline may flow into the right fringe.  */
-
-Lisp_Object Voverflow_newline_into_fringe;
-
-/* List of known fringe bitmap symbols.
-
-   The fringe bitmap number is stored in the `fringe' property on
-   those symbols.  Names for the built-in bitmaps are installed by
-   loading fringe.el.
- */
-
-Lisp_Object Vfringe_bitmaps;
-
 /* Fringe bitmaps are represented in three different ways:
 
    Logical bitmaps are used internally to denote things like
    'end-of-buffer', 'left-truncation', 'overlay-arrow', etc.
 
-   Physical bitmaps specify the visual appearence of the bitmap,
+   Physical bitmaps specify the visual appearance of the bitmap,
    e.g. 'bottom-left-angle', 'left-arrow', 'left-triangle', etc.
    User defined bitmaps are physical bitmaps.
 
@@ -83,11 +64,9 @@ Lisp_Object Vfringe_bitmaps;
    must specify physical bitmap symbols.
 */
 
-extern Lisp_Object Qunknown;
-Lisp_Object Qtruncation, Qcontinuation, Qoverlay_arrow;
-Lisp_Object Qempty_line, Qtop_bottom;
-extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
-Lisp_Object Qhollow_small;
+static Lisp_Object Qtruncation, Qcontinuation, Qoverlay_arrow;
+static Lisp_Object Qempty_line, Qtop_bottom;
+static Lisp_Object Qhollow_small;
 
 enum fringe_bitmap_align
 {
@@ -127,6 +106,22 @@ struct fringe_bitmap
 static unsigned short question_mark_bits[] = {
   0x3c, 0x7e, 0x7e, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x18};
 
+/* An exclamation mark.  */
+/*
+  ...XX...
+  ...XX...
+  ...XX...
+  ...XX...
+  ...XX...
+  ...XX...
+  ...XX...
+  ........
+  ...XX...
+  ...XX...
+*/
+static unsigned short exclamation_mark_bits[] = {
+  0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18};
+
 /* An arrow like this: `<-'.  */
 /*
   ...xx...
@@ -448,10 +443,11 @@ static unsigned short empty_line_bits[] = {
 /* NOTE:  The order of these bitmaps must match the sequence
    used in fringe.el to define the corresponding symbols.  */
 
-struct fringe_bitmap standard_bitmaps[] =
+static struct fringe_bitmap standard_bitmaps[] =
 {
   { NULL, 0, 0, 0, 0, 0 }, /* NO_FRINGE_BITMAP */
   { FRBITS (question_mark_bits),      8, 0, ALIGN_BITMAP_CENTER, 0 },
+  { FRBITS (exclamation_mark_bits),   8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (left_arrow_bits),         8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (right_arrow_bits),        8, 0, ALIGN_BITMAP_CENTER, 0 },
   { FRBITS (up_arrow_bits),           8, 0, ALIGN_BITMAP_TOP,    0 },
@@ -477,12 +473,15 @@ struct fringe_bitmap standard_bitmaps[] =
 
 #define NO_FRINGE_BITMAP 0
 #define UNDEF_FRINGE_BITMAP 1
-#define MAX_STANDARD_FRINGE_BITMAPS (sizeof(standard_bitmaps)/sizeof(standard_bitmaps[0]))
+#define MAX_STANDARD_FRINGE_BITMAPS (sizeof (standard_bitmaps)/sizeof (standard_bitmaps[0]))
 
 static struct fringe_bitmap **fringe_bitmaps;
 static Lisp_Object *fringe_faces;
 static int max_fringe_bitmaps;
 
+#ifndef HAVE_NS
+static
+#endif
 int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
 
 
@@ -490,10 +489,9 @@ int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
    Return 0 if not a bitmap.  */
 
 int
-lookup_fringe_bitmap (bitmap)
-     Lisp_Object bitmap;
+lookup_fringe_bitmap (Lisp_Object bitmap)
 {
-  int bn;
+  EMACS_INT bn;
 
   bitmap = Fget (bitmap, Qfringe);
   if (!INTEGERP (bitmap))
@@ -517,8 +515,7 @@ lookup_fringe_bitmap (bitmap)
    Return BN if not found in Vfringe_bitmaps.  */
 
 static Lisp_Object
-get_fringe_bitmap_name (bn)
-     int bn;
+get_fringe_bitmap_name (int bn)
 {
   Lisp_Object bitmaps;
   Lisp_Object num;
@@ -564,11 +561,7 @@ get_fringe_bitmap_data (int bn)
 */
 
 static void
-draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
-     struct window *w;
-     struct glyph_row *row;
-     int left_p, overlay;
-     int which;
+draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int overlay, int which)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   struct draw_fringe_bitmap_params p;
@@ -599,11 +592,10 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
 
   if (face_id == DEFAULT_FACE_ID)
     {
-      Lisp_Object face;
-
-      if ((face = fringe_faces[which], NILP (face))
-         || (face_id = lookup_derived_face (f, face, FRINGE_FACE_ID, 0),
-             face_id < 0))
+      Lisp_Object face = fringe_faces[which];
+      face_id = NILP (face) ? lookup_named_face (f, Qfringe, 0)
+       : lookup_derived_face (f, face, FRINGE_FACE_ID, 0);
+      if (face_id < 0)
        face_id = FRINGE_FACE_ID;
     }
 
@@ -666,7 +658,14 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
        {
          /* If W has a vertical border to its left, don't draw over it.  */
          wd -= ((!WINDOW_LEFTMOST_P (w)
-                 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
+                 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
+                 /* But don't reduce the fringe width if the window
+                    has a left margin, because that means we are not
+                    in danger of drawing over the vertical border,
+                    and OTOH leaving out that one pixel leaves behind
+                    traces of the cursor, if it was in column zero
+                    before drawing non-empty margin area.  */
+                 && NILP (w->left_margin_cols))
                 ? 1 : 0);
          p.bx = x - wd;
          p.nx = wd;
@@ -695,13 +694,11 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
 }
 
 static int
-get_logical_cursor_bitmap (w, cursor)
-     struct window *w;
-     Lisp_Object cursor;
+get_logical_cursor_bitmap (struct window *w, Lisp_Object cursor)
 {
   Lisp_Object cmap, bm = Qnil;
 
-  if ((cmap = XBUFFER (w->buffer)->fringe_cursor_alist), !NILP (cmap))
+  if ((cmap = BVAR (XBUFFER (w->buffer), fringe_cursor_alist)), !NILP (cmap))
     {
       bm = Fassq (cursor, cmap);
       if (CONSP (bm))
@@ -711,22 +708,19 @@ get_logical_cursor_bitmap (w, cursor)
          return lookup_fringe_bitmap (bm);
        }
     }
-  if (EQ (cmap, buffer_defaults.fringe_cursor_alist))
+  if (EQ (cmap, BVAR (&buffer_defaults, fringe_cursor_alist)))
     return NO_FRINGE_BITMAP;
-  bm = Fassq (cursor, buffer_defaults.fringe_cursor_alist);
+  bm = Fassq (cursor, BVAR (&buffer_defaults, fringe_cursor_alist));
   if (!CONSP (bm) || ((bm = XCDR (bm)), NILP (bm)))
     return NO_FRINGE_BITMAP;
   return lookup_fringe_bitmap (bm);
 }
 
 static int
-get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
-     struct window *w;
-     Lisp_Object bitmap;
-     int right_p, partial_p;
+get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
 {
   Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
-  int ln1 = 0, ln2 = 0;
+  EMACS_INT ln1 = 0, ln2 = 0;
   int ix1 = right_p;
   int ix2 = ix1 + (partial_p ? 2 : 0);
 
@@ -741,7 +735,7 @@ get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
      If partial, lookup partial bitmap in default value if not found here.
      If not partial, or no partial spec is present, use non-partial bitmap.  */
 
-  if ((cmap = XBUFFER (w->buffer)->fringe_indicator_alist), !NILP (cmap))
+  if ((cmap = BVAR (XBUFFER (w->buffer), fringe_indicator_alist)), !NILP (cmap))
     {
       bm1 = Fassq (bitmap, cmap);
       if (CONSP (bm1))
@@ -775,10 +769,10 @@ get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
        }
     }
 
-  if (!EQ (cmap, buffer_defaults.fringe_indicator_alist)
-      && !NILP (buffer_defaults.fringe_indicator_alist))
+  if (!EQ (cmap, BVAR (&buffer_defaults, fringe_indicator_alist))
+      && !NILP (BVAR (&buffer_defaults, fringe_indicator_alist)))
     {
-      bm2 = Fassq (bitmap, buffer_defaults.fringe_indicator_alist);
+      bm2 = Fassq (bitmap, BVAR (&buffer_defaults, fringe_indicator_alist));
       if (CONSP (bm2))
        {
          if ((bm2 = XCDR (bm2)), !NILP (bm2))
@@ -823,14 +817,11 @@ get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
 
 
 void
-draw_fringe_bitmap (w, row, left_p)
-     struct window *w;
-     struct glyph_row *row;
-     int left_p;
+draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
 {
   int overlay = 0;
 
-  if (!left_p && row->cursor_in_fringe_p)
+  if (left_p == row->reversed_p && row->cursor_in_fringe_p)
     {
       Lisp_Object cursor = Qnil;
 
@@ -862,7 +853,7 @@ draw_fringe_bitmap (w, row, left_p)
          int bm = get_logical_cursor_bitmap (w, cursor);
          if (bm != NO_FRINGE_BITMAP)
            {
-             draw_fringe_bitmap_1 (w, row, 0, 2, bm);
+             draw_fringe_bitmap_1 (w, row, left_p, 2, bm);
              overlay = EQ (cursor, Qbox) ? 3 : 1;
            }
        }
@@ -879,11 +870,9 @@ draw_fringe_bitmap (w, row, left_p)
    function with input blocked.  */
 
 void
-draw_row_fringe_bitmaps (w, row)
-     struct window *w;
-     struct glyph_row *row;
+draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
 {
-  xassert (interrupt_input_blocked);
+  eassert (input_blocked_p ());
 
   /* If row is completely invisible, because of vscrolling, we
      don't have to draw anything.  */
@@ -909,9 +898,7 @@ draw_row_fringe_bitmaps (w, row)
 */
 
 int
-draw_window_fringes (w, no_fringe)
-     struct window *w;
-     int no_fringe;
+draw_window_fringes (struct window *w, int no_fringe)
 {
   struct glyph_row *row;
   int yb = window_text_bottom_y (w);
@@ -949,9 +936,7 @@ draw_window_fringes (w, no_fringe)
    If KEEP_CURRENT_P is 0, update current_matrix too.  */
 
 int
-update_window_fringes (w, keep_current_p)
-     struct window *w;
-     int keep_current_p;
+update_window_fringes (struct window *w, int keep_current_p)
 {
   struct glyph_row *row, *cur = 0;
   int yb = window_text_bottom_y (w);
@@ -966,13 +951,18 @@ update_window_fringes (w, keep_current_p)
   int bitmap_cache[MAX_BITMAP_CACHE];
   int top_ind_rn, bot_ind_rn;
   int top_ind_min_y, bot_ind_max_y;
-  int top_row_ends_at_zv_p, bot_row_ends_at_zv_p;
+
+  /* top_ind_rn is set to a nonnegative value whenever
+     row->indicate_bob_p is set, so it's OK that top_row_ends_at_zv_p
+     is not initialized here.  Similarly for bot_ind_rn,
+     row->indicate_eob_p and bot_row_ends_at_zv_p.  */
+  int top_row_ends_at_zv_p IF_LINT (= 0), bot_row_ends_at_zv_p IF_LINT (= 0);
 
   if (w->pseudo_window_p)
     return 0;
 
   if (!MINI_WINDOW_P (w)
-      && (ind = XBUFFER (w->buffer)->indicate_buffer_boundaries, !NILP (ind)))
+      && (ind = BVAR (XBUFFER (w->buffer), indicate_buffer_boundaries), !NILP (ind)))
     {
       if (EQ (ind, Qleft) || EQ (ind, Qright))
        boundary_top = boundary_bot = arrow_top = arrow_bot = ind;
@@ -1033,7 +1023,7 @@ update_window_fringes (w, keep_current_p)
        }
     }
 
-  empty_pos = XBUFFER (w->buffer)->indicate_empty_lines;
+  empty_pos = BVAR (XBUFFER (w->buffer), indicate_empty_lines);
   if (!NILP (empty_pos) && !EQ (empty_pos, Qright))
     empty_pos = WINDOW_LEFT_FRINGE_WIDTH (w) == 0 ? Qright : Qleft;
 
@@ -1197,8 +1187,9 @@ update_window_fringes (w, keep_current_p)
          left = row->left_user_fringe_bitmap;
          left_face_id = row->left_user_fringe_face_id;
        }
-      else if (row->truncated_on_left_p)
-       left = LEFT_FRINGE(0, Qtruncation, 0);
+      else if ((!row->reversed_p && row->truncated_on_left_p)
+              || (row->reversed_p && row->truncated_on_right_p))
+       left = LEFT_FRINGE (0, Qtruncation, 0);
       else if (row->indicate_bob_p && EQ (boundary_top, Qleft))
        {
          left = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
@@ -1213,7 +1204,8 @@ update_window_fringes (w, keep_current_p)
          if (bot_ind_max_y >= 0)
            left_offset = bot_ind_max_y - (row->y + row->visible_height);
        }
-      else if (MATRIX_ROW_CONTINUATION_LINE_P (row))
+      else if ((!row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row))
+              || (row->reversed_p && row->continued_p))
        left = LEFT_FRINGE (4, Qcontinuation, 0);
       else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
        left = LEFT_FRINGE (5, Qempty_line, 0);
@@ -1240,7 +1232,8 @@ update_window_fringes (w, keep_current_p)
          right = row->right_user_fringe_bitmap;
          right_face_id = row->right_user_fringe_face_id;
        }
-      else if (row->truncated_on_right_p)
+      else if ((!row->reversed_p && row->truncated_on_right_p)
+              || (row->reversed_p && row->truncated_on_left_p))
        right = RIGHT_FRINGE (0, Qtruncation, 0);
       else if (row->indicate_bob_p && EQ (boundary_top, Qright))
        {
@@ -1256,7 +1249,8 @@ update_window_fringes (w, keep_current_p)
          if (bot_ind_max_y >= 0)
            right_offset = bot_ind_max_y - (row->y + row->visible_height);
        }
-      else if (row->continued_p)
+      else if ((!row->reversed_p && row->continued_p)
+              || (row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row)))
        right = RIGHT_FRINGE (4, Qcontinuation, 0);
       else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
        {
@@ -1344,9 +1338,7 @@ update_window_fringes (w, keep_current_p)
 */
 
 void
-compute_fringe_widths (f, redraw)
-     struct frame *f;
-     int redraw;
+compute_fringe_widths (struct frame *f, int redraw)
 {
   int o_left = FRAME_LEFT_FRINGE_WIDTH (f);
   int o_right = FRAME_RIGHT_FRINGE_WIDTH (f);
@@ -1427,9 +1419,8 @@ compute_fringe_widths (f, redraw)
 
 /* Free resources used by a user-defined bitmap.  */
 
-void
-destroy_fringe_bitmap (n)
-     int n;
+static void
+destroy_fringe_bitmap (int n)
 {
   struct fringe_bitmap **fbp;
 
@@ -1456,8 +1447,7 @@ DEFUN ("destroy-fringe-bitmap", Fdestroy_fringe_bitmap, Sdestroy_fringe_bitmap,
        1, 1, 0,
        doc: /* Destroy fringe bitmap BITMAP.
 If BITMAP overrides a standard fringe bitmap, the original bitmap is restored.  */)
-  (bitmap)
-     Lisp_Object bitmap;
+  (Lisp_Object bitmap)
 {
   int n;
 
@@ -1497,11 +1487,8 @@ static const unsigned char swap_nibble[16] = {
   0x3, 0xb, 0x7, 0xf};          /* 0011 1011 0111 1111 */
 #endif                          /* HAVE_X_WINDOWS */
 
-void
-init_fringe_bitmap (which, fb, once_p)
-     int which;
-     struct fringe_bitmap *fb;
-     int once_p;
+static void
+init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p)
 {
   if (once_p || fb->dynamic)
     {
@@ -1531,7 +1518,7 @@ init_fringe_bitmap (which, fb, once_p)
                                   | (swap_nibble[(b>>8) & 0xf] << 4)
                                   | (swap_nibble[(b>>12) & 0xf]));
              b >>= (16 - fb->width);
-#ifdef WORDS_BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
              b = ((b >> 8) | (b << 8));
 #endif
              *bits++ = b;
@@ -1571,8 +1558,7 @@ is used; the default is to center the bitmap.  Fifth arg may also be a
 list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
 should be repeated.
 If BITMAP already exists, the existing definition is replaced.  */)
-  (bitmap, bits, height, width, align)
-     Lisp_Object bitmap, bits, height, width, align;
+  (Lisp_Object bitmap, Lisp_Object bits, Lisp_Object height, Lisp_Object width, Lisp_Object align)
 {
   int n, h, i, j;
   unsigned short *b;
@@ -1584,7 +1570,7 @@ If BITMAP already exists, the existing definition is replaced.  */)
   if (STRINGP (bits))
     h = SCHARS (bits);
   else if (VECTORP (bits))
-    h = XVECTOR_SIZE (bits);
+    h = ASIZE (bits);
   else
     wrong_type_argument (Qsequencep, bits);
 
@@ -1593,7 +1579,7 @@ If BITMAP already exists, the existing definition is replaced.  */)
   else
     {
       CHECK_NUMBER (height);
-      fb.height = min (XINT (height), 255);
+      fb.height = max (0, min (XINT (height), 255));
       if (fb.height > h)
        {
          fill1 = (fb.height - h) / 2;
@@ -1606,7 +1592,7 @@ If BITMAP already exists, the existing definition is replaced.  */)
   else
     {
       CHECK_NUMBER (width);
-      fb.width = min (XINT (width), 255);
+      fb.width = max (0, min (XINT (width), 255));
     }
 
   fb.period = 0;
@@ -1648,22 +1634,23 @@ If BITMAP already exists, the existing definition is replaced.  */)
 
          if (n == max_fringe_bitmaps)
            {
-             if ((max_fringe_bitmaps + 20) > MAX_FRINGE_BITMAPS)
+             int bitmaps = max_fringe_bitmaps + 20;
+             if (MAX_FRINGE_BITMAPS < bitmaps)
                error ("No free fringe bitmap slots");
 
              i = max_fringe_bitmaps;
-             max_fringe_bitmaps += 20;
-             fringe_bitmaps
-               = ((struct fringe_bitmap **)
-                  xrealloc (fringe_bitmaps, max_fringe_bitmaps * sizeof (struct fringe_bitmap *)));
-             fringe_faces
-               = (Lisp_Object *) xrealloc (fringe_faces, max_fringe_bitmaps * sizeof (Lisp_Object));
-
-             for (; i < max_fringe_bitmaps; i++)
+             fringe_bitmaps = xrealloc (fringe_bitmaps,
+                                        bitmaps * sizeof *fringe_bitmaps);
+             fringe_faces = xrealloc (fringe_faces,
+                                      bitmaps * sizeof *fringe_faces);
+
+             for (i = max_fringe_bitmaps; i < bitmaps; i++)
                {
                  fringe_bitmaps[i] = NULL;
                  fringe_faces[i] = Qnil;
                }
+
+             max_fringe_bitmaps = bitmaps;
            }
        }
 
@@ -1673,10 +1660,9 @@ If BITMAP already exists, the existing definition is replaced.  */)
 
   fb.dynamic = 1;
 
-  xfb = (struct fringe_bitmap *) xmalloc (sizeof fb
-                                         + fb.height * BYTES_PER_BITMAP_ROW);
+  xfb = xmalloc (sizeof fb + fb.height * BYTES_PER_BITMAP_ROW);
   fb.bits = b = (unsigned short *) (xfb + 1);
-  bzero (b, fb.height);
+  memset (b, 0, fb.height);
 
   j = 0;
   while (j < fb.height)
@@ -1703,27 +1689,30 @@ DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face, Sset_fringe_bitmap_fac
        1, 2, 0,
        doc: /* Set face for fringe bitmap BITMAP to FACE.
 If FACE is nil, reset face to default fringe face.  */)
-  (bitmap, face)
-     Lisp_Object bitmap, face;
+  (Lisp_Object bitmap, Lisp_Object face)
 {
   int n;
-  int face_id;
 
   CHECK_SYMBOL (bitmap);
   n = lookup_fringe_bitmap (bitmap);
   if (!n)
     error ("Undefined fringe bitmap");
 
+  /* The purpose of the following code is to signal an error if FACE
+     is not a face.  This is for the caller's convenience only; the
+     redisplay code should be able to fail gracefully.  Skip the check
+     if FRINGE_FACE_ID is unrealized (as in batch mode and during
+     daemon startup).  */
   if (!NILP (face))
     {
-      face_id = lookup_derived_face (SELECTED_FRAME (), face,
-                                    FRINGE_FACE_ID, 1);
-      if (face_id < 0)
+      struct frame *f = SELECTED_FRAME ();
+
+      if (FACE_FROM_ID (f, FRINGE_FACE_ID)
+         && lookup_derived_face (f, face, FRINGE_FACE_ID, 1) < 0)
        error ("No such face");
     }
 
   fringe_faces[n] = face;
-
   return Qnil;
 }
 
@@ -1736,12 +1725,11 @@ is the symbol for the bitmap in the left fringe (or nil if no bitmap),
 RIGHT is similar for the right fringe, and OV is non-nil if there is an
 overlay arrow in the left fringe.
 Return nil if POS is not visible in WINDOW.  */)
-  (pos, window)
-     Lisp_Object pos, window;
+  (Lisp_Object pos, Lisp_Object window)
 {
   struct window *w;
   struct glyph_row *row;
-  int textpos;
+  ptrdiff_t textpos;
 
   if (NILP (window))
     window = selected_window;
@@ -1751,6 +1739,8 @@ Return nil if POS is not visible in WINDOW.  */)
   if (!NILP (pos))
     {
       CHECK_NUMBER_COERCE_MARKER (pos);
+      if (! (BEGV <= XINT (pos) && XINT (pos) <= ZV))
+       args_out_of_range (window, pos);
       textpos = XINT (pos);
     }
   else if (w == XWINDOW (selected_window))
@@ -1776,28 +1766,22 @@ Return nil if POS is not visible in WINDOW.  */)
  ***********************************************************************/
 
 void
-syms_of_fringe ()
+syms_of_fringe (void)
 {
-  Qtruncation = intern_c_string ("truncation");
-  staticpro (&Qtruncation);
-  Qcontinuation = intern_c_string ("continuation");
-  staticpro (&Qcontinuation);
-  Qoverlay_arrow = intern_c_string ("overlay-arrow");
-  staticpro (&Qoverlay_arrow);
-  Qempty_line = intern_c_string ("empty-line");
-  staticpro (&Qempty_line);
-  Qtop_bottom = intern_c_string ("top-bottom");
-  staticpro (&Qtop_bottom);
-  Qhollow_small = intern_c_string ("hollow-small");
-  staticpro (&Qhollow_small);
+  DEFSYM (Qtruncation, "truncation");
+  DEFSYM (Qcontinuation, "continuation");
+  DEFSYM (Qoverlay_arrow, "overlay-arrow");
+  DEFSYM (Qempty_line, "empty-line");
+  DEFSYM (Qtop_bottom, "top-bottom");
+  DEFSYM (Qhollow_small, "hollow-small");
 
   defsubr (&Sdestroy_fringe_bitmap);
   defsubr (&Sdefine_fringe_bitmap);
   defsubr (&Sfringe_bitmaps_at_pos);
   defsubr (&Sset_fringe_bitmap_face);
 
-  DEFVAR_LISP ("overflow-newline-into-fringe", &Voverflow_newline_into_fringe,
-    doc: /* *Non-nil means that newline may flow into the right fringe.
+  DEFVAR_LISP ("overflow-newline-into-fringe", Voverflow_newline_into_fringe,
+    doc: /* Non-nil means that newline may flow into the right fringe.
 This means that display lines which are exactly as wide as the window
 (not counting the final newline) will only occupy one screen line, by
 showing (or hiding) the final newline in the right fringe; when point
@@ -1805,7 +1789,7 @@ is at the final newline, the cursor is shown in the right fringe.
 If nil, also continue lines which are exactly as wide as the window.  */);
   Voverflow_newline_into_fringe = Qt;
 
-  DEFVAR_LISP ("fringe-bitmaps", &Vfringe_bitmaps,
+  DEFVAR_LISP ("fringe-bitmaps", Vfringe_bitmaps,
     doc: /* List of fringe bitmap symbols.  */);
   Vfringe_bitmaps = Qnil;
 }
@@ -1813,7 +1797,7 @@ If nil, also continue lines which are exactly as wide as the window.  */);
 /* Garbage collection hook */
 
 void
-mark_fringe_data ()
+mark_fringe_data (void)
 {
   int i;
 
@@ -1825,31 +1809,26 @@ mark_fringe_data ()
 /* Initialize this module when Emacs starts.  */
 
 void
-init_fringe_once ()
+init_fringe_once (void)
 {
   int bt;
 
   for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
-    init_fringe_bitmap(bt, &standard_bitmaps[bt], 1);
+    init_fringe_bitmap (bt, &standard_bitmaps[bt], 1);
 }
 
 void
-init_fringe ()
+init_fringe (void)
 {
   int i;
 
   max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20;
 
-  fringe_bitmaps
-    = (struct fringe_bitmap **) xmalloc (max_fringe_bitmaps * sizeof (struct fringe_bitmap *));
-  fringe_faces
-    = (Lisp_Object *) xmalloc (max_fringe_bitmaps * sizeof (Lisp_Object));
+  fringe_bitmaps = xzalloc (max_fringe_bitmaps * sizeof *fringe_bitmaps);
+  fringe_faces = xmalloc (max_fringe_bitmaps * sizeof *fringe_faces);
 
   for (i = 0; i < max_fringe_bitmaps; i++)
-    {
-      fringe_bitmaps[i] = NULL;
-      fringe_faces[i] = Qnil;
-    }
+    fringe_faces[i] = Qnil;
 }
 
 #ifdef HAVE_NTGUI
@@ -1870,7 +1849,7 @@ w32_init_fringe (struct redisplay_interface *rif)
 }
 
 void
-w32_reset_fringes ()
+w32_reset_fringes (void)
 {
   /* Destroy row bitmaps.  */
   int bt;
@@ -1886,6 +1865,3 @@ w32_reset_fringes ()
 #endif /* HAVE_NTGUI */
 
 #endif /* HAVE_WINDOW_SYSTEM */
-
-/* arch-tag: 04596920-43eb-473d-b319-82712338162d
-   (do not change this comment) */