* alloc.c, bytecode.c, ccl.c, coding.c, composite.c, data.c, dosfns.c:
[bpt/emacs.git] / src / window.c
index 397d84a..9420d73 100644 (file)
@@ -23,6 +23,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <setjmp.h>
 
 #include "lisp.h"
+#include "character.h"
 #include "buffer.h"
 #include "keyboard.h"
 #include "keymap.h"
@@ -63,7 +64,7 @@ static int displayed_window_lines (struct window *);
 static struct window *decode_window (Lisp_Object);
 static int count_windows (struct window *);
 static int get_leaf_windows (struct window *, struct window **, int);
-static void window_scroll (Lisp_Object, int, int, int);
+static void window_scroll (Lisp_Object, EMACS_INT, int, int);
 static void window_scroll_pixel_based (Lisp_Object, int, int, int);
 static void window_scroll_line_based (Lisp_Object, int, int, int);
 static int freeze_window_start (struct window *, void *);
@@ -122,16 +123,13 @@ static int window_initialized;
 /* Hook to run when window config changes.  */
 static Lisp_Object Qwindow_configuration_change_hook;
 
-/* If non-nil, run_window_configuration_change_hook does nothing.  */
-Lisp_Object inhibit_window_configuration_change_hook;
-
 /* Used by the function window_scroll_pixel_based */
 static int window_scroll_pixel_based_preserve_x;
 static int window_scroll_pixel_based_preserve_y;
 
 /* Same for window_scroll_line_based.  */
-static int window_scroll_preserve_hpos;
-static int window_scroll_preserve_vpos;
+static EMACS_INT window_scroll_preserve_hpos;
+static EMACS_INT window_scroll_preserve_vpos;
 \f
 static struct window *
 decode_window (register Lisp_Object window)
@@ -381,7 +379,7 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
      redisplay_window has altered point after scrolling,
      because it makes the change only in the window.  */
   {
-    register EMACS_INT new_point = marker_position (w->pointm);
+    register ptrdiff_t new_point = marker_position (w->pointm);
     if (new_point < BEGV)
       SET_PT (BEGV);
     else if (new_point > ZV)
@@ -683,10 +681,10 @@ window so that the location of point moves off-window.  */)
   (Lisp_Object window, Lisp_Object ncol)
 {
   struct window *w = decode_window (window);
-  int hscroll;
+  ptrdiff_t hscroll;
 
   CHECK_NUMBER (ncol);
-  hscroll = max (0, XINT (ncol));
+  hscroll = clip_to_bounds (0, XINT (ncol), PTRDIFF_MAX);
 
   /* Prevent redisplay shortcuts when changing the hscroll.  */
   if (XINT (w->hscroll) != hscroll)
@@ -1396,10 +1394,10 @@ overriding motion of point in order to display at this exact start.  */)
   CHECK_NUMBER_COERCE_MARKER (pos);
   set_marker_restricted (w->start, pos, w->buffer);
   /* this is not right, but much easier than doing what is right. */
-  w->start_at_line_beg = Qnil;
+  w->start_at_line_beg = 0;
   if (NILP (noforce))
-    w->force_start = Qt;
-  w->update_mode_line = Qt;
+    w->force_start = 1;
+  w->update_mode_line = 1;
   XSETFASTINT (w->last_modified, 0);
   XSETFASTINT (w->last_overlay_modified, 0);
   if (!EQ (window, selected_window))
@@ -1498,7 +1496,8 @@ Return nil if window display is not up-to-date.  In that case, use
   register struct window *w;
   register struct buffer *b;
   struct glyph_row *row, *end_row;
-  int max_y, crop, i, n;
+  int max_y, crop, i;
+  EMACS_INT n;
 
   w = decode_window (window);
 
