Index: feature.h =================================================================== RCS file: /cvs/src/gnu/usr.bin/perl/feature.h,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 feature.h --- feature.h 17 Nov 2014 20:52:36 -0000 1.1.1.3 +++ feature.h 22 Nov 2014 20:33:41 -0000 @@ -73,6 +73,13 @@ FEATURE_IS_ENABLED("postderef") \ ) +#define FEATURE_ARC4RANDOM_IS_ENABLED \ + ( \ + CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_DEFAULT \ + || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ + FEATURE_IS_ENABLED("arc4random")) \ + ) + #define FEATURE_ARYBASE_IS_ENABLED \ ( \ CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_511 \ Index: util.c =================================================================== RCS file: /cvs/src/gnu/usr.bin/perl/util.c,v retrieving revision 1.21 diff -u -p -r1.21 util.c --- util.c 17 Nov 2014 21:00:55 -0000 1.21 +++ util.c 22 Nov 2014 20:33:41 -0000 @@ -25,6 +25,7 @@ #define PERL_IN_UTIL_C #include "perl.h" #include "reentr.h" +#include "feature.h" #if defined(USE_PERLIO) #include "perliol.h" /* For PerlIOUnix_refcnt */ @@ -4408,9 +4409,9 @@ Perl_parse_unicode_opts(pTHX_ const char U32 Perl_seed(pTHX) { -#if defined(__OpenBSD__) - return arc4random(); -#else + if (FEATURE_ARC4RANDOM_IS_ENABLED) + return 0; + dVAR; /* * This is really just a quick hack which grabs various garbage @@ -4487,7 +4488,6 @@ Perl_seed(pTHX) u += SEED_C5 * (U32)PTR2UV(&when); #endif return u; -#endif } void @@ -5434,6 +5434,12 @@ Perl_drand48_init_r(perl_drand48_t *rand { PERL_ARGS_ASSERT_DRAND48_INIT_R; + if (FEATURE_ARC4RANDOM_IS_ENABLED) { + if (seed != 0) + Perl_croak(aTHX_ "srand with seed not allowed with arc4random"); + /* else, do nothing */ + } + else { /* !FEATURE_ARC4RANDOM_IS_ENABLED */ #ifdef PERL_DRAND48_QUAD *random_state = FREEBSD_DRAND48_SEED_0 + ((U64TYPE)seed << 16); #else @@ -5441,12 +5447,25 @@ Perl_drand48_init_r(perl_drand48_t *rand random_state->seed[1] = (U16) seed; random_state->seed[2] = (U16) (seed >> 16); #endif + } /* !FEATURE_ARC4RANDOM_IS_ENABLED */ } +/* Obviously not quite what is wanted, but something like this */ +#ifndef __OpenBSD__ +uint32_t +arc4random() { + Perl_croak(aTHX_ "arc4random is not available"); + return 0; /* notreached */ +} +#endif /* __OpenBSD__ */ + double Perl_drand48_r(perl_drand48_t *random_state) { PERL_ARGS_ASSERT_DRAND48_R; + + if (FEATURE_ARC4RANDOM_IS_ENABLED) + return ldexp(arc4random(), -32); #ifdef PERL_DRAND48_QUAD *random_state = (*random_state * DRAND48_MULT + DRAND48_ADD) Index: lib/feature.pm =================================================================== RCS file: /cvs/src/gnu/usr.bin/perl/lib/feature.pm,v retrieving revision 1.1.1.6 diff -u -p -r1.1.1.6 feature.pm --- lib/feature.pm 17 Nov 2014 20:53:07 -0000 1.1.1.6 +++ lib/feature.pm 22 Nov 2014 20:33:42 -0000 @@ -14,6 +14,7 @@ our %feature = ( switch => 'feature_switch', evalbytes => 'feature_evalbytes', postderef => 'feature_postderef', + arc4random => 'feature_arc4random', array_base => 'feature_arybase', signatures => 'feature_signatures', current_sub => 'feature___SUB__', @@ -27,8 +28,8 @@ our %feature_bundle = ( "5.10" => [qw(array_base say state switch)], "5.11" => [qw(array_base say state switch unicode_strings)], "5.15" => [qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)], - "all" => [qw(array_base current_sub evalbytes fc lexical_subs postderef postderef_qq say signatures state switch unicode_eval unicode_strings)], - "default" => [qw(array_base)], + "all" => [qw(arc4random array_base current_sub evalbytes fc lexical_subs postderef postderef_qq say signatures state switch unicode_eval unicode_strings)], + "default" => [qw(arc4random array_base)], ); $feature_bundle{"5.12"} = $feature_bundle{"5.11"}; @@ -278,7 +279,7 @@ The following feature bundles are availa bundle features included --------- ----------------- - :default array_base + :default array_base arc4random :5.10 say state switch array_base Index: regen/feature.pl =================================================================== RCS file: /cvs/src/gnu/usr.bin/perl/regen/feature.pl,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 feature.pl --- regen/feature.pl 17 Nov 2014 20:53:19 -0000 1.1.1.3 +++ regen/feature.pl 22 Nov 2014 20:33:42 -0000 @@ -35,6 +35,7 @@ my %feature = ( unicode_strings => 'unicode', fc => 'fc', signatures => 'signatures', + arc4random => 'arc4random', ); # NOTE: If a feature is ever enabled in a non-contiguous range of Perl @@ -44,7 +45,7 @@ my %feature = ( # 5.odd implies the next 5.even, but an explicit 5.even can override it. my %feature_bundle = ( all => [ keys %feature ], - default => [qw(array_base)], + default => [qw(array_base arc4random)], "5.9.5" => [qw(say state switch array_base)], "5.10" => [qw(say state switch array_base)], "5.11" => [qw(say state switch unicode_strings array_base)],