Change S_doopen_pm() and S_check_type_and_open() to take an SV parameter.
authorNicholas Clark <nick@ccl4.org>
Tue, 9 Nov 2010 15:40:59 +0000 (15:40 +0000)
committerNicholas Clark <nick@ccl4.org>
Tue, 9 Nov 2010 16:19:14 +0000 (16:19 +0000)
Previously S_doopen_pm() took a char */STRLEN pair, but it happened that the
pointer was always from an SV. So pass the SV directly.

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

index 7af946b..030287c 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1661,9 +1661,9 @@ sR        |I32    |dopoptosub_at  |NN const PERL_CONTEXT* cxstk|I32 startingblock
 sR     |I32    |dopoptowhen    |I32 startingblock
 s      |void   |save_lines     |NULLOK AV *array|NN SV *sv
 s      |bool   |doeval         |int gimme|NULLOK OP** startop|NULLOK CV* outside|U32 seq
-sR     |PerlIO *|check_type_and_open|NN const char *name
+sR     |PerlIO *|check_type_and_open|NN SV *name
 #ifndef PERL_DISABLE_PMC
-sR     |PerlIO *|doopen_pm     |NN const char *name|const STRLEN namelen
+sR     |PerlIO *|doopen_pm     |NN SV *name
 #endif
 sRn    |bool   |path_is_absolute|NN const char *name
 sR     |I32    |run_user_filter|int idx|NN SV *buf_sv|int maxlen
diff --git a/embed.h b/embed.h
index 7f079b7..72cdfc0 100644 (file)
--- a/embed.h
+++ b/embed.h
 #  endif
 #  if !defined(PERL_DISABLE_PMC)
 #    if defined(PERL_IN_PP_CTL_C)
-#define doopen_pm(a,b)         S_doopen_pm(aTHX_ a,b)
+#define doopen_pm(a)           S_doopen_pm(aTHX_ a)
 #    endif
 #  endif
 #  if !defined(PERL_NO_UTF16_FILTER)
index ef7be12..343c079 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3331,10 +3331,11 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
 }
 
 STATIC PerlIO *
-S_check_type_and_open(pTHX_ const char *name)
+S_check_type_and_open(pTHX_ SV *name)
 {
     Stat_t st;
-    const int st_rc = PerlLIO_stat(name, &st);
+    const char *p = SvPV_nolen_const(name);
+    const int st_rc = PerlLIO_stat(p, &st);
 
     PERL_ARGS_ASSERT_CHECK_TYPE_AND_OPEN;
 
@@ -3342,41 +3343,32 @@ S_check_type_and_open(pTHX_ const char *name)
        return NULL;
     }
 
-    return PerlIO_open(name, PERL_SCRIPT_MODE);
+    return PerlIO_open(p, PERL_SCRIPT_MODE);
 }
 
 #ifndef PERL_DISABLE_PMC
 STATIC PerlIO *
-S_doopen_pm(pTHX_ const char *name, const STRLEN namelen)
+S_doopen_pm(pTHX_ SV *name)
 {
     PerlIO *fp;
+    STRLEN namelen;
+    const char *p = SvPV_const(name, namelen);
 
     PERL_ARGS_ASSERT_DOOPEN_PM;
 
-    if (namelen > 3 && memEQs(name + namelen - 3, 3, ".pm")) {
-       SV *const pmcsv = newSV(namelen + 2);
-       char *const pmc = SvPVX(pmcsv);
+    if (namelen > 3 && memEQs(p + namelen - 3, 3, ".pm")) {
+       SV *const pmcsv = sv_mortalcopy(name);
        Stat_t pmcstat;
 
-       memcpy(pmc, name, namelen);
-       pmc[namelen] = 'c';
-       pmc[namelen + 1] = '\0';
+       sv_catpvn(pmcsv, "c", 1);
 
-       if (PerlLIO_stat(pmc, &pmcstat) < 0) {
-           fp = check_type_and_open(name);
-       }
-       else {
-           fp = check_type_and_open(pmc);
-       }
-       SvREFCNT_dec(pmcsv);
+       if (PerlLIO_stat(SvPV_nolen_const(pmcsv), &pmcstat) >= 0)
+           return check_type_and_open(pmcsv);
     }
-    else {
-       fp = check_type_and_open(name);
-    }
-    return fp;
+    return check_type_and_open(name);
 }
 #else
-#  define doopen_pm(name, namelen) check_type_and_open(name)
+#  define doopen_pm(name) check_type_and_open(name)
 #endif /* !PERL_DISABLE_PMC */
 
 PP(pp_require)
@@ -3514,8 +3506,9 @@ PP(pp_require)
     /* prepare to compile file */
 
     if (path_is_absolute(name)) {
+       /* At this point, name is SvPVX(sv)  */
        tryname = name;
-       tryrsfp = doopen_pm(name, len);
+       tryrsfp = doopen_pm(sv);
     }
     if (!tryrsfp) {
        AV * const ar = GvAVn(PL_incgv);
@@ -3695,15 +3688,13 @@ PP(pp_require)
                        memcpy(tmp, name, len + 1);
 
                        SvCUR_set(namesv, dirlen + len + 1);
-
-                       /* Don't even actually have to turn SvPOK_on() as we
-                          access it directly with SvPVX() below.  */
+                       SvPOK_on(namesv);
                    }
 #  endif
 #endif
                    TAINT_PROPER("require");
                    tryname = SvPVX_const(namesv);
-                   tryrsfp = doopen_pm(tryname, SvCUR(namesv));
+                   tryrsfp = doopen_pm(namesv);
                    if (tryrsfp) {
                        if (tryname[0] == '.' && tryname[1] == '/') {
                            ++tryname;
diff --git a/proto.h b/proto.h
index a32301a..9f4046d 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -4960,7 +4960,7 @@ STATIC int        S_sv_2iuv_non_preserve(pTHX_ SV *const sv, I32 numtype)
 #endif
 #if !defined(PERL_DISABLE_PMC)
 #  if defined(PERL_IN_PP_CTL_C)
-STATIC PerlIO *        S_doopen_pm(pTHX_ const char *name, const STRLEN namelen)
+STATIC PerlIO *        S_doopen_pm(pTHX_ SV *name)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_DOOPEN_PM     \
@@ -5944,7 +5944,7 @@ PERL_CALLCONV GV* Perl_softref2xv(pTHX_ SV *const sv, const char *const what, co
 
 #endif
 #if defined(PERL_IN_PP_CTL_C)
-STATIC PerlIO *        S_check_type_and_open(pTHX_ const char *name)
+STATIC PerlIO *        S_check_type_and_open(pTHX_ SV *name)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_CHECK_TYPE_AND_OPEN   \