emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e68912e: Port hexdigit init to non-GCC + pdumper


From: Paul Eggert
Subject: master e68912e: Port hexdigit init to non-GCC + pdumper
Date: Fri, 15 Nov 2019 04:29:58 -0500 (EST)

branch: master
commit e68912ea6be6338f3ca659cb01ec2bd616e8e660
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    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.
---
 src/character.c | 23 +++++++++--------------
 src/character.h | 11 ++---------
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/src/character.c b/src/character.c
index a80e6f8..708eb2f 100644
--- a/src/character.c
+++ b/src/character.c
@@ -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");
 
diff --git a/src/character.h b/src/character.h
index cc57a2a..230fc6e 100644
--- a/src/character.h
+++ b/src/character.h
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]