Rationalise the logic in lex_start for creating a new temporary if the
authorNicholas Clark <nick@ccl4.org>
Sun, 31 Dec 2006 16:58:18 +0000 (16:58 +0000)
committerNicholas Clark <nick@ccl4.org>
Sun, 31 Dec 2006 16:58:18 +0000 (16:58 +0000)
passed in SV is read only or doesn't end in ';'. Also, allow a NULL
pointer to imply a zero length string, which saves creating a mortal
in pp_require, only for it to be ignored in favour of a new SV.

p4raw-id: //depot/perl@29647

embed.fnc
pp_ctl.c
proto.h
toke.c

index abbb518..c4dc7c7 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -399,7 +399,7 @@ p   |OP*    |jmaybe         |NN OP* arg
 pP     |I32    |keyword        |NN const char* d|I32 len|bool all_keywords
 Ap     |void   |leave_scope    |I32 base
 p      |void   |lex_end
-p      |void   |lex_start      |NN SV* line
+p      |void   |lex_start      |NULLOK SV* line
 Ap     |void   |op_null        |NN OP* o
 p      |void   |op_clear       |NN OP* o
 Ap     |void   |op_refcnt_lock
index 36f0963..28b0484 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3377,7 +3377,7 @@ PP(pp_require)
 
     ENTER;
     SAVETMPS;
-    lex_start(sv_2mortal(newSVpvs("")));
+    lex_start(NULL);
     SAVEGENERICSV(PL_rsfp_filters);
     PL_rsfp_filters = NULL;
 
diff --git a/proto.h b/proto.h
index a0d3b95..e988ca7 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -1016,9 +1016,7 @@ PERL_CALLCONV I32 Perl_keyword(pTHX_ const char* d, I32 len, bool all_keywords)
 
 PERL_CALLCONV void     Perl_leave_scope(pTHX_ I32 base);
 PERL_CALLCONV void     Perl_lex_end(pTHX);
-PERL_CALLCONV void     Perl_lex_start(pTHX_ SV* line)
-                       __attribute__nonnull__(pTHX_1);
-
+PERL_CALLCONV void     Perl_lex_start(pTHX_ SV* line);
 PERL_CALLCONV void     Perl_op_null(pTHX_ OP* o)
                        __attribute__nonnull__(pTHX_1);
 
diff --git a/toke.c b/toke.c
index eaa7e6b..7166194 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -660,10 +660,16 @@ Perl_lex_start(pTHX_ SV *line)
 #endif
     PL_lex_inwhat = 0;
     PL_sublex_info.sub_inwhat = 0;
-    s = SvPV_const(line, len);
-    if (SvREADONLY(line) || !len || s[len-1] != ';') {
-       PL_linestr = len ? newSVsv(line) : newSVpvn(s, 0);
-       if (!len || s[len-1] != ';')
+    if (line) {
+       s = SvPV_const(line, len);
+    } else {
+       len = 0;
+    }
+    if (!len) {
+       PL_linestr = newSVpvs("\n;");
+    } else if (SvREADONLY(line) || s[len-1] != ';') {
+       PL_linestr = newSVsv(line);
+       if (s[len-1] != ';')
            sv_catpvs(PL_linestr, "\n;");
     } else {
        SvTEMP_off(line);