bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] strverscmp: sync from glibc


From: Paul Eggert
Subject: [PATCH] strverscmp: sync from glibc
Date: Wed, 26 Jun 2019 12:49:17 -0700

* lib/strverscmp.c: Sync from glibc, except use UTF-8 encoding in
comments, include libc-config.h, define __strverscmp to be
strverscmp, and don’t assume types line uint8_t and int8_t that
that C99 doesn’t guarantee.
[!_LIBC]: Include libc-config.h; define __strverscmp.
Include stdint.h.
(__strverscmp): Assume C99.  Use uint_least8_t
and int_least8_t instead of unsigned char and signed char.
* modules/strverscmp (Depends-on): Add libc-config, stdint.
---
 ChangeLog          | 13 +++++++++++++
 lib/strverscmp.c   | 35 +++++++++++++++--------------------
 modules/strverscmp |  2 ++
 3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1e0014522..5ae108e25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2019-06-26  Paul Eggert  <address@hidden>
+
+       strverscmp: sync from glibc
+       * lib/strverscmp.c: Sync from glibc, except use UTF-8 encoding in
+       comments, include libc-config.h, define __strverscmp to be
+       strverscmp, and don’t assume types line uint8_t and int8_t that
+       that C99 doesn’t guarantee.
+       [!_LIBC]: Include libc-config.h; define __strverscmp.
+       Include stdint.h.
+       (__strverscmp): Assume C99.  Use uint_least8_t
+       and int_least8_t instead of unsigned char and signed char.
+       * modules/strverscmp (Depends-on): Add libc-config, stdint.
+
 2019-06-25  Bruno Haible  <address@hidden>
 
        tss tests: Add tests for destructors and races.
diff --git a/lib/strverscmp.c b/lib/strverscmp.c
index 7e8705712..83922eab4 100644
--- a/lib/strverscmp.c
+++ b/lib/strverscmp.c
@@ -17,10 +17,12 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if !_LIBC
-# include <config.h>
+#ifndef _LIBC
+# include <libc-config.h>
+# define __strverscmp strverscmp
 #endif
 
+#include <stdint.h>
 #include <string.h>
 #include <ctype.h>
 
@@ -35,9 +37,6 @@
 #define  CMP    2
 #define  LEN    3
 
-#ifndef weak_alias
-# define __strverscmp strverscmp
-#endif
 
 /* Compare S1 and S2 as strings holding indices/version numbers,
    returning less than, equal to or greater than zero if S1 is less than,
@@ -49,13 +48,10 @@ __strverscmp (const char *s1, const char *s2)
 {
   const unsigned char *p1 = (const unsigned char *) s1;
   const unsigned char *p2 = (const unsigned char *) s2;
-  unsigned char c1, c2;
-  int state;
-  int diff;
 
   /* Symbol(s)    0       [1-9]   others
      Transition   (10) 0  (01) d  (00) x   */
-  static const unsigned char next_state[] =
+  static const uint_least8_t next_state[] =
   {
       /* state    x    d    0  */
       /* S_N */  S_N, S_I, S_Z,
@@ -64,7 +60,7 @@ __strverscmp (const char *s1, const char *s2)
       /* S_Z */  S_N, S_F, S_Z
   };
 
-  static const signed char result_type[] =
+  static const int_least8_t result_type[] =
   {
       /* state   x/x  x/d  x/0  d/x  d/d  d/0  0/x  0/d  0/0  */
 
@@ -77,15 +73,16 @@ __strverscmp (const char *s1, const char *s2)
   if (p1 == p2)
     return 0;
 
-  c1 = *p1++;
-  c2 = *p2++;
+  unsigned char c1 = *p1++;
+  unsigned char c2 = *p2++;
   /* Hint: '0' is a digit too.  */
-  state = S_N + ((c1 == '0') + (isdigit (c1) != 0));
+  int state = S_N + ((c1 == '0') + (isdigit (c1) != 0));
 
+  int diff;
   while ((diff = c1 - c2) == 0)
     {
       if (c1 == '\0')
-        return diff;
+       return diff;
 
       state = next_state[state];
       c1 = *p1++;
@@ -96,22 +93,20 @@ __strverscmp (const char *s1, const char *s2)
   state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))];
 
   switch (state)
-    {
+  {
     case CMP:
       return diff;
 
     case LEN:
       while (isdigit (*p1++))
-        if (!isdigit (*p2++))
-          return 1;
+       if (!isdigit (*p2++))
+         return 1;
 
       return isdigit (*p2) ? -1 : diff;
 
     default:
       return state;
-    }
+  }
 }
-#ifdef weak_alias
 libc_hidden_def (__strverscmp)
 weak_alias (__strverscmp, strverscmp)
-#endif
diff --git a/modules/strverscmp b/modules/strverscmp
index be0291fec..c2eefd520 100644
--- a/modules/strverscmp
+++ b/modules/strverscmp
@@ -7,6 +7,8 @@ m4/strverscmp.m4
 
 Depends-on:
 extensions
+libc-config  [test $HAVE_STRVERSCMP = 0]
+stdint       [test $HAVE_STRVERSCMP = 0]
 string
 
 configure.ac:
-- 
2.17.1




reply via email to

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