diff options
author | Jan Dubois <jand@activestate.com> | 1999-01-24 03:45:32 +0100 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-14 09:57:29 +0000 |
commit | 1fa8b10d8c0f0780dab42b408cc071b5f7ee992b (patch) | |
tree | 79dec658b5a91fedbc68e28af30e38f5bb86f7a5 | |
parent | 4afa425f54235784726a05dc06169d071f280d7a (diff) | |
download | perl-1fa8b10d8c0f0780dab42b408cc071b5f7ee992b.tar.gz |
provide SvPV_nolen(sv) to avoid use of PL_na
Message-ID: <36bb7ada.68485547@smtp1.ibm.net>
Subject: [PATCH 5.005_54] _54 version of SvPV_nolen patch
p4raw-id: //depot/perl@2912
-rw-r--r-- | embed.h | 4 | ||||
-rw-r--r-- | global.sym | 2 | ||||
-rw-r--r-- | objXSUB.h | 4 | ||||
-rw-r--r-- | pod/perlguts.pod | 24 | ||||
-rw-r--r-- | proto.h | 2 | ||||
-rw-r--r-- | sv.c | 18 | ||||
-rw-r--r-- | sv.h | 5 |
7 files changed, 52 insertions, 7 deletions
@@ -869,6 +869,7 @@ #define sv_2mortal Perl_sv_2mortal #define sv_2nv Perl_sv_2nv #define sv_2pv Perl_sv_2pv +#define sv_2pv_nolen Perl_sv_2pv_nolen #define sv_2uv Perl_sv_2uv #define sv_add_arena Perl_sv_add_arena #define sv_backoff Perl_sv_backoff @@ -912,6 +913,7 @@ #define sv_peek Perl_sv_peek #define sv_pos_b2u Perl_sv_pos_b2u #define sv_pos_u2b Perl_sv_pos_u2b +#define sv_pv Perl_sv_pv #define sv_pvn Perl_sv_pvn #define sv_pvn_force Perl_sv_pvn_force #define sv_ref Perl_sv_ref @@ -2054,6 +2056,7 @@ #define sv_2mortal CPerlObj::Perl_sv_2mortal #define sv_2nv CPerlObj::Perl_sv_2nv #define sv_2pv CPerlObj::Perl_sv_2pv +#define sv_2pv_nolen CPerlObj::Perl_sv_2pv_nolen #define sv_2uv CPerlObj::Perl_sv_2uv #define sv_add_arena CPerlObj::Perl_sv_add_arena #define sv_backoff CPerlObj::Perl_sv_backoff @@ -2101,6 +2104,7 @@ #define sv_peek CPerlObj::Perl_sv_peek #define sv_pos_b2u CPerlObj::Perl_sv_pos_b2u #define sv_pos_u2b CPerlObj::Perl_sv_pos_u2b +#define sv_pv CPerlObj::Perl_sv_pv #define sv_pvn CPerlObj::Perl_sv_pvn #define sv_pvn_force CPerlObj::Perl_sv_pvn_force #define sv_ref CPerlObj::Perl_sv_ref diff --git a/global.sym b/global.sym index 7295be6a9f..e49afc7e2b 100644 --- a/global.sym +++ b/global.sym @@ -516,6 +516,7 @@ sv_2iv sv_2mortal sv_2nv sv_2pv +sv_2pv_nolen sv_2uv sv_add_arena sv_backoff @@ -559,6 +560,7 @@ sv_newmortal sv_newref sv_nv sv_peek +sv_pv sv_pvn sv_pvn_force sv_ref @@ -2919,6 +2919,8 @@ #define sv_2nv pPerl->Perl_sv_2nv #undef sv_2pv #define sv_2pv pPerl->Perl_sv_2pv +#undef sv_2pv_nolen +#define sv_2pv_nolen pPerl->Perl_sv_2pv_nolen #undef sv_2uv #define sv_2uv pPerl->Perl_sv_2uv #undef sv_add_arena @@ -3013,6 +3015,8 @@ #define sv_pos_b2u pPerl->Perl_sv_pos_b2u #undef sv_pos_u2b #define sv_pos_u2b pPerl->Perl_sv_pos_u2b +#undef sv_pv +#define sv_pv pPerl->Perl_sv_pv #undef sv_pvn #define sv_pvn pPerl->Perl_sv_pvn #undef sv_pvn_force diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 0b9eed0a8f..ce8c182508 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -89,16 +89,19 @@ To access the actual value that an SV points to, you can use the macros: SvIV(SV*) SvNV(SV*) SvPV(SV*, STRLEN len) + SvPV_nolen(SV*) which will automatically coerce the actual scalar type into an IV, double, or string. In the C<SvPV> macro, the length of the string returned is placed into the -variable C<len> (this is a macro, so you do I<not> use C<&len>). If you do not -care what the length of the data is, use the global variable C<PL_na>, though -this is rather less efficient than using a local variable. Remember, -however, that Perl allows arbitrary strings of data that may both contain -NULs and might not be terminated by a NUL. +variable C<len> (this is a macro, so you do I<not> use C<&len>). If you do +not care what the length of the data is, use the C<SvPV_nolen> macro. +Historically the C<SvPV> macro with the global variable C<PL_na> has been +used in this case. But that can be quite inefficient because C<PL_na> must +be accessed in thread-local storage in threaded Perl. In any case, remember +that Perl allows arbitrary strings of data that may both contain NULs and +might not be terminated by a NUL. If you want to know if the scalar value is TRUE, you can use: @@ -2196,7 +2199,8 @@ the type. Can do overlapping moves. See also C<Copy>. A convenience variable which is typically used with C<SvPV> when one doesn't care about the length of the string. It is usually more efficient to -declare a local variable and use that instead. +either declare a local variable and use that instead or to use the C<SvPV_nolen> +macro. =item New @@ -3026,7 +3030,7 @@ Checks the B<private> setting. Use C<SvPOK>. Returns a pointer to the string in the SV, or a stringified form of the SV if the SV does not contain a string. Handles 'get' magic. - char* SvPV (SV* sv, int len ) + char* SvPV (SV* sv, int len) =item SvPV_force @@ -3035,6 +3039,12 @@ want force if you are going to update the SvPVX directly. char* SvPV_force(SV* sv, int len) +=item SvPV_nolen + +Returns a pointer to the string in the SV, or a stringified form of the SV +if the SV does not contain a string. Handles 'get' magic. + + char* SvPV (SV* sv) =item SvPVX @@ -965,3 +965,5 @@ VIRTUAL void do_pmop_dump _((I32 level, PerlIO *file, PMOP *pm)); VIRTUAL void do_sv_dump _((I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)); VIRTUAL void magic_dump _((MAGIC *mg)); VIRTUAL void reginitcolors _((void)); +VIRTUAL char* sv_2pv_nolen _((SV* sv)); +VIRTUAL char* sv_pv _((SV *sv)); @@ -1507,6 +1507,13 @@ looks_like_number(SV *sv) } char * +sv_2pv_nolen(register SV *sv) +{ + STRLEN n_a; + return sv_2pv(sv, &n_a); +} + +char * sv_2pv(register SV *sv, STRLEN *lp) { register char *s; @@ -3976,6 +3983,17 @@ sv_nv(register SV *sv) } char * +sv_pv(SV *sv) +{ + STRLEN n_a; + + if (SvPOK(sv)) + return SvPVX(sv); + + return sv_2pv(sv, &n_a); +} + +char * sv_pvn(SV *sv, STRLEN *lp) { if (SvPOK(sv)) { @@ -512,6 +512,7 @@ struct xpvio { #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp) #define SvPV(sv, lp) sv_pvn(sv, &lp) +#define SvPV_nolen(sv) sv_pv(sv) #define SvIVx(sv) sv_iv(sv) #define SvUVx(sv) sv_uv(sv) #define SvNVx(sv) sv_nv(sv) @@ -545,6 +546,10 @@ struct xpvio { ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp)) +#undef SvPV_nolen +#define SvPV_nolen(sv) \ + (SvPOK(sv) ? SvPVX(sv) : sv_2pv_nolen(sv)) + #ifdef __GNUC__ # undef SvIVx # undef SvUVx |