3 * Copyright (c) 1991-1994, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * Then he heard Merry change the note, and up went the Horn-cry of Buckland,
14 * Awake! Awake! Fear, Fire, Foes! Awake!
33 TAINT_NOT; /* Each statement is presumed innocent */
34 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
43 if (op->op_private & OPpLVAL_INTRO)
44 PUSHs(save_scalar(cGVOP->op_gv));
46 PUSHs(GvSV(cGVOP->op_gv));
67 sv_setpvn(TARG,s,len);
75 XPUSHs((SV*)cGVOP->op_gv);
86 RETURNOP(cLOGOP->op_other);
95 if (op->op_private & OPpASSIGN_BACKWARDS) {
97 temp = left; left = right; right = temp;
99 if (tainting && tainted && (!SvGMAGICAL(left) || !SvSMAGICAL(left) ||
100 !((mg = mg_find(left, 't')) && mg->mg_len & 1)))
104 SvSetSV(right, left);
114 RETURNOP(cCONDOP->op_true);
116 RETURNOP(cCONDOP->op_false);
122 TAINT_NOT; /* Each statement is presumed innocent */
123 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
125 oldsave = scopestack[scopestack_ix - 1];
126 LEAVE_SCOPE(oldsave);
132 dSP; tryAMAGICbinSET(seq,0);
135 SETs( sv_eq(left, right) ? &sv_yes : &sv_no );
142 dSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
149 sv_setpvn(TARG,s,len);
151 else if (!SvOK(TARG))
152 sv_setpv(TARG, ""); /* Suppress warning. */
154 sv_catpvn(TARG,s,len);
164 if (op->op_private & OPpLVAL_INTRO)
165 SAVECLEARSV(curpad[op->op_targ]);
171 last_in_gv = (GV*)(*stack_sp--);
172 return do_readline();
177 dSP; tryAMAGICbinSET(eq,0);
180 SETs((TOPn == value) ? &sv_yes : &sv_no);
190 SvFLAGS(TOPs) &= ~(SVf_NOK|SVf_POK|SVp_NOK|SVp_POK);
205 RETURNOP(cLOGOP->op_other);
211 dSP; dATARGET; tryAMAGICbin(add,opASSIGN);
214 SETn( left + right );
222 AV *av = GvAV((GV*)cSVOP->op_sv);
223 SV** svp = av_fetch(av, op->op_private, op->op_flags & OPf_MOD);
224 PUSHs(svp ? *svp : &sv_undef);
232 do_join(TARG, *MARK, MARK, SP);
245 /* Oversized hot code. */
249 dSP; dMARK; dORIGMARK;
254 if (op->op_flags & OPf_STACKED)
258 if (!(io = GvIO(gv))) {
260 SV* sv = sv_newmortal();
262 warn("Filehandle %s never opened", SvPV(sv,na));
265 SETERRNO(EBADF,RMS$_IFI);
268 else if (!(fp = IoOFP(io))) {
270 SV* sv = sv_newmortal();
273 warn("Filehandle %s opened only for input", SvPV(sv,na));
275 warn("print on closed filehandle %s", SvPV(sv,na));
277 SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
284 if (!do_print(*MARK, fp))
288 if (fwrite1(ofs, 1, ofslen, fp) == 0 || ferror(fp)) {
297 if (!do_print(*MARK, fp))
306 if (fwrite1(ors, 1, orslen, fp) == 0 || ferror(fp))
309 if (IoFLAGS(io) & IOf_FLUSH)
310 if (fflush(fp) == EOF)
333 if (SvTYPE(av) != SVt_PVAV)
334 DIE("Not an ARRAY reference");
335 if (op->op_private & OPpLVAL_INTRO)
336 av = (AV*)save_svref((SV**)sv);
337 if (op->op_flags & OPf_REF) {
343 if (SvTYPE(sv) == SVt_PVAV) {
345 if (op->op_flags & OPf_REF) {
351 if (SvTYPE(sv) != SVt_PVGV) {
354 if (SvGMAGICAL(sv)) {
360 if (op->op_flags & OPf_REF ||
361 op->op_private & HINT_STRICT_REFS)
362 DIE(no_usym, "an ARRAY");
366 if (op->op_private & HINT_STRICT_REFS)
367 DIE(no_symref, sym, "an ARRAY");
368 sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVAV);
371 if (op->op_private & OPpLVAL_INTRO)
373 if (op->op_flags & OPf_REF) {
380 if (GIMME == G_ARRAY) {
381 I32 maxarg = AvFILL(av) + 1;
383 Copy(AvARRAY(av), SP+1, maxarg, SV*);
388 I32 maxarg = AvFILL(av) + 1;
404 if (SvTYPE(hv) != SVt_PVHV)
405 DIE("Not a HASH reference");
406 if (op->op_private & OPpLVAL_INTRO)
407 hv = (HV*)save_svref((SV**)sv);
408 if (op->op_flags & OPf_REF) {
414 if (SvTYPE(sv) == SVt_PVHV) {
416 if (op->op_flags & OPf_REF) {
422 if (SvTYPE(sv) != SVt_PVGV) {
425 if (SvGMAGICAL(sv)) {
431 if (op->op_flags & OPf_REF ||
432 op->op_private & HINT_STRICT_REFS)
433 DIE(no_usym, "a HASH");
437 if (op->op_private & HINT_STRICT_REFS)
438 DIE(no_symref, sym, "a HASH");
439 sv = (SV*)gv_fetchpv(sym, TRUE, SVt_PVHV);
442 if (op->op_private & OPpLVAL_INTRO)
444 if (op->op_flags & OPf_REF) {
451 if (GIMME == G_ARRAY) { /* array wanted */
458 sprintf(buf, "%d/%d", HvFILL(hv), HvMAX(hv)+1);
471 SV **lastlelem = stack_sp;
472 SV **lastrelem = stack_base + POPMARK;
473 SV **firstrelem = stack_base + POPMARK + 1;
474 SV **firstlelem = lastrelem + 1;
486 delaymagic = DM_DELAY; /* catch simultaneous items */
488 /* If there's a common identifier on both sides we have to take
489 * special care that assigning the identifier on the left doesn't
490 * clobber a value on the right that's used later in the list.
492 if (op->op_private & OPpASSIGN_COMMON) {
493 for (relem = firstrelem; relem <= lastrelem; relem++) {
496 *relem = sv_mortalcopy(sv);
504 while (lelem <= lastlelem) {
506 switch (SvTYPE(sv)) {
509 magic = SvMAGICAL(ary) != 0;
513 while (relem <= lastrelem) { /* gobble up all the rest */
518 (void)av_store(ary,i++,sv);
528 magic = SvMAGICAL(hash) != 0;
531 while (relem < lastrelem) { /* gobble up all the rest */
536 sv = &sv_no, relem++;
537 tmps = SvPV(sv, len);
538 tmpstr = NEWSV(29,0);
540 sv_setsv(tmpstr,*relem); /* value */
542 (void)hv_store(hash,tmps,len,tmpstr,0);
549 if (SvTHINKFIRST(sv)) {
550 if (SvREADONLY(sv) && curcop != &compiling) {
551 if (sv != &sv_undef && sv != &sv_yes && sv != &sv_no)
553 if (relem <= lastrelem)
560 if (relem <= lastrelem) {
561 sv_setsv(sv, *relem);
565 sv_setsv(sv, &sv_undef);
570 if (delaymagic & ~DM_DELAY) {
571 if (delaymagic & DM_UID) {
573 (void)setresuid(uid,euid,(Uid_t)-1);
574 #else /* not HAS_SETRESUID */
576 (void)setreuid(uid,euid);
577 #else /* not HAS_SETREUID */
579 if ((delaymagic & DM_UID) == DM_RUID) {
581 delaymagic &= ~DM_RUID;
583 #endif /* HAS_SETRUID */
584 #endif /* HAS_SETRESUID */
586 if ((delaymagic & DM_UID) == DM_EUID) {
588 delaymagic &= ~DM_EUID;
590 #endif /* HAS_SETEUID */
591 if (delaymagic & DM_UID) {
593 DIE("No setreuid available");
596 #endif /* not HAS_SETREUID */
598 euid = (int)geteuid();
600 if (delaymagic & DM_GID) {
602 (void)setresgid(gid,egid,(Gid_t)-1);
603 #else /* not HAS_SETREGID */
605 (void)setregid(gid,egid);
606 #else /* not HAS_SETREGID */
607 #endif /* not HAS_SETRESGID */
609 if ((delaymagic & DM_GID) == DM_RGID) {
611 delaymagic &= ~DM_RGID;
613 #endif /* HAS_SETRGID */
615 (void)setresgid(gid,egid,(Gid_t)-1);
616 #else /* not HAS_SETREGID */
618 if ((delaymagic & DM_GID) == DM_EGID) {
620 delaymagic &= ~DM_EGID;
622 #endif /* HAS_SETEGID */
623 if (delaymagic & DM_GID) {
625 DIE("No setregid available");
628 #endif /* not HAS_SETRESGID */
629 #endif /* not HAS_SETREGID */
631 egid = (int)getegid();
633 tainting |= (euid != uid || egid != gid);
636 if (GIMME == G_ARRAY) {
640 SP = firstrelem + (lastlelem - firstlelem);
645 for (relem = firstrelem; relem <= lastrelem; ++relem) {
649 SETi(lastrelem - firstrelem + 1);
660 register PMOP *pm = cPMOP;
667 register REGEXP *rx = pm->op_pmregexp;
672 if (op->op_flags & OPf_STACKED)
681 DIE("panic: do_match");
683 if (pm->op_pmflags & PMf_USED) {
684 if (gimme == G_ARRAY)
689 if (!rx->prelen && curpm) {
691 rx = pm->op_pmregexp;
694 if (global = pm->op_pmflags & PMf_GLOBAL) {
696 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
697 MAGIC* mg = mg_find(TARG, 'g');
698 if (mg && mg->mg_len >= 0) {
699 rx->endp[0] = rx->startp[0] = s + mg->mg_len;
700 minmatch = (mg->mg_flags & MGf_MINMATCH);
704 if (!rx->nparens && !global)
705 gimme = G_SCALAR; /* accidental array context? */
706 safebase = (gimme == G_ARRAY) || global;
707 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
709 multiline = pm->op_pmflags & PMf_MULTILINE;
713 if (global && rx->startp[0]) {
717 minmatch = (s == rx->startp[0]);
719 if (pm->op_pmshort) {
720 if (pm->op_pmflags & PMf_SCANFIRST) {
721 if (SvSCREAM(TARG)) {
722 if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
724 else if (!(s = screaminstr(TARG, pm->op_pmshort)))
726 else if (pm->op_pmflags & PMf_ALL)
729 else if (!(s = fbm_instr((unsigned char*)s,
730 (unsigned char*)strend, pm->op_pmshort)))
732 else if (pm->op_pmflags & PMf_ALL)
734 if (s && rx->regback >= 0) {
735 ++BmUSEFUL(pm->op_pmshort);
743 else if (!multiline) {
744 if (*SvPVX(pm->op_pmshort) != *s ||
745 bcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) ) {
746 if (pm->op_pmflags & PMf_FOLD) {
747 if (ibcmp((U8*)SvPVX(pm->op_pmshort), (U8*)s, pm->op_pmslen) )
754 if (!rx->naughty && --BmUSEFUL(pm->op_pmshort) < 0) {
755 SvREFCNT_dec(pm->op_pmshort);
756 pm->op_pmshort = Nullsv; /* opt is being useless */
759 if (regexec(rx, s, strend, truebase, minmatch,
760 SvSCREAM(TARG) ? TARG : Nullsv,
763 if (pm->op_pmflags & PMf_ONCE)
764 pm->op_pmflags |= PMf_USED;
772 if (gimme == G_ARRAY) {
776 if (global && !iters)
780 EXTEND(SP, iters + i);
781 for (i = !i; i <= iters; i++) {
782 PUSHs(sv_newmortal());
784 if ((s = rx->startp[i]) && rx->endp[i] ) {
785 len = rx->endp[i] - s;
786 sv_setpvn(*SP, s, len);
790 truebase = rx->subbeg;
791 if (rx->startp[0] && rx->startp[0] == rx->endp[0])
800 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
801 mg = mg_find(TARG, 'g');
803 sv_magic(TARG, (SV*)0, 'g', Nullch, 0);
804 mg = mg_find(TARG, 'g');
807 mg->mg_len = rx->endp[0] - truebase;
808 if (rx->startp[0] == rx->endp[0])
809 mg->mg_flags |= MGf_MINMATCH;
811 mg->mg_flags &= ~MGf_MINMATCH;
820 ++BmUSEFUL(pm->op_pmshort);
822 if (pm->op_pmflags & PMf_ONCE)
823 pm->op_pmflags |= PMf_USED;
825 rx->subbeg = truebase;
828 rx->endp[0] = s + SvCUR(pm->op_pmshort);
835 Safefree(rx->subbase);
836 tmps = rx->subbase = savepvn(t, strend-t);
838 rx->subend = tmps + (strend-t);
839 tmps = rx->startp[0] = tmps + (s - t);
840 rx->endp[0] = tmps + SvCUR(pm->op_pmshort);
846 ++BmUSEFUL(pm->op_pmshort);
850 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
851 MAGIC* mg = mg_find(TARG, 'g');
856 if (gimme == G_ARRAY)
869 register IO *io = GvIO(last_in_gv);
870 register I32 type = op->op_type;
876 if (IoFLAGS(io) & IOf_ARGV) {
877 if (IoFLAGS(io) & IOf_START) {
878 IoFLAGS(io) &= ~IOf_START;
880 if (av_len(GvAVn(last_in_gv)) < 0) {
881 SV *tmpstr = newSVpv("-", 1); /* assume stdin */
882 av_push(GvAVn(last_in_gv), tmpstr);
885 fp = nextargv(last_in_gv);
886 if (!fp) { /* Note: fp != IoIFP(io) */
887 (void)do_close(last_in_gv, FALSE); /* now it does*/
888 IoFLAGS(io) |= IOf_START;
891 else if (type == OP_GLOB) {
892 SV *tmpcmd = NEWSV(55, 0);
896 #ifdef VMS /* expand the wildcards right here, rather than opening a pipe, */
897 /* since spawning off a process is a real performance hit */
900 #include <lib$routines.h>
903 char rslt[NAM$C_MAXRSS+1+sizeof(unsigned short int)] = {'\0','\0'};
904 char vmsspec[NAM$C_MAXRSS+1];
905 char *rstr = rslt + sizeof(unsigned short int), *begin, *end, *cp;
906 char tmpfnam[L_tmpnam] = "SYS$SCRATCH:";
907 $DESCRIPTOR(dfltdsc,"SYS$DISK:[]*.*;");
910 struct dsc$descriptor_s wilddsc
911 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
912 struct dsc$descriptor_vs rsdsc
913 = {sizeof rslt, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, rslt};
914 unsigned long int cxt = 0, sts = 0, ok = 1, hasdir = 0, hasver = 0, isunix = 0;
916 /* We could find out if there's an explicit dev/dir or version
917 by peeking into lib$find_file's internal context at
918 ((struct NAM *)((struct FAB *)cxt)->fab$l_nam)->nam$l_fnb
919 but that's unsupported, so I don't want to do it now and
920 have it bite someone in the future. */
921 strcat(tmpfnam,tmpnam(NULL));
922 cp = SvPV(tmpglob,i);
924 if (cp[i] == ';') hasver = 1;
933 if (cp[i] == ']' || cp[i] == '>' || cp[i] == ':') {
938 if ((tmpfp = fopen(tmpfnam,"w+","fop=dlt")) != NULL) {
939 ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL);
940 if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer);
941 while (ok && ((sts = lib$find_file(&wilddsc,&rsdsc,&cxt,
942 &dfltdsc,NULL,NULL,NULL))&1)) {
943 end = rstr + (unsigned long int) *rslt;
944 if (!hasver) while (*end != ';') end--;
945 *(end++) = '\n'; *end = '\0';
946 for (cp = rstr; *cp; cp++) *cp = _tolower(*cp);
948 if (isunix) trim_unixpath(SvPVX(tmpglob),rstr);
953 while (*(--begin) != ']' && *begin != '>') ;
956 ok = (fputs(begin,tmpfp) != EOF);
958 if (cxt) (void)lib$find_file_end(&cxt);
959 if (ok && sts != RMS$_NMF &&
960 sts != RMS$_DNF && sts != RMS$_FNF) ok = 0;
967 IoIFP(io) = fp = tmpfp;
973 sv_setpv(tmpcmd, "perlglob ");
974 sv_catsv(tmpcmd, tmpglob);
975 sv_catpv(tmpcmd, " |");
978 sv_setpvn(tmpcmd, cshname, cshlen);
979 sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
980 sv_catsv(tmpcmd, tmpglob);
981 sv_catpv(tmpcmd, "'|");
983 sv_setpv(tmpcmd, "echo ");
984 sv_catsv(tmpcmd, tmpglob);
986 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
988 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
992 (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),Nullfp);
998 else if (type == OP_GLOB)
1002 if (dowarn && !(IoFLAGS(io) & IOf_START))
1003 warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
1004 if (GIMME == G_SCALAR) {
1005 (void)SvOK_off(TARG);
1010 if (GIMME == G_ARRAY) {
1011 sv = sv_2mortal(NEWSV(57, 80));
1016 (void)SvUPGRADE(sv, SVt_PV);
1017 tmplen = SvLEN(sv); /* remember if already alloced */
1019 Sv_Grow(sv, 80); /* try short-buffering it */
1020 if (type == OP_RCATLINE)
1026 if (!sv_gets(sv, fp, offset)) {
1028 if (IoFLAGS(io) & IOf_ARGV) {
1029 fp = nextargv(last_in_gv);
1032 (void)do_close(last_in_gv, FALSE);
1033 IoFLAGS(io) |= IOf_START;
1035 else if (type == OP_GLOB) {
1036 (void)do_close(last_in_gv, FALSE);
1038 if (GIMME == G_SCALAR) {
1039 (void)SvOK_off(TARG);
1048 SvTAINT(sv); /* Anything from the outside world...*/
1050 if (type == OP_GLOB) {
1055 if (*SvEND(sv) == rschar)
1059 for (tmps = SvPVX(sv); *tmps; tmps++)
1060 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
1061 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
1063 if (*tmps && Stat(SvPVX(sv), &statbuf) < 0) {
1064 (void)POPs; /* Unmatched wildcard? Chuck it... */
1068 if (GIMME == G_ARRAY) {
1069 if (SvLEN(sv) - SvCUR(sv) > 20) {
1070 SvLEN_set(sv, SvCUR(sv)+1);
1071 Renew(SvPVX(sv), SvLEN(sv), char);
1073 sv = sv_2mortal(NEWSV(58, 80));
1076 else if (!tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
1077 /* try to reclaim a bit of scalar space (only on 1st alloc) */
1081 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
1082 Renew(SvPVX(sv), SvLEN(sv), char);
1091 register CONTEXT *cx;
1095 * We don't just use the GIMME macro here because it assumes there's
1096 * already a context, which ain't necessarily so at initial startup.
1099 if (op->op_flags & OPf_KNOW)
1100 gimme = op->op_flags & OPf_LIST;
1101 else if (cxstack_ix >= 0)
1102 gimme = cxstack[cxstack_ix].blk_gimme;
1109 PUSHBLOCK(cx, CXt_BLOCK, sp);
1120 char *key = SvPV(keysv, keylen);
1122 I32 lval = op->op_flags & OPf_MOD;
1124 if (SvTYPE(hv) != SVt_PVHV)
1126 svp = hv_fetch(hv, key, keylen, lval);
1128 if (!svp || *svp == &sv_undef)
1130 if (op->op_private & OPpLVAL_INTRO)
1132 else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) {
1137 (void)SvUPGRADE(sv, SVt_RV);
1138 SvRV(sv) = (op->op_private & OPpDEREF_HV ?
1139 (SV*)newHV() : (SV*)newAV());
1145 PUSHs(svp ? *svp : &sv_undef);
1152 register CONTEXT *cx;
1158 if (op->op_flags & OPf_SPECIAL) {
1159 cx = &cxstack[cxstack_ix];
1160 cx->blk_oldpm = curpm; /* fake block should preserve $1 et al */
1165 if (op->op_flags & OPf_KNOW)
1166 gimme = op->op_flags & OPf_LIST;
1167 else if (cxstack_ix >= 0)
1168 gimme = cxstack[cxstack_ix].blk_gimme;
1172 if (gimme == G_SCALAR) {
1173 if (op->op_private & OPpLEAVE_VOID)
1178 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
1181 *MARK = sv_mortalcopy(TOPs);
1190 for (mark = newsp + 1; mark <= SP; mark++)
1191 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP)))
1192 *mark = sv_mortalcopy(*mark);
1193 /* in case LEAVE wipes old return values */
1195 curpm = newpm; /* Don't pop $1 et al till now */
1205 register CONTEXT *cx;
1209 cx = &cxstack[cxstack_ix];
1210 if (cx->cx_type != CXt_LOOP)
1211 DIE("panic: pp_iter");
1213 if (cx->blk_loop.iterix >= cx->blk_oldsp)
1216 if (sv = AvARRAY(cx->blk_loop.iterary)[++cx->blk_loop.iterix]) {
1218 *cx->blk_loop.itervar = sv;
1221 *cx->blk_loop.itervar = &sv_undef;
1229 register PMOP *pm = cPMOP;
1244 register REGEXP *rx = pm->op_pmregexp;
1246 int force_on_match = 0;
1248 if (pm->op_pmflags & PMf_CONST) /* known replacement string? */
1250 if (op->op_flags & OPf_STACKED)
1256 s = SvPV(TARG, len);
1257 if (!SvPOKp(TARG) || SvREADONLY(TARG))
1262 DIE("panic: do_subst");
1265 maxiters = (strend - s) + 10;
1267 if (!rx->prelen && curpm) {
1269 rx = pm->op_pmregexp;
1271 safebase = ((!rx || !rx->nparens) && !sawampersand);
1272 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
1274 multiline = pm->op_pmflags & PMf_MULTILINE;
1277 if (pm->op_pmshort) {
1278 if (pm->op_pmflags & PMf_SCANFIRST) {
1279 if (SvSCREAM(TARG)) {
1280 if (screamfirst[BmRARE(pm->op_pmshort)] < 0)
1282 else if (!(s = screaminstr(TARG, pm->op_pmshort)))
1285 else if (!(s = fbm_instr((unsigned char*)s, (unsigned char*)strend,
1288 if (s && rx->regback >= 0) {
1289 ++BmUSEFUL(pm->op_pmshort);
1297 else if (!multiline) {
1298 if (*SvPVX(pm->op_pmshort) != *s ||
1299 bcmp(SvPVX(pm->op_pmshort), s, pm->op_pmslen) ) {
1300 if (pm->op_pmflags & PMf_FOLD) {
1301 if (ibcmp((U8*)SvPVX(pm->op_pmshort), (U8*)s, pm->op_pmslen) )
1308 if (!rx->naughty && --BmUSEFUL(pm->op_pmshort) < 0) {
1309 SvREFCNT_dec(pm->op_pmshort);
1310 pm->op_pmshort = Nullsv; /* opt is being useless */
1313 once = !(rpm->op_pmflags & PMf_GLOBAL);
1314 if (rpm->op_pmflags & PMf_CONST) { /* known replacement string? */
1315 c = SvPV(dstr, clen);
1316 if (clen <= rx->minlen) {
1317 /* can do inplace substitution */
1318 if (regexec(rx, s, strend, orig, 0,
1319 SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
1320 if (force_on_match) {
1322 s = SvPV_force(TARG, len);
1325 if (rx->subbase) /* oops, no we can't */
1329 SvSCREAM_off(TARG); /* disable possible screamer */
1334 if (m - s > strend - d) { /* faster to shorten from end */
1336 Copy(c, m, clen, char);
1341 Move(d, m, i, char);
1345 SvCUR_set(TARG, m - s);
1346 (void)SvPOK_only(TARG);
1352 else if (i = m - s) { /* faster from front */
1360 Copy(c, m, clen, char);
1361 (void)SvPOK_only(TARG);
1369 Copy(c, d, clen, char);
1370 (void)SvPOK_only(TARG);
1377 (void)SvPOK_only(TARG);
1385 if (iters++ > maxiters)
1386 DIE("Substitution loop");
1391 Move(s, d, i, char);
1395 Copy(c, d, clen, char);
1399 } while (regexec(rx, s, strend, orig, s == m,
1400 Nullsv, TRUE)); /* (don't match same null twice) */
1403 SvCUR_set(TARG, d - SvPVX(TARG) + i);
1404 Move(s, d, i+1, char); /* include the Null */
1406 (void)SvPOK_only(TARG);
1408 PUSHs(sv_2mortal(newSViv((I32)iters)));
1417 if (regexec(rx, s, strend, orig, 0,
1418 SvSCREAM(TARG) ? TARG : Nullsv, safebase)) {
1420 if (force_on_match) {
1422 s = SvPV_force(TARG, len);
1425 dstr = NEWSV(25, sv_len(TARG));
1426 sv_setpvn(dstr, m, s-m);
1429 register CONTEXT *cx;
1431 RETURNOP(cPMOP->op_pmreplroot);
1434 if (iters++ > maxiters)
1435 DIE("Substitution loop");
1436 if (rx->subbase && rx->subbase != orig) {
1441 strend = s + (strend - m);
1444 sv_catpvn(dstr, s, m-s);
1447 sv_catpvn(dstr, c, clen);
1450 } while (regexec(rx, s, strend, orig, s == m, Nullsv,
1452 sv_catpvn(dstr, s, strend - s);
1454 SvPVX(TARG) = SvPVX(dstr);
1455 SvCUR_set(TARG, SvCUR(dstr));
1456 SvLEN_set(TARG, SvLEN(dstr));
1460 (void)SvPOK_only(TARG);
1462 PUSHs(sv_2mortal(newSViv((I32)iters)));
1469 ++BmUSEFUL(pm->op_pmshort);
1479 stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
1481 LEAVE; /* exit inner scope */
1484 if (stack_base + *markstack_ptr > sp) {
1487 LEAVE; /* exit outer scope */
1488 (void)POPMARK; /* pop src */
1489 items = --*markstack_ptr - markstack_ptr[-1];
1490 (void)POPMARK; /* pop dst */
1491 SP = stack_base + POPMARK; /* pop original mark */
1492 if (GIMME != G_ARRAY) {
1503 ENTER; /* enter inner scope */
1506 src = stack_base[*markstack_ptr];
1510 RETURNOP(cLOGOP->op_other);
1521 register CONTEXT *cx;
1526 if (gimme == G_SCALAR) {
1529 if (SvFLAGS(TOPs) & SVs_TEMP)
1532 *MARK = sv_mortalcopy(TOPs);
1540 for (mark = newsp + 1; mark <= SP; mark++)
1541 if (!(SvFLAGS(*mark) & SVs_TEMP))
1542 *mark = sv_mortalcopy(*mark);
1543 /* in case LEAVE wipes old return values */
1546 if (cx->blk_sub.hasargs) { /* You don't exist; go away. */
1547 AV* av = cx->blk_sub.argarray;
1552 curpm = newpm; /* Don't pop $1 et al till now */
1556 return pop_return();
1565 register CONTEXT *cx;
1568 DIE("Not a CODE reference");
1569 switch (SvTYPE(sv)) {
1574 if (sv == &sv_yes) /* unfound import, ignore */
1577 DIE(no_usym, "a subroutine");
1579 if (op->op_private & HINT_STRICT_REFS)
1580 DIE(no_symref, sym, "a subroutine");
1581 cv = perl_get_cv(sym, TRUE);
1585 if (SvTYPE(cv) == SVt_PVCV)
1590 DIE("Not a CODE reference");
1595 if (!(cv = GvCV((GV*)sv)))
1596 cv = sv_2cv(sv, &stash, &gv, TRUE);
1605 DIE("Not a CODE reference");
1607 if (!CvROOT(cv) && !CvXSUB(cv)) {
1608 if (gv = CvGV(cv)) {
1609 SV *tmpstr = sv_newmortal();
1611 gv_efullname(tmpstr, gv);
1612 ngv = gv_fetchmethod(GvESTASH(gv), "AUTOLOAD");
1613 if (ngv && ngv != gv && (cv = GvCV(ngv))) { /* One more chance... */
1615 sv_setsv(GvSV(CvGV(cv)), tmpstr); /* Set CV's $AUTOLOAD */
1619 DIE("Undefined subroutine &%s called",SvPVX(tmpstr));
1621 DIE("Undefined subroutine called");
1624 if ((op->op_private & OPpDEREF_DB) && !CvXSUB(cv)) {
1627 if (SvFLAGS(cv) & SVpcv_ANON) /* Is GV potentially non-unique? */
1628 sv_setsv(sv, newRV((SV*)cv));
1631 gv_efullname(sv,gv);
1635 DIE("No DBsub routine");
1639 if (CvOLDSTYLE(cv)) {
1640 I32 (*fp3)_((int,int,int));
1642 register I32 items = SP - MARK;
1647 stack_sp = mark + 1;
1648 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
1649 items = (*fp3)(CvXSUBANY(cv).any_i32,
1650 MARK - stack_base + 1,
1652 stack_sp = stack_base + items;
1655 I32 markix = TOPMARK;
1658 (void)(*CvXSUB(cv))(cv);
1660 /* Enforce some sanity in scalar context. */
1661 if (GIMME == G_SCALAR && ++markix != stack_sp - stack_base ) {
1662 if (markix > stack_sp - stack_base)
1663 *(stack_base + markix) = &sv_undef;
1665 *(stack_base + markix) = *stack_sp;
1666 stack_sp = stack_base + markix;
1674 register I32 items = SP - MARK;
1675 I32 hasargs = (op->op_flags & OPf_STACKED) != 0;
1677 AV* padlist = CvPADLIST(cv);
1678 SV** svp = AvARRAY(padlist);
1679 push_return(op->op_next);
1680 PUSHBLOCK(cx, CXt_SUB, MARK);
1683 if (CvDEPTH(cv) < 2)
1684 (void)SvREFCNT_inc(cv);
1685 else { /* save temporaries on recursion? */
1686 if (CvDEPTH(cv) == 100 && dowarn)
1687 warn("Deep recursion on subroutine \"%s\"",GvENAME(CvGV(cv)));
1688 if (CvDEPTH(cv) > AvFILL(padlist)) {
1690 AV *newpad = newAV();
1691 AV *oldpad = (AV*)AvARRAY(svp[CvDEPTH(cv)-1]);
1692 I32 ix = AvFILL((AV*)svp[1]);
1693 svp = AvARRAY(svp[0]);
1694 for ( ;ix > 0; ix--) {
1695 if (svp[ix] != &sv_undef) {
1696 char *name = SvPVX(svp[ix]);
1697 if (SvFLAGS(svp[ix]) & SVf_FAKE) { /* outer lexical? */
1698 av_store(newpad, ix,
1699 SvREFCNT_inc(AvARRAY(oldpad)[ix]) );
1701 else { /* our own lexical */
1703 av_store(newpad, ix, sv = (SV*)newAV());
1704 else if (*name == '%')
1705 av_store(newpad, ix, sv = (SV*)newHV());
1707 av_store(newpad, ix, sv = NEWSV(0,0));
1712 av_store(newpad, ix, sv = NEWSV(0,0));
1716 av = newAV(); /* will be @_ */
1718 av_store(newpad, 0, (SV*)av);
1719 AvFLAGS(av) = AVf_REIFY;
1720 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
1721 AvFILL(padlist) = CvDEPTH(cv);
1722 svp = AvARRAY(padlist);
1726 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
1728 AV* av = (AV*)curpad[0];
1735 cx->blk_sub.savearray = GvAV(defgv);
1736 cx->blk_sub.argarray = av;
1737 GvAV(defgv) = cx->blk_sub.argarray;
1740 if (items > AvMAX(av) + 1) {
1742 if (AvARRAY(av) != ary) {
1743 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
1744 SvPVX(av) = (char*)ary;
1746 if (items > AvMAX(av) + 1) {
1747 AvMAX(av) = items - 1;
1748 Renew(ary,items,SV*);
1750 SvPVX(av) = (char*)ary;
1753 Copy(MARK,AvARRAY(av),items,SV*);
1754 AvFILL(av) = items - 1;
1762 RETURNOP(CvSTART(cv));
1772 I32 lval = op->op_flags & OPf_MOD;
1775 elem -= curcop->cop_arybase;
1776 if (SvTYPE(av) != SVt_PVAV)
1778 svp = av_fetch(av, elem, lval);
1780 if (!svp || *svp == &sv_undef)
1781 DIE(no_aelem, elem);
1782 if (op->op_private & OPpLVAL_INTRO)
1784 else if (op->op_private & (OPpDEREF_HV|OPpDEREF_AV)) {
1789 (void)SvUPGRADE(sv, SVt_RV);
1790 SvRV(sv) = (op->op_private & OPpDEREF_HV ?
1791 (SV*)newHV() : (SV*)newAV());
1797 PUSHs(svp ? *svp : &sv_undef);
1810 sv = *(stack_base + TOPMARK + 1);
1820 !(packname = SvPV(sv, na)) ||
1821 !(iogv = gv_fetchpv(packname, FALSE, SVt_PVIO)) ||
1822 !(ob=(SV*)GvIO(iogv)))
1824 char *name = SvPV(nm, na);
1826 if (!packname || !isALPHA(*packname))
1827 DIE("Can't call method \"%s\" without a package or object reference", name);
1828 if (!(stash = gv_stashpv(packname, FALSE))) {
1829 if (gv_stashpv("UNIVERSAL", FALSE))
1830 stash = gv_stashpv(packname, TRUE);
1832 DIE("Can't call method \"%s\" in empty package \"%s\"",
1835 gv = gv_fetchmethod(stash,name);
1837 DIE("Can't locate object method \"%s\" via package \"%s\"",
1842 *(stack_base + TOPMARK + 1) = iogv;
1845 if (!ob || !SvOBJECT(ob)) {
1846 char *name = SvPV(nm, na);
1847 DIE("Can't call method \"%s\" on unblessed reference", name);
1850 if (!gv) { /* nothing cached */
1851 char *name = SvPV(nm, na);
1852 gv = gv_fetchmethod(SvSTASH(ob),name);
1854 DIE("Can't locate object method \"%s\" via package \"%s\"",
1855 name, HvNAME(SvSTASH(ob)));