[PATCH] versionsort() support

Denys Vlasenko vda.linux at googlemail.com
Sat Jan 3 14:58:11 UTC 2009


On Friday 02 January 2009 22:50, Hai Zaar wrote:
> On Fri, Dec 26, 2008 at 1:20 AM, Khem Raj <raj.khem at gmail.com> wrote:
> > On (24/12/08 17:23), Hai Zaar wrote:
> >> Hi!
> >> This patch adds versionsort() and strverscmp() functions to uClibc.
> >> The patch is against uClibc-0.9.29 and is verified to work correctly
> >> on at91sam9260 board.
> >
> > Thanks for patch.
> > Is it possible for you to test is against svn trunk
> Attached is the patch against today's snapshot. Tested on ARM platform.

+int strverscmp (s1, s2)
+     const char *s1;
+     const char *s2;
+{

It's 2009, I think we can do away with old C style definitions.


+#define  S_N    0x0
+#define  S_I    0x4
+#define  S_F    0x8
+#define  S_Z    0xC
...
+#define  CMP    2
+#define  LEN    3
...
+  static const unsigned int next_state[] =
+  {
+      /* state    x    d    0    - */
+      /* S_N */  S_N, S_I, S_Z, S_N,
+      /* S_I */  S_N, S_I, S_I, S_I,
+      /* S_F */  S_N, S_F, S_F, S_F,
+      /* S_Z */  S_N, S_F, S_Z, S_Z
+  };
+  static const int result_type[] =
+  {
+      /* state   x/x  x/d  x/0  x/-  d/x  d/d  d/0  d/-
+                 0/x  0/d  0/0  0/-  -/x  -/d  -/0  -/- */
+
+      /* S_N */  CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+                 CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+      /* S_I */  CMP, -1,  -1,  CMP, +1,  LEN, LEN, CMP,
+                 +1,  LEN, LEN, CMP, CMP, CMP, CMP, CMP,
+      /* S_F */  CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+                 CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+      /* S_Z */  CMP, +1,  +1,  CMP, -1,  CMP, CMP, CMP,
+                 -1,  CMP, CMP, CMP
+  };

This is a waste of memory, since these values fit into int8_t.
Please use smaller datatype.


--- ./libc/misc/dirent/versionsort.c.orig       2008-12-27 21:13:47.000000000 +0200
+++ ./libc/misc/dirent/versionsort.c    2008-12-27 21:13:47.000000000 +0200
@@ -0,0 +1,16 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen at uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */

You are not Erik Andersen, I think you should put your name
in the new files you create.

--
vda


More information about the uClibc mailing list