@@ -2474,7 +2473,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
            if (EQ (w->buffer, obj))
              {
                mark_window_display_accurate (window, 0);
-               w->update_mode_line = Qt;
+               w->update_mode_line = 1;
                XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
                ++update_mode_lines;
                best_window = window;
@@ -2566,7 +2565,7 @@ window-start value is reasonable when this function is called.  */)
   struct window *w, *r, *s;
   struct frame *f;
   Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
-  EMACS_INT startpos IF_LINT (= 0);
+  ptrdiff_t startpos IF_LINT (= 0);
   int top IF_LINT (= 0), new_top, resize_failed;
 
   w = decode_any_window (window);
@@ -2648,6 +2647,24 @@ window-start value is reasonable when this function is called.  */)
     }
 
   BLOCK_INPUT;
+  if (!FRAME_INITIAL_P (f))
+    {
+        Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
+
+      /* We are going to free the glyph matrices of WINDOW, and with
+        that we might lose any information about glyph rows that have
+        some of their glyphs highlighted in mouse face.  (These rows
+        are marked with a non-zero mouse_face_p flag.)  If WINDOW
+        indeed has some glyphs highlighted in mouse face, signal to
+        frame's up-to-date hook that mouse highlight was overwritten,
+        so that it will arrange for redisplaying the highlight.  */
+      if (EQ (hlinfo->mouse_face_window, window))
+       {
+         hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
+         hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
+         hlinfo->mouse_face_window = Qnil;
+       }
+    }
   free_window_matrices (r);
 
   windows_or_buffers_changed++;
@@ -2758,12 +2775,11 @@ window-start value is reasonable when this function is called.  */)
 
          set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
          w->window_end_valid = Qnil;
-         w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
-                                  || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
-                                 : Qnil);
+         w->start_at_line_beg = (pos.bytepos == BEGV_BYTE
+                                   || FETCH_BYTE (pos.bytepos - 1) == '\n');
          /* We need to do this, so that the window-scroll-functions
             get called.  */
-         w->optional_new_start = Qt;
+         w->optional_new_start = 1;
 
          set_buffer_internal (obuf);
        }
