This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
inline.h: Move some fcn '{' to column 1
[perl5.git] / regen / reentr.pl
index 49d7efa..0dbb79b 100644 (file)
@@ -18,7 +18,7 @@
 
 BEGIN {
     # Get function prototypes
-    require 'regen/regen_lib.pl';
+    require './regen/regen_lib.pl';
 }
 
 use strict;
@@ -62,8 +62,8 @@ sub open_print_header {
 
 my $h = open_print_header('reentr.h');
 print $h <<EOF;
-#ifndef REENTR_H
-#define REENTR_H
+#ifndef PERL_REENTR_H_
+#define PERL_REENTR_H_
 
 /* If compiling for a threaded perl, we will macro-wrap the system/library
  * interfaces (e.g. getpwent()) which have threaded versions
@@ -73,7 +73,7 @@ print $h <<EOF;
  */
 
 #ifndef PERL_REENTR_API
-# if defined(PERL_CORE) || defined(PERL_EXT)
+# if defined(PERL_CORE) || defined(PERL_EXT) || defined(PERL_REENTRANT)
 #  define PERL_REENTR_API 1
 # else
 #  define PERL_REENTR_API 0
@@ -91,13 +91,11 @@ print $h <<EOF;
 
 #ifdef __hpux
 #   undef HAS_CRYPT_R
-#   undef HAS_DRAND48_R
 #   undef HAS_ENDGRENT_R
 #   undef HAS_ENDPWENT_R
 #   undef HAS_GETGRENT_R
 #   undef HAS_GETPWENT_R
 #   undef HAS_SETLOCALE_R
-#   undef HAS_SRAND48_R
 #   undef HAS_STRERROR_R
 #   define NETDB_R_OBSOLETE
 #endif
@@ -108,6 +106,11 @@ print $h <<EOF;
 #   define NETDB_R_OBSOLETE
 #endif
 
+#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 24))
+#   undef HAS_READDIR_R
+#   undef HAS_READDIR64_R
+#endif
+
 /*
  * As of OpenBSD 3.7, reentrant functions are now working, they just are
  * incompatible with everyone else.  To make OpenBSD happy, we have to
@@ -151,9 +154,6 @@ print $h <<EOF;
 #ifdef I_NETDB
 #   include <netdb.h>
 #endif
-#ifdef I_STDLIB
-#   include <stdlib.h> /* drand48_data */
-#endif
 #ifdef I_CRYPT
 #   ifdef I_CRYPT
 #       include <crypt.h>
@@ -177,7 +177,7 @@ my %seend; # the type of this function's "D"
 my %seenm; # all the types
 my %seenu; # the length of the argument list of this function
 
-while (<DATA>) { # Read in the protypes.
+while (<DATA>) { # Read in the protoypes.
     next if /^\s+$/;
     chomp;
     my ($func, $hdr, $type, @p) = split(/\s*\|\s*/, $_, -1);
@@ -203,7 +203,7 @@ while (<DATA>) { # Read in the protypes.
     }
 
     # If given the -U option open up the metaconfig unit for this function.
-    if ($opts{U} && open(U, ">d_${func}_r.U"))  {
+    if ($opts{U} && open(U, ">", "d_${func}_r.U"))  {
        binmode U;
     }
 
@@ -504,30 +504,6 @@ EOF
 EOF
            pushssif $endif;
        }
-        elsif ($func =~ /^(drand48|random|srandom)$/) {
-           pushssif $ifdef;
-           push @struct, <<EOF;
-       $seent{$func} _${func}_struct;
-EOF
-           if ($1 eq 'drand48') {
-               push @struct, <<EOF;
-       double  _${func}_double;
-EOF
-           } elsif ($1 eq 'random') {
-           push @struct, <<EOF;
-#   if RANDOM_R_PROTO == REENTRANT_PROTO_I_iS
-       int     _${func}_retval;
-#   endif
-#   if RANDOM_R_PROTO == REENTRANT_PROTO_I_lS
-       long    _${func}_retval;
-#   endif
-#   if RANDOM_R_PROTO == REENTRANT_PROTO_I_St
-       int32_t _${func}_retval;
-#   endif
-EOF
-           }
-           pushssif $endif;
-       }
         elsif ($func =~ /^(getgrnam|getpwnam|getspnam)$/) {
            pushssif $ifdef;
            # 'genfunc' can be read either as 'generic' or 'genre',
@@ -564,16 +540,12 @@ EOF
        PL_reentrant_buffer->$sz = sysconf($sc);
        if (PL_reentrant_buffer->$sz == (size_t) -1)
                PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
-#   else
-#       if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
+#   elif defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
        PL_reentrant_buffer->$sz = SIABUFSIZ;
-#       else
-#           ifdef __sgi
+#   elif defined(__sgi)
        PL_reentrant_buffer->$sz = BUFSIZ;
-#           else
+#   else
        PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
-#           endif
-#       endif
 #   endif 
 EOF
            pushinitfree $genfunc;
@@ -587,7 +559,7 @@ EOF
            my $GENFUNC = uc $genfunc;
            my $D = ifprotomatch($FUNC, grep {/D/} @p);
            my $d = $seend{$func};
-           $d =~ s/\*$//; # snip: we need need the base type.
+           $d =~ s/\*$//; # snip: we need the base type.
            push @struct, <<EOF;
        $seent{$func}   _${genfunc}_struct;
 #   if $D
@@ -664,18 +636,12 @@ EOF
            my $genfunc = $func;
            if ($genfunc =~ /^(?:get|set|end)(pw|gr|host|net|proto|serv|sp)/) {
                $genfunc = "${1}ent";
-           } elsif ($genfunc eq 'srand48') {
-               $genfunc = "drand48";
            }
            my $b = $a;
            my $w = '';
            substr($b, 0, $seenu{$func}) = '';
-           if ($func =~ /^random$/) {
-               $true = "PL_reentrant_buffer->_random_retval";
-           } elsif ($b =~ /R/) {
+           if ($b =~ /R/) {
                $true = "PL_reentrant_buffer->_${genfunc}_ptr";
-           } elsif ($b =~ /T/ && $func eq 'drand48') {
-               $true = "PL_reentrant_buffer->_${genfunc}_double";
            } elsif ($b =~ /S/) {
                if ($func =~ /^readdir/) {
                    $true = "PL_reentrant_buffer->_${genfunc}_struct";
@@ -706,10 +672,6 @@ EOF
                                  $func =~ /^crypt$/ ?
                                  "PL_reentrant_buffer->_${genfunc}_struct_buffer" :
                                  "&PL_reentrant_buffer->_${genfunc}_struct") :
-                            $_ eq 'T' && $func eq 'drand48' ?
-                                "&PL_reentrant_buffer->_${genfunc}_double" :
-                            $_ =~ /^[ilt]$/ && $func eq 'random' ?
-                                "&PL_reentrant_buffer->_random_retval" :
                                 $_
                         } split '', $b;
                $w = ", $w" if length $v;
@@ -787,10 +749,16 @@ read_only_bottom_close_and_rename($h);
 # Prepare to write the reentr.c.
 
 my $c = open_print_header('reentr.c', <<'EOQ');
- *
+ */
+
+/*
  * "Saruman," I said, standing away from him, "only one hand at a time can
  *  wield the One, and you know that well, so do not trouble to say we!"
  *
+ *     [p.260 of _The Lord of the Rings_, II/ii: "The Council of Elrond"]
+ */
+
+/*
  * This file contains a collection of automatically created wrappers
  * (created by running reentr.pl) for reentrant (thread-safe) versions of
  * various library calls, such as getpwent_r.  The wrapping is done so
@@ -806,8 +774,16 @@ print $c <<"EOF";
 #include "perl.h"
 #include "reentr.h"
 
+#define RenewDouble(data_pointer, size_pointer, type) \\
+    STMT_START { \\
+       const size_t size = *(size_pointer) * 2; \\
+       Renew((data_pointer), (size), type); \\
+       *(size_pointer) = size; \\
+    } STMT_END
+
 void
 Perl_reentrant_size(pTHX) {
+       PERL_UNUSED_CONTEXT;
 #ifdef USE_REENTRANT_API
 #define REENTRANTSMALLSIZE      256    /* Make something up. */
 #define REENTRANTUSUALSIZE     4096    /* Make something up. */
@@ -817,6 +793,7 @@ Perl_reentrant_size(pTHX) {
 
 void
 Perl_reentrant_init(pTHX) {
+       PERL_UNUSED_CONTEXT;
 #ifdef USE_REENTRANT_API
        Newx(PL_reentrant_buffer, 1, REENTR);
        Perl_reentrant_size(aTHX);
@@ -826,6 +803,7 @@ Perl_reentrant_init(pTHX) {
 
 void
 Perl_reentrant_free(pTHX) {
+       PERL_UNUSED_CONTEXT;
 #ifdef USE_REENTRANT_API
 @free
        Safefree(PL_reentrant_buffer);
@@ -835,10 +813,10 @@ Perl_reentrant_free(pTHX) {
 void*
 Perl_reentrant_retry(const char *f, ...)
 {
-    dTHX;
     void *retptr = NULL;
     va_list ap;
 #ifdef USE_REENTRANT_API
+    dTHX;
     /* Easier to special case this here than in embed.pl. (Look at what it
        generates for proto.h) */
     PERL_ARGS_ASSERT_REENTRANT_RETRY;
@@ -870,9 +848,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_hostent_size *= 2;
-               Renew(PL_reentrant_buffer->_hostent_buffer,
-                     PL_reentrant_buffer->_hostent_size, char);
+               RenewDouble(PL_reentrant_buffer->_hostent_buffer,
+                       &PL_reentrant_buffer->_hostent_size, char);
                switch (PL_op->op_type) {
                case OP_GHBYADDR:
                    p0    = va_arg(ap, void *);
@@ -903,9 +880,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Gid_t gid;
-               PL_reentrant_buffer->_grent_size *= 2;
-               Renew(PL_reentrant_buffer->_grent_buffer,
-                     PL_reentrant_buffer->_grent_size, char);
+               RenewDouble(PL_reentrant_buffer->_grent_buffer,
+                     &PL_reentrant_buffer->_grent_size, char);
                switch (PL_op->op_type) {
                case OP_GGRNAM:
                    p0 = va_arg(ap, void *);
@@ -938,9 +914,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Netdb_net_t net;
-               PL_reentrant_buffer->_netent_size *= 2;
-               Renew(PL_reentrant_buffer->_netent_buffer,
-                     PL_reentrant_buffer->_netent_size, char);
+               RenewDouble(PL_reentrant_buffer->_netent_buffer,
+                     &PL_reentrant_buffer->_netent_size, char);
                switch (PL_op->op_type) {
                case OP_GNBYADDR:
                    net = va_arg(ap, Netdb_net_t);
@@ -970,9 +945,8 @@ Perl_reentrant_retry(const char *f, ...)
 #endif
            {
                Uid_t uid;
-               PL_reentrant_buffer->_pwent_size *= 2;
-               Renew(PL_reentrant_buffer->_pwent_buffer,
-                     PL_reentrant_buffer->_pwent_size, char);
+               RenewDouble(PL_reentrant_buffer->_pwent_buffer,
+                     &PL_reentrant_buffer->_pwent_size, char);
                switch (PL_op->op_type) {
                case OP_GPWNAM:
                    p0 = va_arg(ap, void *);
@@ -984,8 +958,10 @@ Perl_reentrant_retry(const char *f, ...)
                    uid = va_arg(ap, Uid_t);
 #endif
                    retptr = getpwuid(uid); break;
+#if defined(HAS_GETPWENT) || defined(HAS_GETPWENT_R)
                case OP_GPWENT:
                    retptr = getpwent(); break;
+#endif
                default:
                    SETERRNO(ERANGE, LIB_INVARG);
                    break;
@@ -1004,9 +980,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_protoent_size *= 2;
-               Renew(PL_reentrant_buffer->_protoent_buffer,
-                     PL_reentrant_buffer->_protoent_size, char);
+               RenewDouble(PL_reentrant_buffer->_protoent_buffer,
+                     &PL_reentrant_buffer->_protoent_size, char);
                switch (PL_op->op_type) {
                case OP_GPBYNAME:
                    p0 = va_arg(ap, void *);
@@ -1034,9 +1009,8 @@ Perl_reentrant_retry(const char *f, ...)
                PERL_REENTRANT_MAXSIZE / 2)
 #endif
            {
-               PL_reentrant_buffer->_servent_size *= 2;
-               Renew(PL_reentrant_buffer->_servent_buffer,
-                     PL_reentrant_buffer->_servent_size, char);
+               RenewDouble(PL_reentrant_buffer->_servent_buffer,
+                     &PL_reentrant_buffer->_servent_size, char);
                switch (PL_op->op_type) {
                case OP_GSBYNAME:
                    p0 = va_arg(ap, void *);
@@ -1076,7 +1050,6 @@ asctime S |time   |const struct tm|B_SB|B_SBI|I_SB|I_SBI
 crypt CC       |crypt  |struct crypt_data|B_CCS|B_CCD|D=CRYPTD*
 ctermid        B       |stdio  |               |B_B
 ctime S                |time   |const time_t   |B_SB|B_SBI|I_SB|I_SBI
-drand48                |stdlib |struct drand48_data    |I_ST|T=double*
 endgrent       |grp    |               |I_H|V_H
 endhostent     |netdb  |               |I_D|V_D|D=struct hostent_data*
 endnetent      |netdb  |               |I_D|V_D|D=struct netent_data*
@@ -1103,7 +1076,6 @@ getservbyname CC|netdb    |struct servent |I_CCSBWR|S_CCSBI|I_CCSD|D=struct servent
 getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data*
 getservent     |netdb  |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data*
 getspnam C     |shadow |struct spwd    |I_CSBWR|S_CSBI
-random         |stdlib |struct random_data|I_iS|I_lS|I_St|i=int*|l=long*|t=int32_t*
 readdir T      |dirent |struct dirent  |I_TSR|I_TS|T=DIR*
 readdir64 T    |dirent |struct dirent64|I_TSR|I_TS|T=DIR*
 setgrent       |grp    |               |I_H|V_H
@@ -1113,8 +1085,6 @@ setnetent I       |netdb  |               |I_ID|V_ID|D=struct netent_data*
 setprotoent I  |netdb  |               |I_ID|V_ID|D=struct protoent_data*
 setpwent       |pwd    |               |I_H|V_H
 setservent I   |netdb  |               |I_ID|V_ID|D=struct servent_data*
-srand48 L      |stdlib |struct drand48_data    |I_LS
-srandom        T       |stdlib |struct random_data|I_TS|T=unsigned int
 strerror I     |string |               |I_IBW|I_IBI|B_IBW
 tmpnam B       |stdio  |               |B_B
 ttyname        I       |unistd |               |I_IBW|I_IBI|B_IBI