3 * Copyright (c) 1991-1997, 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!
29 unset_cvowner(void *cvarg)
31 register CV* cv = (CV *) cvarg;
34 #endif /* DEBUGGING */
36 DEBUG_L((PerlIO_printf(PerlIO_stderr(), "%p unsetting CvOWNER of %p:%s\n",
37 thr, cv, SvPEEK((SV*)cv))));
38 MUTEX_LOCK(CvMUTEXP(cv));
39 DEBUG_L(if (CvDEPTH(cv) != 0)
40 PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
42 assert(thr == CvOWNER(cv));
44 MUTEX_UNLOCK(CvMUTEXP(cv));
47 #endif /* USE_THREADS */
59 TAINT_NOT; /* Each statement is presumed innocent */
60 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
69 if (op->op_private & OPpLVAL_INTRO)
70 PUSHs(save_scalar(cGVOP->op_gv));
72 PUSHs(GvSV(cGVOP->op_gv));
93 sv_setpvn(TARG,s,len);
101 XPUSHs((SV*)cGVOP->op_gv);
112 RETURNOP(cLOGOP->op_other);
121 if (op->op_private & OPpASSIGN_BACKWARDS) {
123 temp = left; left = right; right = temp;
125 if (tainting && tainted && !SvTAINTED(left))
127 SvSetMagicSV(right, left);
136 RETURNOP(cCONDOP->op_true);
138 RETURNOP(cCONDOP->op_false);
144 TAINT_NOT; /* Each statement is presumed innocent */
145 stack_sp = stack_base + cxstack[cxstack_ix].blk_oldsp;
147 oldsave = scopestack[scopestack_ix - 1];
148 LEAVE_SCOPE(oldsave);
154 djSP; dATARGET; tryAMAGICbin(concat,opASSIGN);
161 sv_setpvn(TARG,s,len);
163 else if (SvGMAGICAL(TARG))
165 else if (!SvOK(TARG) && SvTYPE(TARG) <= SVt_PVMG) {
166 sv_setpv(TARG, ""); /* Suppress warning. */
167 s = SvPV_force(TARG, len);
171 sv_catpvn(TARG,s,len);
173 sv_setpvn(TARG,s,len); /* suppress warning */
183 if (op->op_flags & OPf_MOD) {
184 if (op->op_private & OPpLVAL_INTRO)
185 SAVECLEARSV(curpad[op->op_targ]);
186 else if (op->op_private & OPpDEREF) {
188 vivify_ref(curpad[op->op_targ], op->op_private & OPpDEREF);
197 last_in_gv = (GV*)(*stack_sp--);
198 return do_readline();
203 djSP; tryAMAGICbinSET(eq,0);
206 SETs(boolSV(TOPn == value));
214 if (SvREADONLY(TOPs) || SvTYPE(TOPs) > SVt_PVLV)
216 if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) &&
217 SvIVX(TOPs) != IV_MAX)
220 SvFLAGS(TOPs) &= ~(SVp_NOK|SVp_POK);
235 RETURNOP(cLOGOP->op_other);
241 djSP; dATARGET; tryAMAGICbin(add,opASSIGN);
244 SETn( left + right );
252 AV *av = GvAV((GV*)cSVOP->op_sv);
253 SV** svp = av_fetch(av, op->op_private, op->op_flags & OPf_MOD);
254 PUSHs(svp ? *svp : &sv_undef);
260 djSP; dMARK; dTARGET;
262 do_join(TARG, *MARK, MARK, SP);
273 * We ass_u_me that LvTARGOFF() comes first, and that two STRLENs
274 * will be enough to hold an OP*.
276 SV* sv = sv_newmortal();
277 sv_upgrade(sv, SVt_PVLV);
279 Copy(&op, &LvTARGOFF(sv), 1, OP*);
287 /* Oversized hot code. */
291 djSP; dMARK; dORIGMARK;
297 if (op->op_flags & OPf_STACKED)
301 if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
302 if (MARK == ORIGMARK) {
303 /* If using default handle then we need to make space to
304 * pass object as 1st arg, so move other args up ...
308 Move(MARK, MARK + 1, (SP - MARK) + 1, SV*);
315 perl_call_method("PRINT", G_SCALAR);
323 if (!(io = GvIO(gv))) {
325 SV* sv = sv_newmortal();
326 gv_fullname3(sv, gv, Nullch);
327 warn("Filehandle %s never opened", SvPV(sv,na));
330 SETERRNO(EBADF,RMS$_IFI);
333 else if (!(fp = IoOFP(io))) {
335 SV* sv = sv_newmortal();
336 gv_fullname3(sv, gv, Nullch);
338 warn("Filehandle %s opened only for input", SvPV(sv,na));
340 warn("print on closed filehandle %s", SvPV(sv,na));
342 SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
349 if (!do_print(*MARK, fp))
353 if (PerlIO_write(fp, ofs, ofslen) == 0 || PerlIO_error(fp)) {
362 if (!do_print(*MARK, fp))
371 if (PerlIO_write(fp, ors, orslen) == 0 || PerlIO_error(fp))
374 if (IoFLAGS(io) & IOf_FLUSH)
375 if (PerlIO_flush(fp) == EOF)
397 if (SvTYPE(av) != SVt_PVAV)
398 DIE("Not an ARRAY reference");
399 if (op->op_flags & OPf_REF) {
405 if (SvTYPE(sv) == SVt_PVAV) {
407 if (op->op_flags & OPf_REF) {
415 if (SvTYPE(sv) != SVt_PVGV) {
418 if (SvGMAGICAL(sv)) {
424 if (op->op_flags & OPf_REF ||
425 op->op_private & HINT_STRICT_REFS)
426 DIE(no_usym, "an ARRAY");
429 if (GIMME == G_ARRAY)
434 if (op->op_private & HINT_STRICT_REFS)
435 DIE(no_symref, sym, "an ARRAY");
436 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVAV);
441 if (op->op_private & OPpLVAL_INTRO)
443 if (op->op_flags & OPf_REF) {
450 if (GIMME == G_ARRAY) {
451 I32 maxarg = AvFILL(av) + 1;
453 if (SvRMAGICAL(av)) {
455 for (i=0; i < maxarg; i++) {
456 SV **svp = av_fetch(av, i, FALSE);
457 SP[i+1] = (svp) ? *svp : &sv_undef;
461 Copy(AvARRAY(av), SP+1, maxarg, SV*);
467 I32 maxarg = AvFILL(av) + 1;
481 if (SvTYPE(hv) != SVt_PVHV && SvTYPE(hv) != SVt_PVAV)
482 DIE("Not a HASH reference");
483 if (op->op_flags & OPf_REF) {
489 if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) {
491 if (op->op_flags & OPf_REF) {
499 if (SvTYPE(sv) != SVt_PVGV) {
502 if (SvGMAGICAL(sv)) {
508 if (op->op_flags & OPf_REF ||
509 op->op_private & HINT_STRICT_REFS)
510 DIE(no_usym, "a HASH");
513 if (GIMME == G_ARRAY) {
520 if (op->op_private & HINT_STRICT_REFS)
521 DIE(no_symref, sym, "a HASH");
522 gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVHV);
527 if (op->op_private & OPpLVAL_INTRO)
529 if (op->op_flags & OPf_REF) {
536 if (GIMME == G_ARRAY) { /* array wanted */
542 /* This bit is OK even when hv is really an AV */
544 sv_setpvf(TARG, "%ld/%ld",
545 (long)HvFILL(hv), (long)HvMAX(hv) + 1);
557 SV **lastlelem = stack_sp;
558 SV **lastrelem = stack_base + POPMARK;
559 SV **firstrelem = stack_base + POPMARK + 1;
560 SV **firstlelem = lastrelem + 1;
573 delaymagic = DM_DELAY; /* catch simultaneous items */
575 /* If there's a common identifier on both sides we have to take
576 * special care that assigning the identifier on the left doesn't
577 * clobber a value on the right that's used later in the list.
579 if (op->op_private & OPpASSIGN_COMMON) {
580 for (relem = firstrelem; relem <= lastrelem; relem++) {
583 TAINT_NOT; /* Each item is independent */
584 *relem = sv_mortalcopy(sv);
593 while (lelem <= lastlelem) {
594 TAINT_NOT; /* Each item stands on its own, taintwise. */
596 switch (SvTYPE(sv)) {
599 magic = SvMAGICAL(ary) != 0;
602 av_extend(ary, lastrelem - relem);
604 while (relem <= lastrelem) { /* gobble up all the rest */
610 didstore = av_store(ary,i++,sv);
624 magic = SvMAGICAL(hash) != 0;
627 while (relem < lastrelem) { /* gobble up all the rest */
633 sv = &sv_no, relem++;
634 tmpstr = NEWSV(29,0);
636 sv_setsv(tmpstr,*relem); /* value */
638 didstore = hv_store_ent(hash,sv,tmpstr,0);
640 if (SvSMAGICAL(tmpstr))
643 SvREFCNT_dec(tmpstr);
647 if (relem == lastrelem && dowarn) {
648 if (relem == firstrelem &&
650 ( SvTYPE(SvRV(*relem)) == SVt_PVAV ||
651 SvTYPE(SvRV(*relem)) == SVt_PVHV ) )
652 warn("Reference found where even-sized list expected");
654 warn("Odd number of elements in hash assignment");
659 if (SvTHINKFIRST(sv)) {
660 if (SvREADONLY(sv) && curcop != &compiling) {
661 if (sv != &sv_undef && sv != &sv_yes && sv != &sv_no)
663 if (relem <= lastrelem)
670 if (relem <= lastrelem) {
671 sv_setsv(sv, *relem);
675 sv_setsv(sv, &sv_undef);
680 if (delaymagic & ~DM_DELAY) {
681 if (delaymagic & DM_UID) {
683 (void)setresuid(uid,euid,(Uid_t)-1);
686 (void)setreuid(uid,euid);
689 if ((delaymagic & DM_UID) == DM_RUID) {
691 delaymagic &= ~DM_RUID;
693 # endif /* HAS_SETRUID */
695 if ((delaymagic & DM_UID) == DM_EUID) {
697 delaymagic &= ~DM_EUID;
699 # endif /* HAS_SETEUID */
700 if (delaymagic & DM_UID) {
702 DIE("No setreuid available");
705 # endif /* HAS_SETREUID */
706 #endif /* HAS_SETRESUID */
708 euid = (int)geteuid();
710 if (delaymagic & DM_GID) {
712 (void)setresgid(gid,egid,(Gid_t)-1);
715 (void)setregid(gid,egid);
718 if ((delaymagic & DM_GID) == DM_RGID) {
720 delaymagic &= ~DM_RGID;
722 # endif /* HAS_SETRGID */
724 if ((delaymagic & DM_GID) == DM_EGID) {
726 delaymagic &= ~DM_EGID;
728 # endif /* HAS_SETEGID */
729 if (delaymagic & DM_GID) {
731 DIE("No setregid available");
734 # endif /* HAS_SETREGID */
735 #endif /* HAS_SETRESGID */
737 egid = (int)getegid();
739 tainting |= (uid && (euid != uid || egid != gid));
746 else if (gimme == G_SCALAR) {
749 SETi(lastrelem - firstrelem + 1);
755 SP = firstrelem + (lastlelem - firstlelem);
756 lelem = firstlelem + (relem - firstrelem);
758 *relem++ = (lelem <= lastlelem) ? *lelem++ : &sv_undef;
766 register PMOP *pm = cPMOP;
773 register REGEXP *rx = pm->op_pmregexp;
777 I32 oldsave = savestack_ix;
778 I32 update_minmatch = 1;
781 if (op->op_flags & OPf_STACKED)
787 PUTBACK; /* EVAL blocks need stack_sp. */
791 DIE("panic: do_match");
794 if (pm->op_pmflags & PMf_USED) {
796 if (gimme == G_ARRAY)
801 if (!rx->prelen && curpm) {
803 rx = pm->op_pmregexp;
805 if (rx->minlen > len) goto failure;
807 screamer = ( (SvSCREAM(TARG) && rx->check_substr
808 && SvTYPE(rx->check_substr) == SVt_PVBM
809 && SvVALID(rx->check_substr))
812 if (global = pm->op_pmflags & PMf_GLOBAL) {
814 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
815 MAGIC* mg = mg_find(TARG, 'g');
816 if (mg && mg->mg_len >= 0) {
817 rx->endp[0] = rx->startp[0] = s + mg->mg_len;
818 minmatch = (mg->mg_flags & MGf_MINMATCH);
823 if (!rx->nparens && !global)
824 gimme = G_SCALAR; /* accidental array context? */
825 safebase = (((gimme == G_ARRAY) || global || !rx->nparens)
827 safebase = safebase ? 0 : REXEC_COPY_STR ;
828 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
830 multiline = pm->op_pmflags & PMf_MULTILINE;
834 if (global && rx->startp[0]) {
836 if ((s + rx->minlen) > strend)
838 if (update_minmatch++)
839 minmatch = (s == rx->startp[0]);
841 if (rx->check_substr) {
842 if (!(rx->reganch & ROPT_NOSCAN)) { /* Floating checkstring. */
846 if (screamfirst[BmRARE(rx->check_substr)] < 0)
848 else if (!(s = screaminstr(TARG, rx->check_substr,
849 rx->check_offset_min, 0, &p, 0)))
851 else if ((rx->reganch & ROPT_CHECK_ALL)
852 && !sawampersand && !SvTAIL(rx->check_substr))
855 else if (!(s = fbm_instr((unsigned char*)s + rx->check_offset_min,
856 (unsigned char*)strend,
859 else if ((rx->reganch & ROPT_CHECK_ALL) && !sawampersand)
861 if (s && rx->check_offset_max < t - s) {
862 ++BmUSEFUL(rx->check_substr);
863 s -= rx->check_offset_max;
868 /* Now checkstring is fixed, i.e. at fixed offset from the
869 beginning of match, and the match is anchored at s. */
870 else if (!multiline) { /* Anchored near beginning of string. */
872 if (*SvPVX(rx->check_substr) != s[rx->check_offset_min]
873 || ((slen = SvCUR(rx->check_substr)) > 1
874 && memNE(SvPVX(rx->check_substr),
875 s + rx->check_offset_min, slen)))
878 if (!rx->naughty && --BmUSEFUL(rx->check_substr) < 0
879 && rx->check_substr == rx->float_substr) {
880 SvREFCNT_dec(rx->check_substr);
881 rx->check_substr = Nullsv; /* opt is being useless */
882 rx->float_substr = Nullsv;
885 if (regexec_flags(rx, s, strend, truebase, minmatch,
886 screamer, NULL, safebase))
889 if (pm->op_pmflags & PMf_ONCE)
890 pm->op_pmflags |= PMf_USED;
898 TAINT_IF(RX_MATCH_TAINTED(rx));
899 if (gimme == G_ARRAY) {
903 if (global && !iters)
907 SPAGAIN; /* EVAL blocks could move the stack. */
908 EXTEND(SP, iters + i);
909 EXTEND_MORTAL(iters + i);
910 for (i = !i; i <= iters; i++) {
911 PUSHs(sv_newmortal());
913 if ((s = rx->startp[i]) && rx->endp[i] ) {
914 len = rx->endp[i] - s;
915 sv_setpvn(*SP, s, len);
919 truebase = rx->subbeg;
921 if (rx->startp[0] && rx->startp[0] == rx->endp[0])
923 PUTBACK; /* EVAL blocks may use stack */
926 LEAVE_SCOPE(oldsave);
932 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
933 mg = mg_find(TARG, 'g');
935 sv_magic(TARG, (SV*)0, 'g', Nullch, 0);
936 mg = mg_find(TARG, 'g');
939 mg->mg_len = rx->endp[0] - rx->subbeg;
940 if (rx->startp[0] == rx->endp[0])
941 mg->mg_flags |= MGf_MINMATCH;
943 mg->mg_flags &= ~MGf_MINMATCH;
946 LEAVE_SCOPE(oldsave);
950 yup: /* Confirmed by check_substr */
951 TAINT_IF(RX_MATCH_TAINTED(rx));
952 ++BmUSEFUL(rx->check_substr);
954 if (pm->op_pmflags & PMf_ONCE)
955 pm->op_pmflags |= PMf_USED;
956 Safefree(rx->subbase);
957 rx->subbase = Nullch;
959 rx->subbeg = truebase;
962 rx->endp[0] = s + SvCUR(rx->check_substr);
968 tmps = rx->subbase = savepvn(t, strend-t);
970 rx->subend = tmps + (strend-t);
971 tmps = rx->startp[0] = tmps + (s - t);
972 rx->endp[0] = tmps + SvCUR(rx->check_substr);
974 LEAVE_SCOPE(oldsave);
978 if (rx->check_substr)
979 ++BmUSEFUL(rx->check_substr);
982 if (global && !(pm->op_pmflags & PMf_CONTINUE)) {
983 if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
984 MAGIC* mg = mg_find(TARG, 'g');
989 LEAVE_SCOPE(oldsave);
990 if (gimme == G_ARRAY)
1003 register IO *io = GvIO(last_in_gv);
1004 register I32 type = op->op_type;
1005 I32 gimme = GIMME_V;
1008 if (SvRMAGICAL(last_in_gv) && (mg = mg_find((SV*)last_in_gv, 'q'))) {
1013 perl_call_method("READLINE", gimme);
1016 if (gimme == G_SCALAR)
1017 SvSetMagicSV_nosteal(TARG, TOPs);
1024 if (IoFLAGS(io) & IOf_ARGV) {
1025 if (IoFLAGS(io) & IOf_START) {
1026 IoFLAGS(io) &= ~IOf_START;
1028 if (av_len(GvAVn(last_in_gv)) < 0) {
1029 SV *tmpstr = newSVpv("-", 1); /* assume stdin */
1030 av_push(GvAVn(last_in_gv), tmpstr);
1033 fp = nextargv(last_in_gv);
1034 if (!fp) { /* Note: fp != IoIFP(io) */
1035 (void)do_close(last_in_gv, FALSE); /* now it does*/
1036 IoFLAGS(io) |= IOf_START;
1039 else if (type == OP_GLOB) {
1040 SV *tmpcmd = NEWSV(55, 0);
1044 #ifdef VMS /* expand the wildcards right here, rather than opening a pipe, */
1045 /* since spawning off a process is a real performance hit */
1047 #include <descrip.h>
1048 #include <lib$routines.h>
1051 char rslt[NAM$C_MAXRSS+1+sizeof(unsigned short int)] = {'\0','\0'};
1052 char vmsspec[NAM$C_MAXRSS+1];
1053 char *rstr = rslt + sizeof(unsigned short int), *begin, *end, *cp;
1054 char tmpfnam[L_tmpnam] = "SYS$SCRATCH:";
1055 $DESCRIPTOR(dfltdsc,"SYS$DISK:[]*.*;");
1058 struct dsc$descriptor_s wilddsc
1059 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
1060 struct dsc$descriptor_vs rsdsc
1061 = {sizeof rslt, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, rslt};
1062 unsigned long int cxt = 0, sts = 0, ok = 1, hasdir = 0, hasver = 0, isunix = 0;
1064 /* We could find out if there's an explicit dev/dir or version
1065 by peeking into lib$find_file's internal context at
1066 ((struct NAM *)((struct FAB *)cxt)->fab$l_nam)->nam$l_fnb
1067 but that's unsupported, so I don't want to do it now and
1068 have it bite someone in the future. */
1069 strcat(tmpfnam,PerlLIO_tmpnam(NULL));
1070 cp = SvPV(tmpglob,i);
1072 if (cp[i] == ';') hasver = 1;
1074 if (sts) hasver = 1;
1078 hasdir = isunix = 1;
1081 if (cp[i] == ']' || cp[i] == '>' || cp[i] == ':') {
1086 if ((tmpfp = PerlIO_open(tmpfnam,"w+","fop=dlt")) != NULL) {
1088 if (!PerlLIO_stat(SvPVX(tmpglob),&st) && S_ISDIR(st.st_mode))
1089 ok = ((wilddsc.dsc$a_pointer = tovmspath(SvPVX(tmpglob),vmsspec)) != NULL);
1090 else ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL);
1091 if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer);
1092 while (ok && ((sts = lib$find_file(&wilddsc,&rsdsc,&cxt,
1093 &dfltdsc,NULL,NULL,NULL))&1)) {
1094 end = rstr + (unsigned long int) *rslt;
1095 if (!hasver) while (*end != ';') end--;
1096 *(end++) = '\n'; *end = '\0';
1097 for (cp = rstr; *cp; cp++) *cp = _tolower(*cp);
1099 if (isunix) trim_unixpath(rstr,SvPVX(tmpglob),1);
1104 while (*(--begin) != ']' && *begin != '>') ;
1107 ok = (PerlIO_puts(tmpfp,begin) != EOF);
1109 if (cxt) (void)lib$find_file_end(&cxt);
1110 if (ok && sts != RMS$_NMF &&
1111 sts != RMS$_DNF && sts != RMS$_FNF) ok = 0;
1114 SETERRNO((sts == RMS$_SYN ? EINVAL : EVMSERR),sts);
1116 PerlIO_close(tmpfp);
1120 PerlIO_rewind(tmpfp);
1122 IoIFP(io) = fp = tmpfp;
1123 IoFLAGS(io) &= ~IOf_UNTAINT; /* maybe redundant */
1130 sv_setpv(tmpcmd, "for a in ");
1131 sv_catsv(tmpcmd, tmpglob);
1132 sv_catpv(tmpcmd, "; do echo \"$a\\0\\c\"; done |");
1135 sv_setpv(tmpcmd, "/dev/dosglob/"); /* File System Extension */
1136 sv_catsv(tmpcmd, tmpglob);
1138 sv_setpv(tmpcmd, "perlglob ");
1139 sv_catsv(tmpcmd, tmpglob);
1140 sv_catpv(tmpcmd, " |");
1145 sv_setpvn(tmpcmd, cshname, cshlen);
1146 sv_catpv(tmpcmd, " -cf 'set nonomatch; glob ");
1147 sv_catsv(tmpcmd, tmpglob);
1148 sv_catpv(tmpcmd, "' 2>/dev/null |");
1150 sv_setpv(tmpcmd, "echo ");
1151 sv_catsv(tmpcmd, tmpglob);
1153 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\012\\012\\012\\012'|");
1155 sv_catpv(tmpcmd, "|tr -s ' \t\f\r' '\\n\\n\\n\\n'|");
1158 #endif /* !DOSISH */
1159 (void)do_open(last_in_gv, SvPVX(tmpcmd), SvCUR(tmpcmd),
1160 FALSE, 0, 0, Nullfp);
1166 else if (type == OP_GLOB)
1170 if (dowarn && io && !(IoFLAGS(io) & IOf_START))
1171 warn("Read on closed filehandle <%s>", GvENAME(last_in_gv));
1172 if (gimme == G_SCALAR) {
1173 (void)SvOK_off(TARG);
1178 if (gimme == G_SCALAR) {
1182 (void)SvUPGRADE(sv, SVt_PV);
1183 tmplen = SvLEN(sv); /* remember if already alloced */
1185 Sv_Grow(sv, 80); /* try short-buffering it */
1186 if (type == OP_RCATLINE)
1192 sv = sv_2mortal(NEWSV(57, 80));
1196 if (!sv_gets(sv, fp, offset)) {
1197 PerlIO_clearerr(fp);
1198 if (IoFLAGS(io) & IOf_ARGV) {
1199 fp = nextargv(last_in_gv);
1202 (void)do_close(last_in_gv, FALSE);
1203 IoFLAGS(io) |= IOf_START;
1205 else if (type == OP_GLOB) {
1206 if (do_close(last_in_gv, FALSE) & ~0xFF)
1207 warn("internal error: glob failed");
1209 if (gimme == G_SCALAR) {
1210 (void)SvOK_off(TARG);
1215 /* This should not be marked tainted if the fp is marked clean */
1216 if (!(IoFLAGS(io) & IOf_UNTAINT)) {
1223 if (type == OP_GLOB) {
1226 if (SvCUR(sv) > 0 && SvCUR(rs) > 0) {
1227 tmps = SvEND(sv) - 1;
1228 if (*tmps == *SvPVX(rs)) {
1233 for (tmps = SvPVX(sv); *tmps; tmps++)
1234 if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
1235 strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
1237 if (*tmps && PerlLIO_stat(SvPVX(sv), &statbuf) < 0) {
1238 (void)POPs; /* Unmatched wildcard? Chuck it... */
1242 if (gimme == G_ARRAY) {
1243 if (SvLEN(sv) - SvCUR(sv) > 20) {
1244 SvLEN_set(sv, SvCUR(sv)+1);
1245 Renew(SvPVX(sv), SvLEN(sv), char);
1247 sv = sv_2mortal(NEWSV(58, 80));
1250 else if (gimme == G_SCALAR && !tmplen && SvLEN(sv) - SvCUR(sv) > 80) {
1251 /* try to reclaim a bit of scalar space (only on 1st alloc) */
1255 SvLEN_set(sv, SvCUR(sv)+40); /* allow some slop */
1256 Renew(SvPVX(sv), SvLEN(sv), char);
1265 register PERL_CONTEXT *cx;
1266 I32 gimme = OP_GIMME(op, -1);
1269 if (cxstack_ix >= 0)
1270 gimme = cxstack[cxstack_ix].blk_gimme;
1278 PUSHBLOCK(cx, CXt_BLOCK, SP);
1290 U32 lval = op->op_flags & OPf_MOD;
1291 U32 defer = op->op_private & OPpLVAL_DEFER;
1293 if (SvTYPE(hv) == SVt_PVHV) {
1294 he = hv_fetch_ent(hv, keysv, lval && !defer, 0);
1295 svp = he ? &HeVAL(he) : 0;
1297 else if (SvTYPE(hv) == SVt_PVAV) {
1298 svp = avhv_fetch_ent((AV*)hv, keysv, lval && !defer, 0);
1304 if (!svp || *svp == &sv_undef) {
1308 DIE(no_helem, SvPV(keysv, na));
1309 lv = sv_newmortal();
1310 sv_upgrade(lv, SVt_PVLV);
1312 sv_magic(lv, key2 = newSVsv(keysv), 'y', Nullch, 0);
1313 SvREFCNT_dec(key2); /* sv_magic() increments refcount */
1314 LvTARG(lv) = SvREFCNT_inc(hv);
1319 if (op->op_private & OPpLVAL_INTRO) {
1320 if (HvNAME(hv) && isGV(*svp))
1321 save_gp((GV*)*svp, !(op->op_flags & OPf_SPECIAL));
1323 save_helem(hv, keysv, svp);
1325 else if (op->op_private & OPpDEREF)
1326 vivify_ref(*svp, op->op_private & OPpDEREF);
1328 PUSHs(svp ? *svp : &sv_undef);
1335 register PERL_CONTEXT *cx;
1341 if (op->op_flags & OPf_SPECIAL) {
1342 cx = &cxstack[cxstack_ix];
1343 cx->blk_oldpm = curpm; /* fake block should preserve $1 et al */
1348 gimme = OP_GIMME(op, -1);
1350 if (cxstack_ix >= 0)
1351 gimme = cxstack[cxstack_ix].blk_gimme;
1357 if (gimme == G_VOID)
1359 else if (gimme == G_SCALAR) {
1362 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
1365 *MARK = sv_mortalcopy(TOPs);
1372 else if (gimme == G_ARRAY) {
1373 /* in case LEAVE wipes old return values */
1374 for (mark = newsp + 1; mark <= SP; mark++) {
1375 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
1376 *mark = sv_mortalcopy(*mark);
1377 TAINT_NOT; /* Each item is independent */
1381 curpm = newpm; /* Don't pop $1 et al till now */
1391 register PERL_CONTEXT *cx;
1396 cx = &cxstack[cxstack_ix];
1397 if (cx->cx_type != CXt_LOOP)
1398 DIE("panic: pp_iter");
1400 av = cx->blk_loop.iterary;
1401 if (cx->blk_loop.iterix >= (av == curstack ? cx->blk_oldsp : AvFILL(av)))
1404 SvREFCNT_dec(*cx->blk_loop.itervar);
1406 if (sv = (SvMAGICAL(av))
1407 ? *av_fetch(av, ++cx->blk_loop.iterix, FALSE)
1408 : AvARRAY(av)[++cx->blk_loop.iterix])
1412 if (av != curstack && SvIMMORTAL(sv)) {
1413 SV *lv = cx->blk_loop.iterlval;
1414 if (lv && SvREFCNT(lv) > 1) {
1419 SvREFCNT_dec(LvTARG(lv));
1421 lv = cx->blk_loop.iterlval = NEWSV(26, 0);
1422 sv_upgrade(lv, SVt_PVLV);
1424 sv_magic(lv, Nullsv, 'y', Nullch, 0);
1426 LvTARG(lv) = SvREFCNT_inc(av);
1427 LvTARGOFF(lv) = cx->blk_loop.iterix;
1428 LvTARGLEN(lv) = (UV) -1;
1432 *cx->blk_loop.itervar = SvREFCNT_inc(sv);
1439 register PMOP *pm = cPMOP;
1455 register REGEXP *rx = pm->op_pmregexp;
1457 int force_on_match = 0;
1458 I32 oldsave = savestack_ix;
1459 I32 update_minmatch = 1;
1462 /* known replacement string? */
1463 dstr = (pm->op_pmflags & PMf_CONST) ? POPs : Nullsv;
1464 if (op->op_flags & OPf_STACKED)
1470 if (SvREADONLY(TARG)
1471 || (SvTYPE(TARG) > SVt_PVLV
1472 && !(SvTYPE(TARG) == SVt_PVGV && SvFAKE(TARG))))
1476 s = SvPV(TARG, len);
1477 if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV)
1483 DIE("panic: do_subst");
1486 maxiters = (strend - s) + 10;
1488 if (!rx->prelen && curpm) {
1490 rx = pm->op_pmregexp;
1492 screamer = ( (SvSCREAM(TARG) && rx->check_substr
1493 && SvTYPE(rx->check_substr) == SVt_PVBM
1494 && SvVALID(rx->check_substr))
1496 safebase = (!rx->nparens && !sawampersand) ? 0 : REXEC_COPY_STR;
1497 if (pm->op_pmflags & (PMf_MULTILINE|PMf_SINGLELINE)) {
1499 multiline = pm->op_pmflags & PMf_MULTILINE;
1502 if (rx->check_substr) {
1503 if (!(rx->reganch & ROPT_NOSCAN)) { /* It floats. */
1507 if (screamfirst[BmRARE(rx->check_substr)] < 0)
1509 else if (!(s = screaminstr(TARG, rx->check_substr, rx->check_offset_min, 0, &p, 0)))
1512 else if (!(s = fbm_instr((unsigned char*)s + rx->check_offset_min,
1513 (unsigned char*)strend,
1516 if (s && rx->check_offset_max < s - m) {
1517 ++BmUSEFUL(rx->check_substr);
1518 s -= rx->check_offset_max;
1523 /* Now checkstring is fixed, i.e. at fixed offset from the
1524 beginning of match, and the match is anchored at s. */
1525 else if (!multiline) { /* Anchored at beginning of string. */
1527 if (*SvPVX(rx->check_substr) != s[rx->check_offset_min]
1528 || ((slen = SvCUR(rx->check_substr)) > 1
1529 && memNE(SvPVX(rx->check_substr),
1530 s + rx->check_offset_min, slen)))
1533 if (!rx->naughty && --BmUSEFUL(rx->check_substr) < 0
1534 && rx->check_substr == rx->float_substr) {
1535 SvREFCNT_dec(rx->check_substr);
1536 rx->check_substr = Nullsv; /* opt is being useless */
1537 rx->float_substr = Nullsv;
1541 /* only replace once? */
1542 once = !(rpm->op_pmflags & PMf_GLOBAL);
1544 /* known replacement string? */
1545 c = dstr ? SvPV(dstr, clen) : Nullch;
1547 /* can do inplace substitution? */
1548 if (c && clen <= rx->minlen && (once || !(safebase & REXEC_COPY_STR))
1549 && !(rx->reganch & ROPT_LOOKBEHIND_SEEN)) {
1550 if (!regexec_flags(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
1553 LEAVE_SCOPE(oldsave);
1556 if (force_on_match) {
1558 s = SvPV_force(TARG, len);
1563 SvSCREAM_off(TARG); /* disable possible screamer */
1565 rxtainted = RX_MATCH_TAINTED(rx);
1567 m = orig + (rx->startp[0] - rx->subbase);
1568 d = orig + (rx->endp[0] - rx->subbase);
1574 if (m - s > strend - d) { /* faster to shorten from end */
1576 Copy(c, m, clen, char);
1581 Move(d, m, i, char);
1585 SvCUR_set(TARG, m - s);
1588 else if (i = m - s) { /* faster from front */
1596 Copy(c, m, clen, char);
1601 Copy(c, d, clen, char);
1606 TAINT_IF(rxtainted);
1613 if (iters++ > maxiters)
1614 DIE("Substitution loop");
1615 rxtainted |= RX_MATCH_TAINTED(rx);
1620 Move(s, d, i, char);
1624 Copy(c, d, clen, char);
1628 } while (regexec_flags(rx, s, strend, orig, s == m,
1629 Nullsv, NULL, 0)); /* don't match same null twice */
1632 SvCUR_set(TARG, d - SvPVX(TARG) + i);
1633 Move(s, d, i+1, char); /* include the NUL */
1635 TAINT_IF(rxtainted);
1637 PUSHs(sv_2mortal(newSViv((I32)iters)));
1639 (void)SvPOK_only(TARG);
1640 if (SvSMAGICAL(TARG)) {
1646 LEAVE_SCOPE(oldsave);
1650 if (regexec_flags(rx, s, strend, orig, 0, screamer, NULL, safebase)) {
1651 if (force_on_match) {
1653 s = SvPV_force(TARG, len);
1656 rxtainted = RX_MATCH_TAINTED(rx);
1657 dstr = NEWSV(25, len);
1658 sv_setpvn(dstr, m, s-m);
1661 register PERL_CONTEXT *cx;
1664 RETURNOP(cPMOP->op_pmreplroot);
1667 if (iters++ > maxiters)
1668 DIE("Substitution loop");
1669 rxtainted |= RX_MATCH_TAINTED(rx);
1670 if (rx->subbase && rx->subbase != orig) {
1675 strend = s + (strend - m);
1678 sv_catpvn(dstr, s, m-s);
1681 sv_catpvn(dstr, c, clen);
1684 } while (regexec_flags(rx, s, strend, orig, s == m, Nullsv, NULL, safebase));
1685 sv_catpvn(dstr, s, strend - s);
1687 TAINT_IF(rxtainted);
1689 (void)SvOOK_off(TARG);
1690 Safefree(SvPVX(TARG));
1691 SvPVX(TARG) = SvPVX(dstr);
1692 SvCUR_set(TARG, SvCUR(dstr));
1693 SvLEN_set(TARG, SvLEN(dstr));
1697 (void)SvPOK_only(TARG);
1701 PUSHs(sv_2mortal(newSViv((I32)iters)));
1702 LEAVE_SCOPE(oldsave);
1708 ++BmUSEFUL(rx->check_substr);
1713 LEAVE_SCOPE(oldsave);
1722 stack_base[markstack_ptr[-1]++] = stack_base[*markstack_ptr];
1724 LEAVE; /* exit inner scope */
1727 if (stack_base + *markstack_ptr > SP) {
1729 I32 gimme = GIMME_V;
1731 LEAVE; /* exit outer scope */
1732 (void)POPMARK; /* pop src */
1733 items = --*markstack_ptr - markstack_ptr[-1];
1734 (void)POPMARK; /* pop dst */
1735 SP = stack_base + POPMARK; /* pop original mark */
1736 if (gimme == G_SCALAR) {
1740 else if (gimme == G_ARRAY)
1747 ENTER; /* enter inner scope */
1750 src = stack_base[*markstack_ptr];
1754 RETURNOP(cLOGOP->op_other);
1765 register PERL_CONTEXT *cx;
1766 struct block_sub cxsub;
1769 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1772 if (gimme == G_SCALAR) {
1775 *MARK = SvTEMP(TOPs) ? TOPs : sv_mortalcopy(TOPs);
1782 else if (gimme == G_ARRAY) {
1783 for (MARK = newsp + 1; MARK <= SP; MARK++) {
1784 if (!SvTEMP(*MARK)) {
1785 *MARK = sv_mortalcopy(*MARK);
1786 TAINT_NOT; /* Each item is independent */
1792 POPSUB2(); /* Stack values are safe: release CV and @_ ... */
1793 curpm = newpm; /* ... and pop $1 et al */
1796 return pop_return();
1800 get_db_sub(SV **svp, CV *cv)
1803 SV *dbsv = GvSV(DBsub);
1805 if (!PERLDB_SUB_NN) {
1809 if ( (CvFLAGS(cv) & (CVf_ANON | CVf_CLONED))
1810 || strEQ(GvNAME(gv), "END")
1811 || ((GvCV(gv) != cv) && /* Could be imported, and old sub redefined. */
1812 !( (SvTYPE(*svp) == SVt_PVGV) && (GvCV((GV*)*svp) == cv)
1813 && (gv = (GV*)*svp) ))) {
1814 /* Use GV from the stack as a fallback. */
1815 /* GV is potentially non-unique, or contain different CV. */
1816 sv_setsv(dbsv, newRV((SV*)cv));
1819 gv_efullname3(dbsv, gv, Nullch);
1823 SvUPGRADE(dbsv, SVt_PVIV);
1825 SAVEIV(SvIVX(dbsv));
1826 SvIVX(dbsv) = (IV)cv; /* Do it the quickest way */
1841 register PERL_CONTEXT *cx;
1843 bool hasargs = (op->op_flags & OPf_STACKED) != 0;
1846 DIE("Not a CODE reference");
1847 switch (SvTYPE(sv)) {
1852 if (sv == &sv_yes) { /* unfound import, ignore */
1854 SP = stack_base + POPMARK;
1857 if (SvGMAGICAL(sv)) {
1859 sym = SvPOKp(sv) ? SvPVX(sv) : Nullch;
1864 DIE(no_usym, "a subroutine");
1865 if (op->op_private & HINT_STRICT_REFS)
1866 DIE(no_symref, sym, "a subroutine");
1867 cv = perl_get_cv(sym, TRUE);
1871 if (SvTYPE(cv) == SVt_PVCV)
1876 DIE("Not a CODE reference");
1881 if (!(cv = GvCVu((GV*)sv)))
1882 cv = sv_2cv(sv, &stash, &gv, TRUE);
1891 DIE("Not a CODE reference");
1893 if (!CvROOT(cv) && !CvXSUB(cv)) {
1897 /* anonymous or undef'd function leaves us no recourse */
1898 if (CvANON(cv) || !(gv = CvGV(cv)))
1899 DIE("Undefined subroutine called");
1900 /* autoloaded stub? */
1901 if (cv != GvCV(gv)) {
1905 /* should call AUTOLOAD now? */
1906 if ((autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv),
1913 sub_name = sv_newmortal();
1914 gv_efullname3(sub_name, gv, Nullch);
1915 DIE("Undefined subroutine &%s called", SvPVX(sub_name));
1919 if ((op->op_private & OPpENTERSUB_DB) && GvCV(DBsub) && !CvNODEBUG(cv))
1920 cv = get_db_sub(&sv, cv);
1922 DIE("No DBsub routine");
1926 * First we need to check if the sub or method requires locking.
1927 * If so, we gain a lock on the CV, the first argument or the
1928 * stash (for static methods), as appropriate. This has to be
1929 * inline because for FAKE_THREADS, COND_WAIT inlines code to
1930 * reschedule by returning a new op.
1932 MUTEX_LOCK(CvMUTEXP(cv));
1933 if (CvFLAGS(cv) & CVf_LOCKED) {
1935 if (CvFLAGS(cv) & CVf_METHOD) {
1936 if (SP > stack_base + TOPMARK)
1937 sv = *(stack_base + TOPMARK + 1);
1939 MUTEX_UNLOCK(CvMUTEXP(cv));
1940 croak("no argument for locked method call");
1946 char *stashname = SvPV(sv, len);
1947 sv = (SV*)gv_stashpvn(stashname, len, TRUE);
1953 MUTEX_UNLOCK(CvMUTEXP(cv));
1954 mg = condpair_magic(sv);
1955 MUTEX_LOCK(MgMUTEXP(mg));
1956 if (MgOWNER(mg) == thr)
1957 MUTEX_UNLOCK(MgMUTEXP(mg));
1960 COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
1962 DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
1964 MUTEX_UNLOCK(MgMUTEXP(mg));
1965 SvREFCNT_inc(sv); /* Keep alive until magic_mutexfree */
1966 save_destructor(unlock_condpair, sv);
1968 MUTEX_LOCK(CvMUTEXP(cv));
1971 * Now we have permission to enter the sub, we must distinguish
1972 * four cases. (0) It's an XSUB (in which case we don't care
1973 * about ownership); (1) it's ours already (and we're recursing);
1974 * (2) it's free (but we may already be using a cached clone);
1975 * (3) another thread owns it. Case (1) is easy: we just use it.
1976 * Case (2) means we look for a clone--if we have one, use it
1977 * otherwise grab ownership of cv. Case (3) means we look for a
1978 * clone (for non-XSUBs) and have to create one if we don't
1980 * Why look for a clone in case (2) when we could just grab
1981 * ownership of cv straight away? Well, we could be recursing,
1982 * i.e. we originally tried to enter cv while another thread
1983 * owned it (hence we used a clone) but it has been freed up
1984 * and we're now recursing into it. It may or may not be "better"
1985 * to use the clone but at least CvDEPTH can be trusted.
1987 if (CvOWNER(cv) == thr || CvXSUB(cv))
1988 MUTEX_UNLOCK(CvMUTEXP(cv));
1990 /* Case (2) or (3) */
1994 * XXX Might it be better to release CvMUTEXP(cv) while we
1995 * do the hv_fetch? We might find someone has pinched it
1996 * when we look again, in which case we would be in case
1997 * (3) instead of (2) so we'd have to clone. Would the fact
1998 * that we released the mutex more quickly make up for this?
2000 svp = hv_fetch(thr->cvcache, (char *)cv, sizeof(cv), FALSE);
2002 /* We already have a clone to use */
2003 MUTEX_UNLOCK(CvMUTEXP(cv));
2005 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2006 "entersub: %p already has clone %p:%s\n",
2007 thr, cv, SvPEEK((SV*)cv)));
2010 if (CvDEPTH(cv) == 0)
2011 SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
2014 /* (2) => grab ownership of cv. (3) => make clone */
2018 MUTEX_UNLOCK(CvMUTEXP(cv));
2019 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2020 "entersub: %p grabbing %p:%s in stash %s\n",
2021 thr, cv, SvPEEK((SV*)cv), CvSTASH(cv) ?
2022 HvNAME(CvSTASH(cv)) : "(none)"));
2024 /* Make a new clone. */
2026 SvREFCNT_inc(cv); /* don't let it vanish from under us */
2027 MUTEX_UNLOCK(CvMUTEXP(cv));
2028 DEBUG_L((PerlIO_printf(PerlIO_stderr(),
2029 "entersub: %p cloning %p:%s\n",
2030 thr, cv, SvPEEK((SV*)cv))));
2032 * We're creating a new clone so there's no race
2033 * between the original MUTEX_UNLOCK and the
2034 * SvREFCNT_inc since no one will be trying to undef
2035 * it out from underneath us. At least, I don't think
2038 clonecv = cv_clone(cv);
2039 SvREFCNT_dec(cv); /* finished with this */
2040 hv_store(thr->cvcache, (char*)cv, sizeof(cv), (SV*)clonecv,0);
2041 CvOWNER(clonecv) = thr;
2045 DEBUG_L(if (CvDEPTH(cv) != 0)
2046 PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
2048 SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
2051 #endif /* USE_THREADS */
2054 if (CvOLDSTYLE(cv)) {
2055 I32 (*fp3)_((int,int,int));
2057 register I32 items = SP - MARK;
2058 /* We dont worry to copy from @_. */
2063 stack_sp = mark + 1;
2064 fp3 = (I32(*)_((int,int,int)))CvXSUB(cv);
2065 items = (*fp3)(CvXSUBANY(cv).any_i32,
2066 MARK - stack_base + 1,
2068 stack_sp = stack_base + items;
2071 I32 markix = TOPMARK;
2076 /* Need to copy @_ to stack. Alternative may be to
2077 * switch stack to @_, and copy return values
2078 * back. This would allow popping @_ in XSUB, e.g.. XXXX */
2082 av = (AV*)curpad[0];
2085 #endif /* USE_THREADS */
2086 items = AvFILLp(av) + 1; /* @_ is not tieable */
2089 /* Mark is at the end of the stack. */
2091 Copy(AvARRAY(av), SP + 1, items, SV*);
2096 if (curcopdb) { /* We assume that the first
2097 XSUB in &DB::sub is the
2103 /* Do we need to open block here? XXXX */
2104 (void)(*CvXSUB(cv))(cv);
2106 /* Enforce some sanity in scalar context. */
2107 if (gimme == G_SCALAR && ++markix != stack_sp - stack_base ) {
2108 if (markix > stack_sp - stack_base)
2109 *(stack_base + markix) = &sv_undef;
2111 *(stack_base + markix) = *stack_sp;
2112 stack_sp = stack_base + markix;
2120 register I32 items = SP - MARK;
2121 AV* padlist = CvPADLIST(cv);
2122 SV** svp = AvARRAY(padlist);
2123 push_return(op->op_next);
2124 PUSHBLOCK(cx, CXt_SUB, MARK);
2127 if (CvDEPTH(cv) < 2)
2128 (void)SvREFCNT_inc(cv);
2129 else { /* save temporaries on recursion? */
2130 if (CvDEPTH(cv) == 100 && dowarn
2131 && !(PERLDB_SUB && cv == GvCV(DBsub)))
2132 sub_crush_depth(cv);
2133 if (CvDEPTH(cv) > AvFILLp(padlist)) {
2135 AV *newpad = newAV();
2136 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
2137 I32 ix = AvFILLp((AV*)svp[1]);
2138 svp = AvARRAY(svp[0]);
2139 for ( ;ix > 0; ix--) {
2140 if (svp[ix] != &sv_undef) {
2141 char *name = SvPVX(svp[ix]);
2142 if ((SvFLAGS(svp[ix]) & SVf_FAKE) /* outer lexical? */
2143 || *name == '&') /* anonymous code? */
2145 av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
2147 else { /* our own lexical */
2149 av_store(newpad, ix, sv = (SV*)newAV());
2150 else if (*name == '%')
2151 av_store(newpad, ix, sv = (SV*)newHV());
2153 av_store(newpad, ix, sv = NEWSV(0,0));
2158 av_store(newpad, ix, sv = NEWSV(0,0));
2162 av = newAV(); /* will be @_ */
2164 av_store(newpad, 0, (SV*)av);
2165 AvFLAGS(av) = AVf_REIFY;
2166 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
2167 AvFILLp(padlist) = CvDEPTH(cv);
2168 svp = AvARRAY(padlist);
2173 AV* av = (AV*)curpad[0];
2175 items = AvFILLp(av) + 1;
2177 /* Mark is at the end of the stack. */
2179 Copy(AvARRAY(av), SP + 1, items, SV*);
2184 #endif /* USE_THREADS */
2186 curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
2189 #endif /* USE_THREADS */
2195 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2196 "%p entersub preparing @_\n", thr));
2198 av = (AV*)curpad[0];
2204 cx->blk_sub.savearray = GvAV(defgv);
2205 GvAV(defgv) = (AV*)SvREFCNT_inc(av);
2206 #endif /* USE_THREADS */
2207 cx->blk_sub.argarray = av;
2210 if (items > AvMAX(av) + 1) {
2212 if (AvARRAY(av) != ary) {
2213 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2214 SvPVX(av) = (char*)ary;
2216 if (items > AvMAX(av) + 1) {
2217 AvMAX(av) = items - 1;
2218 Renew(ary,items,SV*);
2220 SvPVX(av) = (char*)ary;
2223 Copy(MARK,AvARRAY(av),items,SV*);
2224 AvFILLp(av) = items - 1;
2233 DEBUG_L(PerlIO_printf(PerlIO_stderr(),
2234 "%p entersub returning %p\n", thr, CvSTART(cv)));
2236 RETURNOP(CvSTART(cv));
2241 sub_crush_depth(CV *cv)
2244 warn("Deep recursion on anonymous subroutine");
2246 SV* tmpstr = sv_newmortal();
2247 gv_efullname3(tmpstr, CvGV(cv), Nullch);
2248 warn("Deep recursion on subroutine \"%s\"", SvPVX(tmpstr));
2258 U32 lval = op->op_flags & OPf_MOD;
2259 U32 defer = (op->op_private & OPpLVAL_DEFER) && (elem > AvFILL(av));
2262 elem -= curcop->cop_arybase;
2263 if (SvTYPE(av) != SVt_PVAV)
2265 svp = av_fetch(av, elem, lval && !defer);
2267 if (!svp || *svp == &sv_undef) {
2270 DIE(no_aelem, elem);
2271 lv = sv_newmortal();
2272 sv_upgrade(lv, SVt_PVLV);
2274 sv_magic(lv, Nullsv, 'y', Nullch, 0);
2275 LvTARG(lv) = SvREFCNT_inc(av);
2276 LvTARGOFF(lv) = elem;
2281 if (op->op_private & OPpLVAL_INTRO)
2282 save_aelem(av, elem, svp);
2283 else if (op->op_private & OPpDEREF)
2284 vivify_ref(*svp, op->op_private & OPpDEREF);
2286 PUSHs(svp ? *svp : &sv_undef);
2291 vivify_ref(SV *sv, U32 to_what)
2298 if (SvTYPE(sv) < SVt_RV)
2299 sv_upgrade(sv, SVt_RV);
2300 else if (SvTYPE(sv) >= SVt_PV) {
2301 (void)SvOOK_off(sv);
2302 Safefree(SvPVX(sv));
2303 SvLEN(sv) = SvCUR(sv) = 0;
2307 SvRV(sv) = NEWSV(355,0);
2310 SvRV(sv) = (SV*)newAV();
2313 SvRV(sv) = (SV*)newHV();
2334 if (SvTYPE(sv) == SVt_PVCV) {
2340 name = SvPV(TOPs, na);
2341 sv = *(stack_base + TOPMARK + 1);
2352 !(packname = SvPV(sv, packlen)) ||
2353 !(iogv = gv_fetchpv(packname, FALSE, SVt_PVIO)) ||
2354 !(ob=(SV*)GvIO(iogv)))
2356 if (!packname || !isIDFIRST(*packname))
2357 DIE("Can't call method \"%s\" without a package or object reference", name);
2358 stash = gv_stashpvn(packname, packlen, TRUE);
2361 *(stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
2364 if (!ob || !SvOBJECT(ob))
2365 DIE("Can't call method \"%s\" on unblessed reference", name);
2367 stash = SvSTASH(ob);
2370 gv = gv_fetchmethod(stash, name);
2376 for (p = name; *p; p++) {
2378 sep = p, leaf = p + 1;
2379 else if (*p == ':' && *(p + 1) == ':')
2380 sep = p, leaf = p + 2;
2382 if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
2383 packname = HvNAME(sep ? curcop->cop_stash : stash);
2384 packlen = strlen(packname);
2388 packlen = sep - name;
2390 DIE("Can't locate object method \"%s\" via package \"%.*s\"",
2391 leaf, (int)packlen, packname);
2393 SETs(isGV(gv) ? (SV*)GvCV(gv) : (SV*)gv);