Generate a new SV if we do this, to save needing to copy the SV we push
onto @INC */
STATIC SV *
-S_incpush_if_exists(pTHX_ AV *const av, SV *dir)
+S_incpush_if_exists(pTHX_ AV *const av, SV *dir, SV *const stem)
{
dVAR;
Stat_t tmpstatbuf;
if (PerlLIO_stat(SvPVX_const(dir), &tmpstatbuf) >= 0 &&
S_ISDIR(tmpstatbuf.st_mode)) {
av_push(av, dir);
- dir = newSV(0);
+ dir = newSVsv(stem);
+ } else {
+ /* Truncate dir back to stem. */
+ SvCUR_set(dir, SvCUR(stem));
}
return dir;
}
* archname-specific sub-directories.
*/
if (using_sub_dirs) {
- SV *subdir = newSV(0);
+ SV *subdir;
#ifdef PERL_INC_VERSION_LIST
/* Configure terminates PERL_INC_VERSION_LIST with a NULL */
const char * const incverlist[] = { PERL_INC_VERSION_LIST };
"Failed to unixify @INC element \"%s\"\n",
SvPV(libdir,len));
#endif
+
+ subdir = newSVsv(libdir);
+
if (add_versioned_sub_dirs) {
#ifdef MACOS_TRADITIONAL
#define PERL_ARCH_FMT_PREFIX ""
#define PERL_ARCH_FMT_PATH "/" PERL_FS_VERSION
#endif
/* .../version/archname if -d .../version/archname */
- sv_setsv(subdir, libdir);
sv_catpvs(subdir, PERL_ARCH_FMT_PATH \
PERL_ARCH_FMT_PREFIX ARCHNAME PERL_ARCH_FMT_SUFFIX);
- subdir = S_incpush_if_exists(aTHX_ av, subdir);
+ subdir = S_incpush_if_exists(aTHX_ av, subdir, libdir);
/* .../version if -d .../version */
- sv_setsv(subdir, libdir);
sv_catpvs(subdir, PERL_ARCH_FMT_PATH);
- subdir = S_incpush_if_exists(aTHX_ av, subdir);
+ subdir = S_incpush_if_exists(aTHX_ av, subdir, libdir);
}
#ifdef PERL_INC_VERSION_LIST
if (addoldvers) {
for (incver = incverlist; *incver; incver++) {
/* .../xxx if -d .../xxx */
- Perl_sv_setpvf(aTHX_ subdir, "%"SVf PERL_ARCH_FMT_PREFIX \
- "%s" PERL_ARCH_FMT_SUFFIX,
- SVfARG(libdir), *incver);
- subdir = S_incpush_if_exists(aTHX_ av, subdir);
+ Perl_sv_catpvf(aTHX_ subdir, PERL_ARCH_FMT_PREFIX \
+ "%s" PERL_ARCH_FMT_SUFFIX, *incver);
+ subdir = S_incpush_if_exists(aTHX_ av, subdir, libdir);
}
}
#endif
if (add_archonly_sub_dirs) {
/* .../archname if -d .../archname */
- sv_setsv(subdir, libdir);
sv_catpvs(subdir,
PERL_ARCH_FMT_PREFIX ARCHNAME PERL_ARCH_FMT_SUFFIX);
- subdir = S_incpush_if_exists(aTHX_ av, subdir);
+ subdir = S_incpush_if_exists(aTHX_ av, subdir, libdir);
}
STATIC void S_run_body(pTHX_ I32 oldscope)
__attribute__noreturn__;
-STATIC SV * S_incpush_if_exists(pTHX_ AV *const av, SV *dir)
+STATIC SV * S_incpush_if_exists(pTHX_ AV *const av, SV *dir, SV *const stem)
__attribute__nonnull__(pTHX_1)
- __attribute__nonnull__(pTHX_2);
+ __attribute__nonnull__(pTHX_2)
+ __attribute__nonnull__(pTHX_3);
#define PERL_ARGS_ASSERT_INCPUSH_IF_EXISTS \
- assert(av); assert(dir)
+ assert(av); assert(dir); assert(stem)
#endif