This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove small memory leak in newATTRSUB that manifested as a
[perl5.git] / reentr.pl
index 0e1cefd..0622a80 100644 (file)
--- a/reentr.pl
+++ b/reentr.pl
@@ -41,7 +41,7 @@ print <<EOF;
 /*
  *    reentr.h
  *
- *    Copyright (c) 1997-2003, Larry Wall
+ *    Copyright (C) 2002, 2003, by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -135,6 +135,7 @@ my %seenp; # the different prototype signatures for all functions
 my %seent; # the return type of this function
 my %seens; # the type of this function's "S"
 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.
@@ -188,7 +189,7 @@ while (<DATA>) { # Read in the protypes.
        print <<EOF;
 ?RCS: \$Id: d_${func}_r.U,v $
 ?RCS:
-?RCS: Copyright (c) 2002 Jarkko Hietaniemi
+?RCS: Copyright (c) 2002,2003 Jarkko Hietaniemi
 ?RCS:
 ?RCS: You may distribute under the terms of either the GNU General Public
 ?RCS: License or the Artistic License, as specified in the README file.
@@ -259,6 +260,7 @@ EOF
         $seent{$func} = $type;
         $seens{$func} = $m{S};
         $seend{$func} = $m{D};
+       $seenm{$func} = \%m;
     }
     if ($opts{U}) {
        print <<EOF;
@@ -363,6 +365,7 @@ EOF
 EOF
         }
     }
+    return if @F == 1;
     push @define, <<EOF;
 
 /* Any of the @F using \L$n? */
@@ -451,19 +454,22 @@ EOF
 #if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
        $seend{$func} _${func}_data;
 #else
-       $seent{$func} _${func}_struct;
+       $seent{$func} *_${func}_struct_buffer;
 #endif
 EOF
            push @init, <<EOF;
-#ifdef __GLIBC__
-       PL_reentrant_buffer->_${func}_struct.initialized = 0;
-       /* work around glibc-2.2.5 bug */
-       PL_reentrant_buffer->_${func}_struct.current_saltbits = 0;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       PL_reentrant_buffer->_${func}_struct_buffer = 0;
+#endif
+EOF
+           push @free, <<EOF;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       Safefree(PL_reentrant_buffer->_${func}_struct_buffer);
 #endif
 EOF
            pushssif $endif;
        }
