#include "EXTERN.h"
#include "perl.h"
+#ifdef I_UNISTD
+#include <unistd.h>
+#endif
+#ifdef I_FCNTL
+#include <fcntl.h>
+#endif
+#ifdef I_SYS_FILE
+#include <sys/file.h>
+#endif
+
+#define HOP(pos,off) (IN_UTF8 ? utf8_hop(pos, off) : (pos + off))
+
/* Hot code. */
#ifdef USE_THREADS
static void
-unset_cvowner(cvarg)
-void *cvarg;
+unset_cvowner(void *cvarg)
{
register CV* cv = (CV *) cvarg;
#ifdef DEBUGGING
dTHR;
#endif /* DEBUGGING */
- DEBUG_L((PerlIO_printf(PerlIO_stderr(), "%p unsetting CvOWNER of %p:%s\n",
+ DEBUG_S((PerlIO_printf(PerlIO_stderr(), "%p unsetting CvOWNER of %p:%s\n",
thr, cv, SvPEEK((SV*)cv))));
MUTEX_LOCK(CvMUTEXP(cv));
- DEBUG_L(if (CvDEPTH(cv) != 0)
+ DEBUG_S(if (CvDEPTH(cv) != 0)
PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
CvDEPTH(cv)););
assert(thr == CvOWNER(cv));
PP(pp_const)
{
- dSP;
+ djSP;
XPUSHs(cSVOP->op_sv);
RETURN;
}
PP(pp_nextstate)
{
- curcop = (COP*)op;
+ PL_curcop = (COP*)PL_op;
TAINT_NOT; /* Each statement is presumed innocent */
- stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
+ PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
FREETMPS;
return NORMAL;
}
PP(pp_gvsv)
{
- dSP;
- EXTEND(sp,1);
- if (op->op_private & OPpLVAL_INTRO)
+ djSP;
+ EXTEND(SP,1);
+ if (PL_op->op_private & OPpLVAL_INTRO)
PUSHs(save_scalar(cGVOP->op_gv));
else
PUSHs(GvSV(cGVOP->op_gv));
PP(pp_pushmark)
{
- PUSHMARK(stack_sp);
+ PUSHMARK(PL_stack_sp);
return NORMAL;
}
PP(pp_stringify)
{
- dSP; dTARGET;
+ djSP; dTARGET;
STRLEN len;
char *s;
s = SvPV(TOPs,len);
PP(pp_gv)
{
- dSP;
+ djSP;
XPUSHs((SV*)cGVOP->op_gv);
RETURN;
}
PP(pp_and)
{
- dSP;
+ djSP;
if (!SvTRUE(TOPs))
RETURN;
else {
PP(pp_sassign)
{
- dSP; dPOPTOPssrl;
+ djSP; dPOPTOPssrl;
MAGIC *mg;
- if (op->op_private & OPpASSIGN_BACKWARDS) {
+ if (PL_op->op_private & OPpASSIGN_BACKWARDS) {
SV *temp;
temp = left; left = right; right = temp;
}
- if (tainting && tainted && !SvTAINTED(left))
+ if (PL_tainting && PL_tainted && !SvTAINTED(left))
TAINT_NOT;
SvSetMagicSV(right, left);
SETs(right);
PP(pp_cond_expr)
{
- dSP;
+ djSP;
if (SvTRUEx(POPs))
RETURNOP(cCONDOP->op_true);
else
{
I32 oldsave;
TAINT_NOT; /* Each statement is presumed innocent */
- stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
+ PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
FREETMPS;
- oldsave = scopestack[scopestack_ix - 1];
+ oldsave = PL_scopestack[PL_scopestack_ix - 1];
LEAVE_SCOPE(oldsave);
return NORMAL;
}
PP(pp_concat)
{
- dSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
+ djSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
{
dPOPTOPssrl;
STRLEN len;
PP(pp_padsv)
{
- dSP; dTARGET;
+ djSP; dTARGET;
XPUSHs(TARG);
- if (op->op_flags & OPf_MOD) {
- if (op->op_private & OPpLVAL_INTRO)
- SAVECLEARSV(curpad[op->op_targ]);
- else if (op->op_private & OPpDEREF)
- vivify_ref(curpad[op->op_targ], op->op_private & OPpDEREF);
+ if (PL_op->op_flags & OPf_MOD) {
+ if (PL_op->op_private & OPpLVAL_INTRO)
+ SAVECLEARSV(PL_curpad[PL_op->op_targ]);
+ else if (PL_op->op_private & OPpDEREF) {
+ PUTBACK;
+ vivify_ref(PL_curpad[PL_op->op_targ], PL_op->op_private & OPpDEREF);
+ SPAGAIN;
+ }
}
RETURN;
}
PP(pp_readline)
{
- last_in_gv = (GV*)(*stack_sp--);
+ PL_last_in_gv = (GV*)(*PL_stack_sp--);
return do_readline();
}
PP(pp_eq)
{
- dSP; tryAMAGICbinSET(eq,0);
+ djSP; tryAMAGICbinSET(eq,0);
{
dPOPnv;
SETs(boolSV(TOPn == value));
PP(pp_preinc)
{
- dSP;
+ djSP;
if (SvREADONLY(TOPs) || SvTYPE(TOPs) > SVt_PVLV)
croak(no_modify);
if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) &&
PP(pp_or)
{
- dSP;
+ djSP;
if (SvTRUE(TOPs))
RETURN;
else {
PP(pp_add)
{
- dSP; dATARGET; tryAMAGICbin(add,opASSIGN);
+ djSP; dATARGET; tryAMAGICbin(add,opASSIGN);
{
dPOPTOPnnrl_ul;
SETn( left + right );
PP(pp_aelemfast)
{
- dSP;
+ djSP;
AV *av = GvAV((GV*)cSVOP->op_sv);
- SV** svp = av_fetch(av, op->op_private, op->op_flags & OPf_MOD);
- PUSHs(svp ? *svp : &sv_undef);
+ U32 lval = PL_op->op_flags & OPf_MOD;
+ SV** svp = av_fetch(av, PL_op->op_private, lval);
+ SV *sv = (svp ? *svp : &PL_sv_undef);
+ EXTEND(SP, 1);
+ if (!lval && SvGMAGICAL(sv)) /* see note in pp_helem() */
+ sv = sv_mortalcopy(sv);
+ PUSHs(sv);
RETURN;
}
PP(pp_join)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
MARK++;
do_join(TARG, *MARK, MARK, SP);
SP = MARK;
PP(pp_pushre)
{
- dSP;
+ djSP;
#ifdef DEBUGGING
/*
* We ass_u_me that LvTARGOFF() comes first, and that two STRLENs
SV* sv = sv_newmortal();
sv_upgrade(sv, SVt_PVLV);
LvTYPE(sv) = '/';
- Copy(&op, &LvTARGOFF(sv), 1, OP*);
+ Copy(&PL_op, &LvTARGOFF(sv), 1, OP*);
XPUSHs(sv);
#else
- XPUSHs((SV*)op);
+ XPUSHs((SV*)PL_op);
#endif
RETURN;
}
PP(pp_print)
{
- dSP; dMARK; dORIGMARK;
+ djSP; dMARK; dORIGMARK;
GV *gv;
IO *io;
register PerlIO *fp;
MAGIC *mg;
- if (op->op_flags & OPf_STACKED)
+ if (PL_op->op_flags & OPf_STACKED)
gv = (GV*)*++MARK;
else
- gv = defoutgv;
- if (SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
+ gv = PL_defoutgv;
+ if (mg = SvTIED_mg((SV*)gv, 'q')) {
if (MARK == ORIGMARK) {
- EXTEND(SP, 1);
+ /* If using default handle then we need to make space to
+ * pass object as 1st arg, so move other args up ...
+ */
+ MEXTEND(SP, 1);
++MARK;
Move(MARK, MARK + 1, (SP - MARK) + 1, SV*);
++SP;
}
PUSHMARK(MARK - 1);
- *MARK = mg->mg_obj;
+ *MARK = SvTIED_obj((SV*)gv, mg);
PUTBACK;
ENTER;
perl_call_method("PRINT", G_SCALAR);
RETURN;
}
if (!(io = GvIO(gv))) {
- if (dowarn) {
+ if (ckWARN(WARN_UNOPENED)) {
SV* sv = sv_newmortal();
gv_fullname3(sv, gv, Nullch);
- warn("Filehandle %s never opened", SvPV(sv,na));
+ warner(WARN_UNOPENED, "Filehandle %s never opened", SvPV(sv,PL_na));
}
SETERRNO(EBADF,RMS$_IFI);
goto just_say_no;
}
else if (!(fp = IoOFP(io))) {
- if (dowarn) {
+ if (ckWARN2(WARN_CLOSED, WARN_IO)) {
SV* sv = sv_newmortal();
gv_fullname3(sv, gv, Nullch);
if (IoIFP(io))
- warn("Filehandle %s opened only for input", SvPV(sv,na));
- else
- warn("print on closed filehandle %s", SvPV(sv,na));
+ warner(WARN_IO, "Filehandle %s opened only for input",
+ SvPV(sv,PL_na));
+ else if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "print on closed filehandle %s",
+ SvPV(sv,PL_na));
}
SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
goto just_say_no;
}
else {
MARK++;
- if (ofslen) {
+ if (PL_ofslen) {
while (MARK <= SP) {
if (!do_print(*MARK, fp))
break;
MARK++;
if (MARK <= SP) {
- if (PerlIO_write(fp, ofs, ofslen) == 0 || PerlIO_error(fp)) {
+ if (PerlIO_write(fp, PL_ofs, PL_ofslen) == 0 || PerlIO_error(fp)) {
MARK--;
break;
}
if (MARK <= SP)
goto just_say_no;
else {
- if (orslen)
- if (PerlIO_write(fp, ors, orslen) == 0 || PerlIO_error(fp))
+ if (PL_orslen)
+ if (PerlIO_write(fp, PL_ors, PL_orslen) == 0 || PerlIO_error(fp))
goto just_say_no;
if (IoFLAGS(io) & IOf_FLUSH)
}
}
SP = ORIGMARK;
- PUSHs(&sv_yes);
+ PUSHs(&PL_sv_yes);
RETURN;
just_say_no:
SP = ORIGMARK;
- PUSHs(&sv_undef);
+ PUSHs(&PL_sv_undef);
RETURN;
}
PP(pp_rv2av)
{
- dSP; dPOPss;
+ djSP; dPOPss;
AV *av;
if (SvROK(sv)) {
av = (AV*)SvRV(sv);
if (SvTYPE(av) != SVt_PVAV)
DIE("Not an ARRAY reference");
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
PUSHs((SV*)av);
RETURN;
}
else {
if (SvTYPE(sv) == SVt_PVAV) {
av = (AV*)sv;
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
PUSHs((SV*)av);
RETURN;
}
goto wasref;
}
if (!SvOK(sv)) {
- if (op->op_flags & OPf_REF ||
- op->op_private & HINT_STRICT_REFS)
+ if (PL_op->op_flags & OPf_REF ||
+ PL_op->op_private & HINT_STRICT_REFS)
DIE(no_usym, "an ARRAY");
- if (dowarn)
- warn(warn_uninit);
+ if (ckWARN(WARN_UNINITIALIZED))
+ warner(WARN_UNINITIALIZED, warn_uninit);
if (GIMME == G_ARRAY)
RETURN;
RETPUSHUNDEF;
}
- sym = SvPV(sv,na);
- if (op->op_private & HINT_STRICT_REFS)
+ sym = SvPV(sv,PL_na);
+ if (PL_op->op_private & HINT_STRICT_REFS)
DIE(no_symref, sym, "an ARRAY");
gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVAV);
} else {
gv = (GV*)sv;
}
av = GvAVn(gv);
- if (op->op_private & OPpLVAL_INTRO)
+ if (PL_op->op_private & OPpLVAL_INTRO)
av = save_ary(gv);
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
PUSHs((SV*)av);
RETURN;
}
if (GIMME == G_ARRAY) {
I32 maxarg = AvFILL(av) + 1;
- EXTEND(SP, maxarg);
- Copy(AvARRAY(av), SP+1, maxarg, SV*);
+ EXTEND(SP, maxarg);
+ if (SvRMAGICAL(av)) {
+ U32 i;
+ for (i=0; i < maxarg; i++) {
+ SV **svp = av_fetch(av, i, FALSE);
+ SP[i+1] = (svp) ? *svp : &PL_sv_undef;
+ }
+ }
+ else {
+ Copy(AvARRAY(av), SP+1, maxarg, SV*);
+ }
SP += maxarg;
}
else {
PP(pp_rv2hv)
{
- dSP; dTOPss;
+ djSP; dTOPss;
HV *hv;
if (SvROK(sv)) {
hv = (HV*)SvRV(sv);
if (SvTYPE(hv) != SVt_PVHV && SvTYPE(hv) != SVt_PVAV)
DIE("Not a HASH reference");
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
SETs((SV*)hv);
RETURN;
}
else {
if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) {
hv = (HV*)sv;
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
SETs((SV*)hv);
RETURN;
}
goto wasref;
}
if (!SvOK(sv)) {
- if (op->op_flags & OPf_REF ||
- op->op_private & HINT_STRICT_REFS)
+ if (PL_op->op_flags & OPf_REF ||
+ PL_op->op_private & HINT_STRICT_REFS)
DIE(no_usym, "a HASH");
- if (dowarn)
- warn(warn_uninit);
+ if (ckWARN(WARN_UNINITIALIZED))
+ warner(WARN_UNINITIALIZED, warn_uninit);
if (GIMME == G_ARRAY) {
SP--;
RETURN;
}
RETSETUNDEF;
}
- sym = SvPV(sv,na);
- if (op->op_private & HINT_STRICT_REFS)
+ sym = SvPV(sv,PL_na);
+ if (PL_op->op_private & HINT_STRICT_REFS)
DIE(no_symref, sym, "a HASH");
gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVHV);
} else {
gv = (GV*)sv;
}
hv = GvHVn(gv);
- if (op->op_private & OPpLVAL_INTRO)
+ if (PL_op->op_private & OPpLVAL_INTRO)
hv = save_hash(gv);
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
SETs((SV*)hv);
RETURN;
}
}
if (GIMME == G_ARRAY) { /* array wanted */
- *stack_sp = (SV*)hv;
+ *PL_stack_sp = (SV*)hv;
return do_kv(ARGS);
}
else {
dTARGET;
- /* This bit is OK even when hv is really an AV */
+ if (SvTYPE(hv) == SVt_PVAV)
+ hv = avhv_keys((AV*)hv);
if (HvFILL(hv))
sv_setpvf(TARG, "%ld/%ld",
(long)HvFILL(hv), (long)HvMAX(hv) + 1);
PP(pp_aassign)
{
- dSP;
- SV **lastlelem = stack_sp;
- SV **lastrelem = stack_base + POPMARK;
- SV **firstrelem = stack_base + POPMARK + 1;
+ djSP;
+ SV **lastlelem = PL_stack_sp;
+ SV **lastrelem = PL_stack_base + POPMARK;
+ SV **firstrelem = PL_stack_base + POPMARK + 1;
SV **firstlelem = lastrelem + 1;
register SV **relem;
I32 i;
int magic;
- delaymagic = DM_DELAY; /* catch simultaneous items */
+ PL_delaymagic = DM_DELAY; /* catch simultaneous items */
/* If there's a common identifier on both sides we have to take
* special care that assigning the identifier on the left doesn't
* clobber a value on the right that's used later in the list.
*/
- if (op->op_private & OPpASSIGN_COMMON) {
+ if (PL_op->op_private & OPpASSIGN_COMMON) {
+ EXTEND_MORTAL(lastrelem - firstrelem + 1);
for (relem = firstrelem; relem <= lastrelem; relem++) {
/*SUPPRESS 560*/
if (sv = *relem) {
hv_clear(hash);
while (relem < lastrelem) { /* gobble up all the rest */
- STRLEN len;
HE *didstore;
if (*relem)
sv = *(relem++);
else
- sv = &sv_no, relem++;
+ sv = &PL_sv_no, relem++;
tmpstr = NEWSV(29,0);
if (*relem)
sv_setsv(tmpstr,*relem); /* value */
}
TAINT_NOT;
}
- if (relem == lastrelem && dowarn)
- warn("Odd number of elements in hash list");
+ if (relem == lastrelem) {
+ if (*relem) {
+ HE *didstore;
+ if (ckWARN(WARN_UNSAFE)) {
+ if (relem == firstrelem &&
+ SvROK(*relem) &&
+ ( SvTYPE(SvRV(*relem)) == SVt_PVAV ||
+ SvTYPE(SvRV(*relem)) == SVt_PVHV ) )
+ warner(WARN_UNSAFE, "Reference found where even-sized list expected");
+ else
+ warner(WARN_UNSAFE, "Odd number of elements in hash assignment");
+ }
+ tmpstr = NEWSV(29,0);
+ didstore = hv_store_ent(hash,*relem,tmpstr,0);
+ if (magic) {
+ if (SvSMAGICAL(tmpstr))
+ mg_set(tmpstr);
+ if (!didstore)
+ SvREFCNT_dec(tmpstr);
+ }
+ TAINT_NOT;
+ }
+ relem++;
+ }
}
break;
default:
if (SvTHINKFIRST(sv)) {
- if (SvREADONLY(sv) && curcop != &compiling) {
- if (sv != &sv_undef && sv != &sv_yes && sv != &sv_no)
+ if (SvREADONLY(sv) && PL_curcop != &PL_compiling) {
+ if (!SvIMMORTAL(sv))
DIE(no_modify);
if (relem <= lastrelem)
relem++;
*(relem++) = sv;
}
else
- sv_setsv(sv, &sv_undef);
+ sv_setsv(sv, &PL_sv_undef);
SvSETMAGIC(sv);
break;
}
}
- if (delaymagic & ~DM_DELAY) {
- if (delaymagic & DM_UID) {
+ if (PL_delaymagic & ~DM_DELAY) {
+ if (PL_delaymagic & DM_UID) {
#ifdef HAS_SETRESUID
- (void)setresuid(uid,euid,(Uid_t)-1);
+ (void)setresuid(PL_uid,PL_euid,(Uid_t)-1);
#else
# ifdef HAS_SETREUID
- (void)setreuid(uid,euid);
+ (void)setreuid(PL_uid,PL_euid);
# else
# ifdef HAS_SETRUID
- if ((delaymagic & DM_UID) == DM_RUID) {
- (void)setruid(uid);
- delaymagic &= ~DM_RUID;
+ if ((PL_delaymagic & DM_UID) == DM_RUID) {
+ (void)setruid(PL_uid);
+ PL_delaymagic &= ~DM_RUID;
}
# endif /* HAS_SETRUID */
# ifdef HAS_SETEUID
- if ((delaymagic & DM_UID) == DM_EUID) {
- (void)seteuid(uid);
- delaymagic &= ~DM_EUID;
+ if ((PL_delaymagic & DM_UID) == DM_EUID) {
+ (void)seteuid(PL_uid);
+ PL_delaymagic &= ~DM_EUID;
}
# endif /* HAS_SETEUID */
- if (delaymagic & DM_UID) {
- if (uid != euid)
+ if (PL_delaymagic & DM_UID) {
+ if (PL_uid != PL_euid)
DIE("No setreuid available");
- (void)setuid(uid);
+ (void)PerlProc_setuid(PL_uid);
}
# endif /* HAS_SETREUID */
#endif /* HAS_SETRESUID */
- uid = (int)getuid();
- euid = (int)geteuid();
+ PL_uid = (int)PerlProc_getuid();
+ PL_euid = (int)PerlProc_geteuid();
}
- if (delaymagic & DM_GID) {
+ if (PL_delaymagic & DM_GID) {
#ifdef HAS_SETRESGID
- (void)setresgid(gid,egid,(Gid_t)-1);
+ (void)setresgid(PL_gid,PL_egid,(Gid_t)-1);
#else
# ifdef HAS_SETREGID
- (void)setregid(gid,egid);
+ (void)setregid(PL_gid,PL_egid);
# else
# ifdef HAS_SETRGID
- if ((delaymagic & DM_GID) == DM_RGID) {
- (void)setrgid(gid);
- delaymagic &= ~DM_RGID;
+ if ((PL_delaymagic & DM_GID) == DM_RGID) {
+ (void)setrgid(PL_gid);
+ PL_delaymagic &= ~DM_RGID;
}
# endif /* HAS_SETRGID */
# ifdef HAS_SETEGID
- if ((delaymagic & DM_GID) == DM_EGID) {
- (void)setegid(gid);
- delaymagic &= ~DM_EGID;
+ if ((PL_delaymagic & DM_GID) == DM_EGID) {
+ (void)setegid(PL_gid);
+ PL_delaymagic &= ~DM_EGID;
}
# endif /* HAS_SETEGID */
- if (delaymagic & DM_GID) {
- if (gid != egid)
+ if (PL_delaymagic & DM_GID) {
+ if (PL_gid != PL_egid)
DIE("No setregid available");
- (void)setgid(gid);
+ (void)PerlProc_setgid(PL_gid);
}
# endif /* HAS_SETREGID */
#endif /* HAS_SETRESGID */
- gid = (int)getgid();
- egid = (int)getegid();
+ PL_gid = (int)PerlProc_getgid();
+ PL_egid = (int)PerlProc_getegid();
}
- tainting |= (uid && (euid != uid || egid != gid));
+ PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
}
- delaymagic = 0;
+ PL_delaymagic = 0;
gimme = GIMME_V;
if (gimme == G_VOID)
SP = firstrelem + (lastlelem - firstlelem);
lelem = firstlelem + (relem - firstrelem);
while (relem <= SP)
- *relem++ = (lelem <= lastlelem) ? *lelem++ : &sv_undef;
+ *relem++ = (lelem <= lastlelem) ? *lelem++ : &PL_sv_undef;
}
RETURN;
}
+PP(pp_qr)
+{
+ djSP;
+ register PMOP *pm = cPMOP;
+ SV *rv = sv_newmortal();
+ SV *sv = newSVrv(rv, "Regexp");
+ sv_magic(sv,(SV*)ReREFCNT_inc(pm->op_pmregexp),'r',0,0);
+ RETURNX(PUSHs(rv));
+}
+
PP(pp_match)
{
- dSP; dTARG;
+ djSP; dTARG;
register PMOP *pm = cPMOP;
register char *t;
register char *s;
I32 safebase;
char *truebase;
register REGEXP *rx = pm->op_pmregexp;
+ bool rxtainted;
I32 gimme = GIMME;
STRLEN len;
I32 minmatch = 0;
- I32 oldsave = savestack_ix;
+ I32 oldsave = PL_savestack_ix;
I32 update_minmatch = 1;
+ SV *screamer;
- if (op->op_flags & OPf_STACKED)
+ if (PL_op->op_flags & OPf_STACKED)
TARG = POPs;
else {
- TARG = GvSV(defgv);
+ TARG = DEFSV;
EXTEND(SP,1);
}
+ PUTBACK; /* EVAL blocks need stack_sp. */
s = SvPV(TARG, len);
strend = s + len;
if (!s)
DIE("panic: do_match");
+ rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) ||
+ (PL_tainted && (pm->op_pmflags & PMf_RETAINT)));
TAINT_NOT;
- if (pm->op_pmflags & PMf_USED) {
+ if (pm->op_pmdynflags & PMdf_USED) {
+ failure:
if (gimme == G_ARRAY)
RETURN;
RETPUSHNO;
}
- if (!rx->prelen && curpm) {
- pm = curpm;
+ if (!rx->prelen && PL_curpm) {
+ pm = PL_curpm;
rx = pm->op_pmregexp;
}
+ if (rx->minlen > len) goto failure;
+
+ screamer = ( (SvSCREAM(TARG) && rx->check_substr
+ && SvTYPE(rx->check_substr) == SVt_PVBM
+ && SvVALID(rx->check_substr))
+ ? TARG : Nullsv);
truebase = t = s;
if (global = pm->op_pmflags & PMf_GLOBAL) {
rx->startp[0] = 0;
}
}
}
- if (!rx->nparens && !global)
- gimme = G_SCALAR; /* accidental array context? */
- safebase = (((gimme == G_ARRAY) || global || !rx->nparens)
- && !sawampersand);
+ safebase = ((gimme != G_ARRAY && !global && rx->nparens)
+ || SvTEMP(TARG) || PL_sawampersand)
+ ? REXEC_COPY_STR : 0;
if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
- SAVEINT(multiline);
- multiline = pm->op_pmflags & PMf_MULTILINE;
+ SAVEINT(PL_multiline);
+ PL_multiline = pm->op_pmflags & PMf_MULTILINE;
}
play_it_again:
if (update_minmatch++)
minmatch = (s == rx->startp[0]);
}
- if (pm->op_pmshort) {
- if (pm->op_pmflags & PMf_SCANFIRST) {
- if (SvSCREAM(TARG)) {
- if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
+ if (rx->check_substr) {
+ if (!(rx->reganch & ROPT_NOSCAN)) { /* Floating checkstring. */
+ if ( screamer ) {
+ I32 p = -1;
+ char *b;
+
+ if (PL_screamfirst[BmRARE(rx->check_substr)] < 0)
goto nope;
- else if (!(s = screaminstr(TARG, pm->op_pmshort)))
+
+ b = (char*)HOP((U8*)s, rx->check_offset_min);
+ if (!(s = screaminstr(TARG, rx->check_substr, b - s, 0, &p, 0)))
goto nope;
- else if (pm->op_pmflags & PMf_ALL)
+
+ if ((rx->reganch & ROPT_CHECK_ALL)
+ && !PL_sawampersand && !SvTAIL(rx->check_substr))
goto yup;
}
- else if (!(s = fbm_instr((unsigned char*)s,
- (unsigned char*)strend, pm->op_pmshort)))
+ else if (!(s = fbm_instr((unsigned char*)HOP((U8*)s, rx->check_offset_min),
+ (unsigned char*)strend,
+ rx->check_substr, 0)))
goto nope;
- else if (pm->op_pmflags & PMf_ALL)
+ else if ((rx->reganch & ROPT_CHECK_ALL) && !PL_sawampersand)
goto yup;
- if (s && rx->regback >= 0) {
- ++BmUSEFUL(pm->op_pmshort);
- s -= rx->regback;
- if (s < t)
- s = t;
+ if (s && rx->check_offset_max < s - t) {
+ ++BmUSEFUL(rx->check_substr);
+ s = (char*)HOP((U8*)s, -rx->check_offset_max);
}
else
s = t;
}
- else if (!multiline) {
- if (*SvPVX(pm->op_pmshort) != *s
- || (pm->op_pmslen > 1
- && memNE(SvPVX(pm->op_pmshort), s, pm->op_pmslen)))
+ /* Now checkstring is fixed, i.e. at fixed offset from the
+ beginning of match, and the match is anchored at s. */
+ else if (!PL_multiline) { /* Anchored near beginning of string. */
+ I32 slen;
+ char *b = (char*)HOP((U8*)s, rx->check_offset_min);
+ if (*SvPVX(rx->check_substr) != *b
+ || ((slen = SvCUR(rx->check_substr)) > 1
+ && memNE(SvPVX(rx->check_substr), b, slen)))
goto nope;
}
- if (!rx->naughty && --BmUSEFUL(pm->op_pmshort) < 0) {
- SvREFCNT_dec(pm->op_pmshort);
- pm->op_pmshort = Nullsv; /* opt is being useless */
+ if (!(rx->reganch & ROPT_NAUGHTY) && --BmUSEFUL(rx->check_substr) < 0
+ && rx->check_substr == rx->float_substr) {
+ SvREFCNT_dec(rx->check_substr);
+ rx->check_substr = Nullsv; /* opt is being useless */
+ rx->float_substr = Nullsv;
}
}
- if (pregexec(rx, s, strend, truebase, minmatch,
- SvSCREAM(TARG) ? TARG : Nullsv, safebase))
+ if (CALLREGEXEC(rx, s, strend, truebase, minmatch,
+ screamer, NULL, safebase))
{
- curpm = pm;
+ PL_curpm = pm;
if (pm->op_pmflags & PMf_ONCE)
- pm->op_pmflags |= PMf_USED;
+ pm->op_pmdynflags |= PMdf_USED;
goto gotcha;
}
else
/*NOTREACHED*/
gotcha:
- TAINT_IF(rx->exec_tainted);
+ if (rxtainted)
+ RX_MATCH_TAINTED_on(rx);
+ TAINT_IF(RX_MATCH_TAINTED(rx));
if (gimme == G_ARRAY) {
I32 iters, i, len;
i = 1;
else
i = 0;
+ SPAGAIN; /* EVAL blocks could move the stack. */
EXTEND(SP, iters + i);
EXTEND_MORTAL(iters + i);
for (i = !i; i <= iters; i++) {
strend = rx->subend;
if (rx->startp[0] && rx->startp[0] == rx->endp[0])
++rx->endp[0];
+ PUTBACK; /* EVAL blocks may use stack */
goto play_it_again;
}
+ else if (!iters)
+ XPUSHs(&PL_sv_yes);
LEAVE_SCOPE(oldsave);
RETURN;
}
RETPUSHYES;
}
-yup:
- TAINT_IF(rx->exec_tainted);
- ++BmUSEFUL(pm->op_pmshort);
- curpm = pm;
+yup: /* Confirmed by check_substr */
+ if (rxtainted)
+ RX_MATCH_TAINTED_on(rx);
+ TAINT_IF(RX_MATCH_TAINTED(rx));
+ ++BmUSEFUL(rx->check_substr);
+ PL_curpm = pm;
if (pm->op_pmflags & PMf_ONCE)
- pm->op_pmflags |= PMf_USED;
+ pm->op_pmdynflags |= PMdf_USED;
Safefree(rx->subbase);
rx->subbase = Nullch;
if (global) {
rx->subbeg = truebase;
rx->subend = strend;
rx->startp[0] = s;
- rx->endp[0] = s + SvCUR(pm->op_pmshort);
+ rx->endp[0] = s + SvCUR(rx->check_substr);
goto gotcha;
}
- if (sawampersand) {
+ if (PL_sawampersand) {
char *tmps;
tmps = rx->subbase = savepvn(t, strend-t);
rx->subbeg = tmps;
rx->subend = tmps + (strend-t);
tmps = rx->startp[0] = tmps + (s - t);
- rx->endp[0] = tmps + SvCUR(pm->op_pmshort);
+ rx->endp[0] = tmps + SvCUR(rx->check_substr);
}
LEAVE_SCOPE(oldsave);
RETPUSHYES;
nope:
- if (pm->op_pmshort)
- ++BmUSEFUL(pm->op_pmshort);
+ if (rx->check_substr)
+ ++BmUSEFUL(rx->check_substr);
ret_no:
if (global && !(pm->op_pmflags & PMf_CONTINUE)) {
}
OP *
-do_readline()
+do_readline(void)
{
- dTHR;
dSP; dTARGETSTACKED;
register SV *sv;
STRLEN tmplen = 0;
STRLEN offset;
PerlIO *fp;
- register IO *io = GvIO(last_in_gv);
- register I32 type = op->op_type;
+ register IO *io = GvIO(PL_last_in_gv);
+ register I32 type = PL_op->op_type;
I32 gimme = GIMME_V;
MAGIC *mg;
- if (SvMAGICAL(last_in_gv) && (mg = mg_find((SV*)last_in_gv, 'q'))) {
+ if (mg = SvTIED_mg((SV*)PL_last_in_gv, 'q')) {
PUSHMARK(SP);
- XPUSHs(mg->mg_obj);
+ XPUSHs(SvTIED_obj((SV*)PL_last_in_gv, mg));
PUTBACK;
ENTER;
perl_call_method("READLINE", gimme);
if (IoFLAGS(io) & IOf_START) {
IoFLAGS(io) &= ~IOf_START;
IoLINES(io) = 0;
- if (av_len(GvAVn(last_in_gv)) < 0) {
- SV *tmpstr = newSVpv("-", 1); /* assume stdin */
- av_push(GvAVn(last_in_gv), tmpstr);
+ if (av_len(GvAVn(PL_last_in_gv)) < 0) {
+ do_open(PL_last_in_gv,"-",1,FALSE,O_RDONLY,0,Nullfp);
+ sv_setpvn(GvSV(PL_last_in_gv), "-", 1);
+ SvSETMAGIC(GvSV(PL_last_in_gv));
+ fp = IoIFP(io);
+ goto have_fp;
}
}
- fp = nextargv(last_in_gv);
+ fp = nextargv(PL_last_in_gv);
if (!fp) { /* Note: fp != IoIFP(io) */
- (void)do_close(last_in_gv, FALSE); /* now it does*/
+ (void)do_close(PL_last_in_gv, FALSE); /* now it does*/
IoFLAGS(io) |= IOf_START;
}
}
((struct NAM *)((struct FAB *)cxt)->fab$l_nam)->nam$l_fnb
but that's unsupported, so I don't want to do it now and
have it bite someone in the future. */
- strcat(tmpfnam,tmpnam(NULL));
+ strcat(tmpfnam,PerlLIO_tmpnam(NULL));
cp = SvPV(tmpglob,i);
for (; i; i--) {
if (cp[i] == ';') hasver = 1;
}
}
if ((tmpfp = PerlIO_open(tmpfnam,"w+","fop=dlt")) != NULL) {
- ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL);
+ Stat_t st;
+ if (!PerlLIO_stat(SvPVX(tmpglob),&st) && S_ISDIR(st.st_mode))
+ ok = ((wilddsc.dsc$a_pointer = tovmspath(SvPVX(tmpglob),vmsspec)) != NULL);
+ else ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL);
if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer);
while (ok && ((sts = lib$find_file(&wilddsc,&rsdsc,&cxt,
&dfltdsc,NULL,NULL,NULL))&1)) {
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, "; do echo \"$a\\0\\c\"; done |");
#else
+#ifdef DJGPP
+ sv_setpv(tmpcmd, "/dev/dosglob/"); /* File System Extension */
+ sv_catsv(tmpcmd, tmpglob);
+#else
sv_setpv(tmpcmd, "perlglob ");
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, " |");
+#endif /* !DJGPP */
#endif /* !OS2 */
#else /* !DOSISH */
#if defined(CSH)
- sv_setpvn(tmpcmd, cshname, cshlen);
+ sv_setpvn(tmpcmd, PL_cshname, PL_cshlen);
sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
sv_catsv(tmpcmd, tmpglob);
sv_catpv(tmpcmd, "' 2>/dev/null |");
#endif
#endif /* !CSH */
#endif /* !DOSISH */
- (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
- FALSE, 0, 0, Nullfp);
+ (void)do_open(PL_last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
+ FALSE, O_RDONLY, 0, Nullfp);
fp = IoIFP(io);
#endif /* !VMS */
LEAVE;
SP--;
}
if (!fp) {
- if (dowarn && io && !(IoFLAGS(io) & IOf_START))
- warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
+ if (ckWARN(WARN_CLOSED) && io && !(IoFLAGS(io) & IOf_START))
+ warner(WARN_CLOSED,
+ "Read on closed filehandle <%s>", GvENAME(PL_last_in_gv));
if (gimme == G_SCALAR) {
(void)SvOK_off(TARG);
PUSHTARG;
}
RETURN;
}
+ have_fp:
if (gimme == G_SCALAR) {
sv = TARG;
if (SvROK(sv))
if (!sv_gets(sv, fp, offset)) {
PerlIO_clearerr(fp);
if (IoFLAGS(io) & IOf_ARGV) {
- fp = nextargv(last_in_gv);
+ fp = nextargv(PL_last_in_gv);
if (fp)
continue;
- (void)do_close(last_in_gv, FALSE);
+ (void)do_close(PL_last_in_gv, FALSE);
IoFLAGS(io) |= IOf_START;
}
else if (type == OP_GLOB) {
- if (do_close(last_in_gv, FALSE) & ~0xFF)
- warn("internal error: glob failed");
+ if (!do_close(PL_last_in_gv, FALSE) && ckWARN(WARN_CLOSED)) {
+ warner(WARN_CLOSED,
+ "glob failed (child exited with status %d%s)",
+ STATUS_CURRENT >> 8,
+ (STATUS_CURRENT & 0x80) ? ", core dumped" : "");
+ }
}
if (gimme == G_SCALAR) {
(void)SvOK_off(TARG);
if (type == OP_GLOB) {
char *tmps;
- if (SvCUR(sv) > 0 && SvCUR(rs) > 0) {
+ if (SvCUR(sv) > 0 && SvCUR(PL_rs) > 0) {
tmps = SvEND(sv) - 1;
- if (*tmps == *SvPVX(rs)) {
+ if (*tmps == *SvPVX(PL_rs)) {
*tmps = '\0';
SvCUR(sv)--;
}
if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
break;
- if (*tmps && Stat(SvPVX(sv), &statbuf) < 0) {
+ if (*tmps && PerlLIO_stat(SvPVX(sv), &PL_statbuf) < 0) {
(void)POPs; /* Unmatched wildcard? Chuck it... */
continue;
}
PP(pp_enter)
{
- dSP;
- register CONTEXT *cx;
- I32 gimme = OP_GIMME(op, -1);
+ djSP;
+ register PERL_CONTEXT *cx;
+ I32 gimme = OP_GIMME(PL_op, -1);
if (gimme == -1) {
if (cxstack_ix >= 0)
ENTER;
SAVETMPS;
- PUSHBLOCK(cx, CXt_BLOCK, sp);
+ PUSHBLOCK(cx, CXt_BLOCK, SP);
RETURN;
}
PP(pp_helem)
{
- dSP;
+ djSP;
HE* he;
SV **svp;
SV *keysv = POPs;
HV *hv = (HV*)POPs;
- U32 lval = op->op_flags & OPf_MOD;
- U32 defer = op->op_private & OPpLVAL_DEFER;
+ U32 lval = PL_op->op_flags & OPf_MOD;
+ U32 defer = PL_op->op_private & OPpLVAL_DEFER;
+ SV *sv;
if (SvTYPE(hv) == SVt_PVHV) {
he = hv_fetch_ent(hv, keysv, lval && !defer, 0);
svp = he ? &HeVAL(he) : 0;
}
else if (SvTYPE(hv) == SVt_PVAV) {
+ if (PL_op->op_private & OPpLVAL_INTRO)
+ DIE("Can't localize pseudo-hash element");
svp = avhv_fetch_ent((AV*)hv, keysv, lval && !defer, 0);
}
else {
RETPUSHUNDEF;
}
if (lval) {
- if (!svp || *svp == &sv_undef) {
+ if (!svp || *svp == &PL_sv_undef) {
SV* lv;
SV* key2;
if (!defer)
- DIE(no_helem, SvPV(keysv, na));
+ DIE(no_helem, SvPV(keysv, PL_na));
lv = sv_newmortal();
sv_upgrade(lv, SVt_PVLV);
LvTYPE(lv) = 'y';
PUSHs(lv);
RETURN;
}
- if (op->op_private & OPpLVAL_INTRO) {
+ if (PL_op->op_private & OPpLVAL_INTRO) {
if (HvNAME(hv) && isGV(*svp))
- save_gp((GV*)*svp, !(op->op_flags & OPf_SPECIAL));
+ save_gp((GV*)*svp, !(PL_op->op_flags & OPf_SPECIAL));
else
- save_svref(svp);
- }
- else if (op->op_private & OPpDEREF)
- vivify_ref(*svp, op->op_private & OPpDEREF);
- }
- PUSHs(svp ? *svp : &sv_undef);
+ save_helem(hv, keysv, svp);
+ }
+ else if (PL_op->op_private & OPpDEREF)
+ vivify_ref(*svp, PL_op->op_private & OPpDEREF);
+ }
+ sv = (svp ? *svp : &PL_sv_undef);
+ /* This makes C<local $tied{foo} = $tied{foo}> possible.
+ * Pushing the magical RHS on to the stack is useless, since
+ * that magic is soon destined to be misled by the local(),
+ * and thus the later pp_sassign() will fail to mg_get() the
+ * old value. This should also cure problems with delayed
+ * mg_get()s. GSAR 98-07-03 */
+ if (!lval && SvGMAGICAL(sv))
+ sv = sv_mortalcopy(sv);
+ PUSHs(sv);
RETURN;
}
PP(pp_leave)
{
- dSP;
- register CONTEXT *cx;
+ djSP;
+ register PERL_CONTEXT *cx;
register SV **mark;
SV **newsp;
PMOP *newpm;
I32 gimme;
- if (op->op_flags & OPf_SPECIAL) {
+ if (PL_op->op_flags & OPf_SPECIAL) {
cx = &cxstack[cxstack_ix];
- cx->blk_oldpm = curpm; /* fake block should preserve $1 et al */
+ cx->blk_oldpm = PL_curpm; /* fake block should preserve $1 et al */
}
POPBLOCK(cx,newpm);
- gimme = OP_GIMME(op, -1);
+ gimme = OP_GIMME(PL_op, -1);
if (gimme == -1) {
if (cxstack_ix >= 0)
gimme = cxstack[cxstack_ix].blk_gimme;
*MARK = sv_mortalcopy(TOPs);
else {
MEXTEND(mark,0);
- *MARK = &sv_undef;
+ *MARK = &PL_sv_undef;
}
SP = MARK;
}
}
}
}
- curpm = newpm; /* Don't pop $1 et al till now */
+ PL_curpm = newpm; /* Don't pop $1 et al till now */
LEAVE;
PP(pp_iter)
{
- dSP;
- register CONTEXT *cx;
+ djSP;
+ register PERL_CONTEXT *cx;
SV* sv;
AV* av;
- EXTEND(sp, 1);
+ EXTEND(SP, 1);
cx = &cxstack[cxstack_ix];
- if (cx->cx_type != CXt_LOOP)
+ if (CxTYPE(cx) != CXt_LOOP)
DIE("panic: pp_iter");
av = cx->blk_loop.iterary;
- if (cx->blk_loop.iterix >= (av == curstack ? cx->blk_oldsp : AvFILL(av)))
+ if (SvTYPE(av) != SVt_PVAV) {
+ /* iterate ($min .. $max) */
+ if (cx->blk_loop.iterlval) {
+ /* string increment */
+ register SV* cur = cx->blk_loop.iterlval;
+ STRLEN maxlen;
+ char *max = SvPV((SV*)av, maxlen);
+ if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
+#ifndef USE_THREADS /* don't risk potential race */
+ if (SvREFCNT(*cx->blk_loop.itervar) == 1
+ && !SvMAGICAL(*cx->blk_loop.itervar))
+ {
+ /* safe to reuse old SV */
+ sv_setsv(*cx->blk_loop.itervar, cur);
+ }
+ else
+#endif
+ {
+ /* we need a fresh SV every time so that loop body sees a
+ * completely new SV for closures/references to work as
+ * they used to */
+ SvREFCNT_dec(*cx->blk_loop.itervar);
+ *cx->blk_loop.itervar = newSVsv(cur);
+ }
+ if (strEQ(SvPVX(cur), max))
+ sv_setiv(cur, 0); /* terminate next time */
+ else
+ sv_inc(cur);
+ RETPUSHYES;
+ }
+ RETPUSHNO;
+ }
+ /* integer increment */
+ if (cx->blk_loop.iterix > cx->blk_loop.itermax)
+ RETPUSHNO;
+
+#ifndef USE_THREADS /* don't risk potential race */
+ if (SvREFCNT(*cx->blk_loop.itervar) == 1
+ && !SvMAGICAL(*cx->blk_loop.itervar))
+ {
+ /* safe to reuse old SV */
+ sv_setiv(*cx->blk_loop.itervar, cx->blk_loop.iterix++);
+ }
+ else
+#endif
+ {
+ /* we need a fresh SV every time so that loop body sees a
+ * completely new SV for closures/references to work as they
+ * used to */
+ SvREFCNT_dec(*cx->blk_loop.itervar);
+ *cx->blk_loop.itervar = newSViv(cx->blk_loop.iterix++);
+ }
+ RETPUSHYES;
+ }
+
+ /* iterate array */
+ if (cx->blk_loop.iterix >= (av == PL_curstack ? cx->blk_oldsp : AvFILL(av)))
RETPUSHNO;
SvREFCNT_dec(*cx->blk_loop.itervar);
- if (sv = AvARRAY(av)[++cx->blk_loop.iterix])
+ if (sv = (SvMAGICAL(av))
+ ? *av_fetch(av, ++cx->blk_loop.iterix, FALSE)
+ : AvARRAY(av)[++cx->blk_loop.iterix])
SvTEMP_off(sv);
else
- sv = &sv_undef;
- if (av != curstack && SvIMMORTAL(sv)) {
+ sv = &PL_sv_undef;
+ if (av != PL_curstack && SvIMMORTAL(sv)) {
SV *lv = cx->blk_loop.iterlval;
if (lv && SvREFCNT(lv) > 1) {
SvREFCNT_dec(lv);
}
LvTARG(lv) = SvREFCNT_inc(av);
LvTARGOFF(lv) = cx->blk_loop.iterix;
- LvTARGLEN(lv) = -1;
+ LvTARGLEN(lv) = (UV) -1;
sv = (SV*)lv;
}
PP(pp_subst)
{
- dSP; dTARG;
+ djSP; dTARG;
register PMOP *pm = cPMOP;
PMOP *rpm = pm;
register SV *dstr;
register REGEXP *rx = pm->op_pmregexp;
STRLEN len;
int force_on_match = 0;
- I32 oldsave = savestack_ix;
+ I32 oldsave = PL_savestack_ix;
+ I32 update_minmatch = 1;
+ SV *screamer;
/* known replacement string? */
dstr = (pm->op_pmflags & PMf_CONST) ? POPs : Nullsv;
- if (op->op_flags & OPf_STACKED)
+ if (PL_op->op_flags & OPf_STACKED)
TARG = POPs;
else {
- TARG = GvSV(defgv);
+ TARG = DEFSV;
EXTEND(SP,1);
- }
+ }
if (SvREADONLY(TARG)
|| (SvTYPE(TARG) > SVt_PVLV
&& !(SvTYPE(TARG) == SVt_PVGV && SvFAKE(TARG))))
croak(no_modify);
+ PUTBACK;
+
s = SvPV(TARG, len);
if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV)
force_on_match = 1;
+ rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) ||
+ (PL_tainted && (pm->op_pmflags & PMf_RETAINT)));
+ if (PL_tainted)
+ rxtainted |= 2;
TAINT_NOT;
force_it:
DIE("panic: do_subst");
strend = s + len;
- maxiters = (strend - s) + 10;
+ maxiters = 2*(strend - s) + 10; /* We can match twice at each
+ position, once with zero-length,
+ second time with non-zero. */
- if (!rx->prelen && curpm) {
- pm = curpm;
+ if (!rx->prelen && PL_curpm) {
+ pm = PL_curpm;
rx = pm->op_pmregexp;
}
- safebase = (!rx->nparens && !sawampersand);
+ screamer = ( (SvSCREAM(TARG) && rx->check_substr
+ && SvTYPE(rx->check_substr) == SVt_PVBM
+ && SvVALID(rx->check_substr))
+ ? TARG : Nullsv);
+ safebase = (rx->nparens || SvTEMP(TARG) || PL_sawampersand)
+ ? REXEC_COPY_STR : 0;
if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
- SAVEINT(multiline);
- multiline = pm->op_pmflags & PMf_MULTILINE;
+ SAVEINT(PL_multiline);
+ PL_multiline = pm->op_pmflags & PMf_MULTILINE;
}
orig = m = s;
- if (pm->op_pmshort) {
- if (pm->op_pmflags & PMf_SCANFIRST) {
- if (SvSCREAM(TARG)) {
- if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
+ if (rx->check_substr) {
+ if (!(rx->reganch & ROPT_NOSCAN)) { /* It floats. */
+ if (screamer) {
+ I32 p = -1;
+ char *b;
+
+ if (PL_screamfirst[BmRARE(rx->check_substr)] < 0)
goto nope;
- else if (!(s = screaminstr(TARG, pm->op_pmshort)))
+
+ b = (char*)HOP((U8*)s, rx->check_offset_min);
+ if (!(s = screaminstr(TARG, rx->check_substr, b - s, 0, &p, 0)))
goto nope;
}
- else if (!(s = fbm_instr((unsigned char*)s, (unsigned char*)strend,
- pm->op_pmshort)))
+ else if (!(s = fbm_instr((unsigned char*)HOP((U8*)s, rx->check_offset_min),
+ (unsigned char*)strend,
+ rx->check_substr, 0)))
goto nope;
- if (s && rx->regback >= 0) {
- ++BmUSEFUL(pm->op_pmshort);
- s -= rx->regback;
- if (s < m)
- s = m;
+ if (s && rx->check_offset_max < s - m) {
+ ++BmUSEFUL(rx->check_substr);
+ s = (char*)HOP((U8*)s, -rx->check_offset_max);
}
else
s = m;
}
- else if (!multiline) {
- if (*SvPVX(pm->op_pmshort) != *s
- || (pm->op_pmslen > 1
- && memNE(SvPVX(pm->op_pmshort), s, pm->op_pmslen)))
+ /* Now checkstring is fixed, i.e. at fixed offset from the
+ beginning of match, and the match is anchored at s. */
+ else if (!PL_multiline) { /* Anchored at beginning of string. */
+ I32 slen;
+ char *b = (char*)HOP((U8*)s, rx->check_offset_min);
+ if (*SvPVX(rx->check_substr) != *b
+ || ((slen = SvCUR(rx->check_substr)) > 1
+ && memNE(SvPVX(rx->check_substr), b, slen)))
goto nope;
}
- if (!rx->naughty && --BmUSEFUL(pm->op_pmshort) < 0) {
- SvREFCNT_dec(pm->op_pmshort);
- pm->op_pmshort = Nullsv; /* opt is being useless */
+ if (!(rx->reganch & ROPT_NAUGHTY) && --BmUSEFUL(rx->check_substr) < 0
+ && rx->check_substr == rx->float_substr) {
+ SvREFCNT_dec(rx->check_substr);
+ rx->check_substr = Nullsv; /* opt is being useless */
+ rx->float_substr = Nullsv;
}
}
c = dstr ? SvPV(dstr, clen) : Nullch;
/* can do inplace substitution? */
- if (c && clen <= rx->minlen && safebase) {
- if (! pregexec(rx, s, strend, orig, 0,
- SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
- PUSHs(&sv_no);
+ if (c && clen <= rx->minlen && (once || !(safebase & REXEC_COPY_STR))
+ && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)) {
+ if (!CALLREGEXEC(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
+ SPAGAIN;
+ PUSHs(&PL_sv_no);
LEAVE_SCOPE(oldsave);
RETURN;
}
goto force_it;
}
d = s;
- curpm = pm;
+ PL_curpm = pm;
SvSCREAM_off(TARG); /* disable possible screamer */
if (once) {
- rxtainted = rx->exec_tainted;
- m = rx->startp[0];
- d = rx->endp[0];
+ rxtainted |= RX_MATCH_TAINTED(rx);
+ if (rx->subbase) {
+ m = orig + (rx->startp[0] - rx->subbase);
+ d = orig + (rx->endp[0] - rx->subbase);
+ } else {
+ m = rx->startp[0];
+ d = rx->endp[0];
+ }
s = orig;
if (m - s > strend - d) { /* faster to shorten from end */
if (clen) {
else {
sv_chop(TARG, d);
}
- TAINT_IF(rxtainted);
- PUSHs(&sv_yes);
+ TAINT_IF(rxtainted & 1);
+ SPAGAIN;
+ PUSHs(&PL_sv_yes);
}
else {
- rxtainted = 0;
do {
if (iters++ > maxiters)
DIE("Substitution loop");
- rxtainted |= rx->exec_tainted;
+ rxtainted |= RX_MATCH_TAINTED(rx);
m = rx->startp[0];
/*SUPPRESS 560*/
if (i = m - s) {
d += clen;
}
s = rx->endp[0];
- } while (pregexec(rx, s, strend, orig, s == m,
- Nullsv, TRUE)); /* don't match same null twice */
+ } while (CALLREGEXEC(rx, s, strend, orig, s == m,
+ Nullsv, NULL, 0)); /* don't match same null twice */
if (s != d) {
i = strend - s;
SvCUR_set(TARG, d - SvPVX(TARG) + i);
Move(s, d, i+1, char); /* include the NUL */
}
- TAINT_IF(rxtainted);
+ TAINT_IF(rxtainted & 1);
+ SPAGAIN;
PUSHs(sv_2mortal(newSViv((I32)iters)));
}
(void)SvPOK_only(TARG);
- SvSETMAGIC(TARG);
+ TAINT_IF(rxtainted);
+ if (SvSMAGICAL(TARG)) {
+ PUTBACK;
+ mg_set(TARG);
+ SPAGAIN;
+ }
SvTAINT(TARG);
LEAVE_SCOPE(oldsave);
RETURN;
}
- if (pregexec(rx, s, strend, orig, 0,
- SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
+ if (CALLREGEXEC(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
if (force_on_match) {
force_on_match = 0;
s = SvPV_force(TARG, len);
goto force_it;
}
- rxtainted = rx->exec_tainted;
- dstr = NEWSV(25, sv_len(TARG));
+ rxtainted |= RX_MATCH_TAINTED(rx);
+ dstr = NEWSV(25, len);
sv_setpvn(dstr, m, s-m);
- curpm = pm;
+ PL_curpm = pm;
if (!c) {
- register CONTEXT *cx;
+ register PERL_CONTEXT *cx;
+ SPAGAIN;
PUSHSUBST(cx);
RETURNOP(cPMOP->op_pmreplroot);
}
do {
if (iters++ > maxiters)
DIE("Substitution loop");
- rxtainted |= rx->exec_tainted;
+ rxtainted |= RX_MATCH_TAINTED(rx);
if (rx->subbase && rx->subbase != orig) {
m = s;
s = orig;
sv_catpvn(dstr, c, clen);
if (once)
break;
- } while (pregexec(rx, s, strend, orig, s == m, Nullsv, safebase));
+ } while (CALLREGEXEC(rx, s, strend, orig, s == m, Nullsv, NULL, safebase));
sv_catpvn(dstr, s, strend - s);
- TAINT_IF(rxtainted);
-
(void)SvOOK_off(TARG);
Safefree(SvPVX(TARG));
SvPVX(TARG) = SvPVX(dstr);
SvPVX(dstr) = 0;
sv_free(dstr);
+ TAINT_IF(rxtainted & 1);
+ SPAGAIN;
+ PUSHs(sv_2mortal(newSViv((I32)iters)));
+
(void)SvPOK_only(TARG);
+ TAINT_IF(rxtainted);
SvSETMAGIC(TARG);
SvTAINT(TARG);
- PUSHs(sv_2mortal(newSViv((I32)iters)));
LEAVE_SCOPE(oldsave);
RETURN;
}
goto ret_no;
nope:
- ++BmUSEFUL(pm->op_pmshort);
+ ++BmUSEFUL(rx->check_substr);
-ret_no:
- PUSHs(&sv_no);
+ret_no:
+ SPAGAIN;
+ PUSHs(&PL_sv_no);
LEAVE_SCOPE(oldsave);
RETURN;
}
PP(pp_grepwhile)
{
- dSP;
+ djSP;
if (SvTRUEx(POPs))
- stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
- ++*markstack_ptr;
+ PL_stack_base[PL_markstack_ptr[-1]++] = PL_stack_base[*PL_markstack_ptr];
+ ++*PL_markstack_ptr;
LEAVE; /* exit inner scope */
/* All done yet? */
- if (stack_base + *markstack_ptr > sp) {
+ if (PL_stack_base + *PL_markstack_ptr > SP) {
I32 items;
I32 gimme = GIMME_V;
LEAVE; /* exit outer scope */
(void)POPMARK; /* pop src */
- items = --*markstack_ptr - markstack_ptr[-1];
+ items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
(void)POPMARK; /* pop dst */
- SP = stack_base + POPMARK; /* pop original mark */
+ SP = PL_stack_base + POPMARK; /* pop original mark */
if (gimme == G_SCALAR) {
dTARGET;
XPUSHi(items);
SV *src;
ENTER; /* enter inner scope */
- SAVESPTR(curpm);
+ SAVESPTR(PL_curpm);
- src = stack_base[*markstack_ptr];
+ src = PL_stack_base[*PL_markstack_ptr];
SvTEMP_off(src);
- GvSV(defgv) = src;
+ DEFSV = src;
RETURNOP(cLOGOP->op_other);
}
PP(pp_leavesub)
{
- dSP;
+ djSP;
SV **mark;
SV **newsp;
PMOP *newpm;
I32 gimme;
- register CONTEXT *cx;
+ register PERL_CONTEXT *cx;
struct block_sub cxsub;
POPBLOCK(cx,newpm);
TAINT_NOT;
if (gimme == G_SCALAR) {
MARK = newsp + 1;
- if (MARK <= SP)
- *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
- else {
+ if (MARK <= SP) {
+ if (cxsub.cv && CvDEPTH(cxsub.cv) > 1) {
+ if (SvTEMP(TOPs)) {
+ *MARK = SvREFCNT_inc(TOPs);
+ FREETMPS;
+ sv_2mortal(*MARK);
+ } else {
+ FREETMPS;
+ *MARK = sv_mortalcopy(TOPs);
+ }
+ } else
+ *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
+ } else {
MEXTEND(MARK, 0);
- *MARK = &sv_undef;
+ *MARK = &PL_sv_undef;
}
SP = MARK;
}
PUTBACK;
POPSUB2(); /* Stack values are safe: release CV and @_ ... */
- curpm = newpm; /* ... and pop $1 et al */
+ PL_curpm = newpm; /* ... and pop $1 et al */
LEAVE;
return pop_return();
}
-static CV *
-get_db_sub(sv)
-SV *sv;
+STATIC CV *
+get_db_sub(SV **svp, CV *cv)
{
dTHR;
- SV *oldsv = sv;
- GV *gv;
- CV *cv;
-
- sv = GvSV(DBsub);
- save_item(sv);
- gv = CvGV(cv);
- if ( (CvFLAGS(cv) & (CVf_ANON | CVf_CLONED))
- || strEQ(GvNAME(gv), "END")
- || ((GvCV(gv) != cv) && /* Could be imported, and old sub redefined. */
- !( (SvTYPE(oldsv) == SVt_PVGV) && (GvCV((GV*)oldsv) == cv)
- && (gv = (GV*)oldsv) ))) {
- /* Use GV from the stack as a fallback. */
- /* GV is potentially non-unique, or contain different CV. */
- sv_setsv(sv, newRV((SV*)cv));
+ SV *dbsv = GvSV(PL_DBsub);
+
+ if (!PERLDB_SUB_NN) {
+ GV *gv = CvGV(cv);
+
+ save_item(dbsv);
+ if ( (CvFLAGS(cv) & (CVf_ANON | CVf_CLONED))
+ || strEQ(GvNAME(gv), "END")
+ || ((GvCV(gv) != cv) && /* Could be imported, and old sub redefined. */
+ !( (SvTYPE(*svp) == SVt_PVGV) && (GvCV((GV*)*svp) == cv)
+ && (gv = (GV*)*svp) ))) {
+ /* Use GV from the stack as a fallback. */
+ /* GV is potentially non-unique, or contain different CV. */
+ sv_setsv(dbsv, newRV((SV*)cv));
+ }
+ else {
+ gv_efullname3(dbsv, gv, Nullch);
+ }
}
else {
- gv_efullname3(sv, gv, Nullch);
+ SvUPGRADE(dbsv, SVt_PVIV);
+ SvIOK_on(dbsv);
+ SAVEIV(SvIVX(dbsv));
+ SvIVX(dbsv) = (IV)cv; /* Do it the quickest way */
}
- cv = GvCV(DBsub);
+
if (CvXSUB(cv))
- curcopdb = curcop;
+ PL_curcopdb = PL_curcop;
+ cv = GvCV(PL_DBsub);
return cv;
}
PP(pp_entersub)
{
- dSP; dPOPss;
+ djSP; dPOPss;
GV *gv;
HV *stash;
register CV *cv;
- register CONTEXT *cx;
+ register PERL_CONTEXT *cx;
I32 gimme;
- bool hasargs = (op->op_flags & OPf_STACKED) != 0;
+ bool hasargs = (PL_op->op_flags & OPf_STACKED) != 0;
if (!sv)
DIE("Not a CODE reference");
if (!SvROK(sv)) {
char *sym;
- if (sv == &sv_yes) { /* unfound import, ignore */
+ if (sv == &PL_sv_yes) { /* unfound import, ignore */
if (hasargs)
- SP = stack_base + POPMARK;
+ SP = PL_stack_base + POPMARK;
RETURN;
}
if (SvGMAGICAL(sv)) {
sym = SvPOKp(sv) ? SvPVX(sv) : Nullch;
}
else
- sym = SvPV(sv, na);
+ sym = SvPV(sv, PL_na);
if (!sym)
DIE(no_usym, "a subroutine");
- if (op->op_private & HINT_STRICT_REFS)
+ if (PL_op->op_private & HINT_STRICT_REFS)
DIE(no_symref, sym, "a subroutine");
cv = perl_get_cv(sym, TRUE);
break;
if (!CvROOT(cv) && !CvXSUB(cv)) {
GV* autogv;
- SV* subname;
+ SV* sub_name;
/* anonymous or undef'd function leaves us no recourse */
if (CvANON(cv) || !(gv = CvGV(cv)))
goto retry;
}
/* sorry */
- subname = sv_newmortal();
- gv_efullname3(subname, gv, Nullch);
- DIE("Undefined subroutine &%s called", SvPVX(subname));
+ sub_name = sv_newmortal();
+ gv_efullname3(sub_name, gv, Nullch);
+ DIE("Undefined subroutine &%s called", SvPVX(sub_name));
}
gimme = GIMME_V;
- if ((op->op_private & OPpENTERSUB_DB) && GvCV(DBsub) && !CvNODEBUG(cv))
- cv = get_db_sub(sv);
+ if ((PL_op->op_private & OPpENTERSUB_DB) && GvCV(PL_DBsub) && !CvNODEBUG(cv))
+ cv = get_db_sub(&sv, cv);
if (!cv)
DIE("No DBsub routine");
#ifdef USE_THREADS
/*
* First we need to check if the sub or method requires locking.
- * If so, we gain a lock on the CV or the first argument, as
- * appropriate. This has to be inline because for FAKE_THREADS,
- * COND_WAIT inlines code to reschedule by returning a new op.
+ * If so, we gain a lock on the CV, the first argument or the
+ * stash (for static methods), as appropriate. This has to be
+ * inline because for FAKE_THREADS, COND_WAIT inlines code to
+ * reschedule by returning a new op.
*/
MUTEX_LOCK(CvMUTEXP(cv));
if (CvFLAGS(cv) & CVf_LOCKED) {
MAGIC *mg;
if (CvFLAGS(cv) & CVf_METHOD) {
- if (SP > stack_base + TOPMARK)
- sv = *(stack_base + TOPMARK + 1);
+ if (SP > PL_stack_base + TOPMARK)
+ sv = *(PL_stack_base + TOPMARK + 1);
else {
MUTEX_UNLOCK(CvMUTEXP(cv));
croak("no argument for locked method call");
}
if (SvROK(sv))
sv = SvRV(sv);
+ else {
+ STRLEN len;
+ char *stashname = SvPV(sv, len);
+ sv = (SV*)gv_stashpvn(stashname, len, TRUE);
+ }
}
else {
sv = (SV*)cv;
while (MgOWNER(mg))
COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
MgOWNER(mg) = thr;
- DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
thr, sv);)
MUTEX_UNLOCK(MgMUTEXP(mg));
save_destructor(unlock_condpair, sv);
* (3) instead of (2) so we'd have to clone. Would the fact
* that we released the mutex more quickly make up for this?
*/
- svp = hv_fetch(cvcache, (char *)cv, sizeof(cv), FALSE);
- if (svp) {
+ if (PL_threadnum &&
+ (svp = hv_fetch(thr->cvcache, (char *)cv, sizeof(cv), FALSE)))
+ {
/* We already have a clone to use */
MUTEX_UNLOCK(CvMUTEXP(cv));
cv = *(CV**)svp;
- DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(),
"entersub: %p already has clone %p:%s\n",
thr, cv, SvPEEK((SV*)cv)));
CvOWNER(cv) = thr;
CvOWNER(cv) = thr;
SvREFCNT_inc(cv);
MUTEX_UNLOCK(CvMUTEXP(cv));
- DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(),
"entersub: %p grabbing %p:%s in stash %s\n",
thr, cv, SvPEEK((SV*)cv), CvSTASH(cv) ?
HvNAME(CvSTASH(cv)) : "(none)"));
CV *clonecv;
SvREFCNT_inc(cv); /* don't let it vanish from under us */
MUTEX_UNLOCK(CvMUTEXP(cv));
- DEBUG_L((PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S((PerlIO_printf(PerlIO_stderr(),
"entersub: %p cloning %p:%s\n",
thr, cv, SvPEEK((SV*)cv))));
/*
*/
clonecv = cv_clone(cv);
SvREFCNT_dec(cv); /* finished with this */
- hv_store(cvcache, (char*)cv, sizeof(cv), (SV*)clonecv,0);
+ hv_store(thr->cvcache, (char*)cv, sizeof(cv), (SV*)clonecv,0);
CvOWNER(clonecv) = thr;
cv = clonecv;
SvREFCNT_inc(cv);
}
- DEBUG_L(if (CvDEPTH(cv) != 0)
+ DEBUG_S(if (CvDEPTH(cv) != 0)
PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
CvDEPTH(cv)););
SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
}
#endif /* USE_THREADS */
- gimme = GIMME;
-
if (CvXSUB(cv)) {
if (CvOLDSTYLE(cv)) {
I32 (*fp3)_((int,int,int));
dMARK;
register I32 items = SP - MARK;
/* We dont worry to copy from @_. */
- while (sp > mark) {
- sp[1] = sp[0];
- sp--;
+ while (SP > mark) {
+ SP[1] = SP[0];
+ SP--;
}
- stack_sp = mark + 1;
+ PL_stack_sp = mark + 1;
fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
items = (*fp3)(CvXSUBANY(cv).any_i32,
- MARK - stack_base + 1,
+ MARK - PL_stack_base + 1,
items);
- stack_sp = stack_base + items;
+ PL_stack_sp = PL_stack_base + items;
}
else {
I32 markix = TOPMARK;
AV* av;
I32 items;
#ifdef USE_THREADS
- av = (AV*)curpad[0];
+ av = (AV*)PL_curpad[0];
#else
- av = GvAV(defgv);
+ av = GvAV(PL_defgv);
#endif /* USE_THREADS */
- items = AvFILL(av) + 1;
+ items = AvFILLp(av) + 1; /* @_ is not tieable */
if (items) {
/* Mark is at the end of the stack. */
- EXTEND(sp, items);
- Copy(AvARRAY(av), sp + 1, items, SV*);
- sp += items;
+ EXTEND(SP, items);
+ Copy(AvARRAY(av), SP + 1, items, SV*);
+ SP += items;
PUTBACK ;
}
}
- if (curcopdb) { /* We assume that the first
+ if (PL_curcopdb) { /* We assume that the first
XSUB in &DB::sub is the
called one. */
- SAVESPTR(curcop);
- curcop = curcopdb;
- curcopdb = NULL;
+ SAVESPTR(PL_curcop);
+ PL_curcop = PL_curcopdb;
+ PL_curcopdb = NULL;
}
/* Do we need to open block here? XXXX */
- (void)(*CvXSUB(cv))(cv);
+ (void)(*CvXSUB(cv))(cv _PERL_OBJECT_THIS);
/* 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;
+ if (gimme == G_SCALAR && ++markix != PL_stack_sp - PL_stack_base ) {
+ if (markix > PL_stack_sp - PL_stack_base)
+ *(PL_stack_base + markix) = &PL_sv_undef;
else
- *(stack_base + markix) = *stack_sp;
- stack_sp = stack_base + markix;
+ *(PL_stack_base + markix) = *PL_stack_sp;
+ PL_stack_sp = PL_stack_base + markix;
}
}
LEAVE;
register I32 items = SP - MARK;
AV* padlist = CvPADLIST(cv);
SV** svp = AvARRAY(padlist);
- push_return(op->op_next);
+ push_return(PL_op->op_next);
PUSHBLOCK(cx, CXt_SUB, MARK);
PUSHSUB(cx);
CvDEPTH(cv)++;
+ /* XXX This would be a natural place to set C<PL_compcv = cv> so
+ * that eval'' ops within this sub know the correct lexical space.
+ * Owing the speed considerations, we choose to search for the cv
+ * in doeval() instead.
+ */
if (CvDEPTH(cv) < 2)
(void)SvREFCNT_inc(cv);
else { /* save temporaries on recursion? */
- if (CvDEPTH(cv) == 100 && dowarn
- && !(PERLDB_SUB && cv == GvCV(DBsub)))
- sub_crush_depth(cv);
- if (CvDEPTH(cv) > AvFILL(padlist)) {
+ if (CvDEPTH(cv) > AvFILLp(padlist)) {
AV *av;
AV *newpad = newAV();
SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
- I32 ix = AvFILL((AV*)svp[1]);
+ I32 ix = AvFILLp((AV*)svp[1]);
svp = AvARRAY(svp[0]);
for ( ;ix > 0; ix--) {
- if (svp[ix] != &sv_undef) {
+ if (svp[ix] != &PL_sv_undef) {
char *name = SvPVX(svp[ix]);
if ((SvFLAGS(svp[ix]) & SVf_FAKE) /* outer lexical? */
|| *name == '&') /* anonymous code? */
av_store(newpad, 0, (SV*)av);
AvFLAGS(av) = AVf_REIFY;
av_store(padlist, CvDEPTH(cv), (SV*)newpad);
- AvFILL(padlist) = CvDEPTH(cv);
+ AvFILLp(padlist) = CvDEPTH(cv);
svp = AvARRAY(padlist);
}
}
#ifdef USE_THREADS
if (!hasargs) {
- AV* av = (AV*)curpad[0];
+ AV* av = (AV*)PL_curpad[0];
- items = AvFILL(av) + 1;
+ items = AvFILLp(av) + 1;
if (items) {
/* Mark is at the end of the stack. */
- EXTEND(sp, items);
- Copy(AvARRAY(av), sp + 1, items, SV*);
- sp += items;
+ EXTEND(SP, items);
+ Copy(AvARRAY(av), SP + 1, items, SV*);
+ SP += items;
PUTBACK ;
}
}
#endif /* USE_THREADS */
- SAVESPTR(curpad);
- curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
+ SAVESPTR(PL_curpad);
+ PL_curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
#ifndef USE_THREADS
if (hasargs)
#endif /* USE_THREADS */
SV** ary;
#if 0
- DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(),
"%p entersub preparing @_\n", thr));
#endif
- av = (AV*)curpad[0];
+ av = (AV*)PL_curpad[0];
if (AvREAL(av)) {
av_clear(av);
AvREAL_off(av);
}
#ifndef USE_THREADS
- cx->blk_sub.savearray = GvAV(defgv);
- GvAV(defgv) = (AV*)SvREFCNT_inc(av);
+ cx->blk_sub.savearray = GvAV(PL_defgv);
+ GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
#endif /* USE_THREADS */
cx->blk_sub.argarray = av;
++MARK;
}
}
Copy(MARK,AvARRAY(av),items,SV*);
- AvFILL(av) = items - 1;
+ AvFILLp(av) = items - 1;
while (items--) {
if (*MARK)
MARK++;
}
}
+ /* warning must come *after* we fully set up the context
+ * stuff so that __WARN__ handlers can safely dounwind()
+ * if they want to
+ */
+ if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION)
+ && !(PERLDB_SUB && cv == GvCV(PL_DBsub)))
+ sub_crush_depth(cv);
#if 0
- DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(),
"%p entersub returning %p\n", thr, CvSTART(cv)));
#endif
RETURNOP(CvSTART(cv));
}
void
-sub_crush_depth(cv)
-CV* cv;
+sub_crush_depth(CV *cv)
{
if (CvANON(cv))
- warn("Deep recursion on anonymous subroutine");
+ warner(WARN_RECURSION, "Deep recursion on anonymous subroutine");
else {
SV* tmpstr = sv_newmortal();
gv_efullname3(tmpstr, CvGV(cv), Nullch);
- warn("Deep recursion on subroutine \"%s\"", SvPVX(tmpstr));
+ warner(WARN_RECURSION, "Deep recursion on subroutine \"%s\"",
+ SvPVX(tmpstr));
}
}
PP(pp_aelem)
{
- dSP;
+ djSP;
SV** svp;
I32 elem = POPi;
AV* av = (AV*)POPs;
- U32 lval = op->op_flags & OPf_MOD;
- U32 defer = (op->op_private & OPpLVAL_DEFER) && (elem > AvFILL(av));
+ U32 lval = PL_op->op_flags & OPf_MOD;
+ U32 defer = (PL_op->op_private & OPpLVAL_DEFER) && (elem > AvFILL(av));
+ SV *sv;
if (elem > 0)
- elem -= curcop->cop_arybase;
+ elem -= PL_curcop->cop_arybase;
if (SvTYPE(av) != SVt_PVAV)
RETPUSHUNDEF;
svp = av_fetch(av, elem, lval && !defer);
if (lval) {
- if (!svp || *svp == &sv_undef) {
+ if (!svp || *svp == &PL_sv_undef) {
SV* lv;
if (!defer)
DIE(no_aelem, elem);
PUSHs(lv);
RETURN;
}
- if (op->op_private & OPpLVAL_INTRO)
- save_svref(svp);
- else if (op->op_private & OPpDEREF)
- vivify_ref(*svp, op->op_private & OPpDEREF);
+ if (PL_op->op_private & OPpLVAL_INTRO)
+ save_aelem(av, elem, svp);
+ else if (PL_op->op_private & OPpDEREF)
+ vivify_ref(*svp, PL_op->op_private & OPpDEREF);
}
- PUSHs(svp ? *svp : &sv_undef);
+ sv = (svp ? *svp : &PL_sv_undef);
+ if (!lval && SvGMAGICAL(sv)) /* see note in pp_helem() */
+ sv = sv_mortalcopy(sv);
+ PUSHs(sv);
RETURN;
}
void
-vivify_ref(sv, to_what)
-SV* sv;
-U32 to_what;
+vivify_ref(SV *sv, U32 to_what)
{
if (SvGMAGICAL(sv))
mg_get(sv);
}
switch (to_what) {
case OPpDEREF_SV:
- SvRV(sv) = newSV(0);
+ SvRV(sv) = NEWSV(355,0);
break;
case OPpDEREF_AV:
SvRV(sv) = (SV*)newAV();
PP(pp_method)
{
- dSP;
+ djSP;
SV* sv;
SV* ob;
GV* gv;
}
}
- name = SvPV(TOPs, na);
- sv = *(stack_base + TOPMARK + 1);
+ name = SvPV(TOPs, PL_na);
+ sv = *(PL_stack_base + TOPMARK + 1);
if (SvGMAGICAL(sv))
mg_get(sv);
!(iogv = gv_fetchpv(packname, FALSE, SVt_PVIO)) ||
!(ob=(SV*)GvIO(iogv)))
{
- if (!packname || !isIDFIRST(*packname))
- DIE("Can't call method \"%s\" without a package or object reference", name);
+ if (!packname ||
+ ((*(U8*)packname >= 0xc0 && IN_UTF8)
+ ? !isIDFIRST_utf8(packname)
+ : !isIDFIRST(*packname)
+ ))
+ {
+ DIE("Can't call method \"%s\" %s", name,
+ SvOK(sv)? "without a package or object reference"
+ : "on an undefined value");
+ }
stash = gv_stashpvn(packname, packlen, TRUE);
goto fetch;
}
- *(stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
+ *(PL_stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
}
if (!ob || !SvOBJECT(ob))
sep = p, leaf = p + 2;
}
if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
- packname = HvNAME(sep ? curcop->cop_stash : stash);
+ packname = HvNAME(sep ? PL_curcop->cop_stash : stash);
packlen = strlen(packname);
}
else {
SETs(isGV(gv) ? (SV*)GvCV(gv) : (SV*)gv);
RETURN;
}
+