@@ -2892,12 +2908,12 @@ select_frame_norecord (Lisp_Object frame)
 void
 run_window_configuration_change_hook (struct frame *f)
 {
-  int count = SPECPDL_INDEX ();
+  ptrdiff_t count = SPECPDL_INDEX ();
   Lisp_Object frame, global_wcch
     = Fdefault_value (Qwindow_configuration_change_hook);
   XSETFRAME (frame, f);
 
-  if (NILP (Vrun_hooks) || !NILP (inhibit_window_configuration_change_hook))
+  if (NILP (Vrun_hooks) || !NILP (inhibit_lisp_code))
     return;
 
   /* Use the right buffer.  Matters when running the local hooks.  */
@@ -2923,7 +2939,7 @@ run_window_configuration_change_hook (struct frame *f)
        if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
                                      buffer)))
          {
-           int inner_count = SPECPDL_INDEX ();
+           ptrdiff_t inner_count = SPECPDL_INDEX ();
            record_unwind_protect (select_window_norecord, Fselected_window ());
            select_window_norecord (window);
            run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
@@ -2958,7 +2974,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
 {
   struct window *w = XWINDOW (window);
   struct buffer *b = XBUFFER (buffer);
-  int count = SPECPDL_INDEX ();
+  ptrdiff_t count = SPECPDL_INDEX ();
   int samebuf = EQ (buffer, w->buffer);
 
   w->buffer = buffer;
@@ -2993,8 +3009,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
       set_marker_restricted (w->start,
                             make_number (b->last_window_start),
                             buffer);
-      w->start_at_line_beg = Qnil;
-      w->force_start = Qnil;
+      w->start_at_line_beg = 0;
+      w->force_start = 0;
       XSETFASTINT (w->last_modified, 0);
       XSETFASTINT (w->last_overlay_modified, 0);
     }
@@ -3130,7 +3146,7 @@ displaying that buffer.  */)
     {
       struct window *w = XWINDOW (object);
       mark_window_display_accurate (object, 0);
-      w->update_mode_line = Qt;
+      w->update_mode_line = 1;
       if (BUFFERP (w->buffer))
        XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
       ++update_mode_lines;
@@ -3189,7 +3205,7 @@ temp_output_buffer_show (register Lisp_Object buf)
       /* Run temp-buffer-show-hook, with the chosen window selected
         and its buffer current.  */
       {
-        int count = SPECPDL_INDEX ();
+        ptrdiff_t count = SPECPDL_INDEX ();
         Lisp_Object prev_window, prev_buffer;
         prev_window = selected_window;
         XSETBUFFER (prev_buffer, old);
@@ -3262,7 +3278,8 @@ make_window (void)
 
   w = allocate_window ();
   /* Initialize all Lisp data.  */
-  w->frame = w->mini_p = Qnil;
+  w->frame = Qnil;
+  w->mini = 0;
   w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil;
   XSETFASTINT (w->left_col, 0);
   XSETFASTINT (w->top_line, 0);
@@ -3275,7 +3292,7 @@ make_window (void)
   w->buffer = Qnil;
   w->start = Fmake_marker ();
   w->pointm = Fmake_marker ();
-  w->force_start = w->optional_new_start = Qnil;
+  w->force_start = w->optional_new_start = 0;
   XSETFASTINT (w->hscroll, 0);
   XSETFASTINT (w->min_hscroll, 0);
   XSETFASTINT (w->use_time, 0);
@@ -3283,17 +3300,18 @@ make_window (void)
   XSETFASTINT (w->sequence_number, sequence_number);
   w->temslot = w->last_modified = w->last_overlay_modified = Qnil;
   XSETFASTINT (w->last_point, 0);
-  w->last_had_star = w->vertical_scroll_bar = Qnil;
+  w->last_had_star = 0;
+  w->vertical_scroll_bar = Qnil;
   w->left_margin_cols = w->right_margin_cols = Qnil;
   w->left_fringe_width = w->right_fringe_width = Qnil;
   w->fringes_outside_margins = Qnil;
   w->scroll_bar_width = Qnil;
   w->vertical_scroll_bar_type = Qt;
-  w->last_mark_x = w->last_mark_y = Qnil;
   XSETFASTINT (w->window_end_pos, 0);
   XSETFASTINT (w->window_end_vpos, 0);
-  w->window_end_valid = w->update_mode_line = Qnil;
-  w->start_at_line_beg = w->display_table = w->dedicated = Qnil;
+  w->window_end_valid = w->display_table = Qnil;
+  w->update_mode_line = w->start_at_line_beg = 0;
+  w->dedicated = Qnil;
   w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
   w->column_number_displayed = w->redisplay_end_trigger = Qnil;
   w->combination_limit = w->window_parameters = Qnil;
@@ -3889,7 +3907,6 @@ Signal an error when WINDOW is the only window on its frame.  */)
       && EQ (r->new_total, (horflag ? r->total_cols : r->total_lines)))
     /* We can delete WINDOW now.  */
     {
-      Mouse_HLInfo *hlinfo;
 
       /* Block input.  */
       BLOCK_INPUT;
@@ -3897,9 +3914,13 @@ Signal an error when WINDOW is the only window on its frame.  */)
 
       /* If this window is referred to by the dpyinfo's mouse
         highlight, invalidate that slot to be safe (Bug#9904).  */
-      hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
-      if (EQ (hlinfo->mouse_face_window, window))
-       hlinfo->mouse_face_window = Qnil;
+      if (!FRAME_INITIAL_P (f))
+       {
+         Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
+
+         if (EQ (hlinfo->mouse_face_window, window))
+           hlinfo->mouse_face_window = Qnil;
+       }
 
       windows_or_buffers_changed++;
       Vwindow_list = Qnil;
