[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 657275529e3 2/2: Revert "Add new `swap` macro and use it"
From: |
Po Lu |
Subject: |
master 657275529e3 2/2: Revert "Add new `swap` macro and use it" |
Date: |
Sat, 6 Jan 2024 02:31:06 -0500 (EST) |
branch: master
commit 657275529e31226bbc6c92eb7f7af887474a0bb8
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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 37889523278fe65733938fb11c3701898309961c.
---
lwlib/xlwmenu.c | 14 ++++++++++++--
src/androidterm.c | 7 ++++++-
src/buffer.c | 16 +++++++++++++---
src/dispnew.c | 20 +++++++++++++++++---
src/editfns.c | 10 +++++-----
src/eval.c | 9 ++++++---
src/fns.c | 6 +++++-
src/lisp.h | 4 ----
src/regex-emacs.c | 4 ++--
src/textconv.c | 28 +++++++++++++++++++++-------
src/textprop.c | 13 +++++++++++--
src/w32uniscribe.c | 4 ++--
src/xfaces.c | 7 ++++++-
src/xterm.c | 10 +++++-----
14 files changed, 111 insertions(+), 41 deletions(-)
diff --git a/lwlib/xlwmenu.c b/lwlib/xlwmenu.c
index a3d9474bed0..0f8f94b803c 100644
--- a/lwlib/xlwmenu.c
+++ b/lwlib/xlwmenu.c
@@ -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;
diff --git a/src/androidterm.c b/src/androidterm.c
index 34734e63c37..2e4ee64f390 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -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. */
diff --git a/src/buffer.c b/src/buffer.c
index 14c67224551..352aca8ddfd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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? */
diff --git a/src/dispnew.c b/src/dispnew.c
index 78ec3537a35..d0f259eef6c 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -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;
}
diff --git a/src/editfns.c b/src/editfns.c
index 2e455a2efed..f3b3cfb7243 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -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
diff --git a/src/eval.c b/src/eval.c
index 6a866d6cc32..94f6d8e31f8 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
}
diff --git a/src/fns.c b/src/fns.c
index c8adc5cb891..c03aea02397 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -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);
diff --git a/src/lisp.h b/src/lisp.h
index f96932ab0c1..44f69892c6f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -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])
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index fdc2cc63445..6aa6f4f9b34 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -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! */
{
diff --git a/src/textconv.c b/src/textconv.c
index e0707522d7e..2a7b0ed330d 100644
--- a/src/textconv.c
+++ b/src/textconv.c
@@ -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. */
diff --git a/src/textprop.c b/src/textprop.c
index ec9435219ea..7d9aae0d2c5 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -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)
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c
index c417159cf9e..a73c0de06f9 100644
--- a/src/w32uniscribe.c
+++ b/src/w32uniscribe.c
@@ -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)
diff --git a/src/xfaces.c b/src/xfaces.c
index f79eb022e15..e30c2fac70c 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -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
diff --git a/src/xterm.c b/src/xterm.c
index 0b83b0554b3..1f398b2e39a 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -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; \
}