diff options
author | Tom Hughes <tom@compton.nu> | 1999-04-24 19:11:59 +0100 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-05-10 03:48:08 +0000 |
commit | b295d1132eed0f33e5e8fda2cd65ee1297fdabdb (patch) | |
tree | 2cc2bb16f505a1d5c1a468bdce46a301cdf37e84 /pp_ctl.c | |
parent | f2f614a63111e79068118dba78b4ac57891a3382 (diff) | |
download | perl-b295d1132eed0f33e5e8fda2cd65ee1297fdabdb.tar.gz |
applied suggested patch, with win32 and PERL_OBJECT additions
Message-ID: <609bdff748.tom@compton.compton.nu>
Subject: ByteLoader patch
p4raw-id: //depot/perl@3356
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -41,6 +41,7 @@ static void save_lines _((AV *array, SV *sv)); static I32 sortcv _((SV *a, SV *b)); static void qsortsv _((SV **array, size_t num_elts, I32 (*fun)(SV *a, SV *b))); static OP *doeval _((int gimme, OP** startop)); +static PerlIO *doopen _((const char *name, const char *mode)); static I32 sv_ncmp _((SV *a, SV *b)); static I32 sv_i_ncmp _((SV *a, SV *b)); static I32 amagic_ncmp _((SV *a, SV *b)); @@ -2771,6 +2772,35 @@ doeval(int gimme, OP** startop) RETURNOP(PL_eval_start); } +static PerlIO * +doopen(const char *name, const char *mode) +{ + STRLEN namelen = strlen(name); + PerlIO *fp; + + if (namelen > 3 && strcmp(name + namelen - 3, ".pm") == 0) { + SV *pmcsv = newSVpvf("%s%c", name, 'c'); + char *pmc = SvPV_nolen(pmcsv); + Stat_t pmstat; + Stat_t pmcstat; + if (PerlLIO_stat(pmc, &pmcstat) < 0) { + fp = PerlIO_open(name, mode); + } else { + if (PerlLIO_stat(name, &pmstat) < 0 || + pmstat.st_mtime < pmcstat.st_mtime) { + fp = PerlIO_open(pmc, mode); + } else { + fp = PerlIO_open(name, mode); + } + } + SvREFCNT_dec(pmcsv); + } else { + fp = PerlIO_open(name, mode); + } + + return fp; +} + PP(pp_require) { djSP; @@ -2821,7 +2851,7 @@ PP(pp_require) ) { tryname = name; - tryrsfp = PerlIO_open(name,PERL_SCRIPT_MODE); + tryrsfp = doopen(name,PERL_SCRIPT_MODE); } else { AV *ar = GvAVn(PL_incgv); @@ -2845,7 +2875,7 @@ PP(pp_require) #endif TAINT_PROPER("require"); tryname = SvPVX(namesv); - tryrsfp = PerlIO_open(tryname, PERL_SCRIPT_MODE); + tryrsfp = doopen(tryname, PERL_SCRIPT_MODE); if (tryrsfp) { if (tryname[0] == '.' && tryname[1] == '/') tryname += 2; |