@@ -4177,9 +4198,10 @@ window_internal_height (struct window *w)
    respectively.  */
 
 static void
-window_scroll (Lisp_Object window, int n, int whole, int noerror)
+window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
 {
   immediate_quit = 1;
+  n = clip_to_bounds (INT_MIN, n, INT_MAX);
 
   /* If we must, use the pixel-based version which is much slower than
      the line-based one but can handle varying line heights.  */
@@ -4209,6 +4231,11 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
   void *itdata = NULL;
 
   SET_TEXT_POS_FROM_MARKER (start, w->start);
+  /* Scrolling a minibuffer window via scroll bar when the echo area
+     shows long text sometimes resets the minibuffer contents behind
+     our backs.  */
+  if (CHARPOS (start) > ZV)
+    SET_TEXT_POS (start, BEGV, BEGV_BYTE);
 
   /* If PT is not visible in WINDOW, move back one half of
      the screen.  Allow PT to be partially visible, otherwise
@@ -4275,7 +4302,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
              /* Maybe modify window start instead of scrolling.  */
              if (rbot > 0 || w->vscroll < 0)
                {
-                 EMACS_INT spos;
+                 ptrdiff_t spos;
 
                  Fset_window_vscroll (window, make_number (0), Qt);
                  /* If there are other text lines above the current row,
@@ -4286,13 +4313,13 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
                    spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
                  set_marker_restricted (w->start, make_number (spos),
                                         w->buffer);
-                 w->start_at_line_beg = Qt;
-                 w->update_mode_line = Qt;
+                 w->start_at_line_beg = 1;
+                 w->update_mode_line = 1;
                  XSETFASTINT (w->last_modified, 0);
                  XSETFASTINT (w->last_overlay_modified, 0);
                  /* Set force_start so that redisplay_window will run the
                     window-scroll-functions.  */
-                 w->force_start = Qt;
+                 w->force_start = 1;
                  return;
                }
            }
