[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] random_r: new module
From: |
Jim Meyering |
Subject: |
Re: [PATCH] random_r: new module |
Date: |
Thu, 23 Oct 2008 16:29:49 +0200 |
Thanks for the thorough review.
Here's an incremental addressing the things you spotted.
I would have spotted the decl-after-stmt problems but for a bug in
gcc-4.3 and newer: http://thread.gmane.org/gmane.comp.gcc.bugs/228246
I'll squash it into the first one and apply shortly.
>From a07b7f3a69902d491f7f49ccd5343e20095199a7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 23 Oct 2008 14:26:13 +0200
Subject: [PATCH] address Bruno's review feedback
---
doc/glibc-functions/initstate_r.texi | 6 +++---
doc/glibc-functions/random_r.texi | 6 +++---
doc/glibc-functions/setstate_r.texi | 6 +++---
doc/glibc-functions/srandom_r.texi | 6 +++---
lib/random_r.c | 17 ++++++++++++-----
lib/stdlib.in.h | 16 ++++++++--------
modules/random_r | 2 --
tests/test-random_r.c | 2 +-
8 files changed, 33 insertions(+), 28 deletions(-)
diff --git a/doc/glibc-functions/initstate_r.texi
b/doc/glibc-functions/initstate_r.texi
index f1eed08..238d5dd 100644
--- a/doc/glibc-functions/initstate_r.texi
+++ b/doc/glibc-functions/initstate_r.texi
@@ -6,11 +6,11 @@ Gnulib module: random_r
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
diff --git a/doc/glibc-functions/random_r.texi
b/doc/glibc-functions/random_r.texi
index 96f9384..be20c04 100644
--- a/doc/glibc-functions/random_r.texi
+++ b/doc/glibc-functions/random_r.texi
@@ -6,11 +6,11 @@ Gnulib module: random_r
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
diff --git a/doc/glibc-functions/setstate_r.texi
b/doc/glibc-functions/setstate_r.texi
index 990fb5a..631e125 100644
--- a/doc/glibc-functions/setstate_r.texi
+++ b/doc/glibc-functions/setstate_r.texi
@@ -6,11 +6,11 @@ Gnulib module: random_r
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
diff --git a/doc/glibc-functions/srandom_r.texi
b/doc/glibc-functions/srandom_r.texi
index 2e32d15..0af243f 100644
--- a/doc/glibc-functions/srandom_r.texi
+++ b/doc/glibc-functions/srandom_r.texi
@@ -6,11 +6,11 @@ Gnulib module: random_r
Portability problems fixed by Gnulib:
@itemize
address@hidden
+This function is missing on some platforms:
+MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, HP-UX 11, IRIX 6.5,
Solaris 10, Cygwin, mingw, Interix 3.5.
@end itemize
diff --git a/lib/random_r.c b/lib/random_r.c
index 40bb005..fa99573 100644
--- a/lib/random_r.c
+++ b/lib/random_r.c
@@ -52,6 +52,8 @@
* Rewritten to be reentrant by Ulrich Drepper, 1995
*/
+#include <config.h>
+
#include <errno.h>
#include <limits.h>
#include <stddef.h>
@@ -239,10 +241,16 @@ int
__initstate_r (unsigned int seed, char *arg_state, size_t n,
struct random_data *buf)
{
+ int32_t *old_state;
+ int32_t *state;
+ int type;
+ int degree;
+ int separation;
+
if (buf == NULL)
goto fail;
- int32_t *old_state = buf->state;
+ old_state = buf->state;
if (old_state != NULL)
{
int old_type = buf->rand_type;
@@ -252,7 +260,6 @@ __initstate_r (unsigned int seed, char *arg_state, size_t n,
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
}
- int type;
if (n >= BREAK_3)
type = n < BREAK_4 ? TYPE_3 : TYPE_4;
else if (n < BREAK_1)
@@ -267,13 +274,13 @@ __initstate_r (unsigned int seed, char *arg_state, size_t
n,
else
type = n < BREAK_2 ? TYPE_1 : TYPE_2;
- int degree = random_poly_info.degrees[type];
- int separation = random_poly_info.seps[type];
+ degree = random_poly_info.degrees[type];
+ separation = random_poly_info.seps[type];
buf->rand_type = type;
buf->rand_sep = separation;
buf->rand_deg = degree;
- int32_t *state = &((int32_t *) arg_state)[1]; /* First location. */
+ state = &((int32_t *) arg_state)[1]; /* First location. */
/* Must set END_PTR before srandom. */
buf->end_ptr = &state[degree];
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 997cf37..b44703b 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -232,25 +232,25 @@ int random_r (struct random_data *buf, int32_t *result);
# endif
#elif defined GNULIB_POSIXCHECK
# undef random_r
-# define random_r(r) \
+# define random_r(b,r) \
(GL_LINK_WARNING ("random_r is unportable - " \
"use gnulib module random_r for portability"), \
- random_r (r))
+ random_r (b,r))
# undef initstate_r
-# define initstate_r(r) \
+# define initstate_r(s,b,sz,r) \
(GL_LINK_WARNING ("initstate_r is unportable - " \
"use gnulib module random_r for portability"), \
- initstate_r (r))
+ initstate_r (s,b,sz,r))
# undef srandom_r
-# define srandom_r(r) \
+# define srandom_r(s,r) \
(GL_LINK_WARNING ("srandom_r is unportable - " \
"use gnulib module random_r for portability"), \
- srandom_r (r))
+ srandom_r (s,r))
# undef setstate_r
-# define setstate_r(r) \
+# define setstate_r(a,r) \
(GL_LINK_WARNING ("setstate_r is unportable - " \
"use gnulib module random_r for portability"), \
- setstate_r (r))
+ setstate_r (a,r))
#endif
diff --git a/modules/random_r b/modules/random_r
index 40d3d41..ad5c0f5 100644
--- a/modules/random_r
+++ b/modules/random_r
@@ -6,7 +6,6 @@ lib/random_r.c
m4/random_r.m4
Depends-on:
-errno
stdlib
configure.ac:
@@ -14,7 +13,6 @@ gl_FUNC_RANDOM_R
gl_STDLIB_MODULE_INDICATOR([random_r])
Makefile.am:
-lib_SOURCES += random_r.c
Include:
#include <stdlib.h>
diff --git a/tests/test-random_r.c b/tests/test-random_r.c
index a236b0a..5308f73 100644
--- a/tests/test-random_r.c
+++ b/tests/test-random_r.c
@@ -40,7 +40,7 @@ main ()
unsigned int n_big = 0;
rand_state.state = NULL;
- if (initstate_r (time (0), buf, sizeof buf, &rand_state))
+ if (initstate_r (time (NULL), buf, sizeof buf, &rand_state))
return 1;
for (i = 0; i < 1000; i++)
{
--
1.6.0.3
- [PATCH] random_r: new module, Jim Meyering, 2008/10/22
- Re: [PATCH] random_r: new module, Bruno Haible, 2008/10/22
- Re: [PATCH] random_r: new module, Simon Josefsson, 2008/10/23
- Re: [PATCH] random_r: new module, Richard W.M. Jones, 2008/10/23
- Re: [PATCH] random_r: new module, Simon Josefsson, 2008/10/23
- Re: [PATCH] random_r: new module, Simon Josefsson, 2008/10/24
- Re: [PATCH] random_r: new module, Jim Meyering, 2008/10/24