From 8801a864d2f7d9b6a77dfffa606f27f338127582 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 30 Mar 2000 09:56:31 +0000 Subject: [PATCH] * lisp.h (XCONS, XSTRING, XSYMBOL, XFLOAT, XPROCESS, XWINDOW, XSUBR, XBUFFER): Verify correct object type before returning pointer, using eassert. * frame.h (XFRAME): Likewise. * buffer.c (Frename_buffer, Fset_buffer_multibyte, swap_out_buffer_local_variables, Fmove_overlay): Don't apply XSYMBOL, XBUFFER, etc, to values that may be nil or of the wrong type. * data.c (set_internal): Likewise. * dispextern.h (WINDOW_WANTS_MODELINE_P, WINDOW_WANTS_HEADER_LINE_P): Likewise. * fileio.c (auto_save_1): Likewise. * insdel.c (check_markers): Likewise. * marker.c (buf_charpos_to_bytepos, unchain_marker): Likewise. * undo.c (record_insert): Likewise. * vmsproc.c (child_sig): Likewise. * window.c (unshow_buffer, window_loop): Likewise. * xterm.c (x_erase_phys_cursor): Likewise. --- src/ChangeLog | 22 ++++++++++++++++++++++ src/buffer.c | 20 ++++++++++---------- src/data.c | 3 ++- src/dispextern.h | 2 ++ src/fileio.c | 3 ++- src/frame.h | 2 +- src/insdel.c | 2 +- src/lisp.h | 16 ++++++++-------- src/marker.c | 6 +++--- src/undo.c | 3 ++- src/vmsproc.c | 4 ++-- src/window.c | 9 ++++++--- src/xterm.c | 3 ++- 13 files changed, 63 insertions(+), 32 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ed70016653..1d09e191d7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ +2000-03-30 Ken Raeburn + + * lisp.h (XCONS, XSTRING, XSYMBOL, XFLOAT, XPROCESS, XWINDOW, + XSUBR, XBUFFER): Verify correct object type before returning + pointer, using eassert. + * frame.h (XFRAME): Likewise. + + * buffer.c (Frename_buffer, Fset_buffer_multibyte, + swap_out_buffer_local_variables, Fmove_overlay): Don't apply + XSYMBOL, XBUFFER, etc, to values that may be nil or of the wrong + type. + * data.c (set_internal): Likewise. + * dispextern.h (WINDOW_WANTS_MODELINE_P, + WINDOW_WANTS_HEADER_LINE_P): Likewise. + * fileio.c (auto_save_1): Likewise. + * insdel.c (check_markers): Likewise. + * marker.c (buf_charpos_to_bytepos, unchain_marker): Likewise. + * undo.c (record_insert): Likewise. + * vmsproc.c (child_sig): Likewise. + * window.c (unshow_buffer, window_loop): Likewise. + * xterm.c (x_erase_phys_cursor): Likewise. + 2000-03-30 Gerd Moellmann * xfns.c (free_image_cache): Free the cache structure itself diff --git a/src/buffer.c b/src/buffer.c index d54555d324..848e999077 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -887,14 +887,14 @@ This does not change the name of the visited file (if any).") error ("Empty string is invalid as a buffer name"); tem = Fget_buffer (newname); - /* Don't short-circuit if UNIQUE is t. That is a useful way to rename - the buffer automatically so you can create another with the original name. - It makes UNIQUE equivalent to - (rename-buffer (generate-new-buffer-name NEWNAME)). */ - if (NILP (unique) && XBUFFER (tem) == current_buffer) - return current_buffer->name; if (!NILP (tem)) { + /* Don't short-circuit if UNIQUE is t. That is a useful way to + rename the buffer automatically so you can create another + with the original name. It makes UNIQUE equivalent to + (rename-buffer (generate-new-buffer-name NEWNAME)). */ + if (NILP (unique) && XBUFFER (tem) == current_buffer) + return current_buffer->name; if (!NILP (unique)) newname = Fgenerate_new_buffer_name (newname, current_buffer->name); else @@ -1815,7 +1815,7 @@ but the contents viewed as characters do change.") TEMP_SET_PT_BOTH (PT_BYTE, PT_BYTE); tail = BUF_MARKERS (current_buffer); - while (XSYMBOL (tail) != XSYMBOL (Qnil)) + while (! NILP (tail)) { XMARKER (tail)->charpos = XMARKER (tail)->bytepos; tail = XMARKER (tail)->chain; @@ -1880,7 +1880,7 @@ but the contents viewed as characters do change.") It is also a signal that it should never create a marker. */ BUF_MARKERS (current_buffer) = Qnil; - while (XSYMBOL (tail) != XSYMBOL (Qnil)) + while (! NILP (tail)) { XMARKER (tail)->bytepos = advance_to_char_boundary (XMARKER (tail)->bytepos); @@ -1996,7 +1996,7 @@ swap_out_buffer_local_variables (b) /* Need not do anything if some other buffer's binding is now encached. */ tem = XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->buffer; - if (XBUFFER (tem) == current_buffer) + if (BUFFERP (tem) && XBUFFER (tem) == current_buffer) { /* Symbol is set up for this buffer's old local value. Set it up for the current buffer with the default value. */ @@ -3166,7 +3166,7 @@ buffer.") obuffer = Fmarker_buffer (OVERLAY_START (overlay)); b = XBUFFER (buffer); - ob = XBUFFER (obuffer); + ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; /* If the overlay has changed buffers, do a thorough redisplay. */ if (!EQ (buffer, obuffer)) diff --git a/src/data.c b/src/data.c index f736f7f6c8..c267c5540f 100644 --- a/src/data.c +++ b/src/data.c @@ -1012,7 +1012,8 @@ set_internal (symbol, newval, buf, bindflag) isn't the right one, or if it's a Lisp_Buffer_Local_Value and the default binding is loaded, the loaded binding may be the wrong one. */ - if (buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer) + if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents)->buffer) + || buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer) || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame && !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)) || (BUFFER_LOCAL_VALUEP (valcontents) diff --git a/src/dispextern.h b/src/dispextern.h index 76578b8fde..2665cf38d3 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -1066,6 +1066,7 @@ extern struct glyph_row scratch_glyph_row; (!MINI_WINDOW_P (W) \ && !(W)->pseudo_window_p \ && FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (W))) \ + && BUFFERP ((W)->buffer) \ && !NILP (XBUFFER ((W)->buffer)->mode_line_format)) /* Value is non-zero if window W wants a top line. */ @@ -1074,6 +1075,7 @@ extern struct glyph_row scratch_glyph_row; (!MINI_WINDOW_P (W) \ && !(W)->pseudo_window_p \ && FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (W))) \ + && BUFFERP ((W)->buffer) \ && !NILP (XBUFFER ((W)->buffer)->header_line_format)) diff --git a/src/fileio.c b/src/fileio.c index 726d3fca80..b68ebfc5b7 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -5144,7 +5144,8 @@ auto_save_1 () struct stat st; /* Get visited file's mode to become the auto save file's mode. */ - if (stat (XSTRING (current_buffer->filename)->data, &st) >= 0) + if (! NILP (current_buffer->filename) + && stat (XSTRING (current_buffer->filename)->data, &st) >= 0) /* But make sure we can overwrite it later! */ auto_save_mode_bits = st.st_mode | 0600; else diff --git a/src/frame.h b/src/frame.h index 724a9ee916..8183b51660 100644 --- a/src/frame.h +++ b/src/frame.h @@ -383,7 +383,7 @@ struct frame typedef struct frame *FRAME_PTR; -#define XFRAME(p) ((struct frame *) XPNTR (p)) +#define XFRAME(p) (eassert (GC_FRAMEP(p)),(struct frame *) XPNTR (p)) #define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME)) /* Given a window, return its frame as a Lisp_Object. */ diff --git a/src/insdel.c b/src/insdel.c index 3cab83711b..9facec4cf3 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -83,7 +83,7 @@ check_markers () tail = BUF_MARKERS (current_buffer); - while (XSYMBOL (tail) != XSYMBOL (Qnil)) + while (! NILP (tail)) { if (XMARKER (tail)->buffer->text != current_buffer->text) abort (); diff --git a/src/lisp.h b/src/lisp.h index 54a3bdd585..13e734a73e 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -432,11 +432,11 @@ extern Lisp_Object make_number (); /* Extract a value or address from a Lisp_Object. */ -#define XCONS(a) ((struct Lisp_Cons *) XPNTR(a)) +#define XCONS(a) (eassert (GC_CONSP(a)),(struct Lisp_Cons *) XPNTR(a)) #define XVECTOR(a) ((struct Lisp_Vector *) XPNTR(a)) -#define XSTRING(a) ((struct Lisp_String *) XPNTR(a)) -#define XSYMBOL(a) ((struct Lisp_Symbol *) XPNTR(a)) -#define XFLOAT(a) ((struct Lisp_Float *) XPNTR(a)) +#define XSTRING(a) (eassert (GC_STRINGP(a)),(struct Lisp_String *) XPNTR(a)) +#define XSYMBOL(a) (eassert (GC_SYMBOLP(a)),(struct Lisp_Symbol *) XPNTR(a)) +#define XFLOAT(a) (eassert (GC_FLOATP(a)),(struct Lisp_Float *) XPNTR(a)) /* Misc types. */ #define XMISC(a) ((union Lisp_Misc *) XPNTR(a)) @@ -451,10 +451,10 @@ extern Lisp_Object make_number (); #define XKBOARD_OBJFWD(a) (&(XMISC(a)->u_kboard_objfwd)) /* Pseudovector types. */ -#define XPROCESS(a) ((struct Lisp_Process *) XPNTR(a)) -#define XWINDOW(a) ((struct window *) XPNTR(a)) -#define XSUBR(a) ((struct Lisp_Subr *) XPNTR(a)) -#define XBUFFER(a) ((struct buffer *) XPNTR(a)) +#define XPROCESS(a) (eassert (GC_PROCESSP(a)),(struct Lisp_Process *) XPNTR(a)) +#define XWINDOW(a) (eassert (GC_WINDOWP(a)),(struct window *) XPNTR(a)) +#define XSUBR(a) (eassert (GC_SUBRP(a)),(struct Lisp_Subr *) XPNTR(a)) +#define XBUFFER(a) (eassert (GC_BUFFERP(a)),(struct buffer *) XPNTR(a)) #define XCHAR_TABLE(a) ((struct Lisp_Char_Table *) XPNTR(a)) #define XBOOL_VECTOR(a) ((struct Lisp_Bool_Vector *) XPNTR(a)) diff --git a/src/marker.c b/src/marker.c index 7e4cd4fa34..5b01738cf9 100644 --- a/src/marker.c +++ b/src/marker.c @@ -168,7 +168,7 @@ buf_charpos_to_bytepos (b, charpos) CONSIDER (cached_charpos, cached_bytepos); tail = BUF_MARKERS (b); - while (XSYMBOL (tail) != XSYMBOL (Qnil)) + while (! NILP (tail)) { CONSIDER (XMARKER (tail)->charpos, XMARKER (tail)->bytepos); @@ -336,7 +336,7 @@ buf_bytepos_to_charpos (b, bytepos) CONSIDER (cached_bytepos, cached_charpos); tail = BUF_MARKERS (b); - while (XSYMBOL (tail) != XSYMBOL (Qnil)) + while (! NILP (tail)) { CONSIDER (XMARKER (tail)->bytepos, XMARKER (tail)->charpos); @@ -747,7 +747,7 @@ unchain_marker (marker) tail = BUF_MARKERS (b); prev = Qnil; - while (XSYMBOL (tail) != XSYMBOL (Qnil)) + while (! GC_NILP (tail)) { next = XMARKER (tail)->chain; XUNMARK (next); diff --git a/src/undo.c b/src/undo.c index 96e3eeb687..a498f2aae7 100644 --- a/src/undo.c +++ b/src/undo.c @@ -54,7 +54,8 @@ record_insert (beg, length) if (NILP (pending_boundary)) pending_boundary = Fcons (Qnil, Qnil); - if (current_buffer != XBUFFER (last_undo_buffer)) + if (!BUFFERP (last_undo_buffer) + || current_buffer != XBUFFER (last_undo_buffer)) Fundo_boundary (); XSETBUFFER (last_undo_buffer, current_buffer); diff --git a/src/vmsproc.c b/src/vmsproc.c index 122cf08bd3..15e2c9d5e6 100644 --- a/src/vmsproc.c +++ b/src/vmsproc.c @@ -758,7 +758,7 @@ child_sig (vs) pid = vs->pid; sys$setef (vs->eventFlag); - for (tail = Vprocess_alist; XSYMBOL (tail) != XSYMBOL (Qnil); tail = XCDR (tail)) + for (tail = Vprocess_alist; ! NILP (tail); tail = XCDR (tail)) { proc = XCDR (XCAR (tail)); p = XPROCESS (proc); @@ -766,7 +766,7 @@ child_sig (vs) break; } - if (XSYMBOL (tail) == XSYMBOL (Qnil)) + if (NILP (tail)) return; p->status = Fcons (Qexit, Fcons (make_number (vs->exitStatus), Qnil)) diff --git a/src/window.c b/src/window.c index 95edbf8e13..72547cad4b 100644 --- a/src/window.c +++ b/src/window.c @@ -905,7 +905,8 @@ unshow_buffer (w) So don't clobber point in that buffer. */ if (! EQ (buf, XWINDOW (selected_window)->buffer) /* This line helps to fix Horsley's testbug.el bug. */ - && !(w != XWINDOW (b->last_selected_window) + && !(WINDOWP (b->last_selected_window) + && w != XWINDOW (b->last_selected_window) && EQ (buf, XWINDOW (b->last_selected_window)->buffer))) temp_set_point_both (b, clip_to_bounds (BUF_BEGV (b), @@ -915,7 +916,8 @@ unshow_buffer (w) marker_byte_position (w->pointm), BUF_ZV_BYTE (b))); - if (w == XWINDOW (b->last_selected_window)) + if (WINDOWP (b->last_selected_window) + && w == XWINDOW (b->last_selected_window)) b->last_selected_window = Qnil; } @@ -1633,7 +1635,8 @@ window_loop (type, obj, mini, frames) case GET_LARGEST_WINDOW: /* Ignore dedicated windows and minibuffers. */ if (MINI_WINDOW_P (XWINDOW (w)) - || !NILP (XWINDOW (w)->dedicated)) + || !NILP (XWINDOW (w)->dedicated) + || NILP (best_window)) break; { struct window *best_window_ptr = XWINDOW (best_window); diff --git a/src/xterm.c b/src/xterm.c index 216c633a58..ed08485904 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -10225,7 +10225,8 @@ x_erase_phys_cursor (w) /* If the cursor is in the mouse face area, redisplay that when we clear the cursor. */ - if (w == XWINDOW (dpyinfo->mouse_face_window) + if (! NILP (dpyinfo->mouse_face_window) + && w == XWINDOW (dpyinfo->mouse_face_window) && (vpos > dpyinfo->mouse_face_beg_row || (vpos == dpyinfo->mouse_face_beg_row && hpos >= dpyinfo->mouse_face_beg_col)) -- 2.20.1