RETURN;
}
+PP(pp_gelem)
+{
+ GV *gv;
+ SV *sv;
+ SV *ref;
+ char *elem;
+ dSP;
+
+ sv = POPs;
+ elem = SvPV(sv, na);
+ gv = (GV*)POPs;
+ ref = Nullsv;
+ sv = Nullsv;
+ switch (elem ? *elem : '\0')
+ {
+ case 'A':
+ if (strEQ(elem, "ARRAY"))
+ ref = (SV*)GvAV(gv);
+ break;
+ case 'C':
+ if (strEQ(elem, "CODE"))
+ ref = (SV*)GvCV(gv);
+ break;
+ case 'F':
+ if (strEQ(elem, "FILEHANDLE"))
+ ref = (SV*)GvIOp(gv);
+ break;
+ case 'G':
+ if (strEQ(elem, "GLOB"))
+ ref = (SV*)gv;
+ break;
+ case 'H':
+ if (strEQ(elem, "HASH"))
+ ref = (SV*)GvHV(gv);
+ break;
+ case 'N':
+ if (strEQ(elem, "NAME"))
+ sv = newSVpv(GvNAME(gv), GvNAMELEN(gv));
+ break;
+ case 'P':
+ if (strEQ(elem, "PACKAGE"))
+ sv = newSVpv(HvNAME(GvSTASH(gv)), 0);
+ break;
+ case 'S':
+ if (strEQ(elem, "SCALAR"))
+ ref = GvSV(gv);
+ break;
+ }
+ if (ref)
+ sv = newRV(ref);
+ if (sv)
+ sv_2mortal(sv);
+ else
+ sv = &sv_undef;
+ XPUSHs(sv);
+ RETURN;
+}
+
PP(pp_and)
{
dSP;
PP(pp_sassign)
{
dSP; dPOPTOPssrl;
+ MAGIC *mg;
+
if (op->op_private & OPpASSIGN_BACKWARDS) {
SV *temp;
temp = left; left = right; right = temp;
}
if (tainting && tainted && (!SvGMAGICAL(left) || !SvSMAGICAL(left) ||
- !mg_find(left, 't'))) {
+ !((mg = mg_find(left, 't')) && mg->mg_len & 1)))
+ {
TAINT_NOT;
}
SvSetSV(right, left);
PP(pp_concat)
{
- dSP; dATARGET; dPOPTOPssrl;
+ dSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
+ {
+ dPOPTOPssrl;
STRLEN len;
char *s;
if (TARG != left) {
s = SvPV(left,len);
sv_setpvn(TARG,s,len);
}
+ else if (SvGMAGICAL(TARG))
+ mg_get(TARG);
+ else if (!SvOK(TARG)) {
+ s = SvPV_force(TARG, len);
+ sv_setpv(TARG, ""); /* Suppress warning. */
+ }
s = SvPV(right,len);
sv_catpvn(TARG,s,len);
SETTARG;
RETURN;
+ }
}
PP(pp_padsv)
{
dSP; dTARGET;
XPUSHs(TARG);
- if (op->op_private & OPpLVAL_INTRO)
- SAVECLEARSV(curpad[op->op_targ]);
+ if (op->op_flags & OPf_MOD) {
+ if (op->op_private & OPpLVAL_INTRO)
+ SAVECLEARSV(curpad[op->op_targ]);
+ else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) {
+ SV* sv = curpad[op->op_targ];
+ if (SvGMAGICAL(sv))
+ mg_get(sv);
+ if (!SvOK(sv)) {
+ if (SvREADONLY(sv))
+ croak(no_modify);
+ (void)SvUPGRADE(sv, SVt_RV);
+ SvRV(sv) = (op->op_private & OPpDEREF_HV ?
+ (SV*)newHV() : (SV*)newAV());
+ SvROK_on(sv);
+ SvSETMAGIC(sv);
+ }
+ }
+ }
RETURN;
}
PP(pp_preinc)
{
dSP;
- sv_inc(TOPs);
+ if (SvIOK(TOPs)) {
+ ++SvIVX(TOPs);
+ SvFLAGS(TOPs) &= ~(SVf_NOK|SVf_POK|SVp_NOK|SVp_POK);
+ }
+ else
+ sv_inc(TOPs);
SvSETMAGIC(TOPs);
return NORMAL;
}
else
gv = defoutgv;
if (!(io = GvIO(gv))) {
- if (dowarn)
- warn("Filehandle %s never opened", GvNAME(gv));
- errno = EBADF;
+ if (dowarn) {
+ SV* sv = sv_newmortal();
+ gv_fullname(sv,gv);
+ warn("Filehandle %s never opened", SvPV(sv,na));
+ }
+
+ SETERRNO(EBADF,RMS$_IFI);
goto just_say_no;
}
else if (!(fp = IoOFP(io))) {
if (dowarn) {
+ SV* sv = sv_newmortal();
+ gv_fullname(sv,gv);
if (IoIFP(io))
- warn("Filehandle %s opened only for input", GvNAME(gv));
+ warn("Filehandle %s opened only for input", SvPV(sv,na));
else
- warn("print on closed filehandle %s", GvNAME(gv));
+ warn("print on closed filehandle %s", SvPV(sv,na));
}
- errno = EBADF;
+ SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
goto just_say_no;
}
else {
}
else {
if (SvTYPE(sv) != SVt_PVGV) {
+ char *sym;
+
if (SvGMAGICAL(sv)) {
mg_get(sv);
if (SvROK(sv))
if (op->op_flags & OPf_REF ||
op->op_private & HINT_STRICT_REFS)
DIE(no_usym, "an ARRAY");
+ if (GIMME == G_ARRAY)
+ RETURN;
RETPUSHUNDEF;
}
+ sym = SvPV(sv,na);
if (op->op_private & HINT_STRICT_REFS)
- DIE(no_symref, "an ARRAY");
- sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE, SVt_PVAV);
+ DIE(no_symref, sym, "an ARRAY");
+ sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVAV);
}
av = GvAVn(sv);
if (op->op_private & OPpLVAL_INTRO)
}
else {
if (SvTYPE(sv) != SVt_PVGV) {
+ char *sym;
+
if (SvGMAGICAL(sv)) {
mg_get(sv);
if (SvROK(sv))
if (op->op_flags & OPf_REF ||
op->op_private & HINT_STRICT_REFS)
DIE(no_usym, "a HASH");
+ if (GIMME == G_ARRAY) {
+ SP--;
+ RETURN;
+ }
RETSETUNDEF;
}
+ sym = SvPV(sv,na);
if (op->op_private & HINT_STRICT_REFS)
- DIE(no_symref, "a HASH");
- sv = (SV*)gv_fetchpv(SvPV(sv, na), TRUE, SVt_PVHV);
+ DIE(no_symref, sym, "a HASH");
+ sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVHV);
}
hv = GvHVn(sv);
if (op->op_private & OPpLVAL_INTRO)
ary = Null(AV*);
hash = Null(HV*);
while (lelem <= lastlelem) {
+ tainted = 0; /* Each item stands on its own, taintwise. */
sv = *lelem++;
switch (SvTYPE(sv)) {
case SVt_PVAV:
ary = (AV*)sv;
- magic = SvSMAGICAL(ary) != 0;
+ magic = SvMAGICAL(ary) != 0;
av_clear(ary);
i = 0;
(void)av_store(ary,i++,sv);
if (magic)
mg_set(sv);
+ tainted = 0;
}
break;
case SVt_PVHV: {
SV *tmpstr;
hash = (HV*)sv;
- magic = SvSMAGICAL(hash) != 0;
+ magic = SvMAGICAL(hash) != 0;
hv_clear(hash);
while (relem < lastrelem) { /* gobble up all the rest */
(void)hv_store(hash,tmps,len,tmpstr,0);
if (magic)
mg_set(tmpstr);
+ tainted = 0;
}
}
break;
if (delaymagic & DM_UID) {
#ifdef HAS_SETRESUID
(void)setresuid(uid,euid,(Uid_t)-1);
-#else /* not HAS_SETRESUID */
-#ifdef HAS_SETREUID
+#else
+# ifdef HAS_SETREUID
(void)setreuid(uid,euid);
-#else /* not HAS_SETREUID */
-#ifdef HAS_SETRUID
+# else
+# ifdef HAS_SETRUID
if ((delaymagic & DM_UID) == DM_RUID) {
(void)setruid(uid);
- delaymagic =~ DM_RUID;
+ delaymagic &= ~DM_RUID;
}
-#endif /* HAS_SETRUID */
-#endif /* HAS_SETRESUID */
-#ifdef HAS_SETEUID
+# endif /* HAS_SETRUID */
+# ifdef HAS_SETEUID
if ((delaymagic & DM_UID) == DM_EUID) {
(void)seteuid(uid);
- delaymagic =~ DM_EUID;
+ delaymagic &= ~DM_EUID;
}
-#endif /* HAS_SETEUID */
+# endif /* HAS_SETEUID */
if (delaymagic & DM_UID) {
if (uid != euid)
DIE("No setreuid available");
(void)setuid(uid);
}
-#endif /* not HAS_SETREUID */
+# endif /* HAS_SETREUID */
+#endif /* HAS_SETRESUID */
uid = (int)getuid();
euid = (int)geteuid();
}
if (delaymagic & DM_GID) {
#ifdef HAS_SETRESGID
(void)setresgid(gid,egid,(Gid_t)-1);
-#else /* not HAS_SETREGID */
-#ifdef HAS_SETREGID
+#else
+# ifdef HAS_SETREGID
(void)setregid(gid,egid);
-#else /* not HAS_SETREGID */
-#endif /* not HAS_SETRESGID */
-#ifdef HAS_SETRGID
+# else
+# ifdef HAS_SETRGID
if ((delaymagic & DM_GID) == DM_RGID) {
(void)setrgid(gid);
- delaymagic =~ DM_RGID;
+ delaymagic &= ~DM_RGID;
}
-#endif /* HAS_SETRGID */
-#ifdef HAS_SETRESGID
- (void)setresgid(gid,egid,(Gid_t)-1);
-#else /* not HAS_SETREGID */
-#ifdef HAS_SETEGID
+# endif /* HAS_SETRGID */
+# ifdef HAS_SETEGID
if ((delaymagic & DM_GID) == DM_EGID) {
(void)setegid(gid);
- delaymagic =~ DM_EGID;
+ delaymagic &= ~DM_EGID;
}
-#endif /* HAS_SETEGID */
+# endif /* HAS_SETEGID */
if (delaymagic & DM_GID) {
if (gid != egid)
DIE("No setregid available");
(void)setgid(gid);
}
-#endif /* not HAS_SETRESGID */
-#endif /* not HAS_SETREGID */
+# endif /* HAS_SETREGID */
+#endif /* HAS_SETRESGID */
gid = (int)getgid();
egid = (int)getegid();
}
- tainting |= (euid != uid || egid != gid);
+ tainting |= (uid && (euid != uid || egid != gid));
}
delaymagic = 0;
if (GIMME == G_ARRAY) {
RETURN;
}
else {
+ dTARGET;
SP = firstrelem;
- for (relem = firstrelem; relem <= lastrelem; ++relem) {
- if (SvOK(*relem)) {
- dTARGET;
- SETi(lastrelem - firstrelem + 1);
- RETURN;
- }
- }
- RETSETUNDEF;
+ SETi(lastrelem - firstrelem + 1);
+ RETURN;
}
}
register REGEXP *rx = pm->op_pmregexp;
I32 gimme = GIMME;
STRLEN len;
+ I32 minmatch = 0;
+ I32 oldsave = savestack_ix;
if (op->op_flags & OPf_STACKED)
TARG = POPs;
rx->startp[0] = 0;
if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
MAGIC* mg = mg_find(TARG, 'g');
- if (mg && mg->mg_len >= 0)
+ if (mg && mg->mg_len >= 0) {
rx->endp[0] = rx->startp[0] = s + mg->mg_len;
+ minmatch = (mg->mg_flags & MGf_MINMATCH);
+ }
}
}
+ if (!rx->nparens && !global)
+ gimme = G_SCALAR; /* accidental array context? */
safebase = (gimme == G_ARRAY) || global;
if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
SAVEINT(multiline);
t = s = rx->endp[0];
if (s > strend)
goto nope;
+ minmatch = (s == rx->startp[0]);
}
if (pm->op_pmshort) {
if (pm->op_pmflags & PMf_SCANFIRST) {
pm->op_pmshort = Nullsv; /* opt is being useless */
}
}
- if (!rx->nparens && !global) {
- gimme = G_SCALAR; /* accidental array context? */
- safebase = FALSE;
- }
- if (regexec(rx, s, strend, truebase, 0,
+ if (pregexec(rx, s, strend, truebase, minmatch,
SvSCREAM(TARG) ? TARG : Nullsv,
safebase)) {
curpm = pm;
++rx->endp[0];
goto play_it_again;
}
+ LEAVE_SCOPE(oldsave);
RETURN;
}
else {
sv_magic(TARG, (SV*)0, 'g', Nullch, 0);
mg = mg_find(TARG, 'g');
}
- mg->mg_len = rx->startp[0] ? rx->endp[0] - truebase : -1;
+ if (rx->startp[0]) {
+ mg->mg_len = rx->endp[0] - truebase;
+ if (rx->startp[0] == rx->endp[0])
+ mg->mg_flags |= MGf_MINMATCH;
+ else
+ mg->mg_flags &= ~MGf_MINMATCH;
+ }
+ else
+ mg->mg_len = -1;
}
+ LEAVE_SCOPE(oldsave);
RETPUSHYES;
}
tmps = rx->startp[0] = tmps + (s - t);
rx->endp[0] = tmps + SvCUR(pm->op_pmshort);
}
+ LEAVE_SCOPE(oldsave);
RETPUSHYES;
nope:
mg->mg_len = -1;
}
}
+ LEAVE_SCOPE(oldsave);
if (gimme == G_ARRAY)
RETURN;
RETPUSHNO;
if (cp[i] == '/') {
hasdir = isunix = 1;
break;
- }
+ }
if (cp[i] == ']' || cp[i] == '>' || cp[i] == ':') {
hasdir = 1;
break;
ok = (fputs(begin,tmpfp) != EOF);
}
if (cxt) (void)lib$find_file_end(&cxt);
- if (ok && sts != RMS$_NMF) ok = 0;
+ if (ok && sts != RMS$_NMF &&
+ sts != RMS$_DNF && sts != RMS$_FNF) ok = 0;
if (!ok) {
+ if (!(sts & 1)) {
+ SETERRNO((sts == RMS$_SYN ? EINVAL : EVMSERR),sts);
+ }
+ fclose(tmpfp);
fp = NULL;
}
else {
sv_setpvn(tmpcmd, cshname, cshlen);
sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
sv_catsv(tmpcmd, tmpglob);
- sv_catpv(tmpcmd, "'|");
+ sv_catpv(tmpcmd, "' 2>/dev/null |");
#else
sv_setpv(tmpcmd, "echo ");
sv_catsv(tmpcmd, tmpglob);
#endif
#endif /* !CSH */
#endif /* !MSDOS */
- (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),Nullfp);
+ (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
+ FALSE, 0, 0, Nullfp);
fp = IoIFP(io);
#endif /* !VMS */
LEAVE;
SP--;
}
if (!fp) {
- if (dowarn)
+ if (dowarn && io && !(IoFLAGS(io) & IOf_START))
warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
if (GIMME == G_SCALAR) {
(void)SvOK_off(TARG);
if (type == OP_GLOB) {
char *tmps;
- if (SvCUR(sv) > 0)
- SvCUR(sv)--;
- if (*SvEND(sv) == rschar)
- *SvEND(sv) = '\0';
- else
- SvCUR(sv)++;
+ if (SvCUR(sv) > 0 && SvCUR(rs) > 0) {
+ tmps = SvEND(sv) - 1;
+ if (*tmps == *SvPVX(rs)) {
+ *tmps = '\0';
+ SvCUR(sv)--;
+ }
+ }
for (tmps = SvPVX(sv); *tmps; tmps++)
if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
dSP;
register CONTEXT *cx;
SV *sv;
+ AV* av;
EXTEND(sp, 1);
cx = &cxstack[cxstack_ix];
if (cx->cx_type != CXt_LOOP)
DIE("panic: pp_iter");
+ av = cx->blk_loop.iterary;
+ if (av == stack && cx->blk_loop.iterix >= cx->blk_oldsp)
+ RETPUSHNO;
- if (cx->blk_loop.iterix >= cx->blk_oldsp)
+ if (cx->blk_loop.iterix >= AvFILL(av))
RETPUSHNO;
- if (sv = AvARRAY(cx->blk_loop.iterary)[++cx->blk_loop.iterix]) {
+ if (sv = AvARRAY(av)[++cx->blk_loop.iterix]) {
SvTEMP_off(sv);
*cx->blk_loop.itervar = sv;
}
register REGEXP *rx = pm->op_pmregexp;
STRLEN len;
int force_on_match = 0;
+ I32 oldsave = savestack_ix;
if (pm->op_pmflags & PMf_CONST) /* known replacement string? */
dstr = POPs;
EXTEND(SP,1);
}
s = SvPV(TARG, len);
- if (!SvPOKp(TARG))
+ if (!SvPOKp(TARG) || SvREADONLY(TARG) || (SvTYPE(TARG) == SVt_PVGV))
force_on_match = 1;
force_it:
c = SvPV(dstr, clen);
if (clen <= rx->minlen) {
/* can do inplace substitution */
- if (regexec(rx, s, strend, orig, 0,
+ if (pregexec(rx, s, strend, orig, 0,
SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
if (force_on_match) {
force_on_match = 0;
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
PUSHs(&sv_yes);
+ LEAVE_SCOPE(oldsave);
RETURN;
}
/*SUPPRESS 560*/
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
PUSHs(&sv_yes);
+ LEAVE_SCOPE(oldsave);
RETURN;
}
else if (clen) {
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
PUSHs(&sv_yes);
+ LEAVE_SCOPE(oldsave);
RETURN;
}
else {
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
PUSHs(&sv_yes);
+ LEAVE_SCOPE(oldsave);
RETURN;
}
/* NOTREACHED */
d += clen;
}
s = rx->endp[0];
- } while (regexec(rx, s, strend, orig, s == m,
+ } while (pregexec(rx, s, strend, orig, s == m,
Nullsv, TRUE)); /* (don't match same null twice) */
if (s != d) {
i = strend - s;
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
PUSHs(sv_2mortal(newSViv((I32)iters)));
+ LEAVE_SCOPE(oldsave);
RETURN;
}
PUSHs(&sv_no);
+ LEAVE_SCOPE(oldsave);
RETURN;
}
}
else
c = Nullch;
- if (regexec(rx, s, strend, orig, 0,
+ if (pregexec(rx, s, strend, orig, 0,
SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
long_way:
if (force_on_match) {
sv_catpvn(dstr, c, clen);
if (once)
break;
- } while (regexec(rx, s, strend, orig, s == m, Nullsv,
+ } while (pregexec(rx, s, strend, orig, s == m, Nullsv,
safebase));
sv_catpvn(dstr, s, strend - s);
- sv_replace(TARG, dstr);
+
+ (void)SvOOK_off(TARG);
+ Safefree(SvPVX(TARG));
+ SvPVX(TARG) = SvPVX(dstr);
+ SvCUR_set(TARG, SvCUR(dstr));
+ SvLEN_set(TARG, SvLEN(dstr));
+ SvPVX(dstr) = 0;
+ sv_free(dstr);
+
(void)SvPOK_only(TARG);
SvSETMAGIC(TARG);
PUSHs(sv_2mortal(newSViv((I32)iters)));
+ LEAVE_SCOPE(oldsave);
RETURN;
}
PUSHs(&sv_no);
+ LEAVE_SCOPE(oldsave);
RETURN;
nope:
++BmUSEFUL(pm->op_pmshort);
PUSHs(&sv_no);
+ LEAVE_SCOPE(oldsave);
RETURN;
}
HV *stash;
register CV *cv;
register CONTEXT *cx;
+ I32 gimme;
if (!sv)
DIE("Not a CODE reference");
switch (SvTYPE(sv)) {
default:
if (!SvROK(sv)) {
+ char *sym;
+
if (sv == &sv_yes) /* unfound import, ignore */
RETURN;
if (!SvOK(sv))
DIE(no_usym, "a subroutine");
+ sym = SvPV(sv,na);
if (op->op_private & HINT_STRICT_REFS)
- DIE(no_symref, "a subroutine");
- gv = gv_fetchpv(SvPV(sv, na), FALSE, SVt_PVCV);
- if (!gv)
- cv = 0;
- else
- cv = GvCV(gv);
+ DIE(no_symref, sym, "a subroutine");
+ cv = perl_get_cv(sym, TRUE);
break;
}
cv = (CV*)SvRV(sv);
if (!CvROOT(cv) && !CvXSUB(cv)) {
if (gv = CvGV(cv)) {
- SV *tmpstr = sv_newmortal();
+ SV *tmpstr;
GV *ngv;
+ if (SvFAKE(cv) && GvCV(gv) != cv) { /* autoloaded stub? */
+ cv = GvCV(gv);
+ if (SvTYPE(sv) == SVt_PVGV) {
+ SvREFCNT_dec(GvCV((GV*)sv));
+ GvCV((GV*)sv) = (CV*)SvREFCNT_inc((SV*)cv);
+ }
+ goto retry;
+ }
+ tmpstr = sv_newmortal();
gv_efullname(tmpstr, gv);
ngv = gv_fetchmethod(GvESTASH(gv), "AUTOLOAD");
if (ngv && ngv != gv && (cv = GvCV(ngv))) { /* One more chance... */
gv = ngv;
sv_setsv(GvSV(CvGV(cv)), tmpstr); /* Set CV's $AUTOLOAD */
+ if (tainting)
+ sv_unmagic(GvSV(CvGV(cv)), 't');
goto retry;
}
else
DIE("Undefined subroutine called");
}
- if ((op->op_private & OPpDEREF_DB) && !CvXSUB(cv)) {
+ gimme = GIMME;
+ if ((op->op_private & OPpENTERSUB_DB) && !CvXSUB(cv)) {
sv = GvSV(DBsub);
save_item(sv);
- gv = CvGV(cv);
- gv_efullname(sv,gv);
+ if (SvFLAGS(cv) & (SVpcv_ANON | SVpcv_CLONED)) /* Is GV potentially non-unique? */
+ sv_setsv(sv, newRV((SV*)cv));
+ else {
+ gv = CvGV(cv);
+ gv_efullname(sv,gv);
+ }
cv = GvCV(DBsub);
if (!cv)
DIE("No DBsub routine");
stack_sp = stack_base + items;
}
else {
+ I32 markix = TOPMARK;
+
PUTBACK;
(void)(*CvXSUB(cv))(cv);
+
+ /* Enforce some sanity in scalar context. */
+ if (gimme == G_SCALAR && ++markix != stack_sp - stack_base ) {
+ if (markix > stack_sp - stack_base)
+ *(stack_base + markix) = &sv_undef;
+ else
+ *(stack_base + markix) = *stack_sp;
+ stack_sp = stack_base + markix;
+ }
}
LEAVE;
return NORMAL;
dMARK;
register I32 items = SP - MARK;
I32 hasargs = (op->op_flags & OPf_STACKED) != 0;
- I32 gimme = GIMME;
AV* padlist = CvPADLIST(cv);
SV** svp = AvARRAY(padlist);
push_return(op->op_next);
if (CvDEPTH(cv) > AvFILL(padlist)) {
AV *av;
AV *newpad = newAV();
+ SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
I32 ix = AvFILL((AV*)svp[1]);
svp = AvARRAY(svp[0]);
- while (ix > 0) {
+ for ( ;ix > 0; ix--) {
if (svp[ix] != &sv_undef) {
- char *name = SvPVX(svp[ix]); /* XXX */
- if (*name == '@')
- av_store(newpad, ix--, sv = (SV*)newAV());
- else if (*name == '%')
- av_store(newpad, ix--, sv = (SV*)newHV());
- else
- av_store(newpad, ix--, sv = NEWSV(0,0));
- SvPADMY_on(sv);
+ char *name = SvPVX(svp[ix]);
+ if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* outer lexical? */
+ av_store(newpad, ix,
+ SvREFCNT_inc(oldpad[ix]) );
+ }
+ else { /* our own lexical */
+ if (*name == '@')
+ av_store(newpad, ix, sv = (SV*)newAV());
+ else if (*name == '%')
+ av_store(newpad, ix, sv = (SV*)newHV());
+ else
+ av_store(newpad, ix, sv = NEWSV(0,0));
+ SvPADMY_on(sv);
+ }
}
else {
- av_store(newpad, ix--, sv = NEWSV(0,0));
+ av_store(newpad, ix, sv = NEWSV(0,0));
SvPADTMP_on(sv);
}
}
{
dSP;
SV** svp;
- I32 elem = POPi - curcop->cop_arybase;
+ I32 elem = POPi;
AV *av = (AV*)POPs;
I32 lval = op->op_flags & OPf_MOD;
+ if (elem > 0)
+ elem -= curcop->cop_arybase;
if (SvTYPE(av) != SVt_PVAV)
RETPUSHUNDEF;
svp = av_fetch(av, elem, lval);
sv = *(stack_base + TOPMARK + 1);
gv = 0;
+ if (SvGMAGICAL(sv))
+ mg_get(sv);
if (SvROK(sv))
- ob = SvRV(sv);
+ ob = (SV*)SvRV(sv);
else {
GV* iogv;
char* packname = 0;
SETs(gv);
RETURN;
}
+ *(stack_base + TOPMARK + 1) = sv_2mortal(newRV(iogv));
}
if (!ob || !SvOBJECT(ob)) {