# and optionally also the relevant metaconfig units (-U option).
#
+BEGIN {
+ # Get function prototypes
+ require 'regen_lib.pl';
+}
+
use strict;
use Getopt::Std;
my %opts;
# Example #3: S_CBI means type func_r(const char*, char*, int)
+safer_unlink 'reentr.h';
die "reentr.h: $!" unless open(H, ">reentr.h");
+binmode H;
select H;
print <<EOF;
-/*
+/* -*- buffer-read-only: t -*-
+ *
* reentr.h
*
- * Copyright (c) 1997-2003, Larry Wall
+ * Copyright (C) 2002, 2003, 2005, 2006, 2007 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
+
+/* If compiling for a threaded perl, we will macro-wrap the system/library
+ * interfaces (e.g. getpwent()) which have threaded versions
+ * (e.g. getpwent_r()), which will handle things correctly for
+ * the Perl interpreter, but otherwise (for XS) the wrapping does
+ * not take place. See L<perlxs/Thread-aware system interfaces>.
+ */
+
+#ifndef PERL_REENTR_API
+# if defined(PERL_CORE) || defined(PERL_EXT)
+# define PERL_REENTR_API 1
+# else
+# define PERL_REENTR_API 0
+# endif
+#endif
#ifdef USE_REENTRANT_API
* but they are declared obsolete and are not to be used. Often this
* means that the platform has threadsafed the interfaces (hopefully).
* All this is OS version dependent, so we are of course fooling ourselves.
- * If you know of more deprecations on some platforms, please add your own. */
+ * If you know of more deprecations on some platforms, please add your own
+ * (by editing reentr.pl, mind!) */
#ifdef __hpux
# undef HAS_CRYPT_R
# 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) 0
+#endif
+
#ifdef NETDB_R_OBSOLETE
# undef HAS_ENDHOSTENT_R
# undef HAS_ENDNETENT_R
# If given the -U option open up the metaconfig unit for this function.
if ($opts{U} && open(U, ">d_${func}_r.U")) {
+ binmode U;
select U;
}
sub pushinitfree {
my $func = shift;
push @init, <<EOF;
- New(31338, PL_reentrant_buffer->_${func}_buffer, PL_reentrant_buffer->_${func}_size, char);
+ Newx(PL_reentrant_buffer->_${func}_buffer, PL_reentrant_buffer->_${func}_size, char);
EOF
push @free, <<EOF;
Safefree(PL_reentrant_buffer->_${func}_buffer);
EOF
}
}
+ return if @F == 1;
push @define, <<EOF;
/* Any of the @F using \L$n? */
#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;
EOF
} elsif ($1 eq 'random') {
push @struct, <<EOF;
-# if RANDOM_R_PROTO == REENTRANT_PROTO_iS
+# if RANDOM_R_PROTO == REENTRANT_PROTO_I_iS
int _${func}_retval;
# endif
-# if RANDOM_R_PROTO == REENTRANT_PROTO_lS
+# if RANDOM_R_PROTO == REENTRANT_PROTO_I_lS
long _${func}_retval;
# endif
-# if RANDOM_R_PROTO == REENTRANT_PROTO_tS
+# if RANDOM_R_PROTO == REENTRANT_PROTO_I_St
int32_t _${func}_retval;
# endif
EOF
push @size, <<EOF;
# if defined(HAS_SYSCONF) && defined($sc) && !defined(__GLIBC__)
PL_reentrant_buffer->$sz = sysconf($sc);
- if (PL_reentrant_buffer->$sz == -1)
+ if (PL_reentrant_buffer->$sz == (size_t) -1)
PL_reentrant_buffer->$sz = REENTRANTUSUALSIZE;
# else
# if defined(__osf__) && defined(__alpha) && defined(SIABUFSIZ)
EOF
push @init, <<EOF;
#if !($D)
- New(31338, PL_reentrant_buffer->_${genfunc}_buffer, PL_reentrant_buffer->_${genfunc}_size, char);
+ Newx(PL_reentrant_buffer->_${genfunc}_buffer, PL_reentrant_buffer->_${genfunc}_size, char);
#endif
EOF
push @free, <<EOF;
push @wrap, $ifdef;
push @wrap, <<EOF;
+# if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
# undef $func
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' ?
} split '', $b;
$w = ", $w" if length $v;
}
+
my $call = "${func}_r($v$w)";
- $call = "((errno = $call))" if $r eq 'I' && $func ne 'random';
+ if ($func eq 'localtime') {
+ $call = "L_R_TZSET $call";
+ }
+
+ # 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
} 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) ($memzero(PL_reentrant_retint = $call)$test ? $true : ((PL_reentrant_retint == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
+EOF
+ } else {
+ push @wrap, <<EOF;
+# define $func($v) ($call$test ? $true : ((errno == ERANGE) ? ($seent{$func} *) Perl_reentrant_retry("$func"$rv) : 0))
EOF
+ }
} else {
push @wrap, <<EOF;
# define $func($v) ($call$test ? $true : 0)
}
}
push @wrap, <<EOF;
-# endif
+# endif /* if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1) */
EOF
}
+ push @wrap, <<EOF;
+# endif /* HAS_\U$func */
+EOF
+
push @wrap, $endif, "\n";
}
}
/* The wrappers. */
@wrap
+
#endif /* USE_REENTRANT_API */
#endif
+/* ex: set ro: */
EOF
close(H);
# Prepare to write the reentr.c.
+safer_unlink 'reentr.c';
die "reentr.c: $!" unless open(C, ">reentr.c");
+binmode C;
select C;
print <<EOF;
-/*
+/* -*- buffer-read-only: t -*-
+ *
* reentr.c
*
- * Copyright (c) 1997-2003, Larry Wall
+ * Copyright (C) 2002, 2003, 2005, 2006, 2007 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"
void
Perl_reentrant_init(pTHX) {
#ifdef USE_REENTRANT_API
- New(31337, PL_reentrant_buffer, 1, REENTR);
+ Newx(PL_reentrant_buffer, 1, REENTR);
Perl_reentrant_size(aTHX);
@init
#endif /* USE_REENTRANT_API */
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)
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:
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);
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:
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);
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;
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:
}
va_end(ap);
+#else
+ PERL_UNUSED_ARG(f);
#endif
return retptr;
}
+/* ex: set ro: */
EOF
__DATA__
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*