X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=op.c;h=d50324aa7e26bdcf5fd586f2360b58721004bfca;hb=bda4119bc5ac877809e21a4c89ea66d3512e38b8;hp=6502673bbfc97ef47bf798fc7b13b17b99424740;hpb=fb5b0d601e4bb1f798f9559cbb4b2e9d69aa3eed;p=p5sagit%2Fp5-mst-13.2.git diff --git a/op.c b/op.c index 6502673..d50324a 100644 --- a/op.c +++ b/op.c @@ -19,9 +19,9 @@ #include "perl.h" #ifdef PERL_OBJECT -#define CHECKCALL this->*check +#define CHECKCALL this->*PL_check #else -#define CHECKCALL *check +#define CHECKCALL *PL_check #endif /* @@ -31,10 +31,12 @@ #define CHECKOP(type,o) \ ((PL_op_mask && PL_op_mask[type]) \ ? ( op_free((OP*)o), \ - croak("%s trapped by operation mask", op_desc[type]), \ + croak("%s trapped by operation mask", PL_op_desc[type]), \ Nullop ) \ : (CHECKCALL[type])((OP*)o)) +#define PAD_MAX 999999999 + static bool scalar_mod_type _((OP *o, I32 type)); #ifndef PERL_OBJECT static I32 list_assignment _((OP *o)); @@ -46,24 +48,26 @@ static OP *too_few_arguments _((OP *o, char* name)); static OP *too_many_arguments _((OP *o, char* name)); static void null _((OP* o)); static PADOFFSET pad_findlex _((char* name, PADOFFSET newoff, U32 seq, - CV* startcv, I32 cx_ix)); + CV* startcv, I32 cx_ix, I32 saweval)); static OP *newDEFSVOP _((void)); static OP *new_logop _((I32 type, I32 flags, OP **firstp, OP **otherp)); +static void simplify_sort _((OP *o)); #endif STATIC char* gv_ename(GV *gv) { + STRLEN n_a; SV* tmpsv = sv_newmortal(); gv_efullname3(tmpsv, gv, Nullch); - return SvPV(tmpsv,PL_na); + return SvPV(tmpsv,n_a); } STATIC OP * no_fh_allowed(OP *o) { yyerror(form("Missing comma after first argument to %s function", - op_desc[o->op_type])); + PL_op_desc[o->op_type])); return o; } @@ -85,7 +89,7 @@ STATIC void bad_type(I32 n, char *t, char *name, OP *kid) { yyerror(form("Type of arg %d to %s must be %s (not %s)", - (int)n, name, t, op_desc[kid->op_type])); + (int)n, name, t, PL_op_desc[kid->op_type])); } void @@ -93,7 +97,7 @@ assertref(OP *o) { int type = o->op_type; if (type != OP_AELEM && type != OP_HELEM && type != OP_GELEM) { - yyerror(form("Can't use subscript on %s", op_desc[type])); + yyerror(form("Can't use subscript on %s", PL_op_desc[type])); if (type == OP_ENTERSUB || type == OP_RV2HV || type == OP_PADHV) { dTHR; SV *msg = sv_2mortal( @@ -118,7 +122,11 @@ pad_allocmy(char *name) PADOFFSET off; SV *sv; - if (!(isALPHA(name[1]) || name[1] == '_' && (int)strlen(name) > 2)) { + if (!( + isALPHA(name[1]) || + (PL_hints & HINT_UTF8 && (name[1] & 0xc0) == 0xc0) || + name[1] == '_' && (int)strlen(name) > 2)) + { if (!isPRINT(name[1])) { name[3] = '\0'; name[2] = toCTRL(name[1]); @@ -126,15 +134,17 @@ pad_allocmy(char *name) } croak("Can't use global %s in \"my\"",name); } - if (PL_dowarn && AvFILLp(PL_comppad_name) >= 0) { + if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) { SV **svp = AvARRAY(PL_comppad_name); for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) { if ((sv = svp[off]) && sv != &PL_sv_undef - && SvIVX(sv) == 999999999 /* var is in open scope */ + && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0) && strEQ(name, SvPVX(sv))) { - warn("\"my\" variable %s masks earlier declaration in same scope", name); + warner(WARN_UNSAFE, + "\"my\" variable %s masks earlier declaration in same %s", + name, (SvIVX(sv) == PAD_MAX ? "scope" : "statement")); break; } } @@ -152,7 +162,7 @@ pad_allocmy(char *name) PL_sv_objcount++; } av_store(PL_comppad_name, off, sv); - SvNVX(sv) = (double)999999999; + SvNVX(sv) = (double)PAD_MAX; SvIVX(sv) = 0; /* Not yet introduced--see newSTATEOP */ if (!PL_min_intro_pending) PL_min_intro_pending = off; @@ -166,7 +176,7 @@ pad_allocmy(char *name) } STATIC PADOFFSET -pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) +pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix, I32 saweval) { dTHR; CV *cv; @@ -174,7 +184,6 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) SV *sv; register I32 i; register PERL_CONTEXT *cx; - int saweval; for (cv = startcv; cv; cv = CvOUTSIDE(cv)) { AV *curlist = CvPADLIST(cv); @@ -214,8 +223,14 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) sv_setpv(namesv, name); av_store(PL_comppad_name, newoff, namesv); SvNVX(namesv) = (double)PL_curcop->cop_seq; - SvIVX(namesv) = 999999999; /* A ref, intro immediately */ + SvIVX(namesv) = PAD_MAX; /* A ref, intro immediately */ SvFAKE_on(namesv); /* A ref, not a real var */ + if (SvOBJECT(sv)) { /* A typed var */ + SvOBJECT_on(namesv); + (void)SvUPGRADE(namesv, SVt_PVMG); + SvSTASH(namesv) = (HV*)SvREFCNT_inc((SV*)SvSTASH(sv)); + PL_sv_objcount++; + } if (CvANON(PL_compcv) || SvTYPE(PL_compcv) == SVt_PVFM) { /* "It's closures all the way down." */ CvCLONE_on(PL_compcv); @@ -227,22 +242,27 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) CV *bcv; for (bcv = startcv; bcv && bcv != cv && !CvCLONE(bcv); - bcv = CvOUTSIDE(bcv)) { + bcv = CvOUTSIDE(bcv)) + { if (CvANON(bcv)) CvCLONE_on(bcv); else { - if (PL_dowarn && !CvUNIQUE(cv)) - warn( + if (ckWARN(WARN_CLOSURE) + && !CvUNIQUE(bcv) && !CvUNIQUE(cv)) + { + warner(WARN_CLOSURE, "Variable \"%s\" may be unavailable", name); + } break; } } } } else if (!CvUNIQUE(PL_compcv)) { - if (PL_dowarn && !SvFAKE(sv) && !CvUNIQUE(cv)) - warn("Variable \"%s\" will not stay shared", name); + if (ckWARN(WARN_CLOSURE) && !SvFAKE(sv) && !CvUNIQUE(cv)) + warner(WARN_CLOSURE, + "Variable \"%s\" will not stay shared", name); } } av_store(PL_comppad, newoff, SvREFCNT_inc(oldsv)); @@ -256,20 +276,20 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) * XXX This will also probably interact badly with eval tree caching. */ - saweval = 0; for (i = cx_ix; i >= 0; i--) { cx = &cxstack[i]; - switch (cx->cx_type) { + switch (CxTYPE(cx)) { default: if (i == 0 && saweval) { seq = cxstack[saweval].blk_oldcop->cop_seq; - return pad_findlex(name, newoff, seq, PL_main_cv, 0); + return pad_findlex(name, newoff, seq, PL_main_cv, -1, saweval); } break; case CXt_EVAL: switch (cx->blk_eval.old_op_type) { case OP_ENTEREVAL: - saweval = i; + if (CxREALEVAL(cx)) + saweval = i; break; case OP_REQUIRE: /* require must have its own scope */ @@ -285,7 +305,7 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix) continue; } seq = cxstack[saweval].blk_oldcop->cop_seq; - return pad_findlex(name, newoff, seq, cv, i-1); + return pad_findlex(name, newoff, seq, cv, i-1, saweval); } } @@ -301,6 +321,8 @@ pad_findmy(char *name) SV *sv; SV **svp = AvARRAY(PL_comppad_name); U32 seq = PL_cop_seqmax; + PERL_CONTEXT *cx; + CV *outside; #ifdef USE_THREADS /* @@ -330,8 +352,20 @@ pad_findmy(char *name) } } + outside = CvOUTSIDE(PL_compcv); + + /* Check if if we're compiling an eval'', and adjust seq to be the + * eval's seq number. This depends on eval'' having a non-null + * CvOUTSIDE() while it is being compiled. The eval'' itself is + * identified by CvUNIQUE being set and CvGV being null. */ + if (outside && CvUNIQUE(PL_compcv) && !CvGV(PL_compcv) && cxstack_ix >= 0) { + cx = &cxstack[cxstack_ix]; + if (CxREALEVAL(cx)) + seq = cx->blk_oldcop->cop_seq; + } + /* See if it's in a nested scope */ - off = pad_findlex(name, 0, seq, CvOUTSIDE(PL_compcv), cxstack_ix); + off = pad_findlex(name, 0, seq, outside, cxstack_ix, 0); if (off) { /* If there is a pending local definition, this new alias must die */ if (pendoff) @@ -355,7 +389,7 @@ pad_leavemy(I32 fill) } /* "Deintroduce" my variables that are leaving with this scope. */ for (off = AvFILLp(PL_comppad_name); off > fill; off--) { - if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == 999999999) + if ((sv = svp[off]) && sv != &PL_sv_undef && SvIVX(sv) == PAD_MAX) SvIVX(sv) = PL_cop_seqmax; } } @@ -400,11 +434,11 @@ pad_alloc(I32 optype, U32 tmptype) #ifdef USE_THREADS DEBUG_X(PerlIO_printf(Perl_debug_log, "0x%lx Pad 0x%lx alloc %ld for %s\n", (unsigned long) thr, (unsigned long) PL_curpad, - (long) retval, op_name[optype])); + (long) retval, PL_op_name[optype])); #else DEBUG_X(PerlIO_printf(Perl_debug_log, "Pad 0x%lx alloc %ld for %s\n", (unsigned long) PL_curpad, - (long) retval, op_name[optype])); + (long) retval, PL_op_name[optype])); #endif /* USE_THREADS */ return (PADOFFSET)retval; } @@ -517,11 +551,15 @@ find_threadsv(char *name) if (!p) return NOT_IN_PAD; key = p - PL_threadsv_names; + MUTEX_LOCK(&thr->mutex); svp = av_fetch(thr->threadsv, key, FALSE); - if (!svp) { + if (svp) + MUTEX_UNLOCK(&thr->mutex); + else { SV *sv = NEWSV(0, 0); av_store(thr->threadsv, key, sv); thr->threadsvp = AvARRAY(thr->threadsv); + MUTEX_UNLOCK(&thr->mutex); /* * Some magic variables used to be automagically initialised * in gv_fetchpv. Those which are now per-thread magicals get @@ -538,6 +576,16 @@ find_threadsv(char *name) case '`': case '\'': PL_sawampersand = TRUE; + /* FALL THROUGH */ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': SvREADONLY_on(sv); /* FALL THROUGH */ @@ -592,7 +640,7 @@ op_free(OP *o) #endif /* USE_THREADS */ default: if (!(o->op_flags & OPf_REF) - || (check[o->op_type] != FUNC_NAME_TO_PTR(ck_ftst))) + || (PL_check[o->op_type] != FUNC_NAME_TO_PTR(ck_ftst))) break; /* FALL THROUGH */ case OP_GVSV: @@ -604,6 +652,8 @@ op_free(OP *o) case OP_DBSTATE: Safefree(cCOPo->cop_label); SvREFCNT_dec(cCOPo->cop_filegv); + if (cCOPo->cop_warnings != WARN_NONE && cCOPo->cop_warnings != WARN_ALL) + SvREFCNT_dec(cCOPo->cop_warnings); break; case OP_CONST: SvREFCNT_dec(cSVOPo->op_sv); @@ -616,7 +666,10 @@ op_free(OP *o) break; /* FALL THROUGH */ case OP_TRANS: - Safefree(cPVOPo->op_pv); + if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) + SvREFCNT_dec(cSVOPo->op_sv); + else + Safefree(cPVOPo->op_pv); break; case OP_SUBST: op_free(cPMOPo->op_pmreplroot); @@ -641,7 +694,7 @@ null(OP *o) pad_free(o->op_targ); o->op_targ = o->op_type; o->op_type = OP_NULL; - o->op_ppaddr = ppaddr[OP_NULL]; + o->op_ppaddr = PL_ppaddr[OP_NULL]; } /* Contextualizers */ @@ -686,15 +739,16 @@ scalarkids(OP *o) STATIC OP * scalarboolean(OP *o) { - if (PL_dowarn && - o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) { + if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST) { dTHR; - line_t oldline = PL_curcop->cop_line; + if (ckWARN(WARN_SYNTAX)) { + line_t oldline = PL_curcop->cop_line; - if (PL_copline != NOLINE) - PL_curcop->cop_line = PL_copline; - warn("Found = in conditional, should be =="); - PL_curcop->cop_line = oldline; + if (PL_copline != NOLINE) + PL_curcop->cop_line = PL_copline; + warner(WARN_SYNTAX, "Found = in conditional, should be =="); + PL_curcop->cop_line = oldline; + } } return scalar(o); } @@ -774,7 +828,8 @@ scalarvoid(OP *o) SV* sv; /* assumes no premature commitment */ - if (!o || (o->op_flags & OPf_WANT) == OPf_WANT_LIST || PL_error_count + U8 want = o->op_flags & OPf_WANT; + if (!o || (want && want != OPf_WANT_SCALAR) || PL_error_count || o->op_type == OP_RETURN) return o; @@ -782,7 +837,7 @@ scalarvoid(OP *o) switch (o->op_type) { default: - if (!(opargs[o->op_type] & OA_FOLDCONST)) + if (!(PL_opargs[o->op_type] & OA_FOLDCONST)) break; /* FALL THROUGH */ case OP_REPEAT: @@ -862,7 +917,7 @@ scalarvoid(OP *o) case OP_GETLOGIN: func_ops: if (!(o->op_private & OPpLVAL_INTRO)) - useless = op_desc[o->op_type]; + useless = PL_op_desc[o->op_type]; break; case OP_RV2GV: @@ -881,15 +936,18 @@ scalarvoid(OP *o) case OP_CONST: sv = cSVOPo->op_sv; - if (PL_dowarn) { - useless = "a constant"; - if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0)) - useless = 0; - else if (SvPOK(sv)) { - if (strnEQ(SvPVX(sv), "di", 2) || - strnEQ(SvPVX(sv), "ds", 2) || - strnEQ(SvPVX(sv), "ig", 2)) - useless = 0; + { + dTHR; + if (ckWARN(WARN_VOID)) { + useless = "a constant"; + if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0)) + useless = 0; + else if (SvPOK(sv)) { + if (strnEQ(SvPVX(sv), "di", 2) || + strnEQ(SvPVX(sv), "ds", 2) || + strnEQ(SvPVX(sv), "ig", 2)) + useless = 0; + } } } null(o); /* don't execute a constant */ @@ -898,12 +956,12 @@ scalarvoid(OP *o) case OP_POSTINC: o->op_type = OP_PREINC; /* pre-increment is faster */ - o->op_ppaddr = ppaddr[OP_PREINC]; + o->op_ppaddr = PL_ppaddr[OP_PREINC]; break; case OP_POSTDEC: o->op_type = OP_PREDEC; /* pre-decrement is faster */ - o->op_ppaddr = ppaddr[OP_PREDEC]; + o->op_ppaddr = PL_ppaddr[OP_PREDEC]; break; case OP_OR: @@ -948,8 +1006,11 @@ scalarvoid(OP *o) } break; } - if (useless && PL_dowarn) - warn("Useless use of %s in void context", useless); + if (useless) { + dTHR; + if (ckWARN(WARN_VOID)) + warner(WARN_VOID, "Useless use of %s in void context", useless); + } return o; } @@ -1076,6 +1137,7 @@ mod(OP *o, I32 type) dTHR; OP *kid; SV *sv; + STRLEN n_a; if (!o || PL_error_count) return o; @@ -1108,7 +1170,7 @@ mod(OP *o, I32 type) if ((type == OP_UNDEF || type == OP_REFGEN) && !(o->op_flags & OPf_STACKED)) { o->op_type = OP_RV2CV; /* entersub => rv2cv */ - o->op_ppaddr = ppaddr[OP_RV2CV]; + o->op_ppaddr = PL_ppaddr[OP_RV2CV]; assert(cUNOPo->op_first->op_type == OP_NULL); null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */ break; @@ -1120,8 +1182,9 @@ mod(OP *o, I32 type) if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) break; yyerror(form("Can't modify %s in %s", - op_desc[o->op_type], - type ? op_desc[type] : "local")); + (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL) + ? "do block" : PL_op_desc[o->op_type]), + type ? PL_op_desc[type] : "local")); return o; case OP_PREINC: @@ -1202,7 +1265,7 @@ mod(OP *o, I32 type) PL_modcount++; if (!type) croak("Can't localize lexical variable %s", - SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), PL_na)); + SvPV(*av_fetch(PL_comppad_name, o->op_targ, 4), n_a)); break; #ifdef USE_THREADS @@ -1249,7 +1312,9 @@ mod(OP *o, I32 type) break; case OP_NULL: - if (!(o->op_flags & OPf_KIDS)) + if (o->op_flags & OPf_SPECIAL) /* do BLOCK */ + goto nomod; + else if (!(o->op_flags & OPf_KIDS)) break; if (o->op_targ != OP_LIST) { mod(cBINOPo->op_first, type); @@ -1346,7 +1411,7 @@ ref(OP *o, I32 type) if ((type == OP_DEFINED || type == OP_LOCK) && !(o->op_flags & OPf_STACKED)) { o->op_type = OP_RV2CV; /* entersub => rv2cv */ - o->op_ppaddr = ppaddr[OP_RV2CV]; + o->op_ppaddr = PL_ppaddr[OP_RV2CV]; assert(cUNOPo->op_first->op_type == OP_NULL); null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */ o->op_flags |= OPf_SPECIAL; @@ -1438,7 +1503,7 @@ my(OP *o) type != OP_PADHV && type != OP_PUSHMARK) { - yyerror(form("Can't declare %s in my", op_desc[o->op_type])); + yyerror(form("Can't declare %s in my", PL_op_desc[o->op_type])); return o; } o->op_flags |= OPf_MOD; @@ -1457,20 +1522,23 @@ sawparens(OP *o) OP * bind_match(I32 type, OP *left, OP *right) { + dTHR; OP *o; - if (PL_dowarn && - (left->op_type == OP_RV2AV || - left->op_type == OP_RV2HV || - left->op_type == OP_PADAV || - left->op_type == OP_PADHV)) { - char *desc = op_desc[(right->op_type == OP_SUBST || - right->op_type == OP_TRANS) - ? right->op_type : OP_MATCH]; - char *sample = ((left->op_type == OP_RV2AV || - left->op_type == OP_PADAV) - ? "@array" : "%hash"); - warn("Applying %s to %s will act on scalar(%s)", desc, sample, sample); + if (ckWARN(WARN_UNSAFE) && + (left->op_type == OP_RV2AV || + left->op_type == OP_RV2HV || + left->op_type == OP_PADAV || + left->op_type == OP_PADHV)) { + char *desc = PL_op_desc[(right->op_type == OP_SUBST || + right->op_type == OP_TRANS) + ? right->op_type : OP_MATCH]; + char *sample = ((left->op_type == OP_RV2AV || + left->op_type == OP_PADAV) + ? "@array" : "%hash"); + warner(WARN_UNSAFE, + "Applying %s to %s will act on scalar(%s)", + desc, sample, sample); } if (right->op_type == OP_MATCH || @@ -1508,13 +1576,13 @@ scope(OP *o) if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || PL_tainting) { o = prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o); o->op_type = OP_LEAVE; - o->op_ppaddr = ppaddr[OP_LEAVE]; + o->op_ppaddr = PL_ppaddr[OP_LEAVE]; } else { if (o->op_type == OP_LINESEQ) { OP *kid; o->op_type = OP_SCOPE; - o->op_ppaddr = ppaddr[OP_SCOPE]; + o->op_ppaddr = PL_ppaddr[OP_SCOPE]; kid = ((LISTOP*)o)->op_first; if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE){ SvREFCNT_dec(((COP*)kid)->cop_filegv); @@ -1559,6 +1627,14 @@ block_start(int full) PL_pad_reset_pending = FALSE; SAVEHINTS(); PL_hints &= ~HINT_BLOCK_SCOPE; + SAVEPPTR(PL_compiling.cop_warnings); + if (PL_compiling.cop_warnings != WARN_ALL && + PL_compiling.cop_warnings != WARN_NONE) { + PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ; + SAVEFREESV(PL_compiling.cop_warnings) ; + } + + return retval; } @@ -1570,6 +1646,7 @@ block_end(I32 floor, OP *seq) OP* retval = scalarseq(seq); LEAVE_SCOPE(floor); PL_pad_reset_pending = FALSE; + PL_compiling.op_private = PL_hints; if (needblockscope) PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */ pad_leavemy(PL_comppad_name_fill); @@ -1629,11 +1706,13 @@ localize(OP *o, I32 lex) if (o->op_flags & OPf_PARENS) list(o); else { - if (PL_dowarn && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') { + dTHR; + if (ckWARN(WARN_PARENTHESIS) && PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == ',') { char *s; - for (s = PL_bufptr; *s && (isALNUM(*s) || strchr("@$%, ",*s)); s++) ; + for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ; if (*s == ';' || *s == '=') - warn("Parens missing around \"%s\" list", lex ? "my" : "local"); + warner(WARN_PARENTHESIS, "Parentheses missing around \"%s\" list", + lex ? "my" : "local"); } } PL_in_my = FALSE; @@ -1668,15 +1747,15 @@ fold_constants(register OP *o) I32 type = o->op_type; SV *sv; - if (opargs[type] & OA_RETSCALAR) + if (PL_opargs[type] & OA_RETSCALAR) scalar(o); - if (opargs[type] & OA_TARGET) + if (PL_opargs[type] & OA_TARGET) o->op_targ = pad_alloc(type, SVs_PADTMP); - if ((opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)) - o->op_ppaddr = ppaddr[type = ++(o->op_type)]; + if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)) + o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)]; - if (!(opargs[type] & OA_FOLDCONST)) + if (!(PL_opargs[type] & OA_FOLDCONST)) goto nope; switch (type) { @@ -1739,7 +1818,7 @@ fold_constants(register OP *o) } nope: - if (!(opargs[type] & OA_OTHERINT)) + if (!(PL_opargs[type] & OA_OTHERINT)) return o; if (!(PL_hints & HINT_INTEGER)) { @@ -1752,11 +1831,11 @@ fold_constants(register OP *o) continue; return o; } - if (opargs[curop->op_type] & OA_RETINTEGER) + if (PL_opargs[curop->op_type] & OA_RETINTEGER) continue; return o; } - o->op_ppaddr = ppaddr[++(o->op_type)]; + o->op_ppaddr = PL_ppaddr[++(o->op_type)]; } return o; @@ -1782,7 +1861,7 @@ gen_constant_list(register OP *o) PL_tmps_floor = oldtmps_floor; o->op_type = OP_RV2AV; - o->op_ppaddr = ppaddr[OP_RV2AV]; + o->op_ppaddr = PL_ppaddr[OP_RV2AV]; curop = ((UNOP*)o)->op_first; ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--)); op_free(curop); @@ -1801,11 +1880,11 @@ convert(I32 type, I32 flags, OP *o) else o->op_flags &= ~OPf_WANT; - if (!(opargs[type] & OA_MARK)) + if (!(PL_opargs[type] & OA_MARK)) null(cLISTOPo->op_first); o->op_type = type; - o->op_ppaddr = ppaddr[type]; + o->op_ppaddr = PL_ppaddr[type]; o->op_flags |= flags; o = CHECKOP(type, o); @@ -1866,7 +1945,7 @@ append_list(I32 type, LISTOP *first, LISTOP *last) first->op_last = last->op_last; first->op_children += last->op_children; if (first->op_children) - last->op_flags |= OPf_KIDS; + first->op_flags |= OPf_KIDS; Safefree(last); return (OP*)first; @@ -1926,7 +2005,7 @@ newLISTOP(I32 type, I32 flags, OP *first, OP *last) Newz(1101, listop, 1, LISTOP); listop->op_type = type; - listop->op_ppaddr = ppaddr[type]; + listop->op_ppaddr = PL_ppaddr[type]; listop->op_children = (first != 0) + (last != 0); listop->op_flags = flags; @@ -1959,14 +2038,14 @@ newOP(I32 type, I32 flags) OP *o; Newz(1101, o, 1, OP); o->op_type = type; - o->op_ppaddr = ppaddr[type]; + o->op_ppaddr = PL_ppaddr[type]; o->op_flags = flags; o->op_next = o; o->op_private = 0 + (flags >> 8); - if (opargs[type] & OA_RETSCALAR) + if (PL_opargs[type] & OA_RETSCALAR) scalar(o); - if (opargs[type] & OA_TARGET) + if (PL_opargs[type] & OA_TARGET) o->op_targ = pad_alloc(type, SVs_PADTMP); return CHECKOP(type, o); } @@ -1978,12 +2057,12 @@ newUNOP(I32 type, I32 flags, OP *first) if (!first) first = newOP(OP_STUB, 0); - if (opargs[type] & OA_MARK) + if (PL_opargs[type] & OA_MARK) first = force_list(first); Newz(1101, unop, 1, UNOP); unop->op_type = type; - unop->op_ppaddr = ppaddr[type]; + unop->op_ppaddr = PL_ppaddr[type]; unop->op_first = first; unop->op_flags = flags | OPf_KIDS; unop->op_private = 1 | (flags >> 8); @@ -2004,7 +2083,7 @@ newBINOP(I32 type, I32 flags, OP *first, OP *last) first = newOP(OP_NULL, 0); binop->op_type = type; - binop->op_ppaddr = ppaddr[type]; + binop->op_ppaddr = PL_ppaddr[type]; binop->op_first = first; binop->op_flags = flags | OPf_KIDS; if (!last) { @@ -2020,11 +2099,24 @@ newBINOP(I32 type, I32 flags, OP *first, OP *last) if (binop->op_next) return (OP*)binop; - binop->op_last = last = binop->op_first->op_sibling; + binop->op_last = binop->op_first->op_sibling; return fold_constants((OP *)binop); } +static int +utf8compare(const void *a, const void *b) +{ + int i; + for (i = 0; i < 10; i++) { + if ((*(U8**)a)[i] < (*(U8**)b)[i]) + return -1; + if ((*(U8**)a)[i] > (*(U8**)b)[i]) + return 1; + } + return 0; +} + OP * pmtrans(OP *o, OP *expr, OP *repl) { @@ -2036,16 +2128,200 @@ pmtrans(OP *o, OP *expr, OP *repl) register U8 *r = (U8*)SvPV(rstr, rlen); register I32 i; register I32 j; - I32 Delete; + I32 del; I32 complement; I32 squash; register short *tbl; - tbl = (short*)cPVOPo->op_pv; complement = o->op_private & OPpTRANS_COMPLEMENT; - Delete = o->op_private & OPpTRANS_DELETE; + del = o->op_private & OPpTRANS_DELETE; squash = o->op_private & OPpTRANS_SQUASH; + if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) { + SV* listsv = newSVpv("# comment\n",0); + SV* transv = 0; + U8* tend = t + tlen; + U8* rend = r + rlen; + I32 ulen; + U32 tfirst = 1; + U32 tlast = 0; + I32 tdiff; + U32 rfirst = 1; + U32 rlast = 0; + I32 rdiff; + I32 diff; + I32 none = 0; + U32 max = 0; + I32 bits; + I32 grows = 0; + I32 havefinal = 0; + U32 final; + HV *hv; + I32 from_utf = o->op_private & OPpTRANS_FROM_UTF; + I32 to_utf = o->op_private & OPpTRANS_TO_UTF; + + if (complement) { + U8 tmpbuf[10]; + U8** cp; + UV nextmin = 0; + New(1109, cp, tlen, U8*); + i = 0; + transv = newSVpv("",0); + while (t < tend) { + cp[i++] = t; + t += UTF8SKIP(t); + if (*t == 0xff) { + t++; + t += UTF8SKIP(t); + } + } + qsort(cp, i, sizeof(U8*), utf8compare); + for (j = 0; j < i; j++) { + U8 *s = cp[j]; + UV val = utf8_to_uv(s, &ulen); + s += ulen; + diff = val - nextmin; + if (diff > 0) { + t = uv_to_utf8(tmpbuf,nextmin); + sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); + if (diff > 1) { + t = uv_to_utf8(tmpbuf, val - 1); + sv_catpvn(transv, "\377", 1); + sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); + } + } + if (*s == 0xff) + val = utf8_to_uv(s+1, &ulen); + if (val >= nextmin) + nextmin = val + 1; + } + t = uv_to_utf8(tmpbuf,nextmin); + sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); + t = uv_to_utf8(tmpbuf, 0x7fffffff); + sv_catpvn(transv, "\377", 1); + sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); + t = (U8*)SvPVX(transv); + tlen = SvCUR(transv); + tend = t + tlen; + } + else if (!rlen && !del) { + r = t; rlen = tlen; rend = tend; + } + if (!squash) { + if (to_utf && from_utf) { /* only counting characters */ + if (t == r || (tlen == rlen && memEQ(t, r, tlen))) + o->op_private |= OPpTRANS_IDENTICAL; + } + else { /* straight latin-1 translation */ + if (tlen == 4 && memEQ(t, "\0\377\303\277", 4) && + rlen == 4 && memEQ(r, "\0\377\303\277", 4)) + o->op_private |= OPpTRANS_IDENTICAL; + } + } + + while (t < tend || tfirst <= tlast) { + /* see if we need more "t" chars */ + if (tfirst > tlast) { + tfirst = (I32)utf8_to_uv(t, &ulen); + t += ulen; + if (t < tend && *t == 0xff) { /* illegal utf8 val indicates range */ + tlast = (I32)utf8_to_uv(++t, &ulen); + t += ulen; + } + else + tlast = tfirst; + } + + /* now see if we need more "r" chars */ + if (rfirst > rlast) { + if (r < rend) { + rfirst = (I32)utf8_to_uv(r, &ulen); + r += ulen; + if (r < rend && *r == 0xff) { /* illegal utf8 val indicates range */ + rlast = (I32)utf8_to_uv(++r, &ulen); + r += ulen; + } + else + rlast = rfirst; + } + else { + if (!havefinal++) + final = rlast; + rfirst = rlast = 0xffffffff; + } + } + + /* now see which range will peter our first, if either. */ + tdiff = tlast - tfirst; + rdiff = rlast - rfirst; + + if (tdiff <= rdiff) + diff = tdiff; + else + diff = rdiff; + + if (rfirst == 0xffffffff) { + diff = tdiff; /* oops, pretend rdiff is infinite */ + if (diff > 0) + sv_catpvf(listsv, "%04x\t%04x\tXXXX\n", tfirst, tlast); + else + sv_catpvf(listsv, "%04x\t\tXXXX\n", tfirst); + } + else { + if (diff > 0) + sv_catpvf(listsv, "%04x\t%04x\t%04x\n", tfirst, tfirst + diff, rfirst); + else + sv_catpvf(listsv, "%04x\t\t%04x\n", tfirst, rfirst); + + if (rfirst + diff > max) + max = rfirst + diff; + rfirst += diff + 1; + if (!grows) { + if (rfirst <= 0x80) + ; + else if (rfirst <= 0x800) + grows |= (tfirst < 0x80); + else if (rfirst <= 0x10000) + grows |= (tfirst < 0x800); + else if (rfirst <= 0x200000) + grows |= (tfirst < 0x10000); + else if (rfirst <= 0x4000000) + grows |= (tfirst < 0x200000); + else if (rfirst <= 0x80000000) + grows |= (tfirst < 0x4000000); + } + } + tfirst += diff + 1; + } + + none = ++max; + if (del) + del = ++max; + + if (max > 0xffff) + bits = 32; + else if (max > 0xff) + bits = 16; + else + bits = 8; + + cSVOPo->op_sv = (SV*)swash_init("utf8", "", listsv, bits, none); + SvREFCNT_dec(listsv); + if (transv) + SvREFCNT_dec(transv); + + if (!del && havefinal) + (void)hv_store((HV*)SvRV((cSVOPo->op_sv)), "FINAL", 5, newSViv((IV)final), 0); + + if (grows && to_utf) + o->op_private |= OPpTRANS_GROWS; + + op_free(expr); + op_free(repl); + return o; + } + + tbl = (short*)cPVOPo->op_pv; if (complement) { Zero(tbl, 256, short); for (i = 0; i < tlen; i++) @@ -2053,7 +2329,7 @@ pmtrans(OP *o, OP *expr, OP *repl) for (i = 0, j = 0; i < 256; i++) { if (!tbl[i]) { if (j >= rlen) { - if (Delete) + if (del) tbl[i] = -2; else if (rlen) tbl[i] = r[j-1]; @@ -2066,16 +2342,16 @@ pmtrans(OP *o, OP *expr, OP *repl) } } else { - if (!rlen && !Delete) { + if (!rlen && !del) { r = t; rlen = tlen; if (!squash) - o->op_private |= OPpTRANS_COUNTONLY; + o->op_private |= OPpTRANS_IDENTICAL; } for (i = 0; i < 256; i++) tbl[i] = -1; for (i = 0, j = 0; i < tlen; i++,j++) { if (j >= rlen) { - if (Delete) { + if (del) { if (tbl[t[i]] == -1) tbl[t[i]] = -2; continue; @@ -2100,7 +2376,7 @@ newPMOP(I32 type, I32 flags) Newz(1101, pmop, 1, PMOP); pmop->op_type = type; - pmop->op_ppaddr = ppaddr[type]; + pmop->op_ppaddr = PL_ppaddr[type]; pmop->op_flags = flags; pmop->op_private = 0 | (flags >> 8); @@ -2155,7 +2431,7 @@ pmruntime(OP *o, OP *expr, OP *repl) Newz(1101, rcop, 1, LOGOP); rcop->op_type = OP_REGCOMP; - rcop->op_ppaddr = ppaddr[OP_REGCOMP]; + rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP]; rcop->op_first = scalar(expr); rcop->op_flags |= ((PL_hints & HINT_RE_EVAL) ? (OPf_SPECIAL | OPf_KIDS) @@ -2194,7 +2470,7 @@ pmruntime(OP *o, OP *expr, OP *repl) else { OP *lastop = 0; for (curop = LINKLIST(repl); curop!=repl; curop = LINKLIST(curop)) { - if (opargs[curop->op_type] & OA_DANGEROUS) { + if (PL_opargs[curop->op_type] & OA_DANGEROUS) { #ifdef USE_THREADS if (curop->op_type == OP_THREADSV) { repl_has_vars = 1; @@ -2247,7 +2523,7 @@ pmruntime(OP *o, OP *expr, OP *repl) } Newz(1101, rcop, 1, LOGOP); rcop->op_type = OP_SUBSTCONT; - rcop->op_ppaddr = ppaddr[OP_SUBSTCONT]; + rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT]; rcop->op_first = scalar(repl); rcop->op_flags |= OPf_KIDS; rcop->op_private = 1; @@ -2272,13 +2548,13 @@ newSVOP(I32 type, I32 flags, SV *sv) SVOP *svop; Newz(1101, svop, 1, SVOP); svop->op_type = type; - svop->op_ppaddr = ppaddr[type]; + svop->op_ppaddr = PL_ppaddr[type]; svop->op_sv = sv; svop->op_next = (OP*)svop; svop->op_flags = flags; - if (opargs[type] & OA_RETSCALAR) + if (PL_opargs[type] & OA_RETSCALAR) scalar((OP*)svop); - if (opargs[type] & OA_TARGET) + if (PL_opargs[type] & OA_TARGET) svop->op_targ = pad_alloc(type, SVs_PADTMP); return CHECKOP(type, svop); } @@ -2290,13 +2566,13 @@ newGVOP(I32 type, I32 flags, GV *gv) GVOP *gvop; Newz(1101, gvop, 1, GVOP); gvop->op_type = type; - gvop->op_ppaddr = ppaddr[type]; + gvop->op_ppaddr = PL_ppaddr[type]; gvop->op_gv = (GV*)SvREFCNT_inc(gv); gvop->op_next = (OP*)gvop; gvop->op_flags = flags; - if (opargs[type] & OA_RETSCALAR) + if (PL_opargs[type] & OA_RETSCALAR) scalar((OP*)gvop); - if (opargs[type] & OA_TARGET) + if (PL_opargs[type] & OA_TARGET) gvop->op_targ = pad_alloc(type, SVs_PADTMP); return CHECKOP(type, gvop); } @@ -2307,13 +2583,13 @@ newPVOP(I32 type, I32 flags, char *pv) PVOP *pvop; Newz(1101, pvop, 1, PVOP); pvop->op_type = type; - pvop->op_ppaddr = ppaddr[type]; + pvop->op_ppaddr = PL_ppaddr[type]; pvop->op_pv = pv; pvop->op_next = (OP*)pvop; pvop->op_flags = flags; - if (opargs[type] & OA_RETSCALAR) + if (PL_opargs[type] & OA_RETSCALAR) scalar((OP*)pvop); - if (opargs[type] & OA_TARGET) + if (PL_opargs[type] & OA_TARGET) pvop->op_targ = pad_alloc(type, SVs_PADTMP); return CHECKOP(type, pvop); } @@ -2339,6 +2615,7 @@ package(OP *o) sv_setpv(PL_curstname,""); PL_curstash = Nullhv; } + PL_hints |= HINT_BLOCK_SCOPE; PL_copline = NOLINE; PL_expect = XSTATE; } @@ -2351,6 +2628,7 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) OP *rqop; OP *imop; OP *veop; + GV *gv; if (id->op_type != OP_CONST) croak("Module name must be constant"); @@ -2402,8 +2680,21 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) newUNOP(OP_METHOD, 0, meth))); } - /* Fake up a require */ - rqop = newUNOP(OP_REQUIRE, 0, id); + /* Fake up a require, handle override, if any */ + gv = gv_fetchpv("require", FALSE, SVt_PVCV); + if (!(gv && GvIMPORTED_CV(gv))) + gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV); + + if (gv && GvIMPORTED_CV(gv)) { + rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, id, + scalar(newUNOP(OP_RV2CV, 0, + newGVOP(OP_GV, 0, + gv)))))); + } + else { + rqop = newUNOP(OP_REQUIRE, 0, id); + } /* Fake up the BEGIN {}, which does its thing immediately. */ newSUB(floor, @@ -2420,6 +2711,29 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) } OP * +dofile(OP *term) +{ + OP *doop; + GV *gv; + + gv = gv_fetchpv("do", FALSE, SVt_PVCV); + if (!(gv && GvIMPORTED_CV(gv))) + gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV); + + if (gv && GvIMPORTED_CV(gv)) { + doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, term, + scalar(newUNOP(OP_RV2CV, 0, + newGVOP(OP_GV, 0, + gv)))))); + } + else { + doop = newUNOP(OP_DOFILE, 0, scalar(term)); + } + return doop; +} + +OP * newSLICEOP(I32 flags, OP *subscript, OP *listval) { return newBINOP(OP_LSLICE, flags, @@ -2499,7 +2813,7 @@ newASSIGNOP(I32 flags, OP *left, I32 optype, OP *right) OP *lastop = o; PL_generation++; for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) { - if (opargs[curop->op_type] & OA_DANGEROUS) { + if (PL_opargs[curop->op_type] & OA_DANGEROUS) { if (curop->op_type == OP_GV) { GV *gv = ((GVOP*)curop)->op_gv; if (gv == PL_defgv || SvCUR(gv) == PL_generation) @@ -2608,17 +2922,18 @@ newSTATEOP(I32 flags, char *label, OP *o) Newz(1101, cop, 1, COP); if (PERLDB_LINE && PL_curcop->cop_line && PL_curstash != PL_debstash) { cop->op_type = OP_DBSTATE; - cop->op_ppaddr = ppaddr[ OP_DBSTATE ]; + cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ]; } else { cop->op_type = OP_NEXTSTATE; - cop->op_ppaddr = ppaddr[ OP_NEXTSTATE ]; + cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ]; } cop->op_flags = flags; - cop->op_private = 0 | (flags >> 8); + cop->op_private = (PL_hints & HINT_UTF8); #ifdef NATIVE_HINTS cop->op_private |= NATIVE_HINTS; #endif + PL_compiling.op_private = cop->op_private; cop->op_next = (OP*)cop; if (label) { @@ -2627,6 +2942,12 @@ newSTATEOP(I32 flags, char *label, OP *o) } cop->cop_seq = seq; cop->cop_arybase = PL_curcop->cop_arybase; + if (PL_curcop->cop_warnings == WARN_NONE + || PL_curcop->cop_warnings == WARN_ALL) + cop->cop_warnings = PL_curcop->cop_warnings ; + else + cop->cop_warnings = newSVsv(PL_curcop->cop_warnings) ; + if (PL_copline == NOLINE) cop->cop_line = PL_curcop->cop_line; @@ -2663,7 +2984,7 @@ intro_my(void) svp = AvARRAY(PL_comppad_name); for (i = PL_min_intro_pending; i <= PL_max_intro_pending; i++) { if ((sv = svp[i]) && sv != &PL_sv_undef && !SvIVX(sv)) { - SvIVX(sv) = 999999999; /* Don't know scope end yet. */ + SvIVX(sv) = PAD_MAX; /* Don't know scope end yet. */ SvNVX(sv) = (double)PL_cop_seqmax; } } @@ -2707,8 +3028,9 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp) } } if (first->op_type == OP_CONST) { - if (PL_dowarn && (first->op_private & OPpCONST_BARE)) - warn("Probable precedence problem on %s", op_desc[type]); + if (ckWARN(WARN_PRECEDENCE) && (first->op_private & OPpCONST_BARE)) + warner(WARN_PRECEDENCE, "Probable precedence problem on %s", + PL_op_desc[type]); if ((type == OP_AND) == (SvTRUE(((SVOP*)first)->op_sv))) { op_free(first); *firstp = Nullop; @@ -2726,7 +3048,7 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp) else scalar(other); } - else if (PL_dowarn && (first->op_flags & OPf_KIDS)) { + else if (ckWARN(WARN_UNSAFE) && (first->op_flags & OPf_KIDS)) { OP *k1 = ((UNOP*)first)->op_first; OP *k2 = k1->op_sibling; OPCODE warnop = 0; @@ -2749,8 +3071,9 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp) if (warnop) { line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = PL_copline; - warn("Value of %s%s can be \"0\"; test with defined()", - op_desc[warnop], + warner(WARN_UNSAFE, + "Value of %s%s can be \"0\"; test with defined()", + PL_op_desc[warnop], ((warnop == OP_READLINE || warnop == OP_GLOB) ? " construct" : "() operator")); PL_curcop->cop_line = oldline; @@ -2766,7 +3089,7 @@ new_logop(I32 type, I32 flags, OP** firstp, OP** otherp) Newz(1101, logop, 1, LOGOP); logop->op_type = type; - logop->op_ppaddr = ppaddr[type]; + logop->op_ppaddr = PL_ppaddr[type]; logop->op_first = first; logop->op_flags = flags | OPf_KIDS; logop->op_other = LINKLIST(other); @@ -2815,7 +3138,7 @@ newCONDOP(I32 flags, OP *first, OP *trueop, OP *falseop) Newz(1101, condop, 1, CONDOP); condop->op_type = OP_COND_EXPR; - condop->op_ppaddr = ppaddr[OP_COND_EXPR]; + condop->op_ppaddr = PL_ppaddr[OP_COND_EXPR]; condop->op_first = first; condop->op_flags = flags | OPf_KIDS; condop->op_true = LINKLIST(trueop); @@ -2848,7 +3171,7 @@ newRANGE(I32 flags, OP *left, OP *right) Newz(1101, condop, 1, CONDOP); condop->op_type = OP_RANGE; - condop->op_ppaddr = ppaddr[OP_RANGE]; + condop->op_ppaddr = PL_ppaddr[OP_RANGE]; condop->op_first = left; condop->op_flags = OPf_KIDS; condop->op_true = LINKLIST(left); @@ -3008,7 +3331,7 @@ newWHILEOP(I32 flags, I32 debuggable, LOOP *loop, I32 whileline, OP *expr, OP *b if (!loop) { Newz(1101,loop,1,LOOP); loop->op_type = OP_ENTERLOOP; - loop->op_ppaddr = ppaddr[OP_ENTERLOOP]; + loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP]; loop->op_private = 0; loop->op_next = (OP*)loop; } @@ -3039,7 +3362,7 @@ newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont if (sv) { if (sv->op_type == OP_RV2SV) { /* symbol table variable */ sv->op_type = OP_RV2GV; - sv->op_ppaddr = ppaddr[OP_RV2GV]; + sv->op_ppaddr = PL_ppaddr[OP_RV2GV]; } else if (sv->op_type == OP_PADSV) { /* private variable */ padoff = sv->op_targ; @@ -3053,7 +3376,7 @@ newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont sv = Nullop; } else - croak("Can't use %s for loop variable", op_desc[sv->op_type]); + croak("Can't use %s for loop variable", PL_op_desc[sv->op_type]); } else { #ifdef USE_THREADS @@ -3115,13 +3438,15 @@ newLOOPEX(I32 type, OP *label) { dTHR; OP *o; + STRLEN n_a; + if (type != OP_GOTO || label->op_type == OP_CONST) { /* "last()" means "last" */ if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS)) o = newOP(type, OPf_SPECIAL); else { o = newPVOP(type, 0, savepv(label->op_type == OP_CONST - ? SvPVx(((SVOP*)label)->op_sv, PL_na) + ? SvPVx(((SVOP*)label)->op_sv, n_a) : "")); } op_free(label); @@ -3211,7 +3536,7 @@ CV* cv; cv, (CvANON(cv) ? "ANON" : (cv == PL_main_cv) ? "MAIN" - : CvUNIQUE(outside) ? "UNIQUE" + : CvUNIQUE(cv) ? "UNIQUE" : CvGV(cv) ? GvNAME(CvGV(cv)) : "UNDEFINED"), outside, (!outside ? "null" @@ -3311,7 +3636,7 @@ cv_clone2(CV *proto, CV *outside) char *name = SvPVX(namesv); /* XXX */ if (SvFLAGS(namesv) & SVf_FAKE) { /* lexical from outside? */ I32 off = pad_findlex(name, ix, SvIVX(namesv), - CvOUTSIDE(cv), cxstack_ix); + CvOUTSIDE(cv), cxstack_ix, 0); if (!off) PL_curpad[ix] = SvREFCNT_inc(ppad[ix]); else if (off != ix) @@ -3375,7 +3700,11 @@ cv_clone2(CV *proto, CV *outside) CV * cv_clone(CV *proto) { - return cv_clone2(proto, CvOUTSIDE(proto)); + CV *cv; + MUTEX_LOCK(&PL_cred_mutex); /* XXX create separate mutex */ + cv = cv_clone2(proto, CvOUTSIDE(proto)); + MUTEX_UNLOCK(&PL_cred_mutex); /* XXX create separate mutex */ + return cv; } void @@ -3451,10 +3780,11 @@ CV * newSUB(I32 floor, OP *o, OP *proto, OP *block) { dTHR; - char *name = o ? SvPVx(cSVOPo->op_sv, PL_na) : Nullch; + STRLEN n_a; + char *name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch; GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI | (block ? 0 : GV_NOINIT), SVt_PVCV); - char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, PL_na) : Nullch; + char *ps = proto ? SvPVx(((SVOP*)proto)->op_sv, n_a) : Nullch; register CV *cv=0; I32 ix; @@ -3498,14 +3828,16 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block) croak("Can't redefine active sort subroutine %s", name); if(const_sv = cv_const_sv(cv)) const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv)); - if ((const_sv && const_changed) || PL_dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv)) + if ((const_sv && const_changed) || ckWARN(WARN_REDEFINE) + && !(CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))) && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) { line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = PL_copline; - warn(const_sv ? "Constant subroutine %s redefined" - : "Subroutine %s redefined", name); + warner(WARN_REDEFINE, + const_sv ? "Constant subroutine %s redefined" + : "Subroutine %s redefined", name); PL_curcop->cop_line = oldline; } SvREFCNT_dec(cv); @@ -3536,9 +3868,10 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block) CvSTASH(cv) = PL_curstash; #ifdef USE_THREADS CvOWNER(cv) = 0; - if (!CvMUTEXP(cv)) + if (!CvMUTEXP(cv)) { New(666, CvMUTEXP(cv), 1, perl_mutex); - MUTEX_INIT(CvMUTEXP(cv)); + MUTEX_INIT(CvMUTEXP(cv)); + } #endif /* USE_THREADS */ if (ps) @@ -3558,7 +3891,7 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block) else { /* force display of errors found but not reported */ sv_catpv(ERRSV, not_safe); - croak("%s", SvPVx(ERRSV, PL_na)); + croak("%s", SvPVx(ERRSV, n_a)); } } } @@ -3660,6 +3993,7 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block) call_list(oldscope, PL_beginav); PL_curcop = &PL_compiling; + PL_compiling.op_private = PL_hints; LEAVE; } else if (strEQ(s, "END") && !PL_error_count) { @@ -3683,6 +4017,7 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block) return cv; } +/* XXX unsafe for threads if eval_owner isn't held */ void newCONSTSUB(HV *stash, char *name, SV *sv) { @@ -3725,12 +4060,13 @@ newXS(char *name, void (*subaddr) (CV * _CPERLproto), char *filename) } else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) { /* already defined (or promised) */ - if (PL_dowarn && !(CvGV(cv) && GvSTASH(CvGV(cv)) + if (ckWARN(WARN_REDEFINE) && !(CvGV(cv) && GvSTASH(CvGV(cv)) && HvNAME(GvSTASH(CvGV(cv))) && strEQ(HvNAME(GvSTASH(CvGV(cv))), "autouse"))) { line_t oldline = PL_curcop->cop_line; - PL_curcop->cop_line = PL_copline; - warn("Subroutine %s redefined",name); + if (PL_copline != NOLINE) + PL_curcop->cop_line = PL_copline; + warner(WARN_REDEFINE, "Subroutine %s redefined",name); PL_curcop->cop_line = oldline; } SvREFCNT_dec(cv); @@ -3781,6 +4117,7 @@ newXS(char *name, void (*subaddr) (CV * _CPERLproto), char *filename) if (!PL_initav) PL_initav = newAV(); av_push(PL_initav, (SV *)cv); + GvCV(gv) = 0; } } else @@ -3797,19 +4134,20 @@ newFORM(I32 floor, OP *o, OP *block) char *name; GV *gv; I32 ix; + STRLEN n_a; if (o) - name = SvPVx(cSVOPo->op_sv, PL_na); + name = SvPVx(cSVOPo->op_sv, n_a); else name = "STDOUT"; gv = gv_fetchpv(name,TRUE, SVt_PVFM); GvMULTI_on(gv); if (cv = GvFORM(gv)) { - if (PL_dowarn) { + if (ckWARN(WARN_REDEFINE)) { line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = PL_copline; - warn("Format %s redefined",name); + warner(WARN_REDEFINE, "Format %s redefined",name); PL_curcop->cop_line = oldline; } SvREFCNT_dec(cv); @@ -3860,12 +4198,12 @@ oopsAV(OP *o) switch (o->op_type) { case OP_PADSV: o->op_type = OP_PADAV; - o->op_ppaddr = ppaddr[OP_PADAV]; - return ref(newUNOP(OP_RV2AV, 0, scalar(o)), OP_RV2AV); + o->op_ppaddr = PL_ppaddr[OP_PADAV]; + return ref(o, OP_RV2AV); case OP_RV2SV: o->op_type = OP_RV2AV; - o->op_ppaddr = ppaddr[OP_RV2AV]; + o->op_ppaddr = PL_ppaddr[OP_RV2AV]; ref(o, OP_RV2AV); break; @@ -3883,13 +4221,13 @@ oopsHV(OP *o) case OP_PADSV: case OP_PADAV: o->op_type = OP_PADHV; - o->op_ppaddr = ppaddr[OP_PADHV]; - return ref(newUNOP(OP_RV2HV, 0, scalar(o)), OP_RV2HV); + o->op_ppaddr = PL_ppaddr[OP_PADHV]; + return ref(o, OP_RV2HV); case OP_RV2SV: case OP_RV2AV: o->op_type = OP_RV2HV; - o->op_ppaddr = ppaddr[OP_RV2HV]; + o->op_ppaddr = PL_ppaddr[OP_RV2HV]; ref(o, OP_RV2HV); break; @@ -3905,7 +4243,7 @@ newAVREF(OP *o) { if (o->op_type == OP_PADANY) { o->op_type = OP_PADAV; - o->op_ppaddr = ppaddr[OP_PADAV]; + o->op_ppaddr = PL_ppaddr[OP_PADAV]; return o; } return newUNOP(OP_RV2AV, 0, scalar(o)); @@ -3924,7 +4262,7 @@ newHVREF(OP *o) { if (o->op_type == OP_PADANY) { o->op_type = OP_PADHV; - o->op_ppaddr = ppaddr[OP_PADHV]; + o->op_ppaddr = PL_ppaddr[OP_PADHV]; return o; } return newUNOP(OP_RV2HV, 0, scalar(o)); @@ -3949,7 +4287,7 @@ newSVREF(OP *o) { if (o->op_type == OP_PADANY) { o->op_type = OP_PADSV; - o->op_ppaddr = ppaddr[OP_PADSV]; + o->op_ppaddr = PL_ppaddr[OP_PADSV]; return o; } else if (o->op_type == OP_THREADSV && !(o->op_flags & OPpDONE_SVREF)) { @@ -4008,7 +4346,7 @@ ck_spair(OP *o) newop = kUNOP->op_first->op_sibling; if (newop && (newop->op_sibling || - !(opargs[newop->op_type] & OA_RETSCALAR) || + !(PL_opargs[newop->op_type] & OA_RETSCALAR) || newop->op_type == OP_PADAV || newop->op_type == OP_PADHV || newop->op_type == OP_RV2AV || newop->op_type == OP_RV2HV)) { @@ -4017,7 +4355,7 @@ ck_spair(OP *o) op_free(kUNOP->op_first); kUNOP->op_first = newop; } - o->op_ppaddr = ppaddr[++o->op_type]; + o->op_ppaddr = PL_ppaddr[++o->op_type]; return ck_fun(o); } @@ -4032,7 +4370,7 @@ ck_delete(OP *o) o->op_private |= OPpSLICE; else if (kid->op_type != OP_HELEM) croak("%s argument is not a HASH element or slice", - op_desc[o->op_type]); + PL_op_desc[o->op_type]); null(kid); } return o; @@ -4074,7 +4412,7 @@ ck_eval(OP *o) Newz(1101, enter, 1, LOGOP); enter->op_type = OP_ENTERTRY; - enter->op_ppaddr = ppaddr[OP_ENTERTRY]; + enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY]; enter->op_private = 0; /* establish postfix order */ @@ -4082,7 +4420,7 @@ ck_eval(OP *o) o = prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid); o->op_type = OP_LEAVETRY; - o->op_ppaddr = ppaddr[OP_LEAVETRY]; + o->op_ppaddr = PL_ppaddr[OP_LEAVETRY]; enter->op_other = o; return o; } @@ -4119,12 +4457,13 @@ ck_exists(OP *o) if (o->op_flags & OPf_KIDS) { OP *kid = cUNOPo->op_first; if (kid->op_type != OP_HELEM) - croak("%s argument is not a HASH element", op_desc[o->op_type]); + croak("%s argument is not a HASH element", PL_op_desc[o->op_type]); null(kid); } return o; } +#if 0 OP * ck_gvconst(register OP *o) { @@ -4133,6 +4472,7 @@ ck_gvconst(register OP *o) o->op_type = OP_GV; return o; } +#endif OP * ck_rvconst(register OP *o) @@ -4145,8 +4485,47 @@ ck_rvconst(register OP *o) char *name; int iscv; GV *gv; + SV *kidsv = kid->op_sv; + STRLEN n_a; - name = SvPV(kid->op_sv, PL_na); + /* Is it a constant from cv_const_sv()? */ + if (SvROK(kidsv) && SvREADONLY(kidsv)) { + SV *rsv = SvRV(kidsv); + int svtype = SvTYPE(rsv); + char *badtype = Nullch; + + switch (o->op_type) { + case OP_RV2SV: + if (svtype > SVt_PVMG) + badtype = "a SCALAR"; + break; + case OP_RV2AV: + if (svtype != SVt_PVAV) + badtype = "an ARRAY"; + break; + case OP_RV2HV: + if (svtype != SVt_PVHV) { + if (svtype == SVt_PVAV) { /* pseudohash? */ + SV **ksv = av_fetch((AV*)rsv, 0, FALSE); + if (ksv && SvROK(*ksv) + && SvTYPE(SvRV(*ksv)) == SVt_PVHV) + { + break; + } + } + badtype = "a HASH"; + } + break; + case OP_RV2CV: + if (svtype != SVt_PVCV) + badtype = "a CODE"; + break; + } + if (badtype) + croak("Constant is not %s reference", badtype); + return o; + } + name = SvPV(kidsv, n_a); if ((PL_hints & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) { char *badthing = Nullch; switch (o->op_type) { @@ -4209,8 +4588,9 @@ ck_ftst(OP *o) SVOP *kid = (SVOP*)cUNOPo->op_first; if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) { + STRLEN n_a; OP *newop = newGVOP(type, OPf_REF, - gv_fetchpv(SvPVx(kid->op_sv, PL_na), TRUE, SVt_PVIO)); + gv_fetchpv(SvPVx(kid->op_sv, n_a), TRUE, SVt_PVIO)); op_free(o); return newop; } @@ -4235,7 +4615,7 @@ ck_fun(OP *o) OP *sibl; I32 numargs = 0; int type = o->op_type; - register I32 oa = opargs[type] >> OASHIFT; + register I32 oa = PL_opargs[type] >> OASHIFT; if (o->op_flags & OPf_STACKED) { if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL)) @@ -4245,6 +4625,7 @@ ck_fun(OP *o) } if (o->op_flags & OPf_KIDS) { + STRLEN n_a; tokid = &cLISTOPo->op_first; kid = cLISTOPo->op_first; if (kid->op_type == OP_PUSHMARK || @@ -4253,7 +4634,7 @@ ck_fun(OP *o) tokid = &kid->op_sibling; kid = kid->op_sibling; } - if (!kid && opargs[type] & OA_DEFGV) + if (!kid && PL_opargs[type] & OA_DEFGV) *tokid = kid = newDEFSVOP(); while (oa && kid) { @@ -4274,37 +4655,39 @@ ck_fun(OP *o) case OA_AVREF: if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) { - char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na); + char *name = SvPVx(((SVOP*)kid)->op_sv, n_a); OP *newop = newAVREF(newGVOP(OP_GV, 0, gv_fetchpv(name, TRUE, SVt_PVAV) )); - if (PL_dowarn) - warn("Array @%s missing the @ in argument %ld of %s()", - name, (long)numargs, op_desc[type]); + if (ckWARN(WARN_SYNTAX)) + warner(WARN_SYNTAX, + "Array @%s missing the @ in argument %ld of %s()", + name, (long)numargs, PL_op_desc[type]); op_free(kid); kid = newop; kid->op_sibling = sibl; *tokid = kid; } else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV) - bad_type(numargs, "array", op_desc[o->op_type], kid); + bad_type(numargs, "array", PL_op_desc[o->op_type], kid); mod(kid, type); break; case OA_HVREF: if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) { - char *name = SvPVx(((SVOP*)kid)->op_sv, PL_na); + char *name = SvPVx(((SVOP*)kid)->op_sv, n_a); OP *newop = newHVREF(newGVOP(OP_GV, 0, gv_fetchpv(name, TRUE, SVt_PVHV) )); - if (PL_dowarn) - warn("Hash %%%s missing the %% in argument %ld of %s()", - name, (long)numargs, op_desc[type]); + if (ckWARN(WARN_SYNTAX)) + warner(WARN_SYNTAX, + "Hash %%%s missing the %% in argument %ld of %s()", + name, (long)numargs, PL_op_desc[type]); op_free(kid); kid = newop; kid->op_sibling = sibl; *tokid = kid; } else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV) - bad_type(numargs, "hash", op_desc[o->op_type], kid); + bad_type(numargs, "hash", PL_op_desc[o->op_type], kid); mod(kid, type); break; case OA_CVREF: @@ -4323,11 +4706,15 @@ ck_fun(OP *o) if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) { OP *newop = newGVOP(OP_GV, 0, - gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, PL_na), TRUE, + gv_fetchpv(SvPVx(((SVOP*)kid)->op_sv, n_a), TRUE, SVt_PVIO) ); op_free(kid); kid = newop; } + else if (kid->op_type == OP_READLINE) { + /* neophyte patrol: open(), close() etc. */ + bad_type(numargs, "HANDLE", PL_op_desc[o->op_type], kid); + } else { kid->op_sibling = 0; kid = newUNOP(OP_RV2GV, 0, scalar(kid)); @@ -4347,10 +4734,10 @@ ck_fun(OP *o) } o->op_private |= numargs; if (kid) - return too_many_arguments(o,op_desc[o->op_type]); + return too_many_arguments(o,PL_op_desc[o->op_type]); listkids(o); } - else if (opargs[type] & OA_DEFGV) { + else if (PL_opargs[type] & OA_DEFGV) { op_free(o); return newUNOP(type, 0, newDEFSVOP()); } @@ -4359,7 +4746,7 @@ ck_fun(OP *o) while (oa & OA_OPTIONAL) oa >>= 4; if (oa && oa != OA_LIST) - return too_few_arguments(o,op_desc[o->op_type]); + return too_few_arguments(o,PL_op_desc[o->op_type]); } return o; } @@ -4381,9 +4768,9 @@ ck_glob(OP *o) append_elem(OP_GLOB, o, newSVOP(OP_CONST, 0, newSViv(glob_index++))); o->op_type = OP_LIST; - o->op_ppaddr = ppaddr[OP_LIST]; + o->op_ppaddr = PL_ppaddr[OP_LIST]; cLISTOPo->op_first->op_type = OP_PUSHMARK; - cLISTOPo->op_first->op_ppaddr = ppaddr[OP_PUSHMARK]; + cLISTOPo->op_first->op_ppaddr = PL_ppaddr[OP_PUSHMARK]; o = newUNOP(OP_ENTERSUB, OPf_STACKED, append_elem(OP_LIST, o, scalar(newUNOP(OP_RV2CV, 0, @@ -4406,7 +4793,7 @@ ck_grep(OP *o) OP *kid; OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE; - o->op_ppaddr = ppaddr[OP_GREPSTART]; + o->op_ppaddr = PL_ppaddr[OP_GREPSTART]; Newz(1101, gwop, 1, LOGOP); if (o->op_flags & OPf_STACKED) { @@ -4433,7 +4820,7 @@ ck_grep(OP *o) kid = kUNOP->op_first; gwop->op_type = type; - gwop->op_ppaddr = ppaddr[type]; + gwop->op_ppaddr = PL_ppaddr[type]; gwop->op_first = listkids(o); gwop->op_flags |= OPf_KIDS; gwop->op_private = 1; @@ -4443,7 +4830,7 @@ ck_grep(OP *o) kid = cLISTOPo->op_first->op_sibling; if (!kid || !kid->op_sibling) - return too_few_arguments(o,op_desc[o->op_type]); + return too_few_arguments(o,PL_op_desc[o->op_type]); for (kid = kid->op_sibling; kid; kid = kid->op_sibling) mod(kid, OP_GREPSTART); @@ -4594,6 +4981,7 @@ ck_require(OP *o) return ck_fun(o); } +#if 0 OP * ck_retarget(OP *o) { @@ -4601,6 +4989,7 @@ ck_retarget(OP *o) /* STUB */ return o; } +#endif OP * ck_select(OP *o) @@ -4610,7 +4999,7 @@ ck_select(OP *o) kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ if (kid && kid->op_sibling) { o->op_type = OP_SSELECT; - o->op_ppaddr = ppaddr[OP_SSELECT]; + o->op_ppaddr = PL_ppaddr[OP_SSELECT]; o = ck_fun(o); return fold_constants(o); } @@ -4660,7 +5049,9 @@ ck_sort(OP *o) o->op_private |= OPpLOCALE; #endif - if (o->op_flags & OPf_STACKED) { + if (o->op_flags & OPf_STACKED) + simplify_sort(o); + if (o->op_flags & OPf_STACKED) { /* may have been cleared */ OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ OP *k; kid = kUNOP->op_first; /* get past rv2gv */ @@ -4695,11 +5086,72 @@ ck_sort(OP *o) kid->op_next = k; o->op_flags |= OPf_SPECIAL; } + else if (kid->op_type == OP_RV2SV || kid->op_type == OP_PADSV) + null(cLISTOPo->op_first->op_sibling); } return o; } +STATIC void +simplify_sort(OP *o) +{ + register OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ + OP *k; + int reversed; + if (!(o->op_flags & OPf_STACKED)) + return; + kid = kUNOP->op_first; /* get past rv2gv */ + if (kid->op_type != OP_SCOPE) + return; + kid = kLISTOP->op_last; /* get past scope */ + switch(kid->op_type) { + case OP_NCMP: + case OP_I_NCMP: + case OP_SCMP: + break; + default: + return; + } + k = kid; /* remember this node*/ + if (kBINOP->op_first->op_type != OP_RV2SV) + return; + kid = kBINOP->op_first; /* get past cmp */ + if (kUNOP->op_first->op_type != OP_GV) + return; + kid = kUNOP->op_first; /* get past rv2sv */ + if (GvSTASH(kGVOP->op_gv) != PL_curstash) + return; + if (strEQ(GvNAME(kGVOP->op_gv), "a")) + reversed = 0; + else if(strEQ(GvNAME(kGVOP->op_gv), "b")) + reversed = 1; + else + return; + kid = k; /* back to cmp */ + if (kBINOP->op_last->op_type != OP_RV2SV) + return; + kid = kBINOP->op_last; /* down to 2nd arg */ + if (kUNOP->op_first->op_type != OP_GV) + return; + kid = kUNOP->op_first; /* get past rv2sv */ + if (GvSTASH(kGVOP->op_gv) != PL_curstash + || ( reversed + ? strNE(GvNAME(kGVOP->op_gv), "a") + : strNE(GvNAME(kGVOP->op_gv), "b"))) + return; + o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL); + if (reversed) + o->op_private |= OPpSORT_REVERSE; + if (k->op_type == OP_NCMP) + o->op_private |= OPpSORT_NUMERIC; + if (k->op_type == OP_I_NCMP) + o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER; + op_free(cLISTOPo->op_first->op_sibling); /* delete comparison block */ + cLISTOPo->op_first->op_sibling = cLISTOPo->op_last; + cLISTOPo->op_children = 1; +} + OP * ck_split(OP *o) { @@ -4730,7 +5182,7 @@ ck_split(OP *o) } kid->op_type = OP_PUSHRE; - kid->op_ppaddr = ppaddr[OP_PUSHRE]; + kid->op_ppaddr = PL_ppaddr[OP_PUSHRE]; scalar(kid); if (!kid->op_sibling) @@ -4746,7 +5198,7 @@ ck_split(OP *o) scalar(kid); if (kid->op_sibling) - return too_many_arguments(o,op_desc[o->op_type]); + return too_many_arguments(o,PL_op_desc[o->op_type]); return o; } @@ -4764,6 +5216,7 @@ ck_subr(OP *o) GV *namegv = 0; int optional = 0; I32 arg = 0; + STRLEN n_a; for (cvop = o2; cvop->op_sibling; cvop = cvop->op_sibling) ; if (cvop->op_type == OP_RV2CV) { @@ -4775,7 +5228,7 @@ ck_subr(OP *o) cv = GvCVu(tmpop->op_sv); if (cv && SvPOK(cv) && !(o->op_private & OPpENTERSUB_AMPER)) { namegv = CvANON(cv) ? (GV*)tmpop->op_sv : CvGV(cv); - proto = SvPV((SV*)cv, PL_na); + proto = SvPV((SV*)cv, n_a); } } } @@ -4867,7 +5320,7 @@ ck_subr(OP *o) default: oops: croak("Malformed prototype for %s: %s", - gv_ename(namegv), SvPV((SV*)cv, PL_na)); + gv_ename(namegv), SvPV((SV*)cv, n_a)); } } else @@ -4911,6 +5364,8 @@ peep(register OP *o) { dTHR; register OP* oldop = 0; + STRLEN n_a; + if (!o || o->op_seq) return; ENTER; @@ -4969,7 +5424,7 @@ peep(register OP *o) o->op_private |= o->op_next->op_private & OPpLVAL_INTRO; o->op_next = o->op_next->op_next; o->op_type = OP_GVSV; - o->op_ppaddr = ppaddr[OP_GVSV]; + o->op_ppaddr = PL_ppaddr[OP_GVSV]; } } else if (o->op_next->op_type == OP_RV2AV) { @@ -4991,7 +5446,7 @@ peep(register OP *o) o->op_flags |= pop->op_next->op_flags & OPf_MOD; o->op_next = pop->op_next->op_next; o->op_type = OP_AELEMFAST; - o->op_ppaddr = ppaddr[OP_AELEMFAST]; + o->op_ppaddr = PL_ppaddr[OP_AELEMFAST]; o->op_private = (U8)i; GvAVn(((GVOP*)o)->op_gv); } @@ -4999,24 +5454,6 @@ peep(register OP *o) o->op_seq = PL_op_seqmax++; break; - case OP_PADAV: - if (o->op_next->op_type == OP_RV2AV - && (o->op_next->op_flags & OPf_REF)) - { - null(o->op_next); - o->op_next = o->op_next->op_next; - } - break; - - case OP_PADHV: - if (o->op_next->op_type == OP_RV2HV - && (o->op_next->op_flags & OPf_REF)) - { - null(o->op_next); - o->op_next = o->op_next->op_next; - } - break; - case OP_MAPWHILE: case OP_GREPWHILE: case OP_AND: @@ -5049,7 +5486,8 @@ peep(register OP *o) case OP_EXEC: o->op_seq = PL_op_seqmax++; - if (PL_dowarn && o->op_next && o->op_next->op_type == OP_NEXTSTATE) { + if (ckWARN(WARN_SYNTAX) && o->op_next + && o->op_next->op_type == OP_NEXTSTATE) { if (o->op_next->op_sibling && o->op_next->op_sibling->op_type != OP_EXIT && o->op_next->op_sibling->op_type != OP_WARN && @@ -5057,8 +5495,8 @@ peep(register OP *o) line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = ((COP*)o->op_next)->cop_line; - warn("Statement unlikely to be reached"); - warn("(Maybe you meant system() when you said exec()?)\n"); + warner(WARN_SYNTAX, "Statement unlikely to be reached"); + warner(WARN_SYNTAX, "(Maybe you meant system() when you said exec()?)\n"); PL_curcop->cop_line = oldline; } } @@ -5090,15 +5528,15 @@ peep(register OP *o) indsvp = hv_fetch(GvHV(*fields), key, keylen, FALSE); if (!indsvp) { croak("No such field \"%s\" in variable %s of type %s", - key, SvPV(lexname, PL_na), HvNAME(SvSTASH(lexname))); + key, SvPV(lexname, n_a), HvNAME(SvSTASH(lexname))); } ind = SvIV(*indsvp); if (ind < 1) croak("Bad index while coercing array into hash"); rop->op_type = OP_RV2AV; - rop->op_ppaddr = ppaddr[OP_RV2AV]; + rop->op_ppaddr = PL_ppaddr[OP_RV2AV]; o->op_type = OP_AELEM; - o->op_ppaddr = ppaddr[OP_AELEM]; + o->op_ppaddr = PL_ppaddr[OP_AELEM]; SvREFCNT_dec(*svp); *svp = newSViv(ind); break;