This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow a null length pointer to sv_pvn_force_flags.
authorNicholas Clark <nick@ccl4.org>
Wed, 8 Jun 2005 14:52:17 +0000 (14:52 +0000)
committerNicholas Clark <nick@ccl4.org>
Wed, 8 Jun 2005 14:52:17 +0000 (14:52 +0000)
Add SvPV_force_nolen and use it to remove some C<n_a>s

p4raw-id: //depot/perl@24759

embed.fnc
pp.c
pp_ctl.c
proto.h
sv.c
sv.h

index b34d59e..942d0b7 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1357,7 +1357,7 @@ Apd       |void   |sv_setsv_flags |NN SV* dsv|SV* ssv|I32 flags
 Apd    |void   |sv_catpvn_flags|NN SV* sv|NN const char* ptr|STRLEN len|I32 flags
 Apd    |void   |sv_catsv_flags |NN SV* dsv|SV* ssv|I32 flags
 Apd    |STRLEN |sv_utf8_upgrade_flags|NN SV *sv|I32 flags
-Apd    |char*  |sv_pvn_force_flags|SV* sv|NN STRLEN* lp|I32 flags
+Apd    |char*  |sv_pvn_force_flags|SV* sv|STRLEN* lp|I32 flags
 Apd    |void   |sv_copypv      |NN SV* dsv|NN SV* ssv
 Ap     |char*  |my_atof2       |NN const char *s|NN NV* value
 Apn    |int    |my_socketpair  |int family|int type|int protocol|int fd[2]
diff --git a/pp.c b/pp.c
index 4feb59d..0e528cd 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -3121,8 +3121,7 @@ PP(pp_substr)
        else if (lvalue) {              /* it's an lvalue! */
            if (!SvGMAGICAL(sv)) {
                if (SvROK(sv)) {
-                   STRLEN n_a;
-                   SvPV_force(sv,n_a);
+                   SvPV_force_nolen(sv);
                    if (ckWARN(WARN_SUBSTR))
                        Perl_warner(aTHX_ packWARN(WARN_SUBSTR),
                                "Attempt to use reference as lvalue in substr");
index e3fd56c..2cdb6ca 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1134,11 +1134,11 @@ PP(pp_flop)
        }
        else {
            SV *final = sv_mortalcopy(right);
-           STRLEN len, n_a;
+           STRLEN len;
            const char *tmps = SvPV(final, len);
 
            sv = sv_mortalcopy(left);
-           SvPV_force(sv,n_a);
+           SvPV_force_nolen(sv);
            while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
                XPUSHs(sv);
                if (strEQ(SvPVX_const(sv),tmps))
@@ -1831,9 +1831,8 @@ PP(pp_enteriter)
                cx->blk_loop.itermax = SvIV(right);
            }
            else {
-               STRLEN n_a;
                cx->blk_loop.iterlval = newSVsv(sv);
-               (void) SvPV_force(cx->blk_loop.iterlval,n_a);
+               (void) SvPV_force_nolen(cx->blk_loop.iterlval);
                (void) SvPV_nolen_const(right);
            }
        }
diff --git a/proto.h b/proto.h
index ad7d72c..955d0aa 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -2508,9 +2508,7 @@ PERL_CALLCONV void        Perl_sv_catsv_flags(pTHX_ SV* dsv, SV* ssv, I32 flags)
 PERL_CALLCONV STRLEN   Perl_sv_utf8_upgrade_flags(pTHX_ SV *sv, I32 flags)
                        __attribute__nonnull__(pTHX_1);
 
-PERL_CALLCONV char*    Perl_sv_pvn_force_flags(pTHX_ SV* sv, STRLEN* lp, I32 flags)
-                       __attribute__nonnull__(pTHX_2);
-
+PERL_CALLCONV char*    Perl_sv_pvn_force_flags(pTHX_ SV* sv, STRLEN* lp, I32 flags);
 PERL_CALLCONV void     Perl_sv_copypv(pTHX_ SV* dsv, SV* ssv)
                        __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2);
diff --git a/sv.c b/sv.c
index 5062520..b580af2 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -8293,11 +8293,13 @@ Perl_sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
         sv_force_normal_flags(sv, 0);
 
     if (SvPOK(sv)) {
-       *lp = SvCUR(sv);
+       if (lp)
+           *lp = SvCUR(sv);
     }
     else {
        char *s;
-
+       STRLEN len;
        if (SvREADONLY(sv) && !(flags & SV_MUTABLE_RETURN)) {
            if (PL_op)
                Perl_croak(aTHX_ "Can't coerce readonly %s to string in %s",
@@ -8311,10 +8313,11 @@ Perl_sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
                OP_NAME(PL_op));
        }
        else
-           s = sv_2pv_flags(sv, lp, flags);
+           s = sv_2pv_flags(sv, &len, flags);
+       if (lp)
+           *lp = len;
+
        if (s != SvPVX_const(sv)) {     /* Almost, but not quite, sv_setpvn() */
-           const STRLEN len = *lp;
-       
            if (SvROK(sv))
                sv_unref(sv);
            SvUPGRADE(sv, SVt_PV);              /* Never FALSE */
diff --git a/sv.h b/sv.h
index d1d719d..13ac3b1 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -1209,6 +1209,7 @@ Like C<sv_catsv> but doesn't process magic.
      (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN))
 
 #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
+#define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC)
 #define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC)
 
 #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
@@ -1216,6 +1217,9 @@ Like C<sv_catsv> but doesn't process magic.
 #define SvPV_force_flags(sv, lp, flags) \
     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
     ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
+#define SvPV_force_flags_nolen(sv, flags) \
+    ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
+    ? SvPVX(sv) : sv_pvn_force_flags(sv, 0, flags))
 #define SvPV_force_flags_mutable(sv, lp, flags) \
     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
     ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \