From: Jan Dubois Date: Sun, 24 Jan 1999 02:45:32 +0000 (+0100) Subject: provide SvPV_nolen(sv) to avoid use of PL_na X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1fa8b10d8c0f0780dab42b408cc071b5f7ee992b;p=p5sagit%2Fp5-mst-13.2.git 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 --- diff --git a/embed.h b/embed.h index 68a90a4..2a70d02 100644 --- a/embed.h +++ b/embed.h @@ -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 7295be6..e49afc7 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 diff --git a/objXSUB.h b/objXSUB.h index 8138d0d..b478a9e 100644 --- a/objXSUB.h +++ b/objXSUB.h @@ -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 0b9eed0..ce8c182 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 macro, the length of the string returned is placed into the -variable C (this is a macro, so you do I use C<&len>). If you do not -care what the length of the data is, use the global variable C, 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 (this is a macro, so you do I use C<&len>). If you do +not care what the length of the data is, use the C macro. +Historically the C macro with the global variable C has been +used in this case. But that can be quite inefficient because C 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. A convenience variable which is typically used with C 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 +macro. =item New @@ -3026,7 +3030,7 @@ Checks the B setting. Use C. 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 diff --git a/proto.h b/proto.h index 903d78b..1a36430 100644 --- a/proto.h +++ b/proto.h @@ -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)); diff --git a/sv.c b/sv.c index 545a9d5..eede077 100644 --- a/sv.c +++ b/sv.c @@ -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)) { diff --git a/sv.h b/sv.h index 456d01c..71e8e55 100644 --- a/sv.h +++ b/sv.h @@ -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