@@ -4330,7 +4357,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
   start_display (&it, w, start);
   if (whole)
     {
-      EMACS_INT start_pos = IT_CHARPOS (it);
+      ptrdiff_t start_pos = IT_CHARPOS (it);
       int dy = WINDOW_FRAME_LINE_HEIGHT (w);
       dy = max ((window_box_height (w)
                 - next_screen_context_lines * dy),
@@ -4417,8 +4444,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
 
   if (! vscrolled)
     {
-      EMACS_INT pos = IT_CHARPOS (it);
-      EMACS_INT bytepos;
+      ptrdiff_t pos = IT_CHARPOS (it);
+      ptrdiff_t bytepos;
 
       /* If in the middle of a multi-glyph character move forward to
         the next character.  */
@@ -4432,14 +4459,13 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
       set_marker_restricted (w->start, make_number (pos),
                             w->buffer);
       bytepos = XMARKER (w->start)->bytepos;
-      w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
-                             ? Qt : Qnil);
-      w->update_mode_line = Qt;
+      w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
+      w->update_mode_line = 1;
       XSETFASTINT (w->last_modified, 0);
       XSETFASTINT (w->last_overlay_modified, 0);
       /* Set force_start so that redisplay_window will run the
         window-scroll-functions.  */
-      w->force_start = Qt;
+      w->force_start = 1;
     }
 
   /* The rest of this function uses current_y in a nonstandard way,
@@ -4488,7 +4514,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
     }
   else if (n < 0)
     {
-      EMACS_INT charpos, bytepos;
+      ptrdiff_t charpos, bytepos;
       int partial_p;
 
       /* Save our position, for the
@@ -4565,12 +4591,12 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
      in `grep-mode-font-lock-keywords').  So we use a marker to record
      the old point position, to prevent crashes in SET_PT_BOTH.  */
   Lisp_Object opoint_marker = Fpoint_marker ();
-  register EMACS_INT pos, pos_byte;
+  register ptrdiff_t pos, pos_byte;
   register int ht = window_internal_height (w);
   register Lisp_Object tem;
   int lose;
   Lisp_Object bolp;
-  EMACS_INT startpos;
+  ptrdiff_t startpos;
   Lisp_Object original_pos = Qnil;
 
   /* If scrolling screen-fulls, compute the number of lines to
@@ -4632,13 +4658,13 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
        max (0, min (scroll_margin, XINT (w->total_lines) / 4));
 
       set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
-      w->start_at_line_beg = bolp;
-      w->update_mode_line = Qt;
+      w->start_at_line_beg = !NILP (bolp);
+      w->update_mode_line = 1;
       XSETFASTINT (w->last_modified, 0);
       XSETFASTINT (w->last_overlay_modified, 0);
       /* Set force_start so that redisplay_window will run
         the window-scroll-functions.  */
-      w->force_start = Qt;
+      w->force_start = 1;
 
       if (!NILP (Vscroll_preserve_screen_position)
          && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
@@ -4719,7 +4745,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
 static void
 scroll_command (Lisp_Object n, int direction)
 {
-  int count = SPECPDL_INDEX ();
+  ptrdiff_t count = SPECPDL_INDEX ();
 
   xassert (eabs (direction) == 1);
 
@@ -4834,7 +4860,7 @@ specifies the window to scroll.  This takes precedence over
 {
   Lisp_Object window;
   struct window *w;
-  int count = SPECPDL_INDEX ();
+  ptrdiff_t count = SPECPDL_INDEX ();
 
   window = Fother_window_for_scrolling ();
   w = XWINDOW (window);
@@ -4876,7 +4902,7 @@ by this function.  This happens in an interactive call.  */)
   (register Lisp_Object arg, Lisp_Object set_minimum)
 {
   Lisp_Object result;
-  int hscroll;
+  EMACS_INT hscroll;
   struct window *w = XWINDOW (selected_window);
 
   if (NILP (arg))
@@ -4905,7 +4931,7 @@ by this function.  This happens in an interactive call.  */)
   (register Lisp_Object arg, Lisp_Object set_minimum)
 {
   Lisp_Object result;
-  int hscroll;
+  EMACS_INT hscroll;
   struct window *w = XWINDOW (selected_window);
 
   if (NILP (arg))
@@ -5016,7 +5042,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
   struct buffer *buf = XBUFFER (w->buffer);
   struct buffer *obuf = current_buffer;
   int center_p = 0;
-  EMACS_INT charpos, bytepos;
+  ptrdiff_t charpos, bytepos;
   EMACS_INT iarg IF_LINT (= 0);
   int this_scroll_margin;
 
@@ -5081,7 +5107,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
        {
          struct it it;
          struct text_pos pt;
-         int nlines = min (INT_MAX, -iarg);
+         ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg);
          int extra_line_spacing;
          int h = window_box_height (w);
          void *itdata = bidi_shelve_cache ();
@@ -5182,12 +5208,10 @@ and redisplay normally--don't erase and redraw the frame.  */)
   set_marker_both (w->start, w->buffer, charpos, bytepos);
   w->window_end_valid = Qnil;
 
-  w->optional_new_start = Qt;
+  w->optional_new_start = 1;
 
-  if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
-    w->start_at_line_beg = Qt;
-  else
-    w->start_at_line_beg = Qnil;
+  w->start_at_line_beg = (bytepos == BEGV_BYTE ||
+                         FETCH_BYTE (bytepos - 1) == '\n');
 
   set_buffer_internal (obuf);
   return Qnil;
@@ -5238,8 +5262,8 @@ zero means top of window, negative means relative to bottom of window.  */)
       int height = window_internal_height (w);
       Fvertical_motion (make_number (- (height / 2)), window);
       set_marker_both (w->start, w->buffer, PT, PT_BYTE);
-      w->start_at_line_beg = Fbolp ();
-      w->force_start = Qt;
+      w->start_at_line_beg = !NILP (Fbolp ());
+      w->force_start = 1;
     }
   else
     Fgoto_char (w->start);
@@ -5365,7 +5389,7 @@ the return value is nil.  Otherwise the value is t.  */)
   Lisp_Object frame;
   Lisp_Object auto_buffer_name;
   FRAME_PTR f;
-  EMACS_INT old_point = -1;
+  ptrdiff_t old_point = -1;
 
   CHECK_WINDOW_CONFIGURATION (configuration);
 
@@ -5588,7 +5612,7 @@ the return value is nil.  Otherwise the value is t.  */)
            /* If saved buffer is alive, install it.  */
            {
              w->buffer = p->buffer;
-             w->start_at_line_beg = p->start_at_line_beg;
+             w->start_at_line_beg = !NILP (p->start_at_line_beg);
              set_marker_restricted (w->start, p->start, w->buffer);
              set_marker_restricted (w->pointm, p->pointm, w->buffer);
              Fset_marker (BVAR (XBUFFER (w->buffer), mark),
@@ -5613,7 +5637,7 @@ the return value is nil.  Otherwise the value is t.  */)
                set_marker_restricted_both (w->pointm, w->buffer,
                                            BUF_PT (XBUFFER (w->buffer)),
                                            BUF_PT_BYTE (XBUFFER (w->buffer)));
-             w->start_at_line_beg = Qt;
+             w->start_at_line_beg = 1;
            }
          else if (STRINGP (auto_buffer_name =
                            Fwindow_parameter (window, Qauto_buffer_name))
@@ -5622,7 +5646,7 @@ the return value is nil.  Otherwise the value is t.  */)
            {
              set_marker_restricted (w->start, make_number (0), w->buffer);
              set_marker_restricted (w->pointm, make_number (0), w->buffer);
-             w->start_at_line_beg = Qt;
+             w->start_at_line_beg = 1;
            }
          else
            /* Window has no live buffer, get one.  */
