3 * Copyright (c) 1996 Malcolm Beattie
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.
10 #define PERL_NO_GET_CONTEXT
17 typedef PerlIO * InputStream;
19 typedef FILE * InputStream;
23 static const char* const svclassnames[] = {
30 #if PERL_VERSION <= 10
34 #if PERL_VERSION >= 19
40 #if PERL_VERSION >= 11
69 static const char* const opclassnames[] = {
86 static const size_t opsizes[] = {
103 #define MY_CXT_KEY "B::_guts" XS_VERSION
106 SV * x_specialsv_list[7];
107 int x_walkoptree_debug; /* Flag for walkoptree debug hook */
112 #define walkoptree_debug (MY_CXT.x_walkoptree_debug)
113 #define specialsv_list (MY_CXT.x_specialsv_list)
116 static void B_init_my_cxt(pTHX_ my_cxt_t * cxt) {
117 cxt->x_specialsv_list[0] = Nullsv;
118 cxt->x_specialsv_list[1] = &PL_sv_undef;
119 cxt->x_specialsv_list[2] = &PL_sv_yes;
120 cxt->x_specialsv_list[3] = &PL_sv_no;
121 cxt->x_specialsv_list[4] = (SV *) pWARN_ALL;
122 cxt->x_specialsv_list[5] = (SV *) pWARN_NONE;
123 cxt->x_specialsv_list[6] = (SV *) pWARN_STD;
127 cc_opclass(pTHX_ const OP *o)
134 if (o->op_type == 0) {
135 if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE)
137 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
140 if (o->op_type == OP_SASSIGN)
141 return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP);
143 if (o->op_type == OP_AELEMFAST) {
144 #if PERL_VERSION <= 14
145 if (o->op_flags & OPf_SPECIAL)
157 if (o->op_type == OP_GV || o->op_type == OP_GVSV ||
158 o->op_type == OP_RCATLINE)
162 if (o->op_type == OP_CUSTOM)
165 switch (OP_CLASS(o)) {
190 case OA_PVOP_OR_SVOP:
192 * Character translations (tr///) are usually a PVOP, keeping a
193 * pointer to a table of shorts used to look up translations.
194 * Under utf8, however, a simple table isn't practical; instead,
195 * the OP is an SVOP (or, under threads, a PADOP),
196 * and the SV is a reference to a swash
197 * (i.e., an RV pointing to an HV).
200 (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
202 #if defined(USE_ITHREADS)
203 ? OPc_PADOP : OPc_PVOP;
205 ? OPc_SVOP : OPc_PVOP;
214 case OA_BASEOP_OR_UNOP:
216 * UNI(OP_foo) in toke.c returns token UNI or FUNC1 depending on
217 * whether parens were seen. perly.y uses OPf_SPECIAL to
218 * signal whether a BASEOP had empty parens or none.
219 * Some other UNOPs are created later, though, so the best
220 * test is OPf_KIDS, which is set in newUNOP.
222 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
226 * The file stat OPs are created via UNI(OP_foo) in toke.c but use
227 * the OPf_REF flag to distinguish between OP types instead of the
228 * usual OPf_SPECIAL flag. As usual, if OPf_KIDS is set, then we
229 * return OPc_UNOP so that walkoptree can find our children. If
230 * OPf_KIDS is not set then we check OPf_REF. Without OPf_REF set
231 * (no argument to the operator) it's an OP; with OPf_REF set it's
232 * an SVOP (and op_sv is the GV for the filehandle argument).
234 return ((o->op_flags & OPf_KIDS) ? OPc_UNOP :
236 (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP);
238 (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP);
242 * next, last, redo, dump and goto use OPf_SPECIAL to indicate that a
243 * label was omitted (in which case it's a BASEOP) or else a term was
244 * seen. In this last case, all except goto are definitely PVOP but
245 * goto is either a PVOP (with an ordinary constant label), an UNOP
246 * with OPf_STACKED (with a non-constant non-sub) or an UNOP for
247 * OP_REFGEN (with goto &sub) in which case OPf_STACKED also seems to
250 if (o->op_flags & OPf_STACKED)
252 else if (o->op_flags & OPf_SPECIAL)
261 warn("can't determine class of operator %s, assuming BASEOP\n",
267 make_op_object(pTHX_ const OP *o)
269 SV *opsv = sv_newmortal();
270 sv_setiv(newSVrv(opsv, opclassnames[cc_opclass(aTHX_ o)]), PTR2IV(o));
276 get_overlay_object(pTHX_ const OP *o, const char * const name, U32 namelen)
281 SV *sv =get_sv("B::overlay", 0);
282 if (!sv || !SvROK(sv))
285 if (SvTYPE(sv) != SVt_PVHV)
287 key = newSViv(PTR2IV(o));
288 he = hv_fetch_ent((HV*)sv, key, 0, 0);
293 if (!sv || !SvROK(sv))
296 if (SvTYPE(sv) != SVt_PVHV)
298 svp = hv_fetch((HV*)sv, name, namelen, 0);
307 make_sv_object(pTHX_ SV *sv)
309 SV *const arg = sv_newmortal();
310 const char *type = 0;
314 for (iv = 0; iv < (IV)(sizeof(specialsv_list)/sizeof(SV*)); iv++) {
315 if (sv == specialsv_list[iv]) {
321 type = svclassnames[SvTYPE(sv)];
324 sv_setiv(newSVrv(arg, type), iv);
329 make_temp_object(pTHX_ SV *temp)
332 SV *arg = sv_newmortal();
333 const char *const type = svclassnames[SvTYPE(temp)];
334 const IV iv = PTR2IV(temp);
336 target = newSVrv(arg, type);
337 sv_setiv(target, iv);
339 /* Need to keep our "temp" around as long as the target exists.
340 Simplest way seems to be to hang it from magic, and let that clear
341 it up. No vtable, so won't actually get in the way of anything. */
342 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
343 /* magic object has had its reference count increased, so we must drop
350 make_warnings_object(pTHX_ const COP *const cop)
352 const STRLEN *const warnings = cop->cop_warnings;
353 const char *type = 0;
355 IV iv = sizeof(specialsv_list)/sizeof(SV*);
357 /* Counting down is deliberate. Before the split between make_sv_object
358 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
359 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
362 if ((SV*)warnings == specialsv_list[iv]) {
368 SV *arg = sv_newmortal();
369 sv_setiv(newSVrv(arg, type), iv);
372 /* B assumes that warnings are a regular SV. Seems easier to keep it
373 happy by making them into a regular SV. */
374 return make_temp_object(aTHX_ newSVpvn((char *)(warnings + 1), *warnings));
379 make_cop_io_object(pTHX_ COP *cop)
381 SV *const value = newSV(0);
383 Perl_emulate_cop_io(aTHX_ cop, value);
386 return make_sv_object(aTHX_ value);
389 return make_sv_object(aTHX_ NULL);
394 make_mg_object(pTHX_ MAGIC *mg)
396 SV *arg = sv_newmortal();
397 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
402 cstring(pTHX_ SV *sv, bool perlstyle)
407 return newSVpvs_flags("0", SVs_TEMP);
409 sstr = newSVpvs_flags("\"", SVs_TEMP);
411 if (perlstyle && SvUTF8(sv)) {
412 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
413 const STRLEN len = SvCUR(sv);
414 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
418 sv_catpvs(sstr, "\\\"");
420 sv_catpvs(sstr, "\\$");
422 sv_catpvs(sstr, "\\@");
425 if (strchr("nrftax\\",*(s+1)))
426 sv_catpvn(sstr, s++, 2);
428 sv_catpvs(sstr, "\\\\");
430 else /* should always be printable */
431 sv_catpvn(sstr, s, 1);
439 const char *s = SvPV(sv, len);
440 for (; len; len--, s++)
442 /* At least try a little for readability */
444 sv_catpvs(sstr, "\\\"");
446 sv_catpvs(sstr, "\\\\");
447 /* trigraphs - bleagh */
448 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
449 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", '?');
451 else if (perlstyle && *s == '$')
452 sv_catpvs(sstr, "\\$");
453 else if (perlstyle && *s == '@')
454 sv_catpvs(sstr, "\\@");
455 else if (isPRINT(*s))
456 sv_catpvn(sstr, s, 1);
458 sv_catpvs(sstr, "\\n");
460 sv_catpvs(sstr, "\\r");
462 sv_catpvs(sstr, "\\t");
464 sv_catpvs(sstr, "\\a");
466 sv_catpvs(sstr, "\\b");
468 sv_catpvs(sstr, "\\f");
469 else if (!perlstyle && *s == '\v')
470 sv_catpvs(sstr, "\\v");
473 /* Don't want promotion of a signed -1 char in sprintf args */
474 const unsigned char c = (unsigned char) *s;
475 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
477 /* XXX Add line breaks if string is long */
480 sv_catpvs(sstr, "\"");
487 SV *sstr = newSVpvs_flags("'", SVs_TEMP);
488 const char *s = SvPV_nolen(sv);
489 /* Don't want promotion of a signed -1 char in sprintf args */
490 const unsigned char c = (unsigned char) *s;
493 sv_catpvs(sstr, "\\'");
495 sv_catpvs(sstr, "\\\\");
497 sv_catpvn(sstr, s, 1);
499 sv_catpvs(sstr, "\\n");
501 sv_catpvs(sstr, "\\r");
503 sv_catpvs(sstr, "\\t");
505 sv_catpvs(sstr, "\\a");
507 sv_catpvs(sstr, "\\b");
509 sv_catpvs(sstr, "\\f");
511 sv_catpvs(sstr, "\\v");
513 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
514 sv_catpvs(sstr, "'");
518 #define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
519 #define PMOP_pmreplroot(o) o->op_pmreplrootu.op_pmreplroot
522 walkoptree(pTHX_ OP *o, const char *method, SV *ref)
527 const char *const classname = opclassnames[cc_opclass(aTHX_ o)];
530 /* Check that no-one has changed our reference, or is holding a reference
532 if (SvREFCNT(ref) == 1 && SvROK(ref) && SvTYPE(ref) == SVt_RV
533 && (object = SvRV(ref)) && SvREFCNT(object) == 1
534 && SvTYPE(object) == SVt_PVMG && SvIOK_only(object)
535 && !SvMAGICAL(object) && !SvMAGIC(object) && SvSTASH(object)) {
536 /* Looks good, so rebless it for the class we need: */
537 sv_bless(ref, gv_stashpv(classname, GV_ADD));
539 /* Need to make a new one. */
540 ref = sv_newmortal();
541 object = newSVrv(ref, classname);
543 sv_setiv(object, PTR2IV(o));
545 if (walkoptree_debug) {
549 perl_call_method("walkoptree_debug", G_DISCARD);
554 perl_call_method(method, G_DISCARD);
555 if (o && (o->op_flags & OPf_KIDS)) {
556 for (kid = ((UNOP*)o)->op_first; kid; kid = OpSIBLING(kid)) {
557 ref = walkoptree(aTHX_ kid, method, ref);
560 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
561 && (kid = PMOP_pmreplroot(cPMOPo)))
563 ref = walkoptree(aTHX_ kid, method, ref);
569 oplist(pTHX_ OP *o, SV **SP)
571 for(; o; o = o->op_next) {
575 XPUSHs(make_op_object(aTHX_ o));
576 switch (o->op_type) {
578 SP = oplist(aTHX_ PMOP_pmreplstart(cPMOPo), SP);
581 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
582 OP *kid = OpSIBLING(cLISTOPo->op_first); /* pass pushmark */
583 kid = kUNOP->op_first; /* pass rv2gv */
584 kid = kUNOP->op_first; /* pass leave */
585 SP = oplist(aTHX_ kid->op_next, SP);
589 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
591 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
594 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
595 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
596 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
604 typedef UNOP *B__UNOP;
605 typedef BINOP *B__BINOP;
606 typedef LOGOP *B__LOGOP;
607 typedef LISTOP *B__LISTOP;
608 typedef PMOP *B__PMOP;
609 typedef SVOP *B__SVOP;
610 typedef PADOP *B__PADOP;
611 typedef PVOP *B__PVOP;
612 typedef LOOP *B__LOOP;
614 typedef METHOP *B__METHOP;
621 #if PERL_VERSION >= 11
622 typedef SV *B__REGEXP;
634 typedef MAGIC *B__MAGIC;
636 typedef struct refcounted_he *B__RHE;
638 typedef PADLIST *B__PADLIST;
640 typedef PADNAMELIST *B__PADNAMELIST;
641 typedef PADNAME *B__PADNAME;
645 # define ASSIGN_COMMON_ALIAS(prefix, var) \
646 STMT_START { XSANY.any_i32 = STRUCT_OFFSET(struct interpreter, prefix##var); } STMT_END
648 # define ASSIGN_COMMON_ALIAS(prefix, var) \
649 STMT_START { XSANY.any_ptr = (void *)&PL_##var; } STMT_END
652 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
654 static XSPROTO(intrpvar_sv_common); /* prototype to pass -Wmissing-prototypes */
655 static XSPROTO(intrpvar_sv_common)
661 croak_xs_usage(cv, "");
663 ret = *(SV **)(XSANY.any_i32 + (char *)my_perl);
665 ret = *(SV **)(XSANY.any_ptr);
667 ST(0) = make_sv_object(aTHX_ ret);
677 #define PADOFFSETp 0x4
681 /* Keep this last: */
682 #define op_offset_special 0x8
684 /* table that drives most of the B::*OP methods */
686 const struct OP_methods {
689 U8 type; /* if op_offset_special, access is handled on a case-by-case basis */
692 { STR_WITH_LEN("next"), OPp, STRUCT_OFFSET(struct op, op_next), },/* 0*/
693 { STR_WITH_LEN("sibling"), op_offset_special, 0, },/* 1*/
694 { STR_WITH_LEN("targ"), PADOFFSETp, STRUCT_OFFSET(struct op, op_targ), },/* 2*/
695 { STR_WITH_LEN("flags"), U8p, STRUCT_OFFSET(struct op, op_flags), },/* 3*/
696 { STR_WITH_LEN("private"), U8p, STRUCT_OFFSET(struct op, op_private), },/* 4*/
697 { STR_WITH_LEN("first"), OPp, STRUCT_OFFSET(struct unop, op_first), },/* 5*/
698 { STR_WITH_LEN("last"), OPp, STRUCT_OFFSET(struct binop, op_last), },/* 6*/
699 { STR_WITH_LEN("other"), OPp, STRUCT_OFFSET(struct logop, op_other), },/* 7*/
700 { STR_WITH_LEN("pmreplstart"), op_offset_special, 0, },/* 8*/
701 { STR_WITH_LEN("redoop"), OPp, STRUCT_OFFSET(struct loop, op_redoop), },/* 9*/
702 { STR_WITH_LEN("nextop"), OPp, STRUCT_OFFSET(struct loop, op_nextop), },/*10*/
703 { STR_WITH_LEN("lastop"), OPp, STRUCT_OFFSET(struct loop, op_lastop), },/*11*/
704 { STR_WITH_LEN("pmflags"), U32p, STRUCT_OFFSET(struct pmop, op_pmflags),},/*12*/
705 #if PERL_VERSION >= 17
706 { STR_WITH_LEN("code_list"),OPp, STRUCT_OFFSET(struct pmop, op_code_list),},/*13*/
708 { STR_WITH_LEN("code_list"),op_offset_special, 0, }, /*13*/
710 { STR_WITH_LEN("sv"), SVp, STRUCT_OFFSET(struct svop, op_sv), },/*14*/
711 { STR_WITH_LEN("gv"), SVp, STRUCT_OFFSET(struct svop, op_sv), },/*15*/
712 { STR_WITH_LEN("padix"), PADOFFSETp,STRUCT_OFFSET(struct padop, op_padix),},/*16*/
713 { STR_WITH_LEN("cop_seq"), U32p, STRUCT_OFFSET(struct cop, cop_seq), },/*17*/
714 { STR_WITH_LEN("line"), line_tp, STRUCT_OFFSET(struct cop, cop_line), },/*18*/
715 { STR_WITH_LEN("hints"), U32p, STRUCT_OFFSET(struct cop, cop_hints), },/*19*/
717 { STR_WITH_LEN("pmoffset"),IVp, STRUCT_OFFSET(struct pmop, op_pmoffset),},/*20*/
718 { STR_WITH_LEN("filegv"), op_offset_special, 0, },/*21*/
719 { STR_WITH_LEN("file"), char_pp, STRUCT_OFFSET(struct cop, cop_file), },/*22*/
720 { STR_WITH_LEN("stash"), op_offset_special, 0, },/*23*/
721 # if PERL_VERSION < 17
722 { STR_WITH_LEN("stashpv"), char_pp, STRUCT_OFFSET(struct cop, cop_stashpv),}, /*24*/
723 { STR_WITH_LEN("stashoff"),op_offset_special, 0, },/*25*/
725 { STR_WITH_LEN("stashpv"), op_offset_special, 0, },/*24*/
726 { STR_WITH_LEN("stashoff"),PADOFFSETp,STRUCT_OFFSET(struct cop,cop_stashoff),},/*25*/
729 { STR_WITH_LEN("pmoffset"),op_offset_special, 0, },/*20*/
730 { STR_WITH_LEN("filegv"), SVp, STRUCT_OFFSET(struct cop, cop_filegv),},/*21*/
731 { STR_WITH_LEN("file"), op_offset_special, 0, },/*22*/
732 { STR_WITH_LEN("stash"), SVp, STRUCT_OFFSET(struct cop, cop_stash), },/*23*/
733 { STR_WITH_LEN("stashpv"), op_offset_special, 0, },/*24*/
734 { STR_WITH_LEN("stashoff"),op_offset_special, 0, },/*25*/
736 { STR_WITH_LEN("size"), op_offset_special, 0, },/*26*/
737 { STR_WITH_LEN("name"), op_offset_special, 0, },/*27*/
738 { STR_WITH_LEN("desc"), op_offset_special, 0, },/*28*/
739 { STR_WITH_LEN("ppaddr"), op_offset_special, 0, },/*29*/
740 { STR_WITH_LEN("type"), op_offset_special, 0, },/*30*/
741 { STR_WITH_LEN("opt"), op_offset_special, 0, },/*31*/
742 { STR_WITH_LEN("spare"), op_offset_special, 0, },/*32*/
743 { STR_WITH_LEN("children"),op_offset_special, 0, },/*33*/
744 { STR_WITH_LEN("pmreplroot"), op_offset_special, 0, },/*34*/
745 { STR_WITH_LEN("pmstashpv"), op_offset_special, 0, },/*35*/
746 { STR_WITH_LEN("pmstash"), op_offset_special, 0, },/*36*/
747 { STR_WITH_LEN("precomp"), op_offset_special, 0, },/*37*/
748 { STR_WITH_LEN("reflags"), op_offset_special, 0, },/*38*/
749 { STR_WITH_LEN("sv"), op_offset_special, 0, },/*39*/
750 { STR_WITH_LEN("gv"), op_offset_special, 0, },/*40*/
751 { STR_WITH_LEN("pv"), op_offset_special, 0, },/*41*/
752 { STR_WITH_LEN("label"), op_offset_special, 0, },/*42*/
753 { STR_WITH_LEN("arybase"), op_offset_special, 0, },/*43*/
754 { STR_WITH_LEN("warnings"),op_offset_special, 0, },/*44*/
755 { STR_WITH_LEN("io"), op_offset_special, 0, },/*45*/
756 { STR_WITH_LEN("hints_hash"),op_offset_special, 0, },/*46*/
757 #if PERL_VERSION >= 17
758 { STR_WITH_LEN("slabbed"), op_offset_special, 0, },/*47*/
759 { STR_WITH_LEN("savefree"),op_offset_special, 0, },/*48*/
760 { STR_WITH_LEN("static"), op_offset_special, 0, },/*49*/
761 # if PERL_VERSION >= 19
762 { STR_WITH_LEN("folded"), op_offset_special, 0, },/*50*/
763 { STR_WITH_LEN("moresib"), op_offset_special, 0, },/*51*/
764 { STR_WITH_LEN("parent"), op_offset_special, 0, },/*52*/
767 #if PERL_VERSION >= 21
768 { STR_WITH_LEN("first"), op_offset_special, 0, },/*53*/
769 { STR_WITH_LEN("meth_sv"), op_offset_special, 0, },/*54*/
770 { STR_WITH_LEN("pmregexp"),op_offset_special, 0, },/*55*/
772 { STR_WITH_LEN("rclass"), op_offset_special, 0, },/*56*/
774 { STR_WITH_LEN("rclass"), op_offset_special, 0, },/*56*/
779 #include "const-c.inc"
781 MODULE = B PACKAGE = B
783 INCLUDE: const-xs.inc
790 const char *file = __FILE__;
793 B_init_my_cxt(aTHX_ &(MY_CXT));
794 cv = newXS("B::init_av", intrpvar_sv_common, file);
795 ASSIGN_COMMON_ALIAS(I, initav);
796 cv = newXS("B::check_av", intrpvar_sv_common, file);
797 ASSIGN_COMMON_ALIAS(I, checkav_save);
798 cv = newXS("B::unitcheck_av", intrpvar_sv_common, file);
799 ASSIGN_COMMON_ALIAS(I, unitcheckav_save);
800 cv = newXS("B::begin_av", intrpvar_sv_common, file);
801 ASSIGN_COMMON_ALIAS(I, beginav_save);
802 cv = newXS("B::end_av", intrpvar_sv_common, file);
803 ASSIGN_COMMON_ALIAS(I, endav);
804 cv = newXS("B::main_cv", intrpvar_sv_common, file);
805 ASSIGN_COMMON_ALIAS(I, main_cv);
806 cv = newXS("B::inc_gv", intrpvar_sv_common, file);
807 ASSIGN_COMMON_ALIAS(I, incgv);
808 cv = newXS("B::defstash", intrpvar_sv_common, file);
809 ASSIGN_COMMON_ALIAS(I, defstash);
810 cv = newXS("B::curstash", intrpvar_sv_common, file);
811 ASSIGN_COMMON_ALIAS(I, curstash);
813 cv = newXS("B::formfeed", intrpvar_sv_common, file);
814 ASSIGN_COMMON_ALIAS(I, formfeed);
817 cv = newXS("B::regex_padav", intrpvar_sv_common, file);
818 ASSIGN_COMMON_ALIAS(I, regex_padav);
820 cv = newXS("B::warnhook", intrpvar_sv_common, file);
821 ASSIGN_COMMON_ALIAS(I, warnhook);
822 cv = newXS("B::diehook", intrpvar_sv_common, file);
823 ASSIGN_COMMON_ALIAS(I, diehook);
824 sv = get_sv("B::OP::does_parent", GV_ADDMULTI);
825 #ifdef PERL_OP_PARENT
826 sv_setsv(sv, &PL_sv_yes);
828 sv_setsv(sv, &PL_sv_no);
837 PUSHs(make_sv_object(aTHX_ GvSV(gv_fetchpvs("\f", GV_ADD, SVt_PV))));
844 RETVAL = PL_amagic_generation;
851 PADLIST *padlist = CvPADLIST(PL_main_cv ? PL_main_cv : PL_compcv);
855 SV * const rv = sv_newmortal();
856 sv_setiv(newSVrv(rv, padlist ? "B::PADLIST" : "B::NULL"),
861 PUSHs(make_sv_object(aTHX_ (SV *)padlist));
870 PUSHs(make_sv_object(aTHX_ ix > 1 ? &PL_sv_yes
871 : ix < 1 ? &PL_sv_undef
879 PUSHs(make_op_object(aTHX_ ix ? PL_main_start : PL_main_root));
886 RETVAL = ix ? PL_dowarn : PL_sub_generation;
891 walkoptree(op, method)
895 (void) walkoptree(aTHX_ op, method, &PL_sv_undef);
898 walkoptree_debug(...)
901 RETVAL = walkoptree_debug;
902 if (items > 0 && SvTRUE(ST(1)))
903 walkoptree_debug = 1;
907 #define address(sv) PTR2IV(sv)
918 croak("argument is not a reference");
919 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
928 ST(0) = sv_newmortal();
929 if (strncmp(name,"pp_",3) == 0)
931 for (i = 0; i < PL_maxo; i++)
933 if (strcmp(name, PL_op_name[i]) == 0)
939 sv_setiv(ST(0),result);
946 ST(0) = sv_newmortal();
947 if (opnum >= 0 && opnum < PL_maxo)
948 Perl_sv_setpvf(aTHX_ ST(0), "pp_%s", PL_op_name[opnum]);
956 const char *s = SvPVbyte(sv, len);
957 PERL_HASH(hash, s, len);
958 ST(0) = sv_2mortal(Perl_newSVpvf(aTHX_ "0x%"UVxf, (UV)hash));
960 #define cast_I32(foo) (I32)foo
982 PUSHs(ix == 2 ? cchar(aTHX_ sv) : cstring(aTHX_ sv, (bool)ix));
993 PUTBACK; /* some vars go out of scope now in machine code */
996 B_init_my_cxt(aTHX_ &(MY_CXT));
998 return; /* dont execute another implied XSPP PUTBACK */
1002 MODULE = B PACKAGE = B::OP
1005 # The type checking code in B has always been identical for all OP types,
1006 # irrespective of whether the action is actually defined on that OP.
1007 # We should fix this
1020 B::PMOP::pmreplstart = 8
1022 B::LOOP::nextop = 10
1023 B::LOOP::lastop = 11
1024 B::PMOP::pmflags = 12
1025 B::PMOP::code_list = 13
1028 B::PADOP::padix = 16
1029 B::COP::cop_seq = 17
1032 B::PMOP::pmoffset = 20
1036 B::COP::stashpv = 24
1037 B::COP::stashoff = 25
1045 B::LISTOP::children = 33
1046 B::PMOP::pmreplroot = 34
1047 B::PMOP::pmstashpv = 35
1048 B::PMOP::pmstash = 36
1049 B::PMOP::precomp = 37
1050 B::PMOP::reflags = 38
1055 B::COP::arybase = 43
1056 B::COP::warnings = 44
1058 B::COP::hints_hash = 46
1060 B::OP::savefree = 48
1065 B::METHOP::first = 53
1066 B::METHOP::meth_sv = 54
1067 B::PMOP::pmregexp = 55
1068 B::METHOP::rclass = 56
1072 if (ix < 0 || (U32)ix >= C_ARRAY_LENGTH(op_methods))
1073 croak("Illegal alias %d for B::*OP::next", (int)ix);
1074 ret = get_overlay_object(aTHX_ o,
1075 op_methods[ix].name, op_methods[ix].namelen);
1081 /* handle non-direct field access */
1083 if (op_methods[ix].type == op_offset_special)
1085 case 1: /* B::OP::op_sibling */
1086 ret = make_op_object(aTHX_ OpSIBLING(o));
1089 case 8: /* B::PMOP::pmreplstart */
1090 ret = make_op_object(aTHX_
1091 cPMOPo->op_type == OP_SUBST
1092 ? cPMOPo->op_pmstashstartu.op_pmreplstart
1097 case 21: /* B::COP::filegv */
1098 ret = make_sv_object(aTHX_ (SV *)CopFILEGV((COP*)o));
1101 #ifndef USE_ITHREADS
1102 case 22: /* B::COP::file */
1103 ret = sv_2mortal(newSVpv(CopFILE((COP*)o), 0));
1107 case 23: /* B::COP::stash */
1108 ret = make_sv_object(aTHX_ (SV *)CopSTASH((COP*)o));
1111 #if PERL_VERSION >= 17 || !defined USE_ITHREADS
1112 case 24: /* B::COP::stashpv */
1113 # if PERL_VERSION >= 17
1114 ret = sv_2mortal(CopSTASH((COP*)o)
1115 && SvTYPE(CopSTASH((COP*)o)) == SVt_PVHV
1116 ? newSVhek(HvNAME_HEK(CopSTASH((COP*)o)))
1119 ret = sv_2mortal(newSVpv(CopSTASHPV((COP*)o), 0));
1123 case 26: /* B::OP::size */
1124 ret = sv_2mortal(newSVuv((UV)(opsizes[cc_opclass(aTHX_ o)])));
1126 case 27: /* B::OP::name */
1127 case 28: /* B::OP::desc */
1128 ret = sv_2mortal(newSVpv(
1129 (char *)(ix == 28 ? OP_DESC(o) : OP_NAME(o)), 0));
1131 case 29: /* B::OP::ppaddr */
1134 ret = sv_2mortal(Perl_newSVpvf(aTHX_ "PL_ppaddr[OP_%s]",
1135 PL_op_name[o->op_type]));
1136 for (i=13; (STRLEN)i < SvCUR(ret); ++i)
1137 SvPVX(ret)[i] = toUPPER(SvPVX(ret)[i]);
1140 case 30: /* B::OP::type */
1141 case 31: /* B::OP::opt */
1142 case 32: /* B::OP::spare */
1143 #if PERL_VERSION >= 17
1144 case 47: /* B::OP::slabbed */
1145 case 48: /* B::OP::savefree */
1146 case 49: /* B::OP::static */
1147 #if PERL_VERSION >= 19
1148 case 50: /* B::OP::folded */
1149 case 51: /* B::OP::moresib */
1152 /* These are all bitfields, so we can't take their addresses */
1153 ret = sv_2mortal(newSVuv((UV)(
1154 ix == 30 ? o->op_type
1155 : ix == 31 ? o->op_opt
1156 : ix == 47 ? o->op_slabbed
1157 : ix == 48 ? o->op_savefree
1158 : ix == 49 ? o->op_static
1159 : ix == 50 ? o->op_folded
1160 : ix == 51 ? o->op_moresib
1163 case 33: /* B::LISTOP::children */
1167 for (kid = ((LISTOP*)o)->op_first; kid; kid = OpSIBLING(kid))
1169 ret = sv_2mortal(newSVuv(i));
1172 case 34: /* B::PMOP::pmreplroot */
1173 if (cPMOPo->op_type == OP_PUSHRE) {
1175 ret = sv_newmortal();
1176 sv_setiv(ret, cPMOPo->op_pmreplrootu.op_pmtargetoff);
1178 GV *const target = cPMOPo->op_pmreplrootu.op_pmtargetgv;
1179 ret = sv_newmortal();
1180 sv_setiv(newSVrv(ret, target ?
1181 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1186 OP *const root = cPMOPo->op_pmreplrootu.op_pmreplroot;
1187 ret = make_op_object(aTHX_ root);
1191 case 35: /* B::PMOP::pmstashpv */
1192 ret = sv_2mortal(newSVpv(PmopSTASHPV(cPMOPo),0));
1195 case 36: /* B::PMOP::pmstash */
1196 ret = make_sv_object(aTHX_ (SV *) PmopSTASH(cPMOPo));
1199 case 37: /* B::PMOP::precomp */
1200 case 38: /* B::PMOP::reflags */
1202 REGEXP *rx = PM_GETRE(cPMOPo);
1203 ret = sv_newmortal();
1206 sv_setuv(ret, RX_EXTFLAGS(rx));
1209 sv_setpvn(ret, RX_PRECOMP(rx), RX_PRELEN(rx));
1216 case 39: /* B::PADOP::sv */
1217 case 40: /* B::PADOP::gv */
1218 /* PADOPs should only be created on threaded builds.
1219 * They don't have an sv or gv field, just an op_padix
1220 * field. Leave it to the caller to retrieve padix
1221 * and look up th value in the pad. Don't do it here,
1222 * becuase PL_curpad is the pad of the caller, not the
1223 * pad of the sub the op is part of */
1224 ret = make_sv_object(aTHX_ NULL);
1226 case 41: /* B::PVOP::pv */
1227 /* OP_TRANS uses op_pv to point to a table of 256 or >=258
1228 * shorts whereas other PVOPs point to a null terminated
1230 if ( (cPVOPo->op_type == OP_TRANS
1231 || cPVOPo->op_type == OP_TRANSR) &&
1232 (cPVOPo->op_private & OPpTRANS_COMPLEMENT) &&
1233 !(cPVOPo->op_private & OPpTRANS_DELETE))
1235 const short* const tbl = (short*)cPVOPo->op_pv;
1236 const short entries = 257 + tbl[256];
1237 ret = newSVpvn_flags(cPVOPo->op_pv, entries * sizeof(short), SVs_TEMP);
1239 else if (cPVOPo->op_type == OP_TRANS || cPVOPo->op_type == OP_TRANSR) {
1240 ret = newSVpvn_flags(cPVOPo->op_pv, 256 * sizeof(short), SVs_TEMP);
1243 ret = newSVpvn_flags(cPVOPo->op_pv, strlen(cPVOPo->op_pv), SVs_TEMP);
1245 case 42: /* B::COP::label */
1246 ret = sv_2mortal(newSVpv(CopLABEL(cCOPo),0));
1248 case 43: /* B::COP::arybase */
1249 ret = sv_2mortal(newSVuv(0));
1251 case 44: /* B::COP::warnings */
1252 ret = make_warnings_object(aTHX_ cCOPo);
1254 case 45: /* B::COP::io */
1255 ret = make_cop_io_object(aTHX_ cCOPo);
1257 case 46: /* B::COP::hints_hash */
1258 ret = sv_newmortal();
1259 sv_setiv(newSVrv(ret, "B::RHE"),
1260 PTR2IV(CopHINTHASH_get(cCOPo)));
1262 case 52: /* B::OP::parent */
1263 #ifdef PERL_OP_PARENT
1264 ret = make_op_object(aTHX_ op_parent(o));
1266 ret = make_op_object(aTHX_ NULL);
1269 case 53: /* B::METHOP::first */
1270 /* METHOP struct has an op_first/op_meth_sv union
1271 * as its first extra field. How to interpret the
1272 * union depends on the op type. For the purposes of
1273 * B, we treat it as a struct with both fields present,
1274 * where one of the fields always happens to be null
1275 * (i.e. we return NULL in preference to croaking with
1276 * 'method not implemented').
1278 ret = make_op_object(aTHX_
1279 o->op_type == OP_METHOD
1280 ? cMETHOPx(o)->op_u.op_first : NULL);
1282 case 54: /* B::METHOP::meth_sv */
1283 /* see comment above about METHOP */
1284 ret = make_sv_object(aTHX_
1285 o->op_type == OP_METHOD
1286 ? NULL : cMETHOPx(o)->op_u.op_meth_sv);
1288 case 55: /* B::PMOP::pmregexp */
1289 ret = make_sv_object(aTHX_ (SV *)PM_GETRE(cPMOPo));
1291 case 56: /* B::METHOP::rclass */
1293 ret = sv_2mortal(newSVuv(
1294 (o->op_type == OP_METHOD_REDIR ||
1295 o->op_type == OP_METHOD_REDIR_SUPER) ?
1296 cMETHOPx(o)->op_rclass_targ : 0
1299 ret = make_sv_object(aTHX_
1300 (o->op_type == OP_METHOD_REDIR ||
1301 o->op_type == OP_METHOD_REDIR_SUPER) ?
1302 cMETHOPx(o)->op_rclass_sv : NULL
1307 croak("method %s not implemented", op_methods[ix].name);
1309 /* do a direct structure offset lookup */
1310 const char *const ptr = (char *)o + op_methods[ix].offset;
1311 switch (op_methods[ix].type) {
1313 ret = make_op_object(aTHX_ *((OP **)ptr));
1316 ret = sv_2mortal(newSVuv(*((PADOFFSET*)ptr)));
1319 ret = sv_2mortal(newSVuv(*((U8*)ptr)));
1322 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1325 ret = make_sv_object(aTHX_ *((SV **)ptr));
1328 ret = sv_2mortal(newSVuv(*((line_t *)ptr)));
1331 ret = sv_2mortal(newSViv(*((IV*)ptr)));
1334 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1337 croak("Illegal type 0x%x for B::*OP::%s",
1338 (unsigned)op_methods[ix].type, op_methods[ix].name);
1349 SP = oplist(aTHX_ o, SP);
1353 MODULE = B PACKAGE = B::UNOP_AUX
1355 # UNOP_AUX class ops are like UNOPs except that they have an extra
1356 # op_aux pointer that points to an array of UNOP_AUX_item unions.
1357 # Element -1 of the array contains the length
1360 # return a string representation of op_aux where possible The op's CV is
1361 # needed as an extra arg to allow GVs and SVs moved into the pad to be
1371 switch (o->op_type) {
1373 ret = multideref_stringify(o, cv);
1376 ret = sv_2mortal(newSVpvn("", 0));
1382 # Return the contents of the op_aux array as a list of IV/GV/etc objects.
1383 # How to interpret each array element is op-dependent. The op's CV is
1384 # needed as an extra arg to allow GVs and SVs which have been moved into
1385 # the pad to be accessed okay.
1392 PERL_UNUSED_VAR(cv); /* not needed on unthreaded builds */
1393 switch (o->op_type) {
1395 XSRETURN(0); /* by default, an empty list */
1399 # define ITEM_SV(item) *av_fetch(comppad, (item)->pad_offset, FALSE);
1401 # define ITEM_SV(item) UNOP_AUX_item_sv(item)
1404 UNOP_AUX_item *items = cUNOP_AUXo->op_aux;
1405 UV actions = items->uv;
1406 UV len = items[-1].uv;
1409 bool is_hash = FALSE;
1411 PADLIST * const padlist = CvPADLIST(cv);
1412 PAD *comppad = PadlistARRAY(padlist)[1];
1416 PUSHs(sv_2mortal(newSViv(actions)));
1419 switch (actions & MDEREF_ACTION_MASK) {
1422 actions = (++items)->uv;
1423 PUSHs(sv_2mortal(newSVuv(actions)));
1425 NOT_REACHED; /* NOTREACHED */
1427 case MDEREF_HV_padhv_helem:
1430 case MDEREF_AV_padav_aelem:
1431 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1433 NOT_REACHED; /* NOTREACHED */
1435 case MDEREF_HV_gvhv_helem:
1438 case MDEREF_AV_gvav_aelem:
1439 sv = ITEM_SV(++items);
1440 PUSHs(make_sv_object(aTHX_ sv));
1442 NOT_REACHED; /* NOTREACHED */
1444 case MDEREF_HV_gvsv_vivify_rv2hv_helem:
1447 case MDEREF_AV_gvsv_vivify_rv2av_aelem:
1448 sv = ITEM_SV(++items);
1449 PUSHs(make_sv_object(aTHX_ sv));
1450 goto do_vivify_rv2xv_elem;
1451 NOT_REACHED; /* NOTREACHED */
1453 case MDEREF_HV_padsv_vivify_rv2hv_helem:
1456 case MDEREF_AV_padsv_vivify_rv2av_aelem:
1457 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1458 goto do_vivify_rv2xv_elem;
1459 NOT_REACHED; /* NOTREACHED */
1461 case MDEREF_HV_pop_rv2hv_helem:
1462 case MDEREF_HV_vivify_rv2hv_helem:
1465 do_vivify_rv2xv_elem:
1466 case MDEREF_AV_pop_rv2av_aelem:
1467 case MDEREF_AV_vivify_rv2av_aelem:
1469 switch (actions & MDEREF_INDEX_MASK) {
1470 case MDEREF_INDEX_none:
1473 case MDEREF_INDEX_const:
1475 sv = ITEM_SV(++items);
1476 PUSHs(make_sv_object(aTHX_ sv));
1479 PUSHs(sv_2mortal(newSViv((++items)->iv)));
1481 case MDEREF_INDEX_padsv:
1482 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1484 case MDEREF_INDEX_gvsv:
1485 sv = ITEM_SV(++items);
1486 PUSHs(make_sv_object(aTHX_ sv));
1489 if (actions & MDEREF_FLAG_last)
1496 actions >>= MDEREF_SHIFT;
1500 } /* OP_MULTIDEREF */
1505 MODULE = B PACKAGE = B::SV
1507 #define MAGICAL_FLAG_BITS (SVs_GMG|SVs_SMG|SVs_RMG)
1517 MAGICAL = MAGICAL_FLAG_BITS
1519 RETVAL = ix ? (SvFLAGS(sv) & (U32)ix) : SvREFCNT(sv);
1527 ST(0) = sv_2mortal(newRV(sv));
1530 MODULE = B PACKAGE = B::IV PREFIX = Sv
1536 MODULE = B PACKAGE = B::IV
1538 #define sv_SVp 0x00000
1539 #define sv_IVp 0x10000
1540 #define sv_UVp 0x20000
1541 #define sv_STRLENp 0x30000
1542 #define sv_U32p 0x40000
1543 #define sv_U8p 0x50000
1544 #define sv_char_pp 0x60000
1545 #define sv_NVp 0x70000
1546 #define sv_char_p 0x80000
1547 #define sv_SSize_tp 0x90000
1548 #define sv_I32p 0xA0000
1549 #define sv_U16p 0xB0000
1551 #define IV_ivx_ix sv_IVp | STRUCT_OFFSET(struct xpviv, xiv_iv)
1552 #define IV_uvx_ix sv_UVp | STRUCT_OFFSET(struct xpvuv, xuv_uv)
1553 #define NV_nvx_ix sv_NVp | STRUCT_OFFSET(struct xpvnv, xnv_u.xnv_nv)
1555 #define PV_cur_ix sv_STRLENp | STRUCT_OFFSET(struct xpv, xpv_cur)
1556 #define PV_len_ix sv_STRLENp | STRUCT_OFFSET(struct xpv, xpv_len)
1558 #define PVMG_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvmg, xmg_stash)
1560 #if PERL_VERSION > 18
1561 # define PVBM_useful_ix sv_IVp | STRUCT_OFFSET(struct xpviv, xiv_u.xivu_iv)
1562 #elif PERL_VERSION > 14
1563 # define PVBM_useful_ix sv_I32p | STRUCT_OFFSET(struct xpvgv, xnv_u.xbm_s.xbm_useful)
1565 #define PVBM_useful_ix sv_I32p | STRUCT_OFFSET(struct xpvgv, xiv_u.xivu_i32)
1568 #define PVLV_targoff_ix sv_U32p | STRUCT_OFFSET(struct xpvlv, xlv_targoff)
1569 #define PVLV_targlen_ix sv_U32p | STRUCT_OFFSET(struct xpvlv, xlv_targlen)
1570 #define PVLV_targ_ix sv_SVp | STRUCT_OFFSET(struct xpvlv, xlv_targ)
1571 #define PVLV_type_ix sv_char_p | STRUCT_OFFSET(struct xpvlv, xlv_type)
1573 #define PVGV_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvgv, xnv_u.xgv_stash)
1574 #define PVGV_flags_ix sv_STRLENp | STRUCT_OFFSET(struct xpvgv, xpv_cur)
1575 #define PVIO_lines_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xiv_iv)
1577 #define PVIO_page_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_page)
1578 #define PVIO_page_len_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_page_len)
1579 #define PVIO_lines_left_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_lines_left)
1580 #define PVIO_top_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_top_name)
1581 #define PVIO_top_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_top_gv)
1582 #define PVIO_fmt_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_fmt_name)
1583 #define PVIO_fmt_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_fmt_gv)
1584 #define PVIO_bottom_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_bottom_name)
1585 #define PVIO_bottom_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_bottom_gv)
1586 #define PVIO_type_ix sv_char_p | STRUCT_OFFSET(struct xpvio, xio_type)
1587 #define PVIO_flags_ix sv_U8p | STRUCT_OFFSET(struct xpvio, xio_flags)
1589 #define PVAV_max_ix sv_SSize_tp | STRUCT_OFFSET(struct xpvav, xav_max)
1591 #define PVCV_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_stash)
1592 #if PERL_VERSION > 17 || (PERL_VERSION == 17 && PERL_SUBVERSION >= 3)
1593 # define PVCV_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_gv_u.xcv_gv)
1595 # define PVCV_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_gv)
1597 #define PVCV_file_ix sv_char_pp | STRUCT_OFFSET(struct xpvcv, xcv_file)
1598 #define PVCV_outside_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_outside)
1599 #define PVCV_outside_seq_ix sv_U32p | STRUCT_OFFSET(struct xpvcv, xcv_outside_seq)
1600 #define PVCV_flags_ix sv_U32p | STRUCT_OFFSET(struct xpvcv, xcv_flags)
1602 #define PVHV_max_ix sv_STRLENp | STRUCT_OFFSET(struct xpvhv, xhv_max)
1604 #if PERL_VERSION > 12
1605 #define PVHV_keys_ix sv_STRLENp | STRUCT_OFFSET(struct xpvhv, xhv_keys)
1607 #define PVHV_keys_ix sv_IVp | STRUCT_OFFSET(struct xpvhv, xhv_keys)
1610 # The type checking code in B has always been identical for all SV types,
1611 # irrespective of whether the action is actually defined on that SV.
1612 # We should fix this
1617 B::IV::IVX = IV_ivx_ix
1618 B::IV::UVX = IV_uvx_ix
1619 B::NV::NVX = NV_nvx_ix
1620 B::PV::CUR = PV_cur_ix
1621 B::PV::LEN = PV_len_ix
1622 B::PVMG::SvSTASH = PVMG_stash_ix
1623 B::PVLV::TARGOFF = PVLV_targoff_ix
1624 B::PVLV::TARGLEN = PVLV_targlen_ix
1625 B::PVLV::TARG = PVLV_targ_ix
1626 B::PVLV::TYPE = PVLV_type_ix
1627 B::GV::STASH = PVGV_stash_ix
1628 B::GV::GvFLAGS = PVGV_flags_ix
1629 B::BM::USEFUL = PVBM_useful_ix
1630 B::IO::LINES = PVIO_lines_ix
1631 B::IO::PAGE = PVIO_page_ix
1632 B::IO::PAGE_LEN = PVIO_page_len_ix
1633 B::IO::LINES_LEFT = PVIO_lines_left_ix
1634 B::IO::TOP_NAME = PVIO_top_name_ix
1635 B::IO::TOP_GV = PVIO_top_gv_ix
1636 B::IO::FMT_NAME = PVIO_fmt_name_ix
1637 B::IO::FMT_GV = PVIO_fmt_gv_ix
1638 B::IO::BOTTOM_NAME = PVIO_bottom_name_ix
1639 B::IO::BOTTOM_GV = PVIO_bottom_gv_ix
1640 B::IO::IoTYPE = PVIO_type_ix
1641 B::IO::IoFLAGS = PVIO_flags_ix
1642 B::AV::MAX = PVAV_max_ix
1643 B::CV::STASH = PVCV_stash_ix
1644 B::CV::FILE = PVCV_file_ix
1645 B::CV::OUTSIDE = PVCV_outside_ix
1646 B::CV::OUTSIDE_SEQ = PVCV_outside_seq_ix
1647 B::CV::CvFLAGS = PVCV_flags_ix
1648 B::HV::MAX = PVHV_max_ix
1649 B::HV::KEYS = PVHV_keys_ix
1654 ptr = (ix & 0xFFFF) + (char *)SvANY(sv);
1655 switch ((U8)(ix >> 16)) {
1656 case (U8)(sv_SVp >> 16):
1657 ret = make_sv_object(aTHX_ *((SV **)ptr));
1659 case (U8)(sv_IVp >> 16):
1660 ret = sv_2mortal(newSViv(*((IV *)ptr)));
1662 case (U8)(sv_UVp >> 16):
1663 ret = sv_2mortal(newSVuv(*((UV *)ptr)));
1665 case (U8)(sv_STRLENp >> 16):
1666 ret = sv_2mortal(newSVuv(*((STRLEN *)ptr)));
1668 case (U8)(sv_U32p >> 16):
1669 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
1671 case (U8)(sv_U8p >> 16):
1672 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
1674 case (U8)(sv_char_pp >> 16):
1675 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1677 case (U8)(sv_NVp >> 16):
1678 ret = sv_2mortal(newSVnv(*((NV *)ptr)));
1680 case (U8)(sv_char_p >> 16):
1681 ret = newSVpvn_flags((char *)ptr, 1, SVs_TEMP);
1683 case (U8)(sv_SSize_tp >> 16):
1684 ret = sv_2mortal(newSViv(*((SSize_t *)ptr)));
1686 case (U8)(sv_I32p >> 16):
1687 ret = sv_2mortal(newSVuv(*((I32 *)ptr)));
1689 case (U8)(sv_U16p >> 16):
1690 ret = sv_2mortal(newSVuv(*((U16 *)ptr)));
1693 croak("Illegal alias 0x%08x for B::*IVX", (unsigned)ix);
1705 ST(0) = boolSV((I32)SvIVX(sv) != SvIVX(sv));
1706 } else if (sizeof(IV) == 8) {
1708 const IV iv = SvIVX(sv);
1710 * The following way of spelling 32 is to stop compilers on
1711 * 32-bit architectures from moaning about the shift count
1712 * being >= the width of the type. Such architectures don't
1713 * reach this code anyway (unless sizeof(IV) > 8 but then
1714 * everything else breaks too so I'm not fussed at the moment).
1717 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1719 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1721 wp[1] = htonl(iv & 0xffffffff);
1722 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1724 U32 w = htonl((U32)SvIVX(sv));
1725 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1728 MODULE = B PACKAGE = B::NV PREFIX = Sv
1734 #if PERL_VERSION < 11
1736 MODULE = B PACKAGE = B::RV PREFIX = Sv
1742 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
1746 MODULE = B PACKAGE = B::REGEXP
1757 PUSHs(newSVpvn_flags(RX_PRECOMP(sv), RX_PRELEN(sv), SVs_TEMP));
1758 } else if (ix == 2) {
1759 PUSHs(make_sv_object(aTHX_ (SV *)ReANY(sv)->qr_anoncv));
1763 PUSHu(RX_COMPFLAGS(sv));
1765 /* FIXME - can we code this method more efficiently? */
1771 MODULE = B PACKAGE = B::PV
1778 croak( "argument is not SvROK" );
1779 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
1794 #ifndef PERL_FBM_TABLE_OFFSET
1795 const MAGIC *const mg = mg_find(sv, PERL_MAGIC_bm);
1798 croak("argument to B::BM::TABLE is not a PVBM");
1803 /* Boyer-Moore table is just after string and its safety-margin \0 */
1804 p += len + PERL_FBM_TABLE_OFFSET;
1807 } else if (ix == 2) {
1808 /* This used to read 257. I think that that was buggy - should have
1809 been 258. (The "\0", the flags byte, and 256 for the table.)
1810 The only user of this method is B::Bytecode in B::PV::bsave.
1811 I'm guessing that nothing tested the runtime correctness of
1812 output of bytecompiled string constant arguments to index (etc).
1814 Note the start pointer is and has always been SvPVX(sv), not
1815 SvPVX(sv) + SvCUR(sv) PVBM was added in 651aa52ea1faa806, and
1816 first used by the compiler in 651aa52ea1faa806. It's used to
1817 get a "complete" dump of the buffer at SvPVX(), not just the
1818 PVBM table. This permits the generated bytecode to "load"
1821 5.15 and later store the BM table via MAGIC, so the compiler
1822 should handle this just fine without changes if PVBM now
1823 always returns the SvPVX() buffer. */
1826 ? RX_WRAPPED_const((REGEXP*)sv)
1829 p = SvPVX_const(sv);
1831 #ifdef PERL_FBM_TABLE_OFFSET
1832 len = SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0);
1838 p = isREGEXP(sv) ? RX_WRAPPED((REGEXP*)sv) : SvPVX(sv);
1843 } else if (SvPOK(sv)) {
1845 p = SvPVX_const(sv);
1849 else if (isREGEXP(sv)) {
1851 p = RX_WRAPPED_const((REGEXP*)sv);
1856 /* XXX for backward compatibility, but should fail */
1857 /* croak( "argument is not SvPOK" ); */
1860 ST(0) = newSVpvn_flags(p, len, SVs_TEMP | utf8);
1862 MODULE = B PACKAGE = B::PVMG
1867 MAGIC * mg = NO_INIT
1869 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1870 XPUSHs(make_mg_object(aTHX_ mg));
1872 MODULE = B PACKAGE = B::MAGIC
1889 XPUSHs(mg->mg_moremagic ? make_mg_object(aTHX_ mg->mg_moremagic)
1893 mPUSHu(mg->mg_private);
1896 PUSHs(newSVpvn_flags(&(mg->mg_type), 1, SVs_TEMP));
1899 mPUSHu(mg->mg_flags);
1905 PUSHs(make_sv_object(aTHX_ mg->mg_obj));
1909 if (mg->mg_len >= 0) {
1910 PUSHs(newSVpvn_flags(mg->mg_ptr, mg->mg_len, SVs_TEMP));
1911 } else if (mg->mg_len == HEf_SVKEY) {
1912 PUSHs(make_sv_object(aTHX_ (SV*)mg->mg_ptr));
1914 PUSHs(sv_newmortal());
1916 PUSHs(sv_newmortal());
1919 if(mg->mg_type == PERL_MAGIC_qr) {
1920 mPUSHi(PTR2IV(mg->mg_obj));
1922 croak("REGEX is only meaningful on r-magic");
1926 if (mg->mg_type == PERL_MAGIC_qr) {
1927 REGEXP *rx = (REGEXP *)mg->mg_obj;
1928 PUSHs(newSVpvn_flags(rx ? RX_PRECOMP(rx) : NULL,
1929 rx ? RX_PRELEN(rx) : 0, SVs_TEMP));
1931 croak( "precomp is only meaningful on r-magic" );
1936 MODULE = B PACKAGE = B::BM PREFIX = Bm
1942 #if PERL_VERSION >= 19
1943 PERL_UNUSED_VAR(sv);
1945 RETVAL = BmPREVIOUS(sv);
1954 #if PERL_VERSION >= 19
1955 PERL_UNUSED_VAR(sv);
1957 RETVAL = BmRARE(sv);
1962 MODULE = B PACKAGE = B::GV PREFIX = Gv
1971 ST(0) = sv_2mortal(newSVhek(!ix ? GvNAME_HEK(gv)
1972 : (ix == 1 ? GvFILE_HEK(gv)
1973 : HvNAME_HEK((HV *)gv))));
1982 RETVAL = isGV_with_GP(gv) ? TRUE : FALSE;
1984 RETVAL = GvGP(gv) == Null(GP*);
1993 #define GP_sv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_sv)
1994 #define GP_io_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_io)
1995 #define GP_cv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_cv)
1996 #define GP_cvgen_ix (U32p << 16) | STRUCT_OFFSET(struct gp, gp_cvgen)
1997 #define GP_refcnt_ix (U32p << 16) | STRUCT_OFFSET(struct gp, gp_refcnt)
1998 #define GP_hv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_hv)
1999 #define GP_av_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_av)
2000 #define GP_form_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_form)
2001 #define GP_egv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_egv)
2011 GvREFCNT = GP_refcnt_ix
2023 const GV *const gv = CvGV(cv);
2024 Perl_croak(aTHX_ "NULL gp in B::GV::%s", gv ? GvNAME(gv) : "???");
2026 ptr = (ix & 0xFFFF) + (char *)gp;
2027 switch ((U8)(ix >> 16)) {
2029 ret = make_sv_object(aTHX_ *((SV **)ptr));
2032 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
2035 croak("Illegal alias 0x%08x for B::*SV", (unsigned)ix);
2052 PUSHs(make_sv_object(aTHX_ (SV *)GvFILEGV(gv)));
2054 MODULE = B PACKAGE = B::IO PREFIX = Io
2064 if( strEQ( name, "stdin" ) ) {
2065 handle = PerlIO_stdin();
2067 else if( strEQ( name, "stdout" ) ) {
2068 handle = PerlIO_stdout();
2070 else if( strEQ( name, "stderr" ) ) {
2071 handle = PerlIO_stderr();
2074 croak( "Invalid value '%s'", name );
2076 RETVAL = handle == IoIFP(io);
2080 MODULE = B PACKAGE = B::AV PREFIX = Av
2090 if (AvFILL(av) >= 0) {
2091 SV **svp = AvARRAY(av);
2093 for (i = 0; i <= AvFILL(av); i++)
2094 XPUSHs(make_sv_object(aTHX_ svp[i]));
2102 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
2103 XPUSHs(make_sv_object(aTHX_ (AvARRAY(av)[idx])));
2105 XPUSHs(make_sv_object(aTHX_ NULL));
2108 MODULE = B PACKAGE = B::FM PREFIX = Fm
2114 PERL_UNUSED_VAR(format);
2120 MODULE = B PACKAGE = B::CV PREFIX = Cv
2132 PUSHs(make_op_object(aTHX_ CvISXSUB(cv) ? NULL
2133 : ix ? CvROOT(cv) : CvSTART(cv)));
2145 RETVAL = CvISXSUB(cv) ? NULL : CvPADLIST(cv);
2155 PUSHs(make_sv_object(aTHX_ (SV *)CvPADLIST(cv)));
2164 RETVAL = newSVuv(CvISXSUB(cv) ? PTR2UV(CvHSCXT(cv)) : 0);
2174 ST(0) = ix && CvCONST(cv)
2175 ? make_sv_object(aTHX_ (SV *)CvXSUBANY(cv).any_ptr)
2176 : sv_2mortal(newSViv(CvISXSUB(cv)
2177 ? (ix ? CvXSUBANY(cv).any_iv
2178 : PTR2IV(CvXSUB(cv)))
2185 PUSHs(make_sv_object(aTHX_ (SV *)cv_const_sv(cv)));
2191 ST(0) = make_sv_object(aTHX_ (SV*)CvGV(cv));
2193 #if PERL_VERSION > 17
2199 RETVAL = CvNAMED(cv) ? newSVhek(CvNAME_HEK(cv)) : &PL_sv_undef;
2205 MODULE = B PACKAGE = B::HV PREFIX = Hv
2219 if (HvUSEDKEYS(hv) > 0) {
2221 (void)hv_iterinit(hv);
2222 EXTEND(sp, HvUSEDKEYS(hv) * 2);
2223 while ((he = hv_iternext(hv))) {
2225 mPUSHs(HeSVKEY(he));
2226 } else if (HeKUTF8(he)) {
2227 PUSHs(newSVpvn_flags(HeKEY(he), HeKLEN(he), SVf_UTF8|SVs_TEMP));
2229 mPUSHp(HeKEY(he), HeKLEN(he));
2231 PUSHs(make_sv_object(aTHX_ HeVAL(he)));
2235 MODULE = B PACKAGE = B::HE PREFIX = He
2243 PUSHs(make_sv_object(aTHX_ ix ? HeSVKEY_force(he) : HeVAL(he)));
2249 MODULE = B PACKAGE = B::RHE
2255 RETVAL = newRV( (SV*)cophh_2hv(h, 0) );
2262 MODULE = B PACKAGE = B::PADLIST PREFIX = Padlist
2267 ALIAS: B::PADNAMELIST::MAX = 0
2269 PERL_UNUSED_VAR(ix);
2270 RETVAL = PadlistMAX(padlist);
2275 PadlistNAMES(padlist)
2279 PadlistARRAY(padlist)
2282 if (PadlistMAX(padlist) >= 0) {
2284 PAD **padp = PadlistARRAY(padlist);
2286 sv_setiv(newSVrv(TARG, PadlistNAMES(padlist)
2289 PTR2IV(PadlistNAMES(padlist)));
2291 for (i = 1; i <= PadlistMAX(padlist); i++)
2292 XPUSHs(make_sv_object(aTHX_ (SV *)padp[i]));
2296 PadlistARRAYelt(padlist, idx)
2300 if (idx < 0 || idx > PadlistMAX(padlist))
2301 XPUSHs(make_sv_object(aTHX_ NULL));
2304 PUSHMARK(PL_stack_sp-1);
2305 XS_B__PADLIST_NAMES(aTHX_ cv);
2309 XPUSHs(make_sv_object(aTHX_
2310 (SV *)PadlistARRAY(padlist)[idx]));
2313 PadlistREFCNT(padlist)
2316 PERL_UNUSED_VAR(padlist);
2317 RETVAL = PadlistREFCNT(padlist);
2323 MODULE = B PACKAGE = B::PADNAMELIST PREFIX = Padnamelist
2326 PadnamelistARRAY(pnl)
2329 if (PadnamelistMAX(pnl) >= 0) {
2330 PADNAME **padp = PadnamelistARRAY(pnl);
2332 for (; i <= PadnamelistMAX(pnl); i++)
2334 SV *rv = sv_newmortal();
2335 sv_setiv(newSVrv(rv,padp[i] ? "B::PADNAME" : "B::SPECIAL"),
2342 PadnamelistARRAYelt(pnl, idx)
2346 if (idx < 0 || idx > PadnamelistMAX(pnl))
2349 RETVAL = PadnamelistARRAY(pnl)[idx];
2353 MODULE = B PACKAGE = B::PADNAME PREFIX = Padname
2355 #define PN_type_ix \
2356 sv_SVp | STRUCT_OFFSET(struct padname,xpadn_type_u.xpadn_typestash)
2357 #define PN_ourstash_ix \
2358 sv_SVp | STRUCT_OFFSET(struct padname,xpadn_ourstash)
2360 sv_U8p | STRUCT_OFFSET(struct padname,xpadn_len)
2361 #define PN_refcnt_ix \
2362 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_refcnt)
2363 #define PN_cop_seq_range_low_ix \
2364 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_low)
2365 #define PN_cop_seq_range_high_ix \
2366 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_high)
2367 #define PNL_refcnt_ix \
2368 sv_U32p | STRUCT_OFFSET(struct padnamelist, xpadnl_refcnt)
2370 sv_U32p | STRUCT_OFFSET(struct padlist, xpadl_id)
2371 #define PL_outid_ix \
2372 sv_U32p | STRUCT_OFFSET(struct padlist, xpadl_outid)
2379 B::PADNAME::TYPE = PN_type_ix
2380 B::PADNAME::OURSTASH = PN_ourstash_ix
2381 B::PADNAME::LEN = PN_len_ix
2382 B::PADNAME::REFCNT = PN_refcnt_ix
2383 B::PADNAME::COP_SEQ_RANGE_LOW = PN_cop_seq_range_low_ix
2384 B::PADNAME::COP_SEQ_RANGE_HIGH = PN_cop_seq_range_high_ix
2385 B::PADNAMELIST::REFCNT = PNL_refcnt_ix
2386 B::PADLIST::id = PL_id_ix
2387 B::PADLIST::outid = PL_outid_ix
2392 ptr = (ix & 0xFFFF) + (char *)pn;
2393 switch ((U8)(ix >> 16)) {
2394 case (U8)(sv_SVp >> 16):
2395 ret = make_sv_object(aTHX_ *((SV **)ptr));
2397 case (U8)(sv_U32p >> 16):
2398 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
2400 case (U8)(sv_U8p >> 16):
2401 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
2415 PERL_UNUSED_ARG(RETVAL);
2416 sv_setpvn(TARG, PadnamePV(pn), PadnameLEN(pn));
2422 /* Uses less memory than an ALIAS. */
2423 GV *gv = gv_fetchpvs("B::PADNAME::TYPE", 1, SVt_PVGV);
2424 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::SvSTASH",1,SVt_PVGV),(SV *)gv);
2425 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PROTOCV",1,SVt_PVGV),(SV *)gv);
2426 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PVX",1,SVt_PVGV),
2427 (SV *)gv_fetchpvs("B::PADNAME::PV" ,1,SVt_PVGV));
2428 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PARENT_PAD_INDEX" ,1,SVt_PVGV),
2429 (SV *)gv_fetchpvs("B::PADNAME::COP_SEQ_RANGE_LOW",1,
2431 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PARENT_FAKELEX_FLAGS",1,
2433 (SV *)gv_fetchpvs("B::PADNAME::COP_SEQ_RANGE_HIGH" ,1,
2441 RETVAL = PadnameFLAGS(pn);
2442 /* backward-compatibility hack, which should be removed if the
2443 flags field becomes large enough to hold SVf_FAKE (and
2444 PADNAMEt_OUTER should be renumbered to match SVf_FAKE) */
2445 STATIC_ASSERT_STMT(SVf_FAKE >= 1<<(sizeof(PadnameFLAGS((B__PADNAME)NULL)) * 8));
2446 if (PadnameOUTER(pn))