mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
portability: beware of max () with MSVC
Reported by Maarten De Braekeleer. https://lists.gnu.org/r/bison-patches/2020-07/msg00080.html We don't want to use gnulib's min and max macros, since we use function calls in min/max arguments. * src/location.c (max_int, min_int): Move to... * src/system.h: here. * src/counterexample.c, src/derivation.c: Use max_int instead of max.
This commit is contained in:
@@ -113,11 +113,6 @@ free_counterexample (counterexample *cex)
|
|||||||
free (cex);
|
free (cex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max (int a, int b)
|
|
||||||
{
|
|
||||||
return a < b ? b : a;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
counterexample_print (const counterexample *cex, FILE *out, const char *prefix)
|
counterexample_print (const counterexample *cex, FILE *out, const char *prefix)
|
||||||
{
|
{
|
||||||
@@ -131,8 +126,8 @@ counterexample_print (const counterexample *cex, FILE *out, const char *prefix)
|
|||||||
const char *deriv2_label
|
const char *deriv2_label
|
||||||
= cex->shift_reduce ? _("Reduce derivation") : _("Second reduce derivation");
|
= cex->shift_reduce ? _("Reduce derivation") : _("Second reduce derivation");
|
||||||
const int width =
|
const int width =
|
||||||
max (max (mbswidth (example1_label, 0), mbswidth (example2_label, 0)),
|
max_int (max_int (mbswidth (example1_label, 0), mbswidth (example2_label, 0)),
|
||||||
max (mbswidth (deriv1_label, 0), mbswidth (deriv2_label, 0)));
|
max_int (mbswidth (deriv1_label, 0), mbswidth (deriv2_label, 0)));
|
||||||
if (flat)
|
if (flat)
|
||||||
fprintf (out, " %s%s%*s ", prefix,
|
fprintf (out, " %s%s%*s ", prefix,
|
||||||
example1_label, width - mbswidth (example1_label, 0), "");
|
example1_label, width - mbswidth (example1_label, 0), "");
|
||||||
|
|||||||
@@ -135,12 +135,6 @@ derivation_size (const derivation *deriv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
max (int a, int b)
|
|
||||||
{
|
|
||||||
return a < b ? b : a;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Longest distance from root to leaf.
|
// Longest distance from root to leaf.
|
||||||
static int
|
static int
|
||||||
derivation_depth (const derivation *deriv)
|
derivation_depth (const derivation *deriv)
|
||||||
@@ -154,7 +148,7 @@ derivation_depth (const derivation *deriv)
|
|||||||
for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
|
for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
|
||||||
derivation_list_next (&it, &child);
|
derivation_list_next (&it, &child);
|
||||||
)
|
)
|
||||||
res = max (res, derivation_depth (child));
|
res = max_int (res, derivation_depth (child));
|
||||||
return res + 1;
|
return res + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -237,7 +231,7 @@ derivation_width (const derivation *deriv)
|
|||||||
// No separator at the beginning.
|
// No separator at the beginning.
|
||||||
children_width -= derivation_separator_width;
|
children_width -= derivation_separator_width;
|
||||||
}
|
}
|
||||||
return max (self_width, children_width);
|
return max_int (self_width, children_width);
|
||||||
}
|
}
|
||||||
else if (deriv == &d_dot)
|
else if (deriv == &d_dot)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,18 +40,6 @@
|
|||||||
|
|
||||||
location const empty_loc = EMPTY_LOCATION_INIT;
|
location const empty_loc = EMPTY_LOCATION_INIT;
|
||||||
|
|
||||||
static int
|
|
||||||
min_int (int a, int b)
|
|
||||||
{
|
|
||||||
return a < b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
max_int (int a, int b)
|
|
||||||
{
|
|
||||||
return a >= b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The terminal width. Not less than 40. */
|
/* The terminal width. Not less than 40. */
|
||||||
static int
|
static int
|
||||||
columns (void)
|
columns (void)
|
||||||
|
|||||||
16
src/system.h
16
src/system.h
@@ -131,6 +131,22 @@ typedef size_t uintptr_t;
|
|||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------.
|
||||||
|
| Integers. |
|
||||||
|
`-----------*/
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
min_int (int a, int b)
|
||||||
|
{
|
||||||
|
return a < b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
max_int (int a, int b)
|
||||||
|
{
|
||||||
|
return a >= b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------.
|
/*-------------.
|
||||||
| Assertions. |
|
| Assertions. |
|
||||||
|
|||||||
Reference in New Issue
Block a user