X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_ctl.c;h=39f18b227bd38bc120bcc8038cc35a5b61473b0d;hb=4d7c789858ca4beacd2cf4028e969fabc2a97426;hp=d9251711efc6ffe9daf7108b642c10e5a02ab2a7;hpb=0786552a25399b1ea99930f794f6bf1973823a24;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_ctl.c b/pp_ctl.c index d925171..39f18b2 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -3018,13 +3018,13 @@ S_check_type_and_open(pTHX_ const char *name) return PerlIO_open(name, PERL_SCRIPT_MODE); } +#ifndef PERL_DISABLE_PMC STATIC PerlIO * S_doopen_pm(pTHX_ const char *name, const STRLEN namelen) { -#ifndef PERL_DISABLE_PMC PerlIO *fp; - if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) { + if (namelen > 3 && memEQs(name + namelen - 3, 3, ".pm")) { SV *const pmcsv = newSV(namelen + 2); char *const pmc = SvPVX(pmcsv); Stat_t pmcstat; @@ -3045,10 +3045,10 @@ S_doopen_pm(pTHX_ const char *name, const STRLEN namelen) fp = check_type_and_open(name); } return fp; +} #else - return check_type_and_open(name); +# define doopen_pm(name, namelen) check_type_and_open(name) #endif /* !PERL_DISABLE_PMC */ -} PP(pp_require) { @@ -3222,6 +3222,7 @@ PP(pp_require) #endif { namesv = newSV(0); + sv_upgrade(namesv, SVt_PV); for (i = 0; i <= AvFILL(ar); i++) { SV * const dirsv = *av_fetch(ar, i, TRUE); @@ -3351,7 +3352,16 @@ PP(pp_require) || (*name == ':' && name[1] != ':' && strchr(name+2, ':')) #endif ) { - const char *dir = SvOK(dirsv) ? SvPV_nolen_const(dirsv) : ""; + const char *dir; + STRLEN dirlen; + + if (SvOK(dirsv)) { + dir = SvPV_const(dirsv, dirlen); + } else { + dir = ""; + dirlen = 0; + } + #ifdef MACOS_TRADITIONAL char buf1[256]; char buf2[256]; @@ -3379,7 +3389,26 @@ PP(pp_require) "%s\\%s", dir, name); # else - Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name); + /* The equivalent of + Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name); + but without the need to parse the format string, or + call strlen on either pointer, and with the correct + allocation up front. */ + { + char *tmp = SvGROW(namesv, dirlen + len + 2); + + memcpy(tmp, dir, dirlen); + tmp +=dirlen; + *tmp++ = '/'; + /* name came from an SV, so it will have a '\0' at the + end that we can copy as part of this memcpy(). */ + 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. */ + } # endif # endif #endif