From: Artur Bergman <sky@nanisky.com>
Date: Thu, 12 Jul 2001 00:58:21 +0000 (+0200)
Subject: Use reentrant API glibc
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e5dd39fcc65538f6d292cb5228105f85fe9eff3e;p=p5sagit%2Fp5-mst-13.2.git

Use reentrant API glibc
Message-ID: <B772A6AD.2288%artur@contiller.se>

p4raw-id: //depot/perl@11283
---

diff --git a/embedvar.h b/embedvar.h
index 80b2e3e..34d781f 100644
--- a/embedvar.h
+++ b/embedvar.h
@@ -360,6 +360,7 @@
 #define PL_psig_pend		(PERL_GET_INTERP->Ipsig_pend)
 #define PL_psig_ptr		(PERL_GET_INTERP->Ipsig_ptr)
 #define PL_ptr_table		(PERL_GET_INTERP->Iptr_table)
+#define PL_reentrant_buffer	(PERL_GET_INTERP->Ireentrant_buffer)
 #define PL_regex_pad		(PERL_GET_INTERP->Iregex_pad)
 #define PL_regex_padav		(PERL_GET_INTERP->Iregex_padav)
 #define PL_replgv		(PERL_GET_INTERP->Ireplgv)
@@ -644,6 +645,7 @@
 #define PL_psig_pend		(vTHX->Ipsig_pend)
 #define PL_psig_ptr		(vTHX->Ipsig_ptr)
 #define PL_ptr_table		(vTHX->Iptr_table)
+#define PL_reentrant_buffer	(vTHX->Ireentrant_buffer)
 #define PL_regex_pad		(vTHX->Iregex_pad)
 #define PL_regex_padav		(vTHX->Iregex_padav)
 #define PL_replgv		(vTHX->Ireplgv)
@@ -1065,6 +1067,7 @@
 #define PL_psig_pend		(aTHXo->interp.Ipsig_pend)
 #define PL_psig_ptr		(aTHXo->interp.Ipsig_ptr)
 #define PL_ptr_table		(aTHXo->interp.Iptr_table)
+#define PL_reentrant_buffer	(aTHXo->interp.Ireentrant_buffer)
 #define PL_regex_pad		(aTHXo->interp.Iregex_pad)
 #define PL_regex_padav		(aTHXo->interp.Iregex_padav)
 #define PL_replgv		(aTHXo->interp.Ireplgv)
@@ -1350,6 +1353,7 @@
 #define PL_Ipsig_pend		PL_psig_pend
 #define PL_Ipsig_ptr		PL_psig_ptr
 #define PL_Iptr_table		PL_ptr_table
+#define PL_Ireentrant_buffer	PL_reentrant_buffer
 #define PL_Iregex_pad		PL_regex_pad
 #define PL_Iregex_padav		PL_regex_padav
 #define PL_Ireplgv		PL_replgv
diff --git a/intrpvar.h b/intrpvar.h
index 6447b27..a346ffe 100644
--- a/intrpvar.h
+++ b/intrpvar.h
@@ -478,6 +478,8 @@ PERLVAR(Inumeric_radix_sv,	SV *)	/* The radix separator if not '.' */
 #if defined(USE_ITHREADS)
 PERLVAR(Iregex_pad,     SV**)    /* All regex objects */
 PERLVAR(Iregex_padav,   AV*)    /* All regex objects */
+
+PERLVAR(Ireentrant_buffer, REBUF*) /* were we store _r buffers */
 #endif
 
 /* New variables must be added to the very end for binary compatibility.
diff --git a/op.h b/op.h
index 33afa0a..05fe77e 100644
--- a/op.h
+++ b/op.h
@@ -456,3 +456,12 @@ struct loop {
 #define PERL_LOADMOD_DENY		0x1
 #define PERL_LOADMOD_NOIMPORT		0x2
 #define PERL_LOADMOD_IMPORT_OPS		0x4
+
+#ifdef USE_REENTRANT_API
+typedef struct {
+  struct tm* tmbuff;
+} REBUF;
+#define localtime(a)       localtime_r(a,PL_reentrant_buffer->tmbuff)
+#define gmtime(a)          gmtime_r(a,PL_reentrant_buffer->tmbuff)
+#endif
+
diff --git a/perl.c b/perl.c
index 2b731c4..25cdcd6 100644
--- a/perl.c
+++ b/perl.c
@@ -309,6 +309,10 @@ perl_construct(pTHXx)
 #ifdef USE_ITHREADS
         PL_regex_padav = newAV();
 #endif
+#ifdef USE_REENTRANT_API
+    New(31337, PL_reentrant_buffer,1, REBUF);
+    New(31337, PL_reentrant_buffer->tmbuff,1, struct tm);
+#endif
     ENTER;
 }
 
@@ -801,6 +805,11 @@ perl_destruct(pTHXx)
     PL_thrsv = Nullsv;
 #endif /* USE_THREADS */
 
+#ifdef USE_REENTRANT_API
+    Safefree(PL_reentrant_buffer->tmbuff);
+    Safefree(PL_reentrant_buffer);
+#endif
+
     sv_free_arenas();
 
     /* As the absolutely last thing, free the non-arena SV for mess() */
