diff options
| author | Paul Eggert | 2019-11-15 01:28:33 -0800 |
|---|---|---|
| committer | Paul Eggert | 2019-11-15 01:29:52 -0800 |
| commit | e68912ea6be6338f3ca659cb01ec2bd616e8e660 (patch) | |
| tree | 2470eb062276645228c38814da639313c9630c7f /src | |
| parent | 0114bb964afd81b6a6dc8c742bceba61d0f2a7dc (diff) | |
| download | emacs-e68912ea6be6338f3ca659cb01ec2bd616e8e660.tar.gz emacs-e68912ea6be6338f3ca659cb01ec2bd616e8e660.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/character.c | 23 | ||||
| -rw-r--r-- | src/character.h | 11 |
2 files changed, 11 insertions, 23 deletions
diff --git a/src/character.c b/src/character.c index a80e6f8de02..708eb2f7024 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -1082,26 +1082,21 @@ confusable_symbol_character_p (int ch) | |||
| 1082 | } | 1082 | } |
| 1083 | } | 1083 | } |
| 1084 | 1084 | ||
| 1085 | signed char HEXDIGIT_CONST hexdigit[UCHAR_MAX + 1] = | 1085 | /* hexdigit[C] is one greater than C's numeric value if C is a |
| 1086 | hexadecimal digit, zero otherwise. */ | ||
| 1087 | signed char const hexdigit[UCHAR_MAX + 1] = | ||
| 1086 | { | 1088 | { |
| 1087 | #if HEXDIGIT_IS_CONST | 1089 | ['0'] = 1 + 0, ['1'] = 1 + 1, ['2'] = 1 + 2, ['3'] = 1 + 3, ['4'] = 1 + 4, |
| 1088 | [0 ... UCHAR_MAX] = -1, | 1090 | ['5'] = 1 + 5, ['6'] = 1 + 6, ['7'] = 1 + 7, ['8'] = 1 + 8, ['9'] = 1 + 9, |
| 1089 | #endif | 1091 | ['A'] = 1 + 10, ['B'] = 1 + 11, ['C'] = 1 + 12, |
| 1090 | ['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4, | 1092 | ['D'] = 1 + 13, ['E'] = 1 + 14, ['F'] = 1 + 15, |
| 1091 | ['5'] = 5, ['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9, | 1093 | ['a'] = 1 + 10, ['b'] = 1 + 11, ['c'] = 1 + 12, |
| 1092 | ['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15, | 1094 | ['d'] = 1 + 13, ['e'] = 1 + 14, ['f'] = 1 + 15 |
| 1093 | ['a'] = 10, ['b'] = 11, ['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15 | ||
| 1094 | }; | 1095 | }; |
| 1095 | 1096 | ||
| 1096 | void | 1097 | void |
| 1097 | syms_of_character (void) | 1098 | syms_of_character (void) |
| 1098 | { | 1099 | { |
| 1099 | #if !HEXDIGIT_IS_CONST | ||
| 1100 | /* Set the non-hex digit values to -1. */ | ||
| 1101 | for (int i = 0; i <= UCHAR_MAX; i++) | ||
| 1102 | hexdigit[i] -= i != '0' && !hexdigit[i]; | ||
| 1103 | #endif | ||
| 1104 | |||
| 1105 | DEFSYM (Qcharacterp, "characterp"); | 1100 | DEFSYM (Qcharacterp, "characterp"); |
| 1106 | DEFSYM (Qauto_fill_chars, "auto-fill-chars"); | 1101 | DEFSYM (Qauto_fill_chars, "auto-fill-chars"); |
| 1107 | 1102 | ||
diff --git a/src/character.h b/src/character.h index cc57a2a7d5c..230fc6eab59 100644 --- a/src/character.h +++ b/src/character.h | |||
| @@ -704,14 +704,7 @@ char_table_translate (Lisp_Object obj, int ch) | |||
| 704 | return CHARACTERP (obj) ? XFIXNUM (obj) : ch; | 704 | return CHARACTERP (obj) ? XFIXNUM (obj) : ch; |
| 705 | } | 705 | } |
| 706 | 706 | ||
| 707 | #if defined __GNUC__ && !defined __STRICT_ANSI__ | 707 | extern signed char const hexdigit[]; |
| 708 | # define HEXDIGIT_CONST const | ||
| 709 | # define HEXDIGIT_IS_CONST true | ||
| 710 | #else | ||
| 711 | # define HEXDIGIT_CONST | ||
| 712 | # define HEXDIGIT_IS_CONST false | ||
| 713 | #endif | ||
| 714 | extern signed char HEXDIGIT_CONST hexdigit[]; | ||
| 715 | 708 | ||
| 716 | /* If C is a hexadecimal digit ('0'-'9', 'a'-'f', 'A'-'F'), return its | 709 | /* If C is a hexadecimal digit ('0'-'9', 'a'-'f', 'A'-'F'), return its |
| 717 | value (0-15). Otherwise return -1. */ | 710 | value (0-15). Otherwise return -1. */ |
| @@ -719,7 +712,7 @@ extern signed char HEXDIGIT_CONST hexdigit[]; | |||
| 719 | INLINE int | 712 | INLINE int |
| 720 | char_hexdigit (int c) | 713 | char_hexdigit (int c) |
| 721 | { | 714 | { |
| 722 | return 0 <= c && c <= UCHAR_MAX ? hexdigit[c] : -1; | 715 | return 0 <= c && c <= UCHAR_MAX ? hexdigit[c] - 1 : -1; |
| 723 | } | 716 | } |
| 724 | 717 | ||
| 725 | INLINE_HEADER_END | 718 | INLINE_HEADER_END |