diff --git a/lwlib/xlwmenu.c b/lwlib/xlwmenu.c index a3d9474bed0..d6fa23841a3 100644 --- a/lwlib/xlwmenu.c +++ b/lwlib/xlwmenu.c @@ -671,7 +671,7 @@ draw_shadow_rectangle (XlwMenuWidget mw, Window window, int x, int y, } if (!erase_p && down_p) - swap (top_gc, bottom_gc); + swap (GC, top_gc, bottom_gc); /* Do draw (or erase) shadows */ points [0].x = x; @@ -752,7 +752,7 @@ draw_shadow_rhombus (XlwMenuWidget mw, Window window, int x, int y, } if (!erase_p && down_p) - swap (top_gc, bottom_gc); + swap (GC, top_gc, bottom_gc); points [0].x = x; points [0].y = y + height / 2; diff --git a/src/androidterm.c b/src/androidterm.c index 34734e63c37..851a066316a 100644 --- a/src/androidterm.c +++ b/src/androidterm.c @@ -5869,7 +5869,7 @@ android_get_surrounding_text (void *data) bad input methods. */ if (request->end < request->start) - swap (request->start, request->end); + swap (ptrdiff_t, request->start, request->end); /* Retrieve the conversion region. */ diff --git a/src/buffer.c b/src/buffer.c index 14c67224551..c03170e8c2d 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3591,7 +3591,7 @@ DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 5, 0, CHECK_FIXNUM_COERCE_MARKER (end); if (XFIXNUM (beg) > XFIXNUM (end)) - swap (beg, end); + swap (Lisp_Object, beg, end); ptrdiff_t obeg = clip_to_bounds (BUF_BEG (b), XFIXNUM (beg), BUF_Z (b)); ptrdiff_t oend = clip_to_bounds (obeg, XFIXNUM (end), BUF_Z (b)); @@ -3611,7 +3611,7 @@ DEFUN ("make-overlay", Fmake_overlay, Smake_overlay, 2, 5, 0, modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) { if (start > end) - swap (start, end); + swap (ptrdiff_t, start, end); BUF_COMPUTE_UNCHANGED (buf, start, end); @@ -3651,7 +3651,7 @@ DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, CHECK_FIXNUM_COERCE_MARKER (end); if (XFIXNUM (beg) > XFIXNUM (end)) - swap (beg, end); + swap (Lisp_Object, beg, end); specbind (Qinhibit_quit, Qt); /* FIXME: Why? */ diff --git a/src/dispnew.c b/src/dispnew.c index 78ec3537a35..a3e6ca416db 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -649,7 +649,7 @@ reverse_rows (struct glyph_matrix *matrix, int start, int end) int i, j; for (i = start, j = end - 1; i < j; ++i, --j) - swap (matrix->rows[i], matrix->rows[j]); + swap (struct glyph_row, matrix->rows[i], matrix->rows[j]); } @@ -975,7 +975,7 @@ swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b) while (glyph_a < glyph_a_end) { - swap (*glyph_a, *glyph_b); + swap (struct glyph, *glyph_a, *glyph_b); ++glyph_a; ++glyph_b; } diff --git a/src/editfns.c b/src/editfns.c index 2e455a2efed..f31d8f5aef3 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -1753,7 +1753,7 @@ DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_subst b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp); e = !NILP (end) ? fix_position (end) : BUF_ZV (bp); if (b > e) - swap (b, e); + swap (EMACS_INT, b, e); if (!(BUF_BEGV (bp) <= b && e <= BUF_ZV (bp))) args_out_of_range (start, end); @@ -1808,7 +1808,7 @@ DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings, Scompare_buffer_ begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1); endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1); if (begp1 > endp1) - swap (begp1, endp1); + swap (EMACS_INT, begp1, endp1); if (!(BUF_BEGV (bp1) <= begp1 && begp1 <= endp1 @@ -1833,7 +1833,7 @@ DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings, Scompare_buffer_ begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2); endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2); if (begp2 > endp2) - swap (begp2, endp2); + swap (EMACS_INT, begp2, endp2); if (!(BUF_BEGV (bp2) <= begp2 && begp2 <= endp2 diff --git a/src/eval.c b/src/eval.c index 6a866d6cc32..7d89c0b621e 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2794,9 +2794,9 @@ DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, static Lisp_Object run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args) { - swap (args[0], args[1]); + swap (Lisp_Object, args[0], args[1]); Lisp_Object ret = Ffuncall (nargs, args); - swap (args[1], args[0]); + swap (Lisp_Object, args[1], args[0]); return ret; } diff --git a/src/fns.c b/src/fns.c index c8adc5cb891..9e7f43b58e1 100644 --- a/src/fns.c +++ b/src/fns.c @@ -5674,7 +5674,7 @@ extract_data_from_object (Lisp_Object spec, b = !NILP (start) ? fix_position (start) : BEGV; e = !NILP (end) ? fix_position (end) : ZV; if (b > e) - swap (b, e); + swap (EMACS_INT, b, e); if (!(BEGV <= b && e <= ZV)) args_out_of_range (start, end); diff --git a/src/lisp.h b/src/lisp.h index f96932ab0c1..a9782868157 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -68,8 +68,13 @@ #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) /* Swap values of a and b. */ -#define swap(a, b) \ - do { typeof (a) __tmp; __tmp = (a); (a) = (b); (b) = __tmp; } while (0); +#if _GL_HAVE___TYPEOF__ +#define swap(type, a, b) \ + do { __typeof__ (a) __tmp; __tmp = (a); (a) = (b); (b) = __tmp; } while (0); +#else +#define swap(type, a, b) \ + do { type __tmp; __tmp = (a); (a) = (b); (b) = __tmp; } while (0); +#endif /* Number of elements in an array. */ #define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0]) diff --git a/src/regex-emacs.c b/src/regex-emacs.c index fdc2cc63445..afaf0d06bd1 100644 --- a/src/regex-emacs.c +++ b/src/regex-emacs.c @@ -2930,7 +2930,7 @@ forall_firstchar_1 (re_char *p, re_char *pend, /* We have to check that both destinations are safe. Arrange for `newp1` to be the smaller of the two. */ if (newp1 > newp2) - swap (newp1, newp2); + swap (re_char *, newp1, newp2); if (newp2 <= p_orig) /* Both destinations go backward! */ { diff --git a/src/textconv.c b/src/textconv.c index e0707522d7e..c8599f78a54 100644 --- a/src/textconv.c +++ b/src/textconv.c @@ -383,8 +383,8 @@ textconv_query (struct frame *f, struct textconv_callback_struct *query, if (end < pos) { eassert (end_byte < pos_byte); - swap (pos_byte, end_byte); - swap (pos, end); + swap (ptrdiff_t, pos_byte, end_byte); + swap (ptrdiff_t, pos, end); } /* Return the string first. */ @@ -1903,7 +1903,7 @@ get_extracted_text (struct frame *f, ptrdiff_t n, /* Sort start and end. */ if (start > end) - swap (start, end); + swap (ptrdiff_t, start, end); } else goto finish; @@ -2002,7 +2002,7 @@ get_surrounding_text (struct frame *f, ptrdiff_t left, /* Now sort start and end. */ if (end < start) - swap (start, end) + swap (ptrdiff_t, start, end) /* And subtract left and right. */ diff --git a/src/textprop.c b/src/textprop.c index ec9435219ea..118a5831c10 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -142,7 +142,7 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin, return NULL; if (XFIXNUM (*begin) > XFIXNUM (*end)) - swap (*begin, *end); + swap (Lisp_Object, *begin, *end); if (BUFFERP (object)) { @@ -2196,7 +2196,7 @@ verify_interval_modification (struct buffer *buf, return; if (start > end) - swap (start, end); + swap (ptrdiff_t, start, end); /* For an insert operation, check the two chars around the position. */ if (start == end) diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c index c417159cf9e..798a90bf594 100644 --- a/src/w32uniscribe.c +++ b/src/w32uniscribe.c @@ -768,7 +768,7 @@ #define OTF_INT16_VAL(TABLE, OFFSET, PTR) \ BYTE data[2]; \ if (GetFontData (context, TABLE, OFFSET, data, 2) != 2) \ goto font_table_error; \ - swap (data[0], data[1]); \ + swap (BYTE, data[0], data[1]); \ memcpy (PTR, data, 2); \ } while (0) diff --git a/src/xfaces.c b/src/xfaces.c index f79eb022e15..95ae3b4b1bc 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -1357,7 +1357,7 @@ load_face_colors (struct frame *f, struct face *face, /* Swap colors if face is inverse-video. */ if (EQ (attrs[LFACE_INVERSE_INDEX], Qt)) - swap (fg, bg); + swap (Lisp_Object, fg, bg); /* Check for support for foreground, not for background because face_color_supported_p is smart enough to know that grays are diff --git a/src/xterm.c b/src/xterm.c index 0b83b0554b3..92e51577cec 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -1571,8 +1571,8 @@ #define SWAPCARD32(l) \ struct { unsigned t : 32; } bit32; \ char *tp = (char *) &bit32; \ bit32.t = l; \ - swap (tp[0], tp[3]); \ - swap (tp[1], tp[2]); \ + swap (char, tp[0], tp[3]); \ + swap (char, tp[1], tp[2]); \ l = bit32.t; \ } @@ -1581,7 +1581,7 @@ #define SWAPCARD16(s) \ struct { unsigned t : 16; } bit16; \ char *tp = (char *) &bit16; \ bit16.t = s; \ - swap (tp[0], tp[1]); \ + swap (char, tp[0], tp[1]); \ s = bit16.t; \ }