Port hexdigit init to non-GCC + pdumper

The old code assumed that hexdigit initialization (needed by
non-GCC) could be done in syms_of_character, but that is no longer
true with pdumper.  Instead, simplify hexdigit init so that it can
be done statically on all C99 platforms.  Problem discovered on
Solaris 10 sparc + Oracle Solaris Studio 12.6.
* src/character.c (hexdigit): Add 1 to every value; all uses
changed.  This simplifies the initialization so that it can be
done statically on any C99 compiler.  hexdigit is now always const.
(syms_of_character): Omit no-longer-necessary initialization.
* src/character.h (HEXDIGIT_CONST, HEXDIGIT_IS_CONST):
Remove.  All uses removed.
This commit is contained in:
Paul Eggert 2019-11-15 01:28:33 -08:00
parent 0114bb964a
commit e68912ea6b
2 changed files with 11 additions and 23 deletions

View file

@ -1082,26 +1082,21 @@ confusable_symbol_character_p (int ch)
}
}
signed char HEXDIGIT_CONST hexdigit[UCHAR_MAX + 1] =
/* hexdigit[C] is one greater than C's numeric value if C is a
hexadecimal digit, zero otherwise. */
signed char const hexdigit[UCHAR_MAX + 1] =
{
#if HEXDIGIT_IS_CONST
[0 ... UCHAR_MAX] = -1,
#endif
['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4,
['5'] = 5, ['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9,
['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15,
['a'] = 10, ['b'] = 11, ['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15
['0'] = 1 + 0, ['1'] = 1 + 1, ['2'] = 1 + 2, ['3'] = 1 + 3, ['4'] = 1 + 4,
['5'] = 1 + 5, ['6'] = 1 + 6, ['7'] = 1 + 7, ['8'] = 1 + 8, ['9'] = 1 + 9,
['A'] = 1 + 10, ['B'] = 1 + 11, ['C'] = 1 + 12,
['D'] = 1 + 13, ['E'] = 1 + 14, ['F'] = 1 + 15,
['a'] = 1 + 10, ['b'] = 1 + 11, ['c'] = 1 + 12,
['d'] = 1 + 13, ['e'] = 1 + 14, ['f'] = 1 + 15
};
void
syms_of_character (void)
{
#if !HEXDIGIT_IS_CONST
/* Set the non-hex digit values to -1. */
for (int i = 0; i <= UCHAR_MAX; i++)
hexdigit[i] -= i != '0' && !hexdigit[i];
#endif
DEFSYM (Qcharacterp, "characterp");
DEFSYM (Qauto_fill_chars, "auto-fill-chars");

View file

@ -704,14 +704,7 @@ char_table_translate (Lisp_Object obj, int ch)
return CHARACTERP (obj) ? XFIXNUM (obj) : ch;
}
#if defined __GNUC__ && !defined __STRICT_ANSI__
# define HEXDIGIT_CONST const
# define HEXDIGIT_IS_CONST true
#else
# define HEXDIGIT_CONST
# define HEXDIGIT_IS_CONST false
#endif
extern signed char HEXDIGIT_CONST hexdigit[];
extern signed char const hexdigit[];
/* If C is a hexadecimal digit ('0'-'9', 'a'-'f', 'A'-'F'), return its
value (0-15). Otherwise return -1. */
@ -719,7 +712,7 @@ extern signed char HEXDIGIT_CONST hexdigit[];
INLINE int
char_hexdigit (int c)
{
return 0 <= c && c <= UCHAR_MAX ? hexdigit[c] : -1;
return 0 <= c && c <= UCHAR_MAX ? hexdigit[c] - 1 : -1;
}
INLINE_HEADER_END