3 * Copyright (c) 1991-1999, 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 * Now far ahead the Road has gone,
12 * And I must follow, if I can,
13 * Pursuing it with eager feet,
14 * Until it joins some larger way
15 * Where many paths and errands meet.
16 * And whither then? I cannot say.
20 #define PERL_IN_PP_CTL_C
24 #define WORD_ALIGN sizeof(U16)
27 #define DOCATCH(o) ((CATCH_GET == TRUE) ? docatch(o) : (o))
30 #define CALLOP this->*PL_op
35 static I32 sortcv(pTHXo_ SV *a, SV *b);
36 static I32 sv_ncmp(pTHXo_ SV *a, SV *b);
37 static I32 sv_i_ncmp(pTHXo_ SV *a, SV *b);
38 static I32 amagic_ncmp(pTHXo_ SV *a, SV *b);
39 static I32 amagic_i_ncmp(pTHXo_ SV *a, SV *b);
40 static I32 amagic_cmp(pTHXo_ SV *a, SV *b);
41 static I32 amagic_cmp_locale(pTHXo_ SV *a, SV *b);
42 static I32 sv_cmp_static(pTHXo_ SV *a, SV *b);
43 static I32 sv_cmp_locale_static(pTHXo_ SV *a, SV *b);
51 cxix = dopoptosub(cxstack_ix);
55 switch (cxstack[cxix].blk_gimme) {
72 /* XXXX Should store the old value to allow for tie/overload - and
73 restore in regcomp, where marked with XXXX. */
81 register PMOP *pm = (PMOP*)cLOGOP->op_other;
85 MAGIC *mg = Null(MAGIC*);
89 SV *sv = SvRV(tmpstr);
91 mg = mg_find(sv, 'r');
94 regexp *re = (regexp *)mg->mg_obj;
95 ReREFCNT_dec(pm->op_pmregexp);
96 pm->op_pmregexp = ReREFCNT_inc(re);
99 t = SvPV(tmpstr, len);
101 /* Check against the last compiled regexp. */
102 if (!pm->op_pmregexp || !pm->op_pmregexp->precomp ||
103 pm->op_pmregexp->prelen != len ||
104 memNE(pm->op_pmregexp->precomp, t, len))
106 if (pm->op_pmregexp) {
107 ReREFCNT_dec(pm->op_pmregexp);
108 pm->op_pmregexp = Null(REGEXP*); /* crucial if regcomp aborts */
110 if (PL_op->op_flags & OPf_SPECIAL)
111 PL_reginterp_cnt = I32_MAX; /* Mark as safe. */
113 pm->op_pmflags = pm->op_pmpermflags; /* reset case sensitivity */
114 pm->op_pmregexp = CALLREGCOMP(aTHX_ t, t + len, pm);
115 PL_reginterp_cnt = 0; /* XXXX Be extra paranoid - needed
116 inside tie/overload accessors. */
120 #ifndef INCOMPLETE_TAINTS
123 pm->op_pmdynflags |= PMdf_TAINTED;
125 pm->op_pmdynflags &= ~PMdf_TAINTED;
129 if (!pm->op_pmregexp->prelen && PL_curpm)
131 else if (strEQ("\\s+", pm->op_pmregexp->precomp))
132 pm->op_pmflags |= PMf_WHITE;
134 if (pm->op_pmflags & PMf_KEEP) {
135 pm->op_private &= ~OPpRUNTIME; /* no point compiling again */
136 cLOGOP->op_first->op_next = PL_op->op_next;
144 register PMOP *pm = (PMOP*) cLOGOP->op_other;
145 register PERL_CONTEXT *cx = &cxstack[cxstack_ix];
146 register SV *dstr = cx->sb_dstr;
147 register char *s = cx->sb_s;
148 register char *m = cx->sb_m;
149 char *orig = cx->sb_orig;
150 register REGEXP *rx = cx->sb_rx;
152 rxres_restore(&cx->sb_rxres, rx);
154 if (cx->sb_iters++) {
155 if (cx->sb_iters > cx->sb_maxiters)
156 DIE(aTHX_ "Substitution loop");
158 if (!(cx->sb_rxtainted & 2) && SvTAINTED(TOPs))
159 cx->sb_rxtainted |= 2;
160 sv_catsv(dstr, POPs);
163 if (cx->sb_once || !CALLREGEXEC(aTHX_ rx, s, cx->sb_strend, orig,
164 s == m, cx->sb_targ, NULL,
165 ((cx->sb_rflags & REXEC_COPY_STR)
166 ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST)
167 : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST))))
169 SV *targ = cx->sb_targ;
170 sv_catpvn(dstr, s, cx->sb_strend - s);
172 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
174 (void)SvOOK_off(targ);
175 Safefree(SvPVX(targ));
176 SvPVX(targ) = SvPVX(dstr);
177 SvCUR_set(targ, SvCUR(dstr));
178 SvLEN_set(targ, SvLEN(dstr));
182 TAINT_IF(cx->sb_rxtainted & 1);
183 PUSHs(sv_2mortal(newSViv((I32)cx->sb_iters - 1)));
185 (void)SvPOK_only(targ);
186 TAINT_IF(cx->sb_rxtainted);
190 LEAVE_SCOPE(cx->sb_oldsave);
192 RETURNOP(pm->op_next);
195 if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
198 cx->sb_orig = orig = rx->subbeg;
200 cx->sb_strend = s + (cx->sb_strend - m);
202 cx->sb_m = m = rx->startp[0] + orig;
203 sv_catpvn(dstr, s, m-s);
204 cx->sb_s = rx->endp[0] + orig;
205 cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
206 rxres_save(&cx->sb_rxres, rx);
207 RETURNOP(pm->op_pmreplstart);
211 Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx)
216 if (!p || p[1] < rx->nparens) {
217 i = 6 + rx->nparens * 2;
225 *p++ = (UV)(RX_MATCH_COPIED(rx) ? rx->subbeg : Nullch);
226 RX_MATCH_COPIED_off(rx);
230 *p++ = (UV)rx->subbeg;
231 *p++ = (UV)rx->sublen;
232 for (i = 0; i <= rx->nparens; ++i) {
233 *p++ = (UV)rx->startp[i];
234 *p++ = (UV)rx->endp[i];
239 Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx)
244 if (RX_MATCH_COPIED(rx))
245 Safefree(rx->subbeg);
246 RX_MATCH_COPIED_set(rx, *p);
251 rx->subbeg = (char*)(*p++);
252 rx->sublen = (I32)(*p++);
253 for (i = 0; i <= rx->nparens; ++i) {
254 rx->startp[i] = (I32)(*p++);
255 rx->endp[i] = (I32)(*p++);
260 Perl_rxres_free(pTHX_ void **rsp)
265 Safefree((char*)(*p));
273 djSP; dMARK; dORIGMARK;
274 register SV *tmpForm = *++MARK;
286 bool chopspace = (strchr(PL_chopset, ' ') != Nullch);
292 STRLEN fudge = SvCUR(tmpForm) * (IN_UTF8 ? 3 : 1) + 1;
294 if (!SvMAGICAL(tmpForm) || !SvCOMPILED(tmpForm)) {
295 SvREADONLY_off(tmpForm);
296 doparseform(tmpForm);
299 SvPV_force(PL_formtarget, len);
300 t = SvGROW(PL_formtarget, len + fudge + 1); /* XXX SvCUR bad */
302 f = SvPV(tmpForm, len);
303 /* need to jump to the next word */
304 s = f + len + WORD_ALIGN - SvCUR(tmpForm) % WORD_ALIGN;
313 case FF_LITERAL: arg = fpc[1]; name = "LITERAL"; break;
314 case FF_BLANK: arg = fpc[1]; name = "BLANK"; break;
315 case FF_SKIP: arg = fpc[1]; name = "SKIP"; break;
316 case FF_FETCH: arg = fpc[1]; name = "FETCH"; break;
317 case FF_DECIMAL: arg = fpc[1]; name = "DECIMAL"; break;
319 case FF_CHECKNL: name = "CHECKNL"; break;
320 case FF_CHECKCHOP: name = "CHECKCHOP"; break;
321 case FF_SPACE: name = "SPACE"; break;
322 case FF_HALFSPACE: name = "HALFSPACE"; break;
323 case FF_ITEM: name = "ITEM"; break;
324 case FF_CHOP: name = "CHOP"; break;
325 case FF_LINEGLOB: name = "LINEGLOB"; break;
326 case FF_NEWLINE: name = "NEWLINE"; break;
327 case FF_MORE: name = "MORE"; break;
328 case FF_LINEMARK: name = "LINEMARK"; break;
329 case FF_END: name = "END"; break;
332 PerlIO_printf(PerlIO_stderr(), "%-16s%ld\n", name, (long) arg);
334 PerlIO_printf(PerlIO_stderr(), "%-16s\n", name);
362 if (ckWARN(WARN_SYNTAX))
363 Perl_warner(aTHX_ WARN_SYNTAX, "Not enough format arguments");
368 item = s = SvPV(sv, len);
371 itemsize = sv_len_utf8(sv);
372 if (itemsize != len) {
374 if (itemsize > fieldsize) {
375 itemsize = fieldsize;
376 itembytes = itemsize;
377 sv_pos_u2b(sv, &itembytes, 0);
381 send = chophere = s + itembytes;
390 sv_pos_b2u(sv, &itemsize);
394 if (itemsize > fieldsize)
395 itemsize = fieldsize;
396 send = chophere = s + itemsize;
408 item = s = SvPV(sv, len);
411 itemsize = sv_len_utf8(sv);
412 if (itemsize != len) {
414 if (itemsize <= fieldsize) {
415 send = chophere = s + itemsize;
426 itemsize = fieldsize;
427 itembytes = itemsize;
428 sv_pos_u2b(sv, &itembytes, 0);
429 send = chophere = s + itembytes;
430 while (s < send || (s == send && isSPACE(*s))) {
440 if (strchr(PL_chopset, *s))
445 itemsize = chophere - item;
446 sv_pos_b2u(sv, &itemsize);
451 if (itemsize <= fieldsize) {
452 send = chophere = s + itemsize;
463 itemsize = fieldsize;
464 send = chophere = s + itemsize;
465 while (s < send || (s == send && isSPACE(*s))) {
475 if (strchr(PL_chopset, *s))
480 itemsize = chophere - item;
485 arg = fieldsize - itemsize;
494 arg = fieldsize - itemsize;
509 switch (UTF8SKIP(s)) {
520 if ( !((*t++ = *s++) & ~31) )
528 int ch = *t++ = *s++;
531 if ( !((*t++ = *s++) & ~31) )
540 while (*s && isSPACE(*s))
547 item = s = SvPV(sv, len);
560 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
561 sv_catpvn(PL_formtarget, item, itemsize);
562 SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1);
563 t = SvPVX(PL_formtarget) + SvCUR(PL_formtarget);
568 /* If the field is marked with ^ and the value is undefined,
571 if ((arg & 512) && !SvOK(sv)) {
579 /* Formats aren't yet marked for locales, so assume "yes". */
581 RESTORE_NUMERIC_LOCAL();
582 #if defined(USE_LONG_DOUBLE)
584 sprintf(t, "%#*.*Lf",
585 (int) fieldsize, (int) arg & 255, value);
587 sprintf(t, "%*.0Lf", (int) fieldsize, value);
592 (int) fieldsize, (int) arg & 255, value);
595 (int) fieldsize, value);
598 RESTORE_NUMERIC_STANDARD();
605 while (t-- > linemark && *t == ' ') ;
613 if (arg) { /* repeat until fields exhausted? */
615 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
616 lines += FmLINES(PL_formtarget);
619 if (strnEQ(linemark, linemark - arg, arg))
620 DIE(aTHX_ "Runaway format");
622 FmLINES(PL_formtarget) = lines;
624 RETURNOP(cLISTOP->op_first);
637 while (*s && isSPACE(*s) && s < send)
641 arg = fieldsize - itemsize;
648 if (strnEQ(s," ",3)) {
649 while (s > SvPVX(PL_formtarget) && isSPACE(s[-1]))
660 SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget));
661 FmLINES(PL_formtarget) += lines;
673 if (PL_stack_base + *PL_markstack_ptr == SP) {
675 if (GIMME_V == G_SCALAR)
676 XPUSHs(sv_2mortal(newSViv(0)));
677 RETURNOP(PL_op->op_next->op_next);
679 PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
680 pp_pushmark(); /* push dst */
681 pp_pushmark(); /* push src */
682 ENTER; /* enter outer scope */
685 /* SAVE_DEFSV does *not* suffice here for USE_THREADS */
687 ENTER; /* enter inner scope */
690 src = PL_stack_base[*PL_markstack_ptr];
695 if (PL_op->op_type == OP_MAPSTART)
696 pp_pushmark(); /* push top */
697 return ((LOGOP*)PL_op->op_next)->op_other;
702 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
708 I32 diff = (SP - PL_stack_base) - *PL_markstack_ptr;
714 ++PL_markstack_ptr[-1];
716 if (diff > PL_markstack_ptr[-1] - PL_markstack_ptr[-2]) {
717 shift = diff - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]);
718 count = (SP - PL_stack_base) - PL_markstack_ptr[-1] + 2;
723 PL_markstack_ptr[-1] += shift;
724 *PL_markstack_ptr += shift;
728 dst = PL_stack_base + (PL_markstack_ptr[-2] += diff) - 1;
731 *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs);
733 LEAVE; /* exit inner scope */
736 if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
740 (void)POPMARK; /* pop top */
741 LEAVE; /* exit outer scope */
742 (void)POPMARK; /* pop src */
743 items = --*PL_markstack_ptr - PL_markstack_ptr[-1];
744 (void)POPMARK; /* pop dst */
745 SP = PL_stack_base + POPMARK; /* pop original mark */
746 if (gimme == G_SCALAR) {
750 else if (gimme == G_ARRAY)
757 ENTER; /* enter inner scope */
760 src = PL_stack_base[PL_markstack_ptr[-1]];
764 RETURNOP(cLOGOP->op_other);
770 djSP; dMARK; dORIGMARK;
772 SV **myorigmark = ORIGMARK;
778 OP* nextop = PL_op->op_next;
781 if (gimme != G_ARRAY) {
787 SAVEPPTR(PL_sortcop);
788 if (PL_op->op_flags & OPf_STACKED) {
789 if (PL_op->op_flags & OPf_SPECIAL) {
790 OP *kid = cLISTOP->op_first->op_sibling; /* pass pushmark */
791 kid = kUNOP->op_first; /* pass rv2gv */
792 kid = kUNOP->op_first; /* pass leave */
793 PL_sortcop = kid->op_next;
794 stash = PL_curcop->cop_stash;
797 cv = sv_2cv(*++MARK, &stash, &gv, 0);
798 if (!(cv && CvROOT(cv))) {
800 SV *tmpstr = sv_newmortal();
801 gv_efullname3(tmpstr, gv, Nullch);
802 if (cv && CvXSUB(cv))
803 DIE(aTHX_ "Xsub \"%s\" called in sort", SvPVX(tmpstr));
804 DIE(aTHX_ "Undefined sort subroutine \"%s\" called",
809 DIE(aTHX_ "Xsub called in sort");
810 DIE(aTHX_ "Undefined subroutine in sort");
812 DIE(aTHX_ "Not a CODE reference in sort");
814 PL_sortcop = CvSTART(cv);
815 SAVESPTR(CvROOT(cv)->op_ppaddr);
816 CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
819 PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
824 stash = PL_curcop->cop_stash;
828 while (MARK < SP) { /* This may or may not shift down one here. */
830 if (*up = *++MARK) { /* Weed out nulls. */
832 if (!PL_sortcop && !SvPOK(*up)) {
837 (void)sv_2pv(*up, &n_a);
842 max = --up - myorigmark;
847 bool oldcatch = CATCH_GET;
853 PUSHSTACKi(PERLSI_SORT);
854 if (PL_sortstash != stash) {
855 PL_firstgv = gv_fetchpv("a", TRUE, SVt_PV);
856 PL_secondgv = gv_fetchpv("b", TRUE, SVt_PV);
857 PL_sortstash = stash;
860 SAVESPTR(GvSV(PL_firstgv));
861 SAVESPTR(GvSV(PL_secondgv));
863 PUSHBLOCK(cx, CXt_NULL, PL_stack_base);
864 if (!(PL_op->op_flags & OPf_SPECIAL)) {
865 bool hasargs = FALSE;
866 cx->cx_type = CXt_SUB;
867 cx->blk_gimme = G_SCALAR;
870 (void)SvREFCNT_inc(cv); /* in preparation for POPSUB */
872 PL_sortcxix = cxstack_ix;
873 qsortsv((myorigmark+1), max, sortcv);
875 POPBLOCK(cx,PL_curpm);
883 MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */
884 qsortsv(ORIGMARK+1, max,
885 (PL_op->op_private & OPpSORT_NUMERIC)
886 ? ( (PL_op->op_private & OPpSORT_INTEGER)
887 ? ( overloading ? amagic_i_ncmp : sv_i_ncmp)
888 : ( overloading ? amagic_ncmp : sv_ncmp))
889 : ( (PL_op->op_private & OPpLOCALE)
892 : sv_cmp_locale_static)
893 : ( overloading ? amagic_cmp : sv_cmp_static)));
894 if (PL_op->op_private & OPpSORT_REVERSE) {
896 SV **q = ORIGMARK+max;
906 PL_stack_sp = ORIGMARK + max;
914 if (GIMME == G_ARRAY)
916 if (SvTRUEx(PAD_SV(PL_op->op_targ)))
917 return cLOGOP->op_other;
926 if (GIMME == G_ARRAY) {
927 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
931 SV *targ = PAD_SV(PL_op->op_targ);
933 if ((PL_op->op_private & OPpFLIP_LINENUM)
934 ? (PL_last_in_gv && SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv)))
936 sv_setiv(PAD_SV(cUNOP->op_first->op_targ), 1);
937 if (PL_op->op_flags & OPf_SPECIAL) {
945 RETURNOP(((LOGOP*)cUNOP->op_first)->op_other);
958 if (GIMME == G_ARRAY) {
964 if (SvGMAGICAL(left))
966 if (SvGMAGICAL(right))
969 if (SvNIOKp(left) || !SvPOKp(left) ||
970 (looks_like_number(left) && *SvPVX(left) != '0') )
972 if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
973 Perl_croak(aTHX_ "Range iterator outside integer range");
984 sv = sv_2mortal(newSViv(i++));
989 SV *final = sv_mortalcopy(right);
991 char *tmps = SvPV(final, len);
993 sv = sv_mortalcopy(left);
995 while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
997 if (strEQ(SvPVX(sv),tmps))
999 sv = sv_2mortal(newSVsv(sv));
1006 SV *targ = PAD_SV(cUNOP->op_first->op_targ);
1008 if ((PL_op->op_private & OPpFLIP_LINENUM)
1009 ? (PL_last_in_gv && SvIV(sv) == (IV)IoLINES(GvIOp(PL_last_in_gv)))
1011 sv_setiv(PAD_SV(((UNOP*)cUNOP->op_first)->op_first->op_targ), 0);
1012 sv_catpv(targ, "E0");
1023 S_dopoptolabel(pTHX_ char *label)
1027 register PERL_CONTEXT *cx;
1029 for (i = cxstack_ix; i >= 0; i--) {
1031 switch (CxTYPE(cx)) {
1033 if (ckWARN(WARN_UNSAFE))
1034 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting substitution via %s",
1035 PL_op_name[PL_op->op_type]);
1038 if (ckWARN(WARN_UNSAFE))
1039 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting subroutine via %s",
1040 PL_op_name[PL_op->op_type]);
1043 if (ckWARN(WARN_UNSAFE))
1044 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting eval via %s",
1045 PL_op_name[PL_op->op_type]);
1048 if (ckWARN(WARN_UNSAFE))
1049 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting pseudo-block via %s",
1050 PL_op_name[PL_op->op_type]);
1053 if (!cx->blk_loop.label ||
1054 strNE(label, cx->blk_loop.label) ) {
1055 DEBUG_l(Perl_deb(aTHX_ "(Skipping label #%ld %s)\n",
1056 (long)i, cx->blk_loop.label));
1059 DEBUG_l( Perl_deb(aTHX_ "(Found label #%ld %s)\n", (long)i, label));
1067 Perl_dowantarray(pTHX)
1069 I32 gimme = block_gimme();
1070 return (gimme == G_VOID) ? G_SCALAR : gimme;
1074 Perl_block_gimme(pTHX)
1079 cxix = dopoptosub(cxstack_ix);
1083 switch (cxstack[cxix].blk_gimme) {
1091 Perl_croak(aTHX_ "panic: bad gimme: %d\n", cxstack[cxix].blk_gimme);
1098 S_dopoptosub(pTHX_ I32 startingblock)
1101 return dopoptosub_at(cxstack, startingblock);
1105 S_dopoptosub_at(pTHX_ PERL_CONTEXT *cxstk, I32 startingblock)
1109 register PERL_CONTEXT *cx;
1110 for (i = startingblock; i >= 0; i--) {
1112 switch (CxTYPE(cx)) {
1117 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
1125 S_dopoptoeval(pTHX_ I32 startingblock)
1129 register PERL_CONTEXT *cx;
1130 for (i = startingblock; i >= 0; i--) {
1132 switch (CxTYPE(cx)) {
1136 DEBUG_l( Perl_deb(aTHX_ "(Found eval #%ld)\n", (long)i));
1144 S_dopoptoloop(pTHX_ I32 startingblock)
1148 register PERL_CONTEXT *cx;
1149 for (i = startingblock; i >= 0; i--) {
1151 switch (CxTYPE(cx)) {
1153 if (ckWARN(WARN_UNSAFE))
1154 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting substitution via %s",
1155 PL_op_name[PL_op->op_type]);
1158 if (ckWARN(WARN_UNSAFE))
1159 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting subroutine via %s",
1160 PL_op_name[PL_op->op_type]);
1163 if (ckWARN(WARN_UNSAFE))
1164 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting eval via %s",
1165 PL_op_name[PL_op->op_type]);
1168 if (ckWARN(WARN_UNSAFE))
1169 Perl_warner(aTHX_ WARN_UNSAFE, "Exiting pseudo-block via %s",
1170 PL_op_name[PL_op->op_type]);
1173 DEBUG_l( Perl_deb(aTHX_ "(Found loop #%ld)\n", (long)i));
1181 Perl_dounwind(pTHX_ I32 cxix)
1184 register PERL_CONTEXT *cx;
1188 while (cxstack_ix > cxix) {
1189 cx = &cxstack[cxstack_ix];
1190 DEBUG_l(PerlIO_printf(Perl_debug_log, "Unwinding block %ld, type %s\n",
1191 (long) cxstack_ix, PL_block_type[CxTYPE(cx)]));
1192 /* Note: we don't need to restore the base context info till the end. */
1193 switch (CxTYPE(cx)) {
1196 continue; /* not break */
1214 * Closures mentioned at top level of eval cannot be referenced
1215 * again, and their presence indirectly causes a memory leak.
1216 * (Note that the fact that compcv and friends are still set here
1217 * is, AFAIK, an accident.) --Chip
1219 * XXX need to get comppad et al from eval's cv rather than
1220 * relying on the incidental global values.
1223 S_free_closures(pTHX)
1226 SV **svp = AvARRAY(PL_comppad_name);
1228 for (ix = AvFILLp(PL_comppad_name); ix >= 0; ix--) {
1230 if (sv && sv != &PL_sv_undef && *SvPVX(sv) == '&') {
1232 svp[ix] = &PL_sv_undef;
1236 SvREFCNT_dec(CvOUTSIDE(sv));
1237 CvOUTSIDE(sv) = Nullcv;
1250 Perl_die_where(pTHX_ char *message, STRLEN msglen)
1256 register PERL_CONTEXT *cx;
1261 if (PL_in_eval & EVAL_KEEPERR) {
1264 svp = hv_fetch(ERRHV, message, msglen, TRUE);
1267 static char prefix[] = "\t(in cleanup) ";
1269 sv_upgrade(*svp, SVt_IV);
1270 (void)SvIOK_only(*svp);
1273 SvGROW(err, SvCUR(err)+sizeof(prefix)+msglen);
1274 sv_catpvn(err, prefix, sizeof(prefix)-1);
1275 sv_catpvn(err, message, msglen);
1276 if (ckWARN(WARN_UNSAFE)) {
1277 STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1;
1278 Perl_warner(aTHX_ WARN_UNSAFE, SvPVX(err)+start);
1285 sv_setpvn(ERRSV, message, msglen);
1288 message = SvPVx(ERRSV, msglen);
1290 while ((cxix = dopoptoeval(cxstack_ix)) < 0 && PL_curstackinfo->si_prev) {
1298 if (cxix < cxstack_ix)
1301 POPBLOCK(cx,PL_curpm);
1302 if (CxTYPE(cx) != CXt_EVAL) {
1303 PerlIO_write(PerlIO_stderr(), "panic: die ", 11);
1304 PerlIO_write(PerlIO_stderr(), message, msglen);
1309 if (gimme == G_SCALAR)
1310 *++newsp = &PL_sv_undef;
1311 PL_stack_sp = newsp;
1315 if (optype == OP_REQUIRE) {
1316 char* msg = SvPVx(ERRSV, n_a);
1317 DIE(aTHX_ "%s", *msg ? msg : "Compilation failed in require");
1319 return pop_return();
1323 message = SvPVx(ERRSV, msglen);
1326 /* SFIO can really mess with your errno */
1329 PerlIO_write(PerlIO_stderr(), message, msglen);
1330 (void)PerlIO_flush(PerlIO_stderr());
1343 if (SvTRUE(left) != SvTRUE(right))
1355 RETURNOP(cLOGOP->op_other);
1364 RETURNOP(cLOGOP->op_other);
1370 register I32 cxix = dopoptosub(cxstack_ix);
1371 register PERL_CONTEXT *cx;
1372 register PERL_CONTEXT *ccstack = cxstack;
1373 PERL_SI *top_si = PL_curstackinfo;
1384 /* we may be in a higher stacklevel, so dig down deeper */
1385 while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
1386 top_si = top_si->si_prev;
1387 ccstack = top_si->si_cxstack;
1388 cxix = dopoptosub_at(ccstack, top_si->si_cxix);
1391 if (GIMME != G_ARRAY)
1395 if (PL_DBsub && cxix >= 0 &&
1396 ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
1400 cxix = dopoptosub_at(ccstack, cxix - 1);
1403 cx = &ccstack[cxix];
1404 if (CxTYPE(cx) == CXt_SUB) {
1405 dbcxix = dopoptosub_at(ccstack, cxix - 1);
1406 /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
1407 field below is defined for any cx. */
1408 if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
1409 cx = &ccstack[dbcxix];
1412 if (GIMME != G_ARRAY) {
1413 hv = cx->blk_oldcop->cop_stash;
1415 PUSHs(&PL_sv_undef);
1418 sv_setpv(TARG, HvNAME(hv));
1424 hv = cx->blk_oldcop->cop_stash;
1426 PUSHs(&PL_sv_undef);
1428 PUSHs(sv_2mortal(newSVpv(HvNAME(hv), 0)));
1429 PUSHs(sv_2mortal(newSVpvn(SvPVX(GvSV(cx->blk_oldcop->cop_filegv)),
1430 SvCUR(GvSV(cx->blk_oldcop->cop_filegv)))));
1431 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->cop_line)));
1434 if (CxTYPE(cx) == CXt_SUB) { /* So is ccstack[dbcxix]. */
1436 gv_efullname3(sv, CvGV(ccstack[cxix].blk_sub.cv), Nullch);
1437 PUSHs(sv_2mortal(sv));
1438 PUSHs(sv_2mortal(newSViv((I32)cx->blk_sub.hasargs)));
1441 PUSHs(sv_2mortal(newSVpvn("(eval)",6)));
1442 PUSHs(sv_2mortal(newSViv(0)));
1444 gimme = (I32)cx->blk_gimme;
1445 if (gimme == G_VOID)
1446 PUSHs(&PL_sv_undef);
1448 PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
1449 if (CxTYPE(cx) == CXt_EVAL) {
1450 if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
1451 PUSHs(cx->blk_eval.cur_text);
1454 else if (cx->blk_eval.old_name) { /* Try blocks have old_name == 0. */
1455 /* Require, put the name. */
1456 PUSHs(sv_2mortal(newSVpv(cx->blk_eval.old_name, 0)));
1460 else if (CxTYPE(cx) == CXt_SUB &&
1461 cx->blk_sub.hasargs &&
1462 PL_curcop->cop_stash == PL_debstash)
1464 AV *ary = cx->blk_sub.argarray;
1465 int off = AvARRAY(ary) - AvALLOC(ary);
1469 PL_dbargs = GvAV(gv_AVadd(tmpgv = gv_fetchpv("DB::args", TRUE,
1472 AvREAL_off(PL_dbargs); /* XXX Should be REIFY */
1475 if (AvMAX(PL_dbargs) < AvFILLp(ary) + off)
1476 av_extend(PL_dbargs, AvFILLp(ary) + off);
1477 Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*);
1478 AvFILLp(PL_dbargs) = AvFILLp(ary) + off;
1480 /* XXX only hints propagated via op_private are currently
1481 * visible (others are not easily accessible, since they
1482 * use the global PL_hints) */
1483 PUSHs(sv_2mortal(newSViv((I32)cx->blk_oldcop->op_private &
1484 HINT_PRIVATE_MASK)));
1498 sv_reset(tmps, PL_curcop->cop_stash);
1510 PL_curcop = (COP*)PL_op;
1511 TAINT_NOT; /* Each statement is presumed innocent */
1512 PL_stack_sp = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1515 if (PL_op->op_private || SvIV(PL_DBsingle) || SvIV(PL_DBsignal) || SvIV(PL_DBtrace))
1519 register PERL_CONTEXT *cx;
1520 I32 gimme = G_ARRAY;
1527 DIE(aTHX_ "No DB::DB routine defined");
1529 if (CvDEPTH(cv) >= 1 && !(PL_debug & (1<<30))) /* don't do recursive DB::DB call */
1541 push_return(PL_op->op_next);
1542 PUSHBLOCK(cx, CXt_SUB, SP);
1545 (void)SvREFCNT_inc(cv);
1546 SAVESPTR(PL_curpad);
1547 PL_curpad = AvARRAY((AV*)*av_fetch(CvPADLIST(cv),1,FALSE));
1548 RETURNOP(CvSTART(cv));
1562 register PERL_CONTEXT *cx;
1563 I32 gimme = GIMME_V;
1570 if (PL_op->op_flags & OPf_SPECIAL) {
1572 svp = &THREADSV(PL_op->op_targ); /* per-thread variable */
1573 SAVEGENERICSV(*svp);
1577 #endif /* USE_THREADS */
1578 if (PL_op->op_targ) {
1579 svp = &PL_curpad[PL_op->op_targ]; /* "my" variable */
1583 svp = &GvSV((GV*)POPs); /* symbol table variable */
1584 SAVEGENERICSV(*svp);
1590 PUSHBLOCK(cx, CXt_LOOP, SP);
1591 PUSHLOOP(cx, svp, MARK);
1592 if (PL_op->op_flags & OPf_STACKED) {
1593 cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
1594 if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
1596 if (SvNIOKp(sv) || !SvPOKp(sv) ||
1597 (looks_like_number(sv) && *SvPVX(sv) != '0')) {
1598 if (SvNV(sv) < IV_MIN ||
1599 SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
1600 Perl_croak(aTHX_ "Range iterator outside integer range");
1601 cx->blk_loop.iterix = SvIV(sv);
1602 cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary);
1605 cx->blk_loop.iterlval = newSVsv(sv);
1609 cx->blk_loop.iterary = PL_curstack;
1610 AvFILLp(PL_curstack) = SP - PL_stack_base;
1611 cx->blk_loop.iterix = MARK - PL_stack_base;
1620 register PERL_CONTEXT *cx;
1621 I32 gimme = GIMME_V;
1627 PUSHBLOCK(cx, CXt_LOOP, SP);
1628 PUSHLOOP(cx, 0, SP);
1636 register PERL_CONTEXT *cx;
1637 struct block_loop cxloop;
1645 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1648 if (gimme == G_VOID)
1650 else if (gimme == G_SCALAR) {
1652 *++newsp = sv_mortalcopy(*SP);
1654 *++newsp = &PL_sv_undef;
1658 *++newsp = sv_mortalcopy(*++mark);
1659 TAINT_NOT; /* Each item is independent */
1665 POPLOOP2(); /* Stack values are safe: release loop vars ... */
1666 PL_curpm = newpm; /* ... and pop $1 et al */
1678 register PERL_CONTEXT *cx;
1679 struct block_sub cxsub;
1680 bool popsub2 = FALSE;
1686 if (PL_curstackinfo->si_type == PERLSI_SORT) {
1687 if (cxstack_ix == PL_sortcxix || dopoptosub(cxstack_ix) <= PL_sortcxix) {
1688 if (cxstack_ix > PL_sortcxix)
1689 dounwind(PL_sortcxix);
1690 AvARRAY(PL_curstack)[1] = *SP;
1691 PL_stack_sp = PL_stack_base + 1;
1696 cxix = dopoptosub(cxstack_ix);
1698 DIE(aTHX_ "Can't return outside a subroutine");
1699 if (cxix < cxstack_ix)
1703 switch (CxTYPE(cx)) {
1705 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1710 if (AvFILLp(PL_comppad_name) >= 0)
1713 if (optype == OP_REQUIRE &&
1714 (MARK == SP || (gimme == G_SCALAR && !SvTRUE(*SP))) )
1716 /* Unassume the success we assumed earlier. */
1717 char *name = cx->blk_eval.old_name;
1718 (void)hv_delete(GvHVn(PL_incgv), name, strlen(name), G_DISCARD);
1719 DIE(aTHX_ "%s did not return a true value", name);
1723 DIE(aTHX_ "panic: return");
1727 if (gimme == G_SCALAR) {
1730 if (cxsub.cv && CvDEPTH(cxsub.cv) > 1) {
1732 *++newsp = SvREFCNT_inc(*SP);
1737 *++newsp = sv_mortalcopy(*SP);
1740 *++newsp = (SvTEMP(*SP)) ? *SP : sv_mortalcopy(*SP);
1742 *++newsp = sv_mortalcopy(*SP);
1744 *++newsp = &PL_sv_undef;
1746 else if (gimme == G_ARRAY) {
1747 while (++MARK <= SP) {
1748 *++newsp = (popsub2 && SvTEMP(*MARK))
1749 ? *MARK : sv_mortalcopy(*MARK);
1750 TAINT_NOT; /* Each item is independent */
1753 PL_stack_sp = newsp;
1755 /* Stack values are safe: */
1757 POPSUB2(); /* release CV and @_ ... */
1759 PL_curpm = newpm; /* ... and pop $1 et al */
1762 return pop_return();
1769 register PERL_CONTEXT *cx;
1770 struct block_loop cxloop;
1771 struct block_sub cxsub;
1778 SV **mark = PL_stack_base + cxstack[cxstack_ix].blk_oldsp;
1780 if (PL_op->op_flags & OPf_SPECIAL) {
1781 cxix = dopoptoloop(cxstack_ix);
1783 DIE(aTHX_ "Can't \"last\" outside a block");
1786 cxix = dopoptolabel(cPVOP->op_pv);
1788 DIE(aTHX_ "Label not found for \"last %s\"", cPVOP->op_pv);
1790 if (cxix < cxstack_ix)
1794 switch (CxTYPE(cx)) {
1796 POPLOOP1(cx); /* Delay POPLOOP2 until stack values are safe */
1798 nextop = cxloop.last_op->op_next;
1801 POPSUB1(cx); /* Delay POPSUB2 until stack values are safe */
1803 nextop = pop_return();
1807 nextop = pop_return();
1810 DIE(aTHX_ "panic: last");
1814 if (gimme == G_SCALAR) {
1816 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*SP))
1817 ? *SP : sv_mortalcopy(*SP);
1819 *++newsp = &PL_sv_undef;
1821 else if (gimme == G_ARRAY) {
1822 while (++MARK <= SP) {
1823 *++newsp = ((pop2 == CXt_SUB) && SvTEMP(*MARK))
1824 ? *MARK : sv_mortalcopy(*MARK);
1825 TAINT_NOT; /* Each item is independent */
1831 /* Stack values are safe: */
1834 POPLOOP2(); /* release loop vars ... */
1838 POPSUB2(); /* release CV and @_ ... */
1841 PL_curpm = newpm; /* ... and pop $1 et al */
1850 register PERL_CONTEXT *cx;
1853 if (PL_op->op_flags & OPf_SPECIAL) {
1854 cxix = dopoptoloop(cxstack_ix);
1856 DIE(aTHX_ "Can't \"next\" outside a block");
1859 cxix = dopoptolabel(cPVOP->op_pv);
1861 DIE(aTHX_ "Label not found for \"next %s\"", cPVOP->op_pv);
1863 if (cxix < cxstack_ix)
1867 oldsave = PL_scopestack[PL_scopestack_ix - 1];
1868 LEAVE_SCOPE(oldsave);
1869 return cx->blk_loop.next_op;
1875 register PERL_CONTEXT *cx;
1878 if (PL_op->op_flags & OPf_SPECIAL) {
1879 cxix = dopoptoloop(cxstack_ix);
1881 DIE(aTHX_ "Can't \"redo\" outside a block");
1884 cxix = dopoptolabel(cPVOP->op_pv);
1886 DIE(aTHX_ "Label not found for \"redo %s\"", cPVOP->op_pv);
1888 if (cxix < cxstack_ix)
1892 oldsave = PL_scopestack[PL_scopestack_ix - 1];
1893 LEAVE_SCOPE(oldsave);
1894 return cx->blk_loop.redo_op;
1898 S_dofindlabel(pTHX_ OP *o, char *label, OP **opstack, OP **oplimit)
1902 static char too_deep[] = "Target of goto is too deeply nested";
1905 Perl_croak(aTHX_ too_deep);
1906 if (o->op_type == OP_LEAVE ||
1907 o->op_type == OP_SCOPE ||
1908 o->op_type == OP_LEAVELOOP ||
1909 o->op_type == OP_LEAVETRY)
1911 *ops++ = cUNOPo->op_first;
1913 Perl_croak(aTHX_ too_deep);
1916 if (o->op_flags & OPf_KIDS) {
1918 /* First try all the kids at this level, since that's likeliest. */
1919 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1920 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1921 kCOP->cop_label && strEQ(kCOP->cop_label, label))
1924 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) {
1925 if (kid == PL_lastgotoprobe)
1927 if ((kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) &&
1929 (ops[-1]->op_type != OP_NEXTSTATE &&
1930 ops[-1]->op_type != OP_DBSTATE)))
1932 if (o = dofindlabel(kid, label, ops, oplimit))
1951 register PERL_CONTEXT *cx;
1952 #define GOTO_DEPTH 64
1953 OP *enterops[GOTO_DEPTH];
1955 int do_dump = (PL_op->op_type == OP_DUMP);
1956 static char must_have_label[] = "goto must have label";
1959 if (PL_op->op_flags & OPf_STACKED) {
1963 /* This egregious kludge implements goto &subroutine */
1964 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
1966 register PERL_CONTEXT *cx;
1967 CV* cv = (CV*)SvRV(sv);
1971 int arg_was_real = 0;
1974 if (!CvROOT(cv) && !CvXSUB(cv)) {
1979 /* autoloaded stub? */
1980 if (cv != GvCV(gv) && (cv = GvCV(gv)))
1982 autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv),
1983 GvNAMELEN(gv), FALSE);
1984 if (autogv && (cv = GvCV(autogv)))
1986 tmpstr = sv_newmortal();
1987 gv_efullname3(tmpstr, gv, Nullch);
1988 DIE(aTHX_ "Goto undefined subroutine &%s",SvPVX(tmpstr));
1990 DIE(aTHX_ "Goto undefined subroutine");
1993 /* First do some returnish stuff. */
1994 cxix = dopoptosub(cxstack_ix);
1996 DIE(aTHX_ "Can't goto subroutine outside a subroutine");
1997 if (cxix < cxstack_ix)
2000 if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_ENTEREVAL)
2001 DIE(aTHX_ "Can't goto subroutine from an eval-string");
2003 if (CxTYPE(cx) == CXt_SUB &&
2004 cx->blk_sub.hasargs) { /* put @_ back onto stack */
2005 AV* av = cx->blk_sub.argarray;
2007 items = AvFILLp(av) + 1;
2009 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2010 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2011 PL_stack_sp += items;
2013 SvREFCNT_dec(GvAV(PL_defgv));
2014 GvAV(PL_defgv) = cx->blk_sub.savearray;
2015 #endif /* USE_THREADS */
2018 AvREAL_off(av); /* so av_clear() won't clobber elts */
2022 else if (CvXSUB(cv)) { /* put GvAV(defgv) back onto stack */
2026 av = (AV*)PL_curpad[0];
2028 av = GvAV(PL_defgv);
2030 items = AvFILLp(av) + 1;
2032 EXTEND(PL_stack_sp, items); /* @_ could have been extended. */
2033 Copy(AvARRAY(av), PL_stack_sp, items, SV*);
2034 PL_stack_sp += items;
2036 if (CxTYPE(cx) == CXt_SUB &&
2037 !(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth))
2038 SvREFCNT_dec(cx->blk_sub.cv);
2039 oldsave = PL_scopestack[PL_scopestack_ix - 1];
2040 LEAVE_SCOPE(oldsave);
2042 /* Now do some callish stuff. */
2045 #ifdef PERL_XSUB_OLDSTYLE
2046 if (CvOLDSTYLE(cv)) {
2047 I32 (*fp3)(int,int,int);
2052 fp3 = (I32(*)(int,int,int)))CvXSUB(cv;
2053 items = (*fp3)(CvXSUBANY(cv).any_i32,
2054 mark - PL_stack_base + 1,
2056 SP = PL_stack_base + items;
2059 #endif /* PERL_XSUB_OLDSTYLE */
2064 PL_stack_sp--; /* There is no cv arg. */
2065 /* Push a mark for the start of arglist */
2067 (void)(*CvXSUB(cv))(aTHXo_ cv);
2068 /* Pop the current context like a decent sub should */
2069 POPBLOCK(cx, PL_curpm);
2070 /* Do _not_ use PUTBACK, keep the XSUB's return stack! */
2073 return pop_return();
2076 AV* padlist = CvPADLIST(cv);
2077 SV** svp = AvARRAY(padlist);
2078 if (CxTYPE(cx) == CXt_EVAL) {
2079 PL_in_eval = cx->blk_eval.old_in_eval;
2080 PL_eval_root = cx->blk_eval.old_eval_root;
2081 cx->cx_type = CXt_SUB;
2082 cx->blk_sub.hasargs = 0;
2084 cx->blk_sub.cv = cv;
2085 cx->blk_sub.olddepth = CvDEPTH(cv);
2087 if (CvDEPTH(cv) < 2)
2088 (void)SvREFCNT_inc(cv);
2089 else { /* save temporaries on recursion? */
2090 if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
2091 sub_crush_depth(cv);
2092 if (CvDEPTH(cv) > AvFILLp(padlist)) {
2093 AV *newpad = newAV();
2094 SV **oldpad = AvARRAY(svp[CvDEPTH(cv)-1]);
2095 I32 ix = AvFILLp((AV*)svp[1]);
2096 svp = AvARRAY(svp[0]);
2097 for ( ;ix > 0; ix--) {
2098 if (svp[ix] != &PL_sv_undef) {
2099 char *name = SvPVX(svp[ix]);
2100 if ((SvFLAGS(svp[ix]) & SVf_FAKE)
2103 /* outer lexical or anon code */
2104 av_store(newpad, ix,
2105 SvREFCNT_inc(oldpad[ix]) );
2107 else { /* our own lexical */
2109 av_store(newpad, ix, sv = (SV*)newAV());
2110 else if (*name == '%')
2111 av_store(newpad, ix, sv = (SV*)newHV());
2113 av_store(newpad, ix, sv = NEWSV(0,0));
2118 av_store(newpad, ix, sv = NEWSV(0,0));
2122 if (cx->blk_sub.hasargs) {
2125 av_store(newpad, 0, (SV*)av);
2126 AvFLAGS(av) = AVf_REIFY;
2128 av_store(padlist, CvDEPTH(cv), (SV*)newpad);
2129 AvFILLp(padlist) = CvDEPTH(cv);
2130 svp = AvARRAY(padlist);
2134 if (!cx->blk_sub.hasargs) {
2135 AV* av = (AV*)PL_curpad[0];
2137 items = AvFILLp(av) + 1;
2139 /* Mark is at the end of the stack. */
2141 Copy(AvARRAY(av), SP + 1, items, SV*);
2146 #endif /* USE_THREADS */
2147 SAVESPTR(PL_curpad);
2148 PL_curpad = AvARRAY((AV*)svp[CvDEPTH(cv)]);
2150 if (cx->blk_sub.hasargs)
2151 #endif /* USE_THREADS */
2153 AV* av = (AV*)PL_curpad[0];
2157 cx->blk_sub.savearray = GvAV(PL_defgv);
2158 GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
2159 #endif /* USE_THREADS */
2160 cx->blk_sub.argarray = av;
2163 if (items >= AvMAX(av) + 1) {
2165 if (AvARRAY(av) != ary) {
2166 AvMAX(av) += AvARRAY(av) - AvALLOC(av);
2167 SvPVX(av) = (char*)ary;
2169 if (items >= AvMAX(av) + 1) {
2170 AvMAX(av) = items - 1;
2171 Renew(ary,items+1,SV*);
2173 SvPVX(av) = (char*)ary;
2176 Copy(mark,AvARRAY(av),items,SV*);
2177 AvFILLp(av) = items - 1;
2178 /* preserve @_ nature */
2189 if (PERLDB_SUB) { /* Checking curstash breaks DProf. */
2191 * We do not care about using sv to call CV;
2192 * it's for informational purposes only.
2194 SV *sv = GvSV(PL_DBsub);
2197 if (PERLDB_SUB_NN) {
2198 SvIVX(sv) = (IV)cv; /* Already upgraded, saved */
2201 gv_efullname3(sv, CvGV(cv), Nullch);
2204 && (gotocv = get_cv("DB::goto", FALSE)) ) {
2205 PUSHMARK( PL_stack_sp );
2206 call_sv((SV*)gotocv, G_SCALAR | G_NODEBUG);
2210 RETURNOP(CvSTART(cv));
2214 label = SvPV(sv,n_a);
2215 if (!(do_dump || *label))
2216 DIE(aTHX_ must_have_label);
2219 else if (PL_op->op_flags & OPf_SPECIAL) {
2221 DIE(aTHX_ must_have_label);
2224 label = cPVOP->op_pv;
2226 if (label && *label) {
2231 PL_lastgotoprobe = 0;
2233 for (ix = cxstack_ix; ix >= 0; ix--) {
2235 switch (CxTYPE(cx)) {
2237 gotoprobe = PL_eval_root; /* XXX not good for nested eval */
2240 gotoprobe = cx->blk_oldcop->op_sibling;
2246 gotoprobe = cx->blk_oldcop->op_sibling;
2248 gotoprobe = PL_main_root;
2251 if (CvDEPTH(cx->blk_sub.cv)) {
2252 gotoprobe = CvROOT(cx->blk_sub.cv);
2257 DIE(aTHX_ "Can't \"goto\" outside a block");
2260 DIE(aTHX_ "panic: goto");
2261 gotoprobe = PL_main_root;
2264 retop = dofindlabel(gotoprobe, label,
2265 enterops, enterops + GOTO_DEPTH);
2268 PL_lastgotoprobe = gotoprobe;
2271 DIE(aTHX_ "Can't find label %s", label);
2273 /* pop unwanted frames */
2275 if (ix < cxstack_ix) {
2282 oldsave = PL_scopestack[PL_scopestack_ix];
2283 LEAVE_SCOPE(oldsave);
2286 /* push wanted frames */
2288 if (*enterops && enterops[1]) {
2290 for (ix = 1; enterops[ix]; ix++) {
2291 PL_op = enterops[ix];
2292 /* Eventually we may want to stack the needed arguments
2293 * for each op. For now, we punt on the hard ones. */
2294 if (PL_op->op_type == OP_ENTERITER)
2295 DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop",
2297 (CALLOP->op_ppaddr)(aTHX);
2305 if (!retop) retop = PL_main_start;
2307 PL_restartop = retop;
2308 PL_do_undump = TRUE;
2312 PL_restartop = 0; /* hmm, must be GNU unexec().. */
2313 PL_do_undump = FALSE;
2329 if (anum == 1 && VMSISH_EXIT)
2334 PUSHs(&PL_sv_undef);
2342 NV value = SvNVx(GvSV(cCOP->cop_gv));
2343 register I32 match = I_32(value);
2346 if (((NV)match) > value)
2347 --match; /* was fractional--truncate other way */
2349 match -= cCOP->uop.scop.scop_offset;
2352 else if (match > cCOP->uop.scop.scop_max)
2353 match = cCOP->uop.scop.scop_max;
2354 PL_op = cCOP->uop.scop.scop_next[match];
2364 PL_op = PL_op->op_next; /* can't assume anything */
2367 match = *(SvPVx(GvSV(cCOP->cop_gv), n_a)) & 255;
2368 match -= cCOP->uop.scop.scop_offset;
2371 else if (match > cCOP->uop.scop.scop_max)
2372 match = cCOP->uop.scop.scop_max;
2373 PL_op = cCOP->uop.scop.scop_next[match];
2382 S_save_lines(pTHX_ AV *array, SV *sv)
2384 register char *s = SvPVX(sv);
2385 register char *send = SvPVX(sv) + SvCUR(sv);
2387 register I32 line = 1;
2389 while (s && s < send) {
2390 SV *tmpstr = NEWSV(85,0);
2392 sv_upgrade(tmpstr, SVt_PVMG);
2393 t = strchr(s, '\n');
2399 sv_setpvn(tmpstr, s, t - s);
2400 av_store(array, line++, tmpstr);
2406 S_docatch_body(pTHX_ va_list args)
2413 S_docatch(pTHX_ OP *o)
2420 assert(CATCH_GET == TRUE);
2424 CALLPROTECT(aTHX_ &ret, MEMBER_TO_FPTR(S_docatch_body));
2430 PL_op = PL_restartop;
2445 Perl_sv_compile_2op(pTHX_ SV *sv, OP** startop, char *code, AV** avp)
2446 /* sv Text to convert to OP tree. */
2447 /* startop op_free() this to undo. */
2448 /* code Short string id of the caller. */
2450 dSP; /* Make POPBLOCK work. */
2453 I32 gimme = 0; /* SUSPECT - INITIALZE TO WHAT? NI-S */
2456 OP *oop = PL_op, *rop;
2457 char tmpbuf[TYPE_DIGITS(long) + 12 + 10];
2463 /* switch to eval mode */
2465 if (PL_curcop == &PL_compiling) {
2466 SAVESPTR(PL_compiling.cop_stash);
2467 PL_compiling.cop_stash = PL_curstash;
2469 SAVESPTR(PL_compiling.cop_filegv);
2470 SAVEI16(PL_compiling.cop_line);
2471 sprintf(tmpbuf, "_<(%.10s_eval %lu)", code, (unsigned long)++PL_evalseq);
2472 PL_compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2473 PL_compiling.cop_line = 1;
2474 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2475 deleting the eval's FILEGV from the stash before gv_check() runs
2476 (i.e. before run-time proper). To work around the coredump that
2477 ensues, we always turn GvMULTI_on for any globals that were
2478 introduced within evals. See force_ident(). GSAR 96-10-12 */
2479 safestr = savepv(tmpbuf);
2480 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2482 #ifdef OP_IN_REGISTER
2490 PL_op->op_type = OP_ENTEREVAL;
2491 PL_op->op_flags = 0; /* Avoid uninit warning. */
2492 PUSHBLOCK(cx, CXt_EVAL, SP);
2493 PUSHEVAL(cx, 0, PL_compiling.cop_filegv);
2494 rop = doeval(G_SCALAR, startop);
2495 POPBLOCK(cx,PL_curpm);
2498 (*startop)->op_type = OP_NULL;
2499 (*startop)->op_ppaddr = PL_ppaddr[OP_NULL];
2501 *avp = (AV*)SvREFCNT_inc(PL_comppad);
2503 if (PL_curcop == &PL_compiling)
2504 PL_compiling.op_private = PL_hints;
2505 #ifdef OP_IN_REGISTER
2511 /* With USE_THREADS, eval_owner must be held on entry to doeval */
2513 S_doeval(pTHX_ int gimme, OP** startop)
2522 PL_in_eval = EVAL_INEVAL;
2526 /* set up a scratch pad */
2529 SAVESPTR(PL_curpad);
2530 SAVESPTR(PL_comppad);
2531 SAVESPTR(PL_comppad_name);
2532 SAVEI32(PL_comppad_name_fill);
2533 SAVEI32(PL_min_intro_pending);
2534 SAVEI32(PL_max_intro_pending);
2537 for (i = cxstack_ix - 1; i >= 0; i--) {
2538 PERL_CONTEXT *cx = &cxstack[i];
2539 if (CxTYPE(cx) == CXt_EVAL)
2541 else if (CxTYPE(cx) == CXt_SUB) {
2542 caller = cx->blk_sub.cv;
2547 SAVESPTR(PL_compcv);
2548 PL_compcv = (CV*)NEWSV(1104,0);
2549 sv_upgrade((SV *)PL_compcv, SVt_PVCV);
2550 CvEVAL_on(PL_compcv);
2552 CvOWNER(PL_compcv) = 0;
2553 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
2554 MUTEX_INIT(CvMUTEXP(PL_compcv));
2555 #endif /* USE_THREADS */
2557 PL_comppad = newAV();
2558 av_push(PL_comppad, Nullsv);
2559 PL_curpad = AvARRAY(PL_comppad);
2560 PL_comppad_name = newAV();
2561 PL_comppad_name_fill = 0;
2562 PL_min_intro_pending = 0;
2565 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
2566 PL_curpad[0] = (SV*)newAV();
2567 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
2568 #endif /* USE_THREADS */
2570 comppadlist = newAV();
2571 AvREAL_off(comppadlist);
2572 av_store(comppadlist, 0, (SV*)PL_comppad_name);
2573 av_store(comppadlist, 1, (SV*)PL_comppad);
2574 CvPADLIST(PL_compcv) = comppadlist;
2576 if (!saveop || saveop->op_type != OP_REQUIRE)
2577 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(caller);
2579 SAVEFREESV(PL_compcv);
2581 /* make sure we compile in the right package */
2583 newstash = PL_curcop->cop_stash;
2584 if (PL_curstash != newstash) {
2585 SAVESPTR(PL_curstash);
2586 PL_curstash = newstash;
2588 SAVESPTR(PL_beginav);
2589 PL_beginav = newAV();
2590 SAVEFREESV(PL_beginav);
2592 /* try to compile it */
2594 PL_eval_root = Nullop;
2596 PL_curcop = &PL_compiling;
2597 PL_curcop->cop_arybase = 0;
2598 SvREFCNT_dec(PL_rs);
2599 PL_rs = newSVpvn("\n", 1);
2600 if (saveop && saveop->op_flags & OPf_SPECIAL)
2601 PL_in_eval |= EVAL_KEEPERR;
2604 if (yyparse() || PL_error_count || !PL_eval_root) {
2608 I32 optype = 0; /* Might be reset by POPEVAL. */
2613 op_free(PL_eval_root);
2614 PL_eval_root = Nullop;
2616 SP = PL_stack_base + POPMARK; /* pop original mark */
2618 POPBLOCK(cx,PL_curpm);
2624 if (optype == OP_REQUIRE) {
2625 char* msg = SvPVx(ERRSV, n_a);
2626 DIE(aTHX_ "%s", *msg ? msg : "Compilation failed in require");
2627 } else if (startop) {
2628 char* msg = SvPVx(ERRSV, n_a);
2630 POPBLOCK(cx,PL_curpm);
2632 Perl_croak(aTHX_ "%sCompilation failed in regexp", (*msg ? msg : "Unknown error\n"));
2634 SvREFCNT_dec(PL_rs);
2635 PL_rs = SvREFCNT_inc(PL_nrs);
2637 MUTEX_LOCK(&PL_eval_mutex);
2639 COND_SIGNAL(&PL_eval_cond);
2640 MUTEX_UNLOCK(&PL_eval_mutex);
2641 #endif /* USE_THREADS */
2644 SvREFCNT_dec(PL_rs);
2645 PL_rs = SvREFCNT_inc(PL_nrs);
2646 PL_compiling.cop_line = 0;
2648 *startop = PL_eval_root;
2649 SvREFCNT_dec(CvOUTSIDE(PL_compcv));
2650 CvOUTSIDE(PL_compcv) = Nullcv;
2652 SAVEFREEOP(PL_eval_root);
2654 scalarvoid(PL_eval_root);
2655 else if (gimme & G_ARRAY)
2658 scalar(PL_eval_root);
2660 DEBUG_x(dump_eval());
2662 /* Register with debugger: */
2663 if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) {
2664 CV *cv = get_cv("DB::postponed", FALSE);
2668 XPUSHs((SV*)PL_compiling.cop_filegv);
2670 call_sv((SV*)cv, G_DISCARD);
2674 /* compiled okay, so do it */
2676 CvDEPTH(PL_compcv) = 1;
2677 SP = PL_stack_base + POPMARK; /* pop original mark */
2678 PL_op = saveop; /* The caller may need it. */
2680 MUTEX_LOCK(&PL_eval_mutex);
2682 COND_SIGNAL(&PL_eval_cond);
2683 MUTEX_UNLOCK(&PL_eval_mutex);
2684 #endif /* USE_THREADS */
2686 RETURNOP(PL_eval_start);
2690 S_doopen_pmc(pTHX_ const char *name, const char *mode)
2692 STRLEN namelen = strlen(name);
2695 if (namelen > 3 && strEQ(name + namelen - 3, ".pm")) {
2696 SV *pmcsv = Perl_newSVpvf(aTHX_ "%s%c", name, 'c');
2697 char *pmc = SvPV_nolen(pmcsv);
2700 if (PerlLIO_stat(pmc, &pmcstat) < 0) {
2701 fp = PerlIO_open(name, mode);
2704 if (PerlLIO_stat(name, &pmstat) < 0 ||
2705 pmstat.st_mtime < pmcstat.st_mtime)
2707 fp = PerlIO_open(pmc, mode);
2710 fp = PerlIO_open(name, mode);
2713 SvREFCNT_dec(pmcsv);
2716 fp = PerlIO_open(name, mode);
2724 register PERL_CONTEXT *cx;
2729 SV *namesv = Nullsv;
2731 I32 gimme = G_SCALAR;
2732 PerlIO *tryrsfp = 0;
2736 if (SvNIOKp(sv) && !SvPOKp(sv)) {
2737 if (Atof(PL_patchlevel) + 0.00000999 < SvNV(sv))
2738 DIE(aTHX_ "Perl %s required--this is only version %s, stopped",
2739 SvPV(sv,n_a),PL_patchlevel);
2742 name = SvPV(sv, len);
2743 if (!(name && len > 0 && *name))
2744 DIE(aTHX_ "Null filename used");
2745 TAINT_PROPER("require");
2746 if (PL_op->op_type == OP_REQUIRE &&
2747 (svp = hv_fetch(GvHVn(PL_incgv), name, len, 0)) &&
2748 *svp != &PL_sv_undef)
2751 /* prepare to compile file */
2756 (name[1] == '.' && name[2] == '/')))
2758 || (name[0] && name[1] == ':')
2761 || (name[0] == '\\' && name[1] == '\\') /* UNC path */
2764 || (strchr(name,':') || ((*name == '[' || *name == '<') &&
2765 (isALNUM(name[1]) || strchr("$-_]>",name[1]))))
2770 tryrsfp = doopen_pmc(name,PERL_SCRIPT_MODE);
2773 AV *ar = GvAVn(PL_incgv);
2777 if ((unixname = tounixspec(name, Nullch)) != Nullch)
2780 namesv = NEWSV(806, 0);
2781 for (i = 0; i <= AvFILL(ar); i++) {
2782 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
2785 if ((unixdir = tounixpath(dir, Nullch)) == Nullch)
2787 sv_setpv(namesv, unixdir);
2788 sv_catpv(namesv, unixname);
2790 Perl_sv_setpvf(aTHX_ namesv, "%s/%s", dir, name);
2792 TAINT_PROPER("require");
2793 tryname = SvPVX(namesv);
2794 tryrsfp = doopen_pmc(tryname, PERL_SCRIPT_MODE);
2796 if (tryname[0] == '.' && tryname[1] == '/')
2803 SAVESPTR(PL_compiling.cop_filegv);
2804 PL_compiling.cop_filegv = gv_fetchfile(tryrsfp ? tryname : name);
2805 SvREFCNT_dec(namesv);
2807 if (PL_op->op_type == OP_REQUIRE) {
2808 char *msgstr = name;
2809 if (namesv) { /* did we lookup @INC? */
2810 SV *msg = sv_2mortal(newSVpv(msgstr,0));
2811 SV *dirmsgsv = NEWSV(0, 0);
2812 AV *ar = GvAVn(PL_incgv);
2814 sv_catpvn(msg, " in @INC", 8);
2815 if (instr(SvPVX(msg), ".h "))
2816 sv_catpv(msg, " (change .h to .ph maybe?)");
2817 if (instr(SvPVX(msg), ".ph "))
2818 sv_catpv(msg, " (did you run h2ph?)");
2819 sv_catpv(msg, " (@INC contains:");
2820 for (i = 0; i <= AvFILL(ar); i++) {
2821 char *dir = SvPVx(*av_fetch(ar, i, TRUE), n_a);
2822 Perl_sv_setpvf(aTHX_ dirmsgsv, " %s", dir);
2823 sv_catsv(msg, dirmsgsv);
2825 sv_catpvn(msg, ")", 1);
2826 SvREFCNT_dec(dirmsgsv);
2827 msgstr = SvPV_nolen(msg);
2829 DIE(aTHX_ "Can't locate %s", msgstr);
2835 SETERRNO(0, SS$_NORMAL);
2837 /* Assume success here to prevent recursive requirement. */
2838 (void)hv_store(GvHVn(PL_incgv), name, strlen(name),
2839 newSVsv(GvSV(PL_compiling.cop_filegv)), 0 );
2843 lex_start(sv_2mortal(newSVpvn("",0)));
2844 SAVEGENERICSV(PL_rsfp_filters);
2845 PL_rsfp_filters = Nullav;
2848 name = savepv(name);
2852 SAVEPPTR(PL_compiling.cop_warnings);
2853 if (PL_dowarn & G_WARN_ALL_ON)
2854 PL_compiling.cop_warnings = WARN_ALL ;
2855 else if (PL_dowarn & G_WARN_ALL_OFF)
2856 PL_compiling.cop_warnings = WARN_NONE ;
2858 PL_compiling.cop_warnings = WARN_STD ;
2860 /* switch to eval mode */
2862 push_return(PL_op->op_next);
2863 PUSHBLOCK(cx, CXt_EVAL, SP);
2864 PUSHEVAL(cx, name, PL_compiling.cop_filegv);
2866 SAVEI16(PL_compiling.cop_line);
2867 PL_compiling.cop_line = 0;
2871 MUTEX_LOCK(&PL_eval_mutex);
2872 if (PL_eval_owner && PL_eval_owner != thr)
2873 while (PL_eval_owner)
2874 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
2875 PL_eval_owner = thr;
2876 MUTEX_UNLOCK(&PL_eval_mutex);
2877 #endif /* USE_THREADS */
2878 return DOCATCH(doeval(G_SCALAR, NULL));
2883 return pp_require();
2889 register PERL_CONTEXT *cx;
2891 I32 gimme = GIMME_V, was = PL_sub_generation;
2892 char tmpbuf[TYPE_DIGITS(long) + 12];
2897 if (!SvPV(sv,len) || !len)
2899 TAINT_PROPER("eval");
2905 /* switch to eval mode */
2907 SAVESPTR(PL_compiling.cop_filegv);
2908 sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
2909 PL_compiling.cop_filegv = gv_fetchfile(tmpbuf+2);
2910 PL_compiling.cop_line = 1;
2911 /* XXX For C<eval "...">s within BEGIN {} blocks, this ends up
2912 deleting the eval's FILEGV from the stash before gv_check() runs
2913 (i.e. before run-time proper). To work around the coredump that
2914 ensues, we always turn GvMULTI_on for any globals that were
2915 introduced within evals. See force_ident(). GSAR 96-10-12 */
2916 safestr = savepv(tmpbuf);
2917 SAVEDELETE(PL_defstash, safestr, strlen(safestr));
2919 PL_hints = PL_op->op_targ;
2920 SAVEPPTR(PL_compiling.cop_warnings);
2921 if (!specialWARN(PL_compiling.cop_warnings)) {
2922 PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
2923 SAVEFREESV(PL_compiling.cop_warnings) ;
2926 push_return(PL_op->op_next);
2927 PUSHBLOCK(cx, (CXt_EVAL|CXp_REAL), SP);
2928 PUSHEVAL(cx, 0, PL_compiling.cop_filegv);
2930 /* prepare to compile string */
2932 if (PERLDB_LINE && PL_curstash != PL_debstash)
2933 save_lines(GvAV(PL_compiling.cop_filegv), PL_linestr);
2936 MUTEX_LOCK(&PL_eval_mutex);
2937 if (PL_eval_owner && PL_eval_owner != thr)
2938 while (PL_eval_owner)
2939 COND_WAIT(&PL_eval_cond, &PL_eval_mutex);
2940 PL_eval_owner = thr;
2941 MUTEX_UNLOCK(&PL_eval_mutex);
2942 #endif /* USE_THREADS */
2943 ret = doeval(gimme, NULL);
2944 if (PERLDB_INTER && was != PL_sub_generation /* Some subs defined here. */
2945 && ret != PL_op->op_next) { /* Successive compilation. */
2946 strcpy(safestr, "_<(eval )"); /* Anything fake and short. */
2948 return DOCATCH(ret);
2958 register PERL_CONTEXT *cx;
2960 U8 save_flags = PL_op -> op_flags;
2965 retop = pop_return();
2968 if (gimme == G_VOID)
2970 else if (gimme == G_SCALAR) {
2973 if (SvFLAGS(TOPs) & SVs_TEMP)
2976 *MARK = sv_mortalcopy(TOPs);
2980 *MARK = &PL_sv_undef;
2984 /* in case LEAVE wipes old return values */
2985 for (mark = newsp + 1; mark <= SP; mark++) {
2986 if (!(SvFLAGS(*mark) & SVs_TEMP)) {
2987 *mark = sv_mortalcopy(*mark);
2988 TAINT_NOT; /* Each item is independent */
2992 PL_curpm = newpm; /* Don't pop $1 et al till now */
2994 if (AvFILLp(PL_comppad_name) >= 0)
2998 assert(CvDEPTH(PL_compcv) == 1);
3000 CvDEPTH(PL_compcv) = 0;
3003 if (optype == OP_REQUIRE &&
3004 !(gimme == G_SCALAR ? SvTRUE(*SP) : SP > newsp))
3006 /* Unassume the success we assumed earlier. */
3007 char *name = cx->blk_eval.old_name;
3008 (void)hv_delete(GvHVn(PL_incgv), name, strlen(name), G_DISCARD);
3009 retop = Perl_die(aTHX_ "%s did not return a true value", name);
3010 /* die_where() did LEAVE, or we won't be here */
3014 if (!(save_flags & OPf_SPECIAL))
3024 register PERL_CONTEXT *cx;
3025 I32 gimme = GIMME_V;
3030 push_return(cLOGOP->op_other->op_next);
3031 PUSHBLOCK(cx, CXt_EVAL, SP);
3033 PL_eval_root = PL_op; /* Only needed so that goto works right. */
3035 PL_in_eval = EVAL_INEVAL;
3038 return DOCATCH(PL_op->op_next);
3048 register PERL_CONTEXT *cx;
3056 if (gimme == G_VOID)
3058 else if (gimme == G_SCALAR) {
3061 if (SvFLAGS(TOPs) & (SVs_PADTMP|SVs_TEMP))
3064 *MARK = sv_mortalcopy(TOPs);
3068 *MARK = &PL_sv_undef;
3073 /* in case LEAVE wipes old return values */
3074 for (mark = newsp + 1; mark <= SP; mark++) {
3075 if (!(SvFLAGS(*mark) & (SVs_PADTMP|SVs_TEMP))) {
3076 *mark = sv_mortalcopy(*mark);
3077 TAINT_NOT; /* Each item is independent */
3081 PL_curpm = newpm; /* Don't pop $1 et al till now */
3089 S_doparseform(pTHX_ SV *sv)
3092 register char *s = SvPV_force(sv, len);
3093 register char *send = s + len;
3094 register char *base;
3095 register I32 skipspaces = 0;
3098 bool postspace = FALSE;
3106 Perl_croak(aTHX_ "Null picture in formline");
3108 New(804, fops, (send - s)*3+10, U16); /* Almost certainly too long... */
3113 *fpc++ = FF_LINEMARK;
3114 noblank = repeat = FALSE;
3132 case ' ': case '\t':
3143 *fpc++ = FF_LITERAL;
3151 *fpc++ = skipspaces;
3155 *fpc++ = FF_NEWLINE;
3159 arg = fpc - linepc + 1;
3166 *fpc++ = FF_LINEMARK;
3167 noblank = repeat = FALSE;
3176 ischop = s[-1] == '^';
3182 arg = (s - base) - 1;
3184 *fpc++ = FF_LITERAL;
3193 *fpc++ = FF_LINEGLOB;
3195 else if (*s == '#' || (*s == '.' && s[1] == '#')) {
3196 arg = ischop ? 512 : 0;
3206 arg |= 256 + (s - f);
3208 *fpc++ = s - base; /* fieldsize for FETCH */
3209 *fpc++ = FF_DECIMAL;
3214 bool ismore = FALSE;
3217 while (*++s == '>') ;
3218 prespace = FF_SPACE;
3220 else if (*s == '|') {
3221 while (*++s == '|') ;
3222 prespace = FF_HALFSPACE;
3227 while (*++s == '<') ;
3230 if (*s == '.' && s[1] == '.' && s[2] == '.') {
3234 *fpc++ = s - base; /* fieldsize for FETCH */
3236 *fpc++ = ischop ? FF_CHECKCHOP : FF_CHECKNL;
3254 { /* need to jump to the next word */
3256 z = WORD_ALIGN - SvCUR(sv) % WORD_ALIGN;
3257 SvGROW(sv, SvCUR(sv) + z + arg * sizeof(U16) + 4);
3258 s = SvPVX(sv) + SvCUR(sv) + z;
3260 Copy(fops, s, arg, U16);
3262 sv_magic(sv, Nullsv, 'f', Nullch, 0);
3267 * The rest of this file was derived from source code contributed
3270 * NOTE: this code was derived from Tom Horsley's qsort replacement
3271 * and should not be confused with the original code.
3274 /* Copyright (C) Tom Horsley, 1997. All rights reserved.
3276 Permission granted to distribute under the same terms as perl which are
3279 This program is free software; you can redistribute it and/or modify
3280 it under the terms of either:
3282 a) the GNU General Public License as published by the Free
3283 Software Foundation; either version 1, or (at your option) any
3286 b) the "Artistic License" which comes with this Kit.
3288 Details on the perl license can be found in the perl source code which
3289 may be located via the www.perl.com web page.
3291 This is the most wonderfulest possible qsort I can come up with (and
3292 still be mostly portable) My (limited) tests indicate it consistently
3293 does about 20% fewer calls to compare than does the qsort in the Visual
3294 C++ library, other vendors may vary.
3296 Some of the ideas in here can be found in "Algorithms" by Sedgewick,
3297 others I invented myself (or more likely re-invented since they seemed
3298 pretty obvious once I watched the algorithm operate for a while).
3300 Most of this code was written while watching the Marlins sweep the Giants
3301 in the 1997 National League Playoffs - no Braves fans allowed to use this
3302 code (just kidding :-).
3304 I realize that if I wanted to be true to the perl tradition, the only
3305 comment in this file would be something like:
3307 ...they shuffled back towards the rear of the line. 'No, not at the
3308 rear!' the slave-driver shouted. 'Three files up. And stay there...
3310 However, I really needed to violate that tradition just so I could keep
3311 track of what happens myself, not to mention some poor fool trying to
3312 understand this years from now :-).
3315 /* ********************************************************** Configuration */
3317 #ifndef QSORT_ORDER_GUESS
3318 #define QSORT_ORDER_GUESS 2 /* Select doubling version of the netBSD trick */
3321 /* QSORT_MAX_STACK is the largest number of partitions that can be stacked up for
3322 future processing - a good max upper bound is log base 2 of memory size
3323 (32 on 32 bit machines, 64 on 64 bit machines, etc). In reality can
3324 safely be smaller than that since the program is taking up some space and
3325 most operating systems only let you grab some subset of contiguous
3326 memory (not to mention that you are normally sorting data larger than
3327 1 byte element size :-).
3329 #ifndef QSORT_MAX_STACK
3330 #define QSORT_MAX_STACK 32
3333 /* QSORT_BREAK_EVEN is the size of the largest partition we should insertion sort.
3334 Anything bigger and we use qsort. If you make this too small, the qsort
3335 will probably break (or become less efficient), because it doesn't expect
3336 the middle element of a partition to be the same as the right or left -
3337 you have been warned).
3339 #ifndef QSORT_BREAK_EVEN
3340 #define QSORT_BREAK_EVEN 6
3343 /* ************************************************************* Data Types */
3345 /* hold left and right index values of a partition waiting to be sorted (the
3346 partition includes both left and right - right is NOT one past the end or
3347 anything like that).
3349 struct partition_stack_entry {
3352 #ifdef QSORT_ORDER_GUESS
3353 int qsort_break_even;
3357 /* ******************************************************* Shorthand Macros */
3359 /* Note that these macros will be used from inside the qsort function where
3360 we happen to know that the variable 'elt_size' contains the size of an
3361 array element and the variable 'temp' points to enough space to hold a
3362 temp element and the variable 'array' points to the array being sorted
3363 and 'compare' is the pointer to the compare routine.
3365 Also note that there are very many highly architecture specific ways
3366 these might be sped up, but this is simply the most generally portable
3367 code I could think of.
3370 /* Return < 0 == 0 or > 0 as the value of elt1 is < elt2, == elt2, > elt2
3372 #define qsort_cmp(elt1, elt2) \
3373 ((*compare)(aTHXo_ array[elt1], array[elt2]))
3375 #ifdef QSORT_ORDER_GUESS
3376 #define QSORT_NOTICE_SWAP swapped++;
3378 #define QSORT_NOTICE_SWAP
3381 /* swaps contents of array elements elt1, elt2.
3383 #define qsort_swap(elt1, elt2) \
3386 temp = array[elt1]; \
3387 array[elt1] = array[elt2]; \
3388 array[elt2] = temp; \
3391 /* rotate contents of elt1, elt2, elt3 such that elt1 gets elt2, elt2 gets
3392 elt3 and elt3 gets elt1.
3394 #define qsort_rotate(elt1, elt2, elt3) \
3397 temp = array[elt1]; \
3398 array[elt1] = array[elt2]; \
3399 array[elt2] = array[elt3]; \
3400 array[elt3] = temp; \
3403 /* ************************************************************ Debug stuff */
3410 return; /* good place to set a breakpoint */
3413 #define qsort_assert(t) (void)( (t) || (break_here(), 0) )
3416 doqsort_all_asserts(
3420 int (*compare)(const void * elt1, const void * elt2),
3421 int pc_left, int pc_right, int u_left, int u_right)
3425 qsort_assert(pc_left <= pc_right);
3426 qsort_assert(u_right < pc_left);
3427 qsort_assert(pc_right < u_left);
3428 for (i = u_right + 1; i < pc_left; ++i) {
3429 qsort_assert(qsort_cmp(i, pc_left) < 0);
3431 for (i = pc_left; i < pc_right; ++i) {
3432 qsort_assert(qsort_cmp(i, pc_right) == 0);
3434 for (i = pc_right + 1; i < u_left; ++i) {
3435 qsort_assert(qsort_cmp(pc_right, i) < 0);
3439 #define qsort_all_asserts(PC_LEFT, PC_RIGHT, U_LEFT, U_RIGHT) \
3440 doqsort_all_asserts(array, num_elts, elt_size, compare, \
3441 PC_LEFT, PC_RIGHT, U_LEFT, U_RIGHT)
3445 #define qsort_assert(t) ((void)0)
3447 #define qsort_all_asserts(PC_LEFT, PC_RIGHT, U_LEFT, U_RIGHT) ((void)0)
3451 /* ****************************************************************** qsort */
3454 S_qsortsv(pTHX_ SV ** array, size_t num_elts, SVCOMPARE_t compare)
3458 struct partition_stack_entry partition_stack[QSORT_MAX_STACK];
3459 int next_stack_entry = 0;
3463 #ifdef QSORT_ORDER_GUESS
3464 int qsort_break_even;
3468 /* Make sure we actually have work to do.
3470 if (num_elts <= 1) {
3474 /* Setup the initial partition definition and fall into the sorting loop
3477 part_right = (int)(num_elts - 1);
3478 #ifdef QSORT_ORDER_GUESS
3479 qsort_break_even = QSORT_BREAK_EVEN;
3481 #define qsort_break_even QSORT_BREAK_EVEN
3484 if ((part_right - part_left) >= qsort_break_even) {
3485 /* OK, this is gonna get hairy, so lets try to document all the
3486 concepts and abbreviations and variables and what they keep
3489 pc: pivot chunk - the set of array elements we accumulate in the
3490 middle of the partition, all equal in value to the original
3491 pivot element selected. The pc is defined by:
3493 pc_left - the leftmost array index of the pc
3494 pc_right - the rightmost array index of the pc
3496 we start with pc_left == pc_right and only one element
3497 in the pivot chunk (but it can grow during the scan).
3499 u: uncompared elements - the set of elements in the partition
3500 we have not yet compared to the pivot value. There are two
3501 uncompared sets during the scan - one to the left of the pc
3502 and one to the right.
3504 u_right - the rightmost index of the left side's uncompared set
3505 u_left - the leftmost index of the right side's uncompared set
3507 The leftmost index of the left sides's uncompared set
3508 doesn't need its own variable because it is always defined
3509 by the leftmost edge of the whole partition (part_left). The
3510 same goes for the rightmost edge of the right partition
3513 We know there are no uncompared elements on the left once we
3514 get u_right < part_left and no uncompared elements on the
3515 right once u_left > part_right. When both these conditions
3516 are met, we have completed the scan of the partition.
3518 Any elements which are between the pivot chunk and the
3519 uncompared elements should be less than the pivot value on
3520 the left side and greater than the pivot value on the right
3521 side (in fact, the goal of the whole algorithm is to arrange
3522 for that to be true and make the groups of less-than and
3523 greater-then elements into new partitions to sort again).
3525 As you marvel at the complexity of the code and wonder why it
3526 has to be so confusing. Consider some of the things this level
3527 of confusion brings:
3529 Once I do a compare, I squeeze every ounce of juice out of it. I
3530 never do compare calls I don't have to do, and I certainly never
3533 I also never swap any elements unless I can prove there is a
3534 good reason. Many sort algorithms will swap a known value with
3535 an uncompared value just to get things in the right place (or
3536 avoid complexity :-), but that uncompared value, once it gets
3537 compared, may then have to be swapped again. A lot of the
3538 complexity of this code is due to the fact that it never swaps
3539 anything except compared values, and it only swaps them when the
3540 compare shows they are out of position.
3542 int pc_left, pc_right;
3543 int u_right, u_left;
3547 pc_left = ((part_left + part_right) / 2);
3549 u_right = pc_left - 1;
3550 u_left = pc_right + 1;
3552 /* Qsort works best when the pivot value is also the median value
3553 in the partition (unfortunately you can't find the median value
3554 without first sorting :-), so to give the algorithm a helping
3555 hand, we pick 3 elements and sort them and use the median value
3556 of that tiny set as the pivot value.
3558 Some versions of qsort like to use the left middle and right as
3559 the 3 elements to sort so they can insure the ends of the
3560 partition will contain values which will stop the scan in the
3561 compare loop, but when you have to call an arbitrarily complex
3562 routine to do a compare, its really better to just keep track of
3563 array index values to know when you hit the edge of the
3564 partition and avoid the extra compare. An even better reason to
3565 avoid using a compare call is the fact that you can drop off the
3566 edge of the array if someone foolishly provides you with an
3567 unstable compare function that doesn't always provide consistent
3570 So, since it is simpler for us to compare the three adjacent
3571 elements in the middle of the partition, those are the ones we
3572 pick here (conveniently pointed at by u_right, pc_left, and
3573 u_left). The values of the left, center, and right elements
3574 are refered to as l c and r in the following comments.
3577 #ifdef QSORT_ORDER_GUESS
3580 s = qsort_cmp(u_right, pc_left);
3583 s = qsort_cmp(pc_left, u_left);
3584 /* if l < c, c < r - already in order - nothing to do */
3586 /* l < c, c == r - already in order, pc grows */
3588 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3590 /* l < c, c > r - need to know more */
3591 s = qsort_cmp(u_right, u_left);
3593 /* l < c, c > r, l < r - swap c & r to get ordered */
3594 qsort_swap(pc_left, u_left);
3595 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3596 } else if (s == 0) {
3597 /* l < c, c > r, l == r - swap c&r, grow pc */
3598 qsort_swap(pc_left, u_left);
3600 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3602 /* l < c, c > r, l > r - make lcr into rlc to get ordered */
3603 qsort_rotate(pc_left, u_right, u_left);
3604 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3607 } else if (s == 0) {
3609 s = qsort_cmp(pc_left, u_left);
3611 /* l == c, c < r - already in order, grow pc */
3613 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3614 } else if (s == 0) {
3615 /* l == c, c == r - already in order, grow pc both ways */
3618 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3620 /* l == c, c > r - swap l & r, grow pc */
3621 qsort_swap(u_right, u_left);
3623 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3627 s = qsort_cmp(pc_left, u_left);
3629 /* l > c, c < r - need to know more */
3630 s = qsort_cmp(u_right, u_left);
3632 /* l > c, c < r, l < r - swap l & c to get ordered */
3633 qsort_swap(u_right, pc_left);
3634 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3635 } else if (s == 0) {
3636 /* l > c, c < r, l == r - swap l & c, grow pc */
3637 qsort_swap(u_right, pc_left);
3639 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3641 /* l > c, c < r, l > r - rotate lcr into crl to order */
3642 qsort_rotate(u_right, pc_left, u_left);
3643 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3645 } else if (s == 0) {
3646 /* l > c, c == r - swap ends, grow pc */
3647 qsort_swap(u_right, u_left);
3649 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3651 /* l > c, c > r - swap ends to get in order */
3652 qsort_swap(u_right, u_left);
3653 qsort_all_asserts(pc_left, pc_right, u_left + 1, u_right - 1);
3656 /* We now know the 3 middle elements have been compared and
3657 arranged in the desired order, so we can shrink the uncompared
3662 qsort_all_asserts(pc_left, pc_right, u_left, u_right);
3664 /* The above massive nested if was the simple part :-). We now have
3665 the middle 3 elements ordered and we need to scan through the
3666 uncompared sets on either side, swapping elements that are on
3667 the wrong side or simply shuffling equal elements around to get
3668 all equal elements into the pivot chunk.
3672 int still_work_on_left;
3673 int still_work_on_right;
3675 /* Scan the uncompared values on the left. If I find a value
3676 equal to the pivot value, move it over so it is adjacent to
3677 the pivot chunk and expand the pivot chunk. If I find a value
3678 less than the pivot value, then just leave it - its already
3679 on the correct side of the partition. If I find a greater
3680 value, then stop the scan.
3682 while (still_work_on_left = (u_right >= part_left)) {
3683 s = qsort_cmp(u_right, pc_left);
3686 } else if (s == 0) {
3688 if (pc_left != u_right) {
3689 qsort_swap(u_right, pc_left);
3695 qsort_assert(u_right < pc_left);
3696 qsort_assert(pc_left <= pc_right);
3697 qsort_assert(qsort_cmp(u_right + 1, pc_left) <= 0);
3698 qsort_assert(qsort_cmp(pc_left, pc_right) == 0);
3701 /* Do a mirror image scan of uncompared values on the right
3703 while (still_work_on_right = (u_left <= part_right)) {
3704 s = qsort_cmp(pc_right, u_left);
3707 } else if (s == 0) {
3709 if (pc_right != u_left) {
3710 qsort_swap(pc_right, u_left);
3716 qsort_assert(u_left > pc_right);
3717 qsort_assert(pc_left <= pc_right);
3718 qsort_assert(qsort_cmp(pc_right, u_left - 1) <= 0);
3719 qsort_assert(qsort_cmp(pc_left, pc_right) == 0);
3722 if (still_work_on_left) {
3723 /* I know I have a value on the left side which needs to be
3724 on the right side, but I need to know more to decide
3725 exactly the best thing to do with it.
3727 if (still_work_on_right) {
3728 /* I know I have values on both side which are out of
3729 position. This is a big win because I kill two birds
3730 with one swap (so to speak). I can advance the
3731 uncompared pointers on both sides after swapping both
3732 of them into the right place.
3734 qsort_swap(u_right, u_left);
3737 qsort_all_asserts(pc_left, pc_right, u_left, u_right);
3739 /* I have an out of position value on the left, but the
3740 right is fully scanned, so I "slide" the pivot chunk
3741 and any less-than values left one to make room for the
3742 greater value over on the right. If the out of position
3743 value is immediately adjacent to the pivot chunk (there
3744 are no less-than values), I can do that with a swap,
3745 otherwise, I have to rotate one of the less than values
3746 into the former position of the out of position value
3747 and the right end of the pivot chunk into the left end
3751 if (pc_left == u_right) {
3752 qsort_swap(u_right, pc_right);
3753 qsort_all_asserts(pc_left, pc_right-1, u_left, u_right-1);
3755 qsort_rotate(u_right, pc_left, pc_right);
3756 qsort_all_asserts(pc_left, pc_right-1, u_left, u_right-1);
3761 } else if (still_work_on_right) {
3762 /* Mirror image of complex case above: I have an out of
3763 position value on the right, but the left is fully
3764 scanned, so I need to shuffle things around to make room
3765 for the right value on the left.
3768 if (pc_right == u_left) {
3769 qsort_swap(u_left, pc_left);
3770 qsort_all_asserts(pc_left+1, pc_right, u_left+1, u_right);
3772 qsort_rotate(pc_right, pc_left, u_left);
3773 qsort_all_asserts(pc_left+1, pc_right, u_left+1, u_right);
3778 /* No more scanning required on either side of partition,
3779 break out of loop and figure out next set of partitions
3785 /* The elements in the pivot chunk are now in the right place. They
3786 will never move or be compared again. All I have to do is decide
3787 what to do with the stuff to the left and right of the pivot
3790 Notes on the QSORT_ORDER_GUESS ifdef code:
3792 1. If I just built these partitions without swapping any (or
3793 very many) elements, there is a chance that the elements are
3794 already ordered properly (being properly ordered will
3795 certainly result in no swapping, but the converse can't be
3798 2. A (properly written) insertion sort will run faster on
3799 already ordered data than qsort will.
3801 3. Perhaps there is some way to make a good guess about
3802 switching to an insertion sort earlier than partition size 6
3803 (for instance - we could save the partition size on the stack
3804 and increase the size each time we find we didn't swap, thus
3805 switching to insertion sort earlier for partitions with a
3806 history of not swapping).
3808 4. Naturally, if I just switch right away, it will make
3809 artificial benchmarks with pure ascending (or descending)
3810 data look really good, but is that a good reason in general?
3814 #ifdef QSORT_ORDER_GUESS
3816 #if QSORT_ORDER_GUESS == 1
3817 qsort_break_even = (part_right - part_left) + 1;
3819 #if QSORT_ORDER_GUESS == 2
3820 qsort_break_even *= 2;
3822 #if QSORT_ORDER_GUESS == 3
3823 int prev_break = qsort_break_even;
3824 qsort_break_even *= qsort_break_even;
3825 if (qsort_break_even < prev_break) {
3826 qsort_break_even = (part_right - part_left) + 1;
3830 qsort_break_even = QSORT_BREAK_EVEN;
3834 if (part_left < pc_left) {
3835 /* There are elements on the left which need more processing.
3836 Check the right as well before deciding what to do.
3838 if (pc_right < part_right) {
3839 /* We have two partitions to be sorted. Stack the biggest one
3840 and process the smallest one on the next iteration. This
3841 minimizes the stack height by insuring that any additional
3842 stack entries must come from the smallest partition which
3843 (because it is smallest) will have the fewest
3844 opportunities to generate additional stack entries.
3846 if ((part_right - pc_right) > (pc_left - part_left)) {
3847 /* stack the right partition, process the left */
3848 partition_stack[next_stack_entry].left = pc_right + 1;
3849 partition_stack[next_stack_entry].right = part_right;
3850 #ifdef QSORT_ORDER_GUESS
3851 partition_stack[next_stack_entry].qsort_break_even = qsort_break_even;
3853 part_right = pc_left - 1;
3855 /* stack the left partition, process the right */
3856 partition_stack[next_stack_entry].left = part_left;
3857 partition_stack[next_stack_entry].right = pc_left - 1;
3858 #ifdef QSORT_ORDER_GUESS
3859 partition_stack[next_stack_entry].qsort_break_even = qsort_break_even;
3861 part_left = pc_right + 1;
3863 qsort_assert(next_stack_entry < QSORT_MAX_STACK);
3866 /* The elements on the left are the only remaining elements
3867 that need sorting, arrange for them to be processed as the
3870 part_right = pc_left - 1;
3872 } else if (pc_right < part_right) {
3873 /* There is only one chunk on the right to be sorted, make it
3874 the new partition and loop back around.
3876 part_left = pc_right + 1;
3878 /* This whole partition wound up in the pivot chunk, so
3879 we need to get a new partition off the stack.
3881 if (next_stack_entry == 0) {
3882 /* the stack is empty - we are done */
3886 part_left = partition_stack[next_stack_entry].left;
3887 part_right = partition_stack[next_stack_entry].right;
3888 #ifdef QSORT_ORDER_GUESS
3889 qsort_break_even = partition_stack[next_stack_entry].qsort_break_even;
3893 /* This partition is too small to fool with qsort complexity, just
3894 do an ordinary insertion sort to minimize overhead.
3897 /* Assume 1st element is in right place already, and start checking
3898 at 2nd element to see where it should be inserted.
3900 for (i = part_left + 1; i <= part_right; ++i) {
3902 /* Scan (backwards - just in case 'i' is already in right place)
3903 through the elements already sorted to see if the ith element
3904 belongs ahead of one of them.
3906 for (j = i - 1; j >= part_left; --j) {
3907 if (qsort_cmp(i, j) >= 0) {
3908 /* i belongs right after j
3915 /* Looks like we really need to move some things
3919 for (k = i - 1; k >= j; --k)
3920 array[k + 1] = array[k];
3925 /* That partition is now sorted, grab the next one, or get out
3926 of the loop if there aren't any more.
3929 if (next_stack_entry == 0) {
3930 /* the stack is empty - we are done */
3934 part_left = partition_stack[next_stack_entry].left;
3935 part_right = partition_stack[next_stack_entry].right;
3936 #ifdef QSORT_ORDER_GUESS
3937 qsort_break_even = partition_stack[next_stack_entry].qsort_break_even;
3942 /* Believe it or not, the array is sorted at this point! */
3955 sortcv(pTHXo_ SV *a, SV *b)
3958 I32 oldsaveix = PL_savestack_ix;
3959 I32 oldscopeix = PL_scopestack_ix;
3961 GvSV(PL_firstgv) = a;
3962 GvSV(PL_secondgv) = b;
3963 PL_stack_sp = PL_stack_base;
3966 if (PL_stack_sp != PL_stack_base + 1)
3967 Perl_croak(aTHX_ "Sort subroutine didn't return single value");
3968 if (!SvNIOKp(*PL_stack_sp))
3969 Perl_croak(aTHX_ "Sort subroutine didn't return a numeric value");
3970 result = SvIV(*PL_stack_sp);
3971 while (PL_scopestack_ix > oldscopeix) {
3974 leave_scope(oldsaveix);
3980 sv_ncmp(pTHXo_ SV *a, SV *b)
3984 return nv1 < nv2 ? -1 : nv1 > nv2 ? 1 : 0;
3988 sv_i_ncmp(pTHXo_ SV *a, SV *b)
3992 return iv1 < iv2 ? -1 : iv1 > iv2 ? 1 : 0;
3994 #define tryCALL_AMAGICbin(left,right,meth,svp) STMT_START { \
3996 if (PL_amagic_generation) { \
3997 if (SvAMAGIC(left)||SvAMAGIC(right))\
3998 *svp = amagic_call(left, \
4006 amagic_ncmp(pTHXo_ register SV *a, register SV *b)
4009 tryCALL_AMAGICbin(a,b,ncmp,&tmpsv);
4014 I32 i = SvIVX(tmpsv);
4024 return sv_ncmp(aTHXo_ a, b);
4028 amagic_i_ncmp(pTHXo_ register SV *a, register SV *b)
4031 tryCALL_AMAGICbin(a,b,ncmp,&tmpsv);
4036 I32 i = SvIVX(tmpsv);
4046 return sv_i_ncmp(aTHXo_ a, b);
4050 amagic_cmp(pTHXo_ register SV *str1, register SV *str2)
4053 tryCALL_AMAGICbin(str1,str2,scmp,&tmpsv);
4058 I32 i = SvIVX(tmpsv);
4068 return sv_cmp(str1, str2);
4072 amagic_cmp_locale(pTHXo_ register SV *str1, register SV *str2)
4075 tryCALL_AMAGICbin(str1,str2,scmp,&tmpsv);
4080 I32 i = SvIVX(tmpsv);
4090 return sv_cmp_locale(str1, str2);
4094 sv_cmp_locale_static(pTHXo_ register SV *str1, register SV *str2)
4096 return sv_cmp_locale(str1, str2);
4100 sv_cmp_static(pTHXo_ register SV *str1, register SV *str2)
4102 return sv_cmp(str1, str2);