@@ -5636,7 +5660,7 @@ the return value is nil.  Otherwise the value is t.  */)
                 range.  */
              set_marker_restricted (w->start, make_number (0), w->buffer);
              set_marker_restricted (w->pointm, make_number (0), w->buffer);
-             w->start_at_line_beg = Qt;
+             w->start_at_line_beg = 1;
              if (!NILP (w->dedicated))
                /* Record this window as dead.  */
                dead_windows = Fcons (window, dead_windows);
@@ -5933,9 +5957,11 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
            }
          else
            p->pointm = Fcopy_marker (w->pointm, Qnil);
+         XMARKER (p->pointm)->insertion_type
+           = !NILP (Vwindow_point_insertion_type);
 
          p->start = Fcopy_marker (w->start, Qnil);
-         p->start_at_line_beg = w->start_at_line_beg;
+         p->start_at_line_beg = w->start_at_line_beg ? Qt : Qnil;
 
          tem = BVAR (XBUFFER (w->buffer), mark);
          p->mark = Fcopy_marker (tem, Qnil);
@@ -6010,8 +6036,8 @@ saved by this function.  */)
   tem = Fmake_vector (make_number (n_windows), Qnil);
   data->saved_windows = tem;
   for (i = 0; i < n_windows; i++)
-    XVECTOR (tem)->contents[i]
-      = Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil);
+    ASET (tem, i,
+         Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil));
   save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
   XSETWINDOW_CONFIGURATION (tem, data);
   return (tem);
@@ -6168,7 +6194,7 @@ Fourth parameter HORIZONTAL-TYPE is currently unused.  */)
 
   if (!NILP (width))
     {
-      CHECK_NATNUM (width);
+      CHECK_RANGED_INTEGER (0, width, INT_MAX);
 
       if (XINT (width) == 0)
        vertical_type = Qnil;