Use reentrant API glibc
authorArtur Bergman <sky@nanisky.com>
Thu, 12 Jul 2001 00:58:21 +0000 (02:58 +0200)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 12 Jul 2001 00:52:36 +0000 (00:52 +0000)
Message-ID: <B772A6AD.2288%artur@contiller.se>

p4raw-id: //depot/perl@11283

embedvar.h
intrpvar.h
op.h
perl.c
perlapi.h
pod/perlapi.pod
sv.c

index 80b2e3e..34d781f 100644 (file)
 #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)
 #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)
 #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)
 #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
index 6447b27..a346ffe 100644 (file)
@@ -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 (file)
--- 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 (file)
--- 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() */
index 36e297c..49e6eed 100644 (file)
--- 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
index 4872a9f..bee65f6 100644 (file)
@@ -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 (file)
--- 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();