Revert "Add new swap macro and use it"

typeof is an extension which does not exist in Standard C, so macros
using it are unsuitable for inclusion in Emacs.

This reverts commit 3788952327.
This commit is contained in:
Po Lu 2024-01-06 15:28:14 +08:00
parent 2f59052602
commit 657275529e
14 changed files with 111 additions and 41 deletions

View file

@ -671,7 +671,12 @@ draw_shadow_rectangle (XlwMenuWidget mw, Window window, int x, int y,
}
if (!erase_p && down_p)
swap (top_gc, bottom_gc);
{
GC temp;
temp = top_gc;
top_gc = bottom_gc;
bottom_gc = temp;
}
/* Do draw (or erase) shadows */
points [0].x = x;
@ -752,7 +757,12 @@ draw_shadow_rhombus (XlwMenuWidget mw, Window window, int x, int y,
}
if (!erase_p && down_p)
swap (top_gc, bottom_gc);
{
GC temp;
temp = top_gc;
top_gc = bottom_gc;
bottom_gc = temp;
}
points [0].x = x;
points [0].y = y + height / 2;

View file

@ -5849,6 +5849,7 @@ android_get_surrounding_text (void *data)
{
struct android_get_surrounding_text_context *request;
struct frame *f;
ptrdiff_t temp;
request = data;
@ -5869,7 +5870,11 @@ android_get_surrounding_text (void *data)
bad input methods. */
if (request->end < request->start)
swap (request->start, request->end);
{
temp = request->start;
request->start = request->end;
request->end = temp;
}
/* Retrieve the conversion region. */

View file

@ -3591,7 +3591,10 @@ for the rear of the overlay advance when text is inserted there
CHECK_FIXNUM_COERCE_MARKER (end);
if (XFIXNUM (beg) > XFIXNUM (end))
swap (beg, end);
{
Lisp_Object temp;
temp = beg; beg = end; end = temp;
}
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 +3614,11 @@ static void
modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
{
if (start > end)
swap (start, end);
{
ptrdiff_t temp = start;
start = end;
end = temp;
}
BUF_COMPUTE_UNCHANGED (buf, start, end);
@ -3651,7 +3658,10 @@ buffer. */)
CHECK_FIXNUM_COERCE_MARKER (end);
if (XFIXNUM (beg) > XFIXNUM (end))
swap (beg, end);
{
Lisp_Object temp;
temp = beg; beg = end; end = temp;
}
specbind (Qinhibit_quit, Qt); /* FIXME: Why? */

View file

@ -649,7 +649,14 @@ 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]);
{
/* Non-ISO HP/UX compiler doesn't like auto struct
initialization. */
struct glyph_row temp;
temp = matrix->rows[i];
matrix->rows[i] = matrix->rows[j];
matrix->rows[j] = temp;
}
}
@ -959,7 +966,9 @@ increment_row_positions (struct glyph_row *row,
static void
swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b)
{
for (int area = 0; area < LAST_AREA; ++area)
int area;
for (area = 0; area < LAST_AREA; ++area)
{
/* Number of glyphs to swap. */
int max_used = max (a->used[area], b->used[area]);
@ -975,7 +984,12 @@ swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b)
while (glyph_a < glyph_a_end)
{
swap (*glyph_a, *glyph_b);
/* Non-ISO HP/UX compiler doesn't like auto struct
initialization. */
struct glyph temp;
temp = *glyph_a;
*glyph_a = *glyph_b;
*glyph_b = temp;
++glyph_a;
++glyph_b;
}

View file

@ -1739,7 +1739,7 @@ versa, strings are converted from unibyte to multibyte or vice versa
using `string-make-multibyte' or `string-make-unibyte', which see. */)
(Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
{
register EMACS_INT b, e;
register EMACS_INT b, e, temp;
register struct buffer *bp, *obuf;
Lisp_Object buf;
@ -1753,7 +1753,7 @@ using `string-make-multibyte' or `string-make-unibyte', which see. */)
b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
if (b > e)
swap (b, e);
temp = b, b = e, e = temp;
if (!(BUF_BEGV (bp) <= b && e <= BUF_ZV (bp)))
args_out_of_range (start, end);
@ -1782,7 +1782,7 @@ The value of `case-fold-search' in the current buffer
determines whether case is significant or ignored. */)
(Lisp_Object buffer1, Lisp_Object start1, Lisp_Object end1, Lisp_Object buffer2, Lisp_Object start2, Lisp_Object end2)
{
register EMACS_INT begp1, endp1, begp2, endp2;
register EMACS_INT begp1, endp1, begp2, endp2, temp;
register struct buffer *bp1, *bp2;
register Lisp_Object trt
= (!NILP (Vcase_fold_search)
@ -1808,7 +1808,7 @@ determines whether case is significant or ignored. */)
begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1);
endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1);
if (begp1 > endp1)
swap (begp1, endp1);
temp = begp1, begp1 = endp1, endp1 = temp;
if (!(BUF_BEGV (bp1) <= begp1
&& begp1 <= endp1
@ -1833,7 +1833,7 @@ determines whether case is significant or ignored. */)
begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2);
endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2);
if (begp2 > endp2)
swap (begp2, endp2);
temp = begp2, begp2 = endp2, endp2 = temp;
if (!(BUF_BEGV (bp2) <= begp2
&& begp2 <= endp2

View file

@ -2794,9 +2794,12 @@ usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
static Lisp_Object
run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
{
swap (args[0], args[1]);
Lisp_Object ret = Ffuncall (nargs, args);
swap (args[1], args[0]);
Lisp_Object tmp = args[0], ret;
args[0] = args[1];
args[1] = tmp;
ret = Ffuncall (nargs, args);
args[1] = args[0];
args[0] = tmp;
return ret;
}

View file

@ -5674,7 +5674,11 @@ 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);
{
EMACS_INT temp = b;
b = e;
e = temp;
}
if (!(BEGV <= b && e <= ZV))
args_out_of_range (start, end);

View file

@ -67,10 +67,6 @@ INLINE_HEADER_BEGIN
#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);
/* Number of elements in an array. */
#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])

View file

@ -2839,7 +2839,7 @@ forall_firstchar_1 (re_char *p, re_char *pend,
while (true)
{
re_char *newp1, *newp2;
re_char *newp1, *newp2, *tmp;
re_char *p_orig = p;
int offset;
@ -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);
(tmp = newp1, newp1 = newp2, newp2 = tmp);
if (newp2 <= p_orig) /* Both destinations go backward! */
{

View file

@ -176,7 +176,7 @@ textconv_query (struct frame *f, struct textconv_callback_struct *query,
{
specpdl_ref count;
ptrdiff_t pos, pos_byte, end, end_byte, start;
ptrdiff_t mark;
ptrdiff_t temp, temp1, mark;
char *buffer;
struct window *w;
@ -383,8 +383,12 @@ 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);
temp = pos_byte;
temp1 = pos;
pos_byte = end_byte;
pos = end;
end = temp1;
end_byte = temp;
}
/* Return the string first. */
@ -1901,9 +1905,15 @@ get_extracted_text (struct frame *f, ptrdiff_t n,
start = marker_position (BVAR (current_buffer, mark));
end = PT;
/* Sort start and end. */
/* Sort start and end. start_byte is used to hold a
temporary value. */
if (start > end)
swap (start, end);
{
start_byte = end;
end = start;
start = start_byte;
}
}
else
goto finish;
@ -1969,7 +1979,7 @@ get_surrounding_text (struct frame *f, ptrdiff_t left,
ptrdiff_t *end_return)
{
specpdl_ref count;
ptrdiff_t start, end, start_byte, end_byte, mark;
ptrdiff_t start, end, start_byte, end_byte, mark, temp;
char *buffer;
if (!WINDOW_LIVE_P (f->old_selected_window))
@ -2002,7 +2012,11 @@ get_surrounding_text (struct frame *f, ptrdiff_t left,
/* Now sort start and end. */
if (end < start)
swap (start, end)
{
temp = start;
start = end;
end = temp;
}
/* And subtract left and right. */

View file

@ -142,7 +142,12 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin,
return NULL;
if (XFIXNUM (*begin) > XFIXNUM (*end))
swap (*begin, *end);
{
Lisp_Object n;
n = *begin;
*begin = *end;
*end = n;
}
if (BUFFERP (object))
{
@ -2196,7 +2201,11 @@ verify_interval_modification (struct buffer *buf,
return;
if (start > end)
swap (start, end);
{
ptrdiff_t temp = start;
start = end;
end = temp;
}
/* For an insert operation, check the two chars around the position. */
if (start == end)

View file

@ -765,10 +765,10 @@ add_opentype_font_name_to_list (ENUMLOGFONTEX *logical_font,
#define OTF_INT16_VAL(TABLE, OFFSET, PTR) \
do { \
BYTE data[2]; \
BYTE temp, data[2]; \
if (GetFontData (context, TABLE, OFFSET, data, 2) != 2) \
goto font_table_error; \
swap (data[0], data[1]); \
temp = data[0], data[0] = data[1], data[1] = temp; \
memcpy (PTR, data, 2); \
} while (0)

View file

@ -1357,7 +1357,12 @@ 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);
{
Lisp_Object tmp;
tmp = fg;
fg = bg;
bg = tmp;
}
/* Check for support for foreground, not for background because
face_color_supported_p is smart enough to know that grays are

View file

@ -1569,19 +1569,19 @@ typedef enum xm_byte_order
#define SWAPCARD32(l) \
{ \
struct { unsigned t : 32; } bit32; \
char *tp = (char *) &bit32; \
char n, *tp = (char *) &bit32; \
bit32.t = l; \
swap (tp[0], tp[3]); \
swap (tp[1], tp[2]); \
n = tp[0]; tp[0] = tp[3]; tp[3] = n; \
n = tp[1]; tp[1] = tp[2]; tp[2] = n; \
l = bit32.t; \
}
#define SWAPCARD16(s) \
{ \
struct { unsigned t : 16; } bit16; \
char *tp = (char *) &bit16; \
char n, *tp = (char *) &bit16; \
bit16.t = s; \
swap (tp[0], tp[1]); \
n = tp[0]; tp[0] = tp[1]; tp[1] = n; \
s = bit16.t; \
}