Source-Changes-HG archive

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

[src/trunk]: src Add a special seeder for cdbw_output that gives stable results.



details:   https://anonhg.NetBSD.org/src/rev/89a180ad23c0
branches:  trunk
changeset: 779575:89a180ad23c0
user:      joerg <joerg%NetBSD.org@localhost>
date:      Sun Jun 03 21:02:50 2012 +0000

description:
Add a special seeder for cdbw_output that gives stable results.
Hook up cdbw(3) for the tool build.

diffstat:

 lib/libc/cdb/cdbw.3   |  16 +++++++++++++---
 lib/libc/cdb/cdbw.c   |  23 ++++++++++++++++++++---
 tools/compat/Makefile |  10 ++++++----
 tools/compat/cdbw.h   |   5 +++++
 4 files changed, 44 insertions(+), 10 deletions(-)

diffs (153 lines):

diff -r 15054fc0fc0e -r 89a180ad23c0 lib/libc/cdb/cdbw.3
--- a/lib/libc/cdb/cdbw.3       Sun Jun 03 21:01:43 2012 +0000
+++ b/lib/libc/cdb/cdbw.3       Sun Jun 03 21:02:50 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: cdbw.3,v 1.3 2010/11/03 16:17:48 plunky Exp $
+.\"    $NetBSD: cdbw.3,v 1.4 2012/06/03 21:02:50 joerg Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
-.Dd November 3, 2010
+.Dd June 3, 2012
 .Dt CDBW 3
 .Os
 .Sh NAME
@@ -36,6 +36,8 @@
 .Nm cdbw_put ,
 .Nm cdbw_put_data ,
 .Nm cdbw_put_key ,
+.Nm cdbw_stable_seeder ,
+.Nm cdbw_output ,
 .Nm cdbw_close
 .Nd create constant databases
 .Sh SYNOPSIS
@@ -64,6 +66,10 @@
 .Fa "size_t keylen"
 .Fa "uint32_t index"
 .Fc
+.Ft uint32_t
+.Fo cdbw_stable_seeder
+.Fa "void"
+.Fc
 .Ft int
 .Fo cdbw_output
 .Fa "struct cdbw *cdbw"
@@ -111,8 +117,12 @@
 The
 .Fn seedgen
 parameter can be used to override the default PRNG.
+The bitwise layout of the output depends on the chosen seed.
 The function should return a different value for each invokation.
-The bitwise layout of the output depends on the chosen seed.
+The
+.Fn cdbw_stable_seeder
+can be used to create reproducable output.
+It may be slower than the default.
 .Sh SEE ALSO
 .Xr cdbr 3 ,
 .Xr cdb 5
diff -r 15054fc0fc0e -r 89a180ad23c0 lib/libc/cdb/cdbw.c
--- a/lib/libc/cdb/cdbw.c       Sun Jun 03 21:01:43 2012 +0000
+++ b/lib/libc/cdb/cdbw.c       Sun Jun 03 21:02:50 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cdbw.c,v 1.3 2012/03/13 21:32:12 joerg Exp $   */
+/*     $NetBSD: cdbw.c,v 1.4 2012/06/03 21:02:50 joerg Exp $   */
 /*-
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,11 +36,13 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: cdbw.c,v 1.3 2012/03/13 21:32:12 joerg Exp $");
+__RCSID("$NetBSD: cdbw.c,v 1.4 2012/06/03 21:02:50 joerg Exp $");
 
 #include "namespace.h"
 
+#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
 #include <sys/endian.h>
+#endif
 #include <sys/queue.h>
 #include <cdbw.h>
 #include <stdlib.h>
@@ -270,6 +272,12 @@
        free(cdbw);
 }
 
+uint32_t
+cdbw_stable_seeder(void)
+{
+       return 0;
+}
+
 #define unused 0xffffffffU
 
 struct vertex {
@@ -556,8 +564,13 @@
                return 0;
        }
 
+#if HAVE_NBTOOL_CONFIG_H
+       if (seedgen == NULL)
+               seedgen = cdbw_stable_seeder;
+#else
        if (seedgen == NULL)
                seedgen = arc4random;
+#endif
 
        rv = 0;
 
@@ -581,8 +594,12 @@
                goto release;
        }
 
+       state.seed = 0;
        do {
-               state.seed = (*seedgen)();
+               if (seedgen == cdbw_stable_seeder)
+                       ++state.seed;
+               else
+                       state.seed = (*seedgen)();
        } while (build_graph(cdbw, &state));
 
        assign_nodes(&state);
diff -r 15054fc0fc0e -r 89a180ad23c0 tools/compat/Makefile
--- a/tools/compat/Makefile     Sun Jun 03 21:01:43 2012 +0000
+++ b/tools/compat/Makefile     Sun Jun 03 21:02:50 2012 +0000
@@ -1,9 +1,10 @@
-#      $NetBSD: Makefile,v 1.56 2012/02/18 17:51:21 njoly Exp $
+#      $NetBSD: Makefile,v 1.57 2012/06/03 21:02:50 joerg Exp $
 
 HOSTLIB=       nbcompat
 
-SRCS=          atoll.c basename.c dirname.c fgetln.c flock.c fparseln.c \
-               fpurge.c getline.c getmode.c getopt_long.c gettemp.c \
+SRCS=          atoll.c basename.c cdbw.c dirname.c \
+               fgetln.c flock.c fparseln.c fpurge.c \
+               getline.c getmode.c getopt_long.c gettemp.c \
                heapsort.c \
                issetugid.c lchflags.c lchmod.c lchown.c libyywrap.c \
                md2.c md2hl.c md4c.c md4hl.c md5c.c md5hl.c \
@@ -31,7 +32,8 @@
 CPPFLAGS+=     -I. -I./include -I${.CURDIR} -I${.CURDIR}/sys \
                -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64
 
-.PATH:         ${.CURDIR}/../../lib/libc/gen \
+.PATH:         ${.CURDIR}/../../lib/libc/cdb \
+               ${.CURDIR}/../../lib/libc/gen \
                ${.CURDIR}/../../lib/libc/hash \
                ${.CURDIR}/../../lib/libc/hash/md2 \
                ${.CURDIR}/../../lib/libc/hash/md5 \
diff -r 15054fc0fc0e -r 89a180ad23c0 tools/compat/cdbw.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/compat/cdbw.h       Sun Jun 03 21:02:50 2012 +0000
@@ -0,0 +1,5 @@
+/*     $NetBSD: cdbw.h,v 1.1 2012/06/03 21:02:50 joerg Exp $   */
+
+/* We unconditionally use the NetBSD cdbw(3) in libnbcompat. */
+#include "nbtool_config.h"
+#include "../../include/cdbw.h"



Home | Main Index | Thread Index | Old Index