This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make pp_split const
[perl5.git] / reentr.pl
index ef18bfa..a38eab1 100644 (file)
--- a/reentr.pl
+++ b/reentr.pl
@@ -38,20 +38,21 @@ my %map = (
 die "reentr.h: $!" unless open(H, ">reentr.h");
 select H;
 print <<EOF;
-/*
+/* -*- buffer-read-only: t -*-
+ *
  *    reentr.h
  *
- *    Copyright (C) 2002, 2003, by Larry Wall and others
+ *    Copyright (C) 2002, 2003, 2005 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.
  *
  *  !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
- *  This file is built by reentrl.pl from data in reentr.pl.
+ *  This file is built by reentr.pl from data in reentr.pl.
  */
 
 #ifndef REENTR_H
-#define REENTR_H 
+#define REENTR_H
 
 #ifdef USE_REENTRANT_API
  
@@ -80,6 +81,17 @@ print <<EOF;
 #   define NETDB_R_OBSOLETE
 #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
+ * memzero out certain structures before calling the functions.
+ */
+#if defined(__OpenBSD__)
+#    define REENTR_MEMZERO(a,b) memzero(a,b),
+#else
+#    define REENTR_MEMZERO(a,b)
+#endif 
+
 #ifdef NETDB_R_OBSOLETE
 #   undef HAS_ENDHOSTENT_R
 #   undef HAS_ENDNETENT_R
@@ -469,7 +481,7 @@ EOF
 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;
@@ -679,6 +691,13 @@ EOF
                $w = ", $w" if length $v;
            }
            my $call = "${func}_r($v$w)";
+
+            # Must make OpenBSD happy
+            my $memzero = '';
+            if($p =~ /D$/ &&
+                ($genfunc eq 'protoent' || $genfunc eq 'servent')) {
+                $memzero = 'REENTR_MEMZERO(&PL_reentrant_buffer->_' . $genfunc . '_data, sizeof(PL_reentrant_buffer->_' . $genfunc . '_data))';
+            }
            push @wrap, <<EOF;
 #   if !defined($func) && ${FUNC}_R_PROTO == REENTRANT_PROTO_$p
 EOF
@@ -691,11 +710,11 @@ EOF
                    my $rv = $v ? ", $v" : "";
                    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))
+#       define $func($v) ($memzero(PL_reentrant_retint = $call)$test ? $true : (((PL_reentrant_retint == ERANGE) || (errno == ERANGE)) ? ($seent{$func} *) 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))
+#       define $func($v) ($call$test ? $true : ((errno == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
 EOF
                     }
                } else {
@@ -733,6 +752,7 @@ typedef struct {
  
 #endif
 
+/* ex: set ro: */
 EOF
 
 close(H);
@@ -742,20 +762,27 @@ close(H);
 die "reentr.c: $!" unless open(C, ">reentr.c");
 select C;
 print <<EOF;
-/*
+/* -*- buffer-read-only: t -*-
+ *
  *    reentr.c
  *
- *    Copyright (C) 2002, 2003, by Larry Wall and others
+ *    Copyright (C) 2002, 2003, 2005 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.
  *
  *  !!!!!!!   DO NOT EDIT THIS FILE   !!!!!!!
- *  This file is built by reentrl.pl from data in reentr.pl.
+ *  This file is built by reentr.pl from data in reentr.pl.
  *
  * "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!"
  *
+ * 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
+ * that other files like pp_sys.c calling those library functions need not
+ * care about the differences between various platforms' idiosyncrasies
+ * regarding these reentrant interfaces.  
  */
 
 #include "EXTERN.h"
@@ -833,7 +860,7 @@ Perl_reentrant_retry(const char *f, ...)
                    retptr = gethostbyaddr(p0, asize, anint); break;
                case OP_GHBYNAME:
                    p0 = va_arg(ap, void *);
-                   retptr = gethostbyname(p0); break;
+                   retptr = gethostbyname((char *)p0); break;
                case OP_GHOSTENT:
                    retptr = gethostent(); break;
                default:
@@ -861,7 +888,7 @@ Perl_reentrant_retry(const char *f, ...)
                switch (PL_op->op_type) {
                case OP_GGRNAM:
                    p0 = va_arg(ap, void *);
-                   retptr = getgrnam(p0); break;
+                   retptr = getgrnam((char *)p0); break;
                case OP_GGRGID:
 #if Gid_t_size < INTSIZE
                    gid = (Gid_t)va_arg(ap, int);
@@ -900,7 +927,7 @@ Perl_reentrant_retry(const char *f, ...)
                    retptr = getnetbyaddr(net, anint); break;
                case OP_GNBYNAME:
                    p0 = va_arg(ap, void *);
-                   retptr = getnetbyname(p0); break;
+                   retptr = getnetbyname((char *)p0); break;
                case OP_GNETENT:
                    retptr = getnetent(); break;
                default:
@@ -928,7 +955,7 @@ Perl_reentrant_retry(const char *f, ...)
                switch (PL_op->op_type) {
                case OP_GPWNAM:
                    p0 = va_arg(ap, void *);
-                   retptr = getpwnam(p0); break;
+                   retptr = getpwnam((char *)p0); break;
                case OP_GPWUID:
 #if Uid_t_size < INTSIZE
                    uid = (Uid_t)va_arg(ap, int);
@@ -962,7 +989,7 @@ Perl_reentrant_retry(const char *f, ...)
                switch (PL_op->op_type) {
                case OP_GPBYNAME:
                    p0 = va_arg(ap, void *);
-                   retptr = getprotobyname(p0); break;
+                   retptr = getprotobyname((char *)p0); break;
                case OP_GPBYNUMBER:
                    anint = va_arg(ap, int);
                    retptr = getprotobynumber(anint); break;
@@ -993,11 +1020,11 @@ Perl_reentrant_retry(const char *f, ...)
                case OP_GSBYNAME:
                    p0 = va_arg(ap, void *);
                    p1 = va_arg(ap, void *);
-                   retptr = getservbyname(p0, p1); break;
+                   retptr = getservbyname((char *)p0, (char *)p1); break;
                case OP_GSBYPORT:
                    anint = va_arg(ap, int);
                    p0 = va_arg(ap, void *);
-                   retptr = getservbyport(anint, p0); break;
+                   retptr = getservbyport(anint, (char *)p0); break;
                case OP_GSERVENT:
                    retptr = getservent(); break;
                default:
@@ -1018,6 +1045,7 @@ Perl_reentrant_retry(const char *f, ...)
     return retptr;
 }
 
+/* ex: set ro: */
 EOF
 
 __DATA__
@@ -1038,7 +1066,7 @@ 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|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
+getlogin       |unistd |char           |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|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*