diff --git a/perlapi.h b/perlapi.h
index 36e297c..49e6eed 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -458,6 +458,8 @@ START_EXTERN_C
 #define PL_psig_ptr		(*Perl_Ipsig_ptr_ptr(aTHXo))
 #undef  PL_ptr_table
 #define PL_ptr_table		(*Perl_Iptr_table_ptr(aTHXo))
+#undef  PL_reentrant_buffer
+#define PL_reentrant_buffer	(*Perl_Ireentrant_buffer_ptr(aTHXo))
 #undef  PL_regex_pad
 #define PL_regex_pad		(*Perl_Iregex_pad_ptr(aTHXo))
 #undef  PL_regex_padav
diff --git a/pod/perlapi.pod b/pod/perlapi.pod
index 4872a9f..bee65f6 100644
--- a/pod/perlapi.pod
+++ b/pod/perlapi.pod
@@ -1344,17 +1344,6 @@ SV is B<not> incremented.
 =for hackers
 Found in file sv.c
 
-=item newSV
-
-Create a new null SV, or if len > 0, create a new empty SVt_PV type SV
-with an initial PV allocation of len+1. Normally accessed via the C<NEWSV>
-macro.
-
-	SV*	newSV(STRLEN len)
-
-=for hackers
-Found in file sv.c
-
 =item NEWSV
 
 Creates a new SV.  A non-zero C<len> parameter indicates the number of
@@ -1368,6 +1357,17 @@ C<id> is an integer id between 0 and 1299 (used to identify leaks).
 =for hackers
 Found in file handy.h
 
+=item newSV
+
+Create a new null SV, or if len > 0, create a new empty SVt_PV type SV
+with an initial PV allocation of len+1. Normally accessed via the C<NEWSV>
+macro.
+
+	SV*	newSV(STRLEN len)
+
+=for hackers
+Found in file sv.c
+
 =item newSViv
 
 Creates a new SV and copies an integer into it.  The reference count for the
@@ -2119,22 +2119,22 @@ version which guarantees to evaluate sv only once.
 =for hackers
 Found in file sv.h
 
-=item SvIVX
+=item SvIVx
 
-Returns the raw value in the SV's IV slot, without checks or conversions.
-Only use when you are sure SvIOK is true. See also C<SvIV()>.
+Coerces the given SV to an integer and returns it. Guarantees to evaluate
+sv only once. Use the more efficent C<SvIV> otherwise.
 
-	IV	SvIVX(SV* sv)
+	IV	SvIVx(SV* sv)
 
 =for hackers
 Found in file sv.h
 
-=item SvIVx
+=item SvIVX
 
-Coerces the given SV to an integer and returns it. Guarantees to evaluate
-sv only once. Use the more efficent C<SvIV> otherwise.
+Returns the raw value in the SV's IV slot, without checks or conversions.
+Only use when you are sure SvIOK is true. See also C<SvIV()>.
 
-	IV	SvIVx(SV* sv)
+	IV	SvIVX(SV* sv)
 
 =for hackers
 Found in file sv.h
@@ -2443,21 +2443,21 @@ Like C<SvPV_nolen>, but converts sv to uft8 first if necessary.
 =for hackers
 Found in file sv.h
 
-=item SvPVX
+=item SvPVx
 
-Returns a pointer to the physical string in the SV.  The SV must contain a
-string.
+A version of C<SvPV> which guarantees to evaluate sv only once.
 
-	char*	SvPVX(SV* sv)
+	char*	SvPVx(SV* sv, STRLEN len)
 
 =for hackers
 Found in file sv.h
 
-=item SvPVx
+=item SvPVX
 
-A version of C<SvPV> which guarantees to evaluate sv only once.
+Returns a pointer to the physical string in the SV.  The SV must contain a
+string.
 
-	char*	SvPVx(SV* sv, STRLEN len)
+	char*	SvPVX(SV* sv)
 
 =for hackers
 Found in file sv.h
@@ -2664,19 +2664,19 @@ false, defined or undefined.  Does not handle 'get' magic.
 =for hackers
 Found in file sv.h
 
-=item svtype
+=item SvTYPE
 
-An enum of flags for Perl types.  These are found in the file B<sv.h> 
-in the C<svtype> enum.  Test these flags with the C<SvTYPE> macro.
+Returns the type of the SV.  See C<svtype>.
+
+	svtype	SvTYPE(SV* sv)
 
 =for hackers
 Found in file sv.h
 
-=item SvTYPE
-
-Returns the type of the SV.  See C<svtype>.
+=item svtype
 
-	svtype	SvTYPE(SV* sv)
+An enum of flags for Perl types.  These are found in the file B<sv.h> 
+in the C<svtype> enum.  Test these flags with the C<SvTYPE> macro.
 
 =for hackers
 Found in file sv.h
diff --git a/sv.c b/sv.c
index 0f84074..496c02c 100644
--- a/sv.c
+++ b/sv.c
@@ -9589,6 +9589,11 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
 
     PL_debug		= proto_perl->Idebug;
 
+#ifdef USE_REENTRANT_API
+    New(31337, PL_reentrant_buffer,1, REBUF);
+    New(31337, PL_reentrant_buffer->tmbuff,1, struct tm);
+#endif
+
     /* create SV map for pointer relocation */
     PL_ptr_table = ptr_table_new();