Skip to content

Commit

Permalink
Use reentrant API glibc
Browse files Browse the repository at this point in the history
Message-ID: <B772A6AD.2288%artur@contiller.se>

p4raw-id: //depot/perl@11283
  • Loading branch information
Artur Bergman authored and jhi committed Jul 12, 2001
1 parent 0698c26 commit e5dd39f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 33 deletions.
4 changes: 4 additions & 0 deletions embedvar.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions intrpvar.h
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions op.h
Expand Up @@ -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

9 changes: 9 additions & 0 deletions perl.c
Expand Up @@ -308,6 +308,10 @@ perl_construct(pTHXx)
PL_errors = newSVpvn("",0);
#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;
}
Expand Down Expand Up @@ -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() */
Expand Down
2 changes: 2 additions & 0 deletions perlapi.h
Expand Up @@ -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
Expand Down
66 changes: 33 additions & 33 deletions pod/perlapi.pod
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions sv.c
Expand Up @@ -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();

Expand Down

0 comments on commit e5dd39f

Please sign in to comment.