-        elsif ($func =~ /^(drand48|gmtime|localtime|random)$/) {
+        elsif ($func =~ /^(drand48|gmtime|localtime|random|srandom)$/) {
            pushssif $ifdef;
            push @struct, <<EOF;
        $seent{$func} _${func}_struct;
@@ -472,6 +478,18 @@ EOF
                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;
        }
@@ -616,7 +634,9 @@ EOF
            my $b = $a;
            my $w = '';
            substr($b, 0, $seenu{$func}) = '';
-           if ($b =~ /R/) {
+           if ($func =~ /^random$/) {
+               $true = "PL_reentrant_buffer->_random_retval";
+           } elsif ($b =~ /R/) {
                $true = "PL_reentrant_buffer->_${genfunc}_ptr";
            } elsif ($b =~ /T/ && $func eq 'drand48') {
                $true = "PL_reentrant_buffer->_${genfunc}_double";
@@ -645,17 +665,20 @@ EOF
                             $_ eq 'D' ?
                                 "&PL_reentrant_buffer->_${genfunc}_data" :
                             $_ eq 'S' ?
-                                ($func =~ /^readdir/ ?
+                                ($func =~ /^readdir\d*$/ ?
                                  "PL_reentrant_buffer->_${genfunc}_struct" :
-                                 "&PL_reentrant_buffer->_${genfunc}_struct" ) :
+                                 $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;
            }
            my $call = "${func}_r($v$w)";
-           $call = "((errno = $call))" if $r eq 'I';
            push @wrap, <<EOF;
 #   if !defined($func) && ${FUNC}_R_PROTO == REENTRANT_PROTO_$p
 EOF
@@ -666,9 +689,15 @@ EOF
            } else {
                if ($func =~ /^get/) {
                    my $rv = $v ? ", $v" : "";
-                   push @wrap, <<EOF;
-#       define $func($v) ($call$test ? $true : (errno == ERANGE ? Perl_reentrant_retry("$func"$rv) : 0))
+                   if ($r eq 'I') {
+                       push @wrap, <<EOF;
+#       define $func($v) ((PL_reentrant_retint = $call)$test ? $true : (((PL_reentrant_retint == ERANGE) || (errno == ERANGE)) ? Perl_reentrant_retry("$func"$rv) : 0))
+EOF
+                   } else {
+                       push @wrap, <<EOF;
+#       define $func($v) ($call$test ? $true : ((errno == ERANGE) ? Perl_reentrant_retry("$func"$rv) : 0))
 EOF
+                    }
                } else {
                    push @wrap, <<EOF;
 #       define $func($v) ($call$test ? $true : 0)
@@ -699,6 +728,7 @@ typedef struct {
 /* The wrappers. */
 
 @wrap
+
 #endif /* USE_REENTRANT_API */
  
 #endif
@@ -715,7 +745,7 @@ print <<EOF;
 /*
  *    reentr.c
  *
- *    Copyright (c) 1997-2003, Larry Wall
+ *    Copyright (C) 2002, 2003, by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -765,7 +795,7 @@ Perl_reentrant_retry(const char *f, ...)
     dTHX;
     void *retptr = NULL;
 #ifdef USE_REENTRANT_API
-#  if defined(USE_HOSTENT_BUFFER) || defined(USE_GRENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PWENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SRVENT_BUFFER)
+#  if defined(USE_HOSTENT_BUFFER) || defined(USE_GRENT_BUFFER) || defined(USE_NETENT_BUFFER) || defined(USE_PWENT_BUFFER) || defined(USE_PROTOENT_BUFFER) || defined(USE_SERVENT_BUFFER)
     void *p0;
 #  endif
 #  if defined(USE_SERVENT_BUFFER)
@@ -833,7 +863,11 @@ Perl_reentrant_retry(const char *f, ...)
                    p0 = va_arg(ap, void *);
                    retptr = getgrnam(p0); break;
                case OP_GGRGID:
+#if Gid_t_size < INTSIZE
+                   gid = (Gid_t)va_arg(ap, int);
+#else
                    gid = va_arg(ap, Gid_t);
+#endif
                    retptr = getgrgid(gid); break;
                case OP_GGRENT:
                    retptr = getgrent(); break;
@@ -896,7 +930,11 @@ Perl_reentrant_retry(const char *f, ...)
                    p0 = va_arg(ap, void *);
                    retptr = getpwnam(p0); break;
                case OP_GPWUID:
+#if Uid_t_size < INTSIZE
+                   uid = (Uid_t)va_arg(ap, int);
+#else
                    uid = va_arg(ap, Uid_t);
+#endif
                    retptr = getpwuid(uid); break;
                case OP_GPWENT:
                    retptr = getpwent(); break;
@@ -997,11 +1035,11 @@ endservent       |netdb  |               |I_D|V_D|D=struct servent_data*
 getgrent       |grp    |struct group   |I_SBWR|I_SBIR|S_SBW|S_SBI|I_SBI|I_SBIH
 getgrgid T     |grp    |struct group   |I_TSBWR|I_TSBIR|I_TSBI|S_TSBI|T=gid_t
 getgrnam C     |grp    |struct group   |I_CSBWR|I_CSBIR|S_CBI|I_CSBI|S_CSBI
-gethostbyaddr CWI      |netdb  |struct hostent |I_CWISBWRE|S_CWISBWIE|S_CWISBIE|S_TWISBIE|S_CIISBIE|S_CSBIE|S_TSBIE|I_CWISD|I_CIISD|I_CII|D=struct hostent_data*|T=const void*
+gethostbyaddr CWI      |netdb  |struct hostent |I_CWISBWRE|S_CWISBWIE|S_CWISBIE|S_TWISBIE|S_CIISBIE|S_CSBIE|S_TSBIE|I_CWISD|I_CIISD|I_CII|I_TsISBWRE|D=struct hostent_data*|T=const void*|s=socklen_t
 gethostbyname C        |netdb  |struct hostent |I_CSBWRE|S_CSBIE|I_CSD|D=struct hostent_data*
 gethostent     |netdb  |struct hostent |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct hostent_data*
 getlogin       |unistd |               |I_BW|I_BI|B_BW|B_BI
-getnetbyaddr LI        |netdb  |struct netent  |I_UISBWRE|I_LISBI|S_TISBI|S_LISBI|I_TISD|I_LISD|I_IISD|D=struct netent_data*|T=in_addr_t|U=unsigned long
+getnetbyaddr LI        |netdb  |struct netent  |I_UISBWRE|I_LISBI|S_TISBI|S_LISBI|I_TISD|I_LISD|I_IISD|I_uISBWRE|D=struct netent_data*|T=in_addr_t|U=unsigned long|u=uint32_t
 getnetbyname C |netdb  |struct netent  |I_CSBWRE|I_CSBI|S_CSBI|I_CSD|D=struct netent_data*
 getnetent      |netdb  |struct netent  |I_SBWRE|I_SBIE|S_SBIE|S_SBI|I_SBI|I_SD|D=struct netent_data*
 getprotobyname C|netdb |struct protoent|I_CSBWR|S_CSBI|I_CSD|D=struct protoent_data*
@@ -1016,7 +1054,7 @@ 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
 gmtime T       |time   |struct tm      |S_TS|I_TS|T=const time_t*
 localtime T    |time   |struct tm      |S_TS|I_TS|T=const time_t*
-random         |stdlib |struct random_data|I_TS|T=int*
+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