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
16 typedef PerlIO * InputStream;
18 typedef FILE * InputStream;
22 static const char* const svclassnames[] = {
29 #if PERL_VERSION <= 10
33 #if PERL_VERSION >= 19
39 #if PERL_VERSION >= 11
66 static const char* const opclassnames[] = {
81 static const size_t opsizes[] = {
96 #define MY_CXT_KEY "B::_guts" XS_VERSION
99 int x_walkoptree_debug; /* Flag for walkoptree debug hook */
100 SV * x_specialsv_list[7];
105 #define walkoptree_debug (MY_CXT.x_walkoptree_debug)
106 #define specialsv_list (MY_CXT.x_specialsv_list)
109 cc_opclass(pTHX_ const OP *o)
117 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
119 if (o->op_type == OP_SASSIGN)
120 return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP);
122 if (o->op_type == OP_AELEMFAST) {
123 #if PERL_VERSION <= 14
124 if (o->op_flags & OPf_SPECIAL)
136 if (o->op_type == OP_GV || o->op_type == OP_GVSV ||
137 o->op_type == OP_RCATLINE)
141 if (o->op_type == OP_CUSTOM)
144 switch (OP_CLASS(o)) {
169 case OA_PVOP_OR_SVOP:
171 * Character translations (tr///) are usually a PVOP, keeping a
172 * pointer to a table of shorts used to look up translations.
173 * Under utf8, however, a simple table isn't practical; instead,
174 * the OP is an SVOP (or, under threads, a PADOP),
175 * and the SV is a reference to a swash
176 * (i.e., an RV pointing to an HV).
179 (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
181 #if defined(USE_ITHREADS)
182 ? OPc_PADOP : OPc_PVOP;
184 ? OPc_SVOP : OPc_PVOP;
193 case OA_BASEOP_OR_UNOP:
195 * UNI(OP_foo) in toke.c returns token UNI or FUNC1 depending on
196 * whether parens were seen. perly.y uses OPf_SPECIAL to
197 * signal whether a BASEOP had empty parens or none.
198 * Some other UNOPs are created later, though, so the best
199 * test is OPf_KIDS, which is set in newUNOP.
201 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
205 * The file stat OPs are created via UNI(OP_foo) in toke.c but use
206 * the OPf_REF flag to distinguish between OP types instead of the
207 * usual OPf_SPECIAL flag. As usual, if OPf_KIDS is set, then we
208 * return OPc_UNOP so that walkoptree can find our children. If
209 * OPf_KIDS is not set then we check OPf_REF. Without OPf_REF set
210 * (no argument to the operator) it's an OP; with OPf_REF set it's
211 * an SVOP (and op_sv is the GV for the filehandle argument).
213 return ((o->op_flags & OPf_KIDS) ? OPc_UNOP :
215 (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP);
217 (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP);
221 * next, last, redo, dump and goto use OPf_SPECIAL to indicate that a
222 * label was omitted (in which case it's a BASEOP) or else a term was
223 * seen. In this last case, all except goto are definitely PVOP but
224 * goto is either a PVOP (with an ordinary constant label), an UNOP
225 * with OPf_STACKED (with a non-constant non-sub) or an UNOP for
226 * OP_REFGEN (with goto &sub) in which case OPf_STACKED also seems to
229 if (o->op_flags & OPf_STACKED)
231 else if (o->op_flags & OPf_SPECIAL)
236 warn("can't determine class of operator %s, assuming BASEOP\n",
242 make_op_object(pTHX_ const OP *o)
244 SV *opsv = sv_newmortal();
245 sv_setiv(newSVrv(opsv, opclassnames[cc_opclass(aTHX_ o)]), PTR2IV(o));
251 get_overlay_object(pTHX_ const OP *o, const char * const name, U32 namelen)
256 SV *sv =get_sv("B::overlay", 0);
257 if (!sv || !SvROK(sv))
260 if (SvTYPE(sv) != SVt_PVHV)
262 key = newSViv(PTR2IV(o));
263 he = hv_fetch_ent((HV*)sv, key, 0, 0);
268 if (!sv || !SvROK(sv))
271 if (SvTYPE(sv) != SVt_PVHV)
273 svp = hv_fetch((HV*)sv, name, namelen, 0);
282 make_sv_object(pTHX_ SV *sv)
284 SV *const arg = sv_newmortal();
285 const char *type = 0;
289 for (iv = 0; iv < (IV)(sizeof(specialsv_list)/sizeof(SV*)); iv++) {
290 if (sv == specialsv_list[iv]) {
296 type = svclassnames[SvTYPE(sv)];
299 sv_setiv(newSVrv(arg, type), iv);
304 make_temp_object(pTHX_ SV *temp)
307 SV *arg = sv_newmortal();
308 const char *const type = svclassnames[SvTYPE(temp)];
309 const IV iv = PTR2IV(temp);
311 target = newSVrv(arg, type);
312 sv_setiv(target, iv);
314 /* Need to keep our "temp" around as long as the target exists.
315 Simplest way seems to be to hang it from magic, and let that clear
316 it up. No vtable, so won't actually get in the way of anything. */
317 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
318 /* magic object has had its reference count increased, so we must drop
325 make_warnings_object(pTHX_ const COP *const cop)
327 const STRLEN *const warnings = cop->cop_warnings;
328 const char *type = 0;
330 IV iv = sizeof(specialsv_list)/sizeof(SV*);
332 /* Counting down is deliberate. Before the split between make_sv_object
333 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
334 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
337 if ((SV*)warnings == specialsv_list[iv]) {
343 SV *arg = sv_newmortal();
344 sv_setiv(newSVrv(arg, type), iv);
347 /* B assumes that warnings are a regular SV. Seems easier to keep it
348 happy by making them into a regular SV. */
349 return make_temp_object(aTHX_ newSVpvn((char *)(warnings + 1), *warnings));
354 make_cop_io_object(pTHX_ COP *cop)
356 SV *const value = newSV(0);
358 Perl_emulate_cop_io(aTHX_ cop, value);
361 return make_sv_object(aTHX_ value);
364 return make_sv_object(aTHX_ NULL);
369 make_mg_object(pTHX_ MAGIC *mg)
371 SV *arg = sv_newmortal();
372 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
377 cstring(pTHX_ SV *sv, bool perlstyle)
382 return newSVpvs_flags("0", SVs_TEMP);
384 sstr = newSVpvs_flags("\"", SVs_TEMP);
386 if (perlstyle && SvUTF8(sv)) {
387 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
388 const STRLEN len = SvCUR(sv);
389 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
393 sv_catpvs(sstr, "\\\"");
395 sv_catpvs(sstr, "\\$");
397 sv_catpvs(sstr, "\\@");
400 if (strchr("nrftax\\",*(s+1)))
401 sv_catpvn(sstr, s++, 2);
403 sv_catpvs(sstr, "\\\\");
405 else /* should always be printable */
406 sv_catpvn(sstr, s, 1);
414 const char *s = SvPV(sv, len);
415 for (; len; len--, s++)
417 /* At least try a little for readability */
419 sv_catpvs(sstr, "\\\"");
421 sv_catpvs(sstr, "\\\\");
422 /* trigraphs - bleagh */
423 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
424 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", '?');
426 else if (perlstyle && *s == '$')
427 sv_catpvs(sstr, "\\$");
428 else if (perlstyle && *s == '@')
429 sv_catpvs(sstr, "\\@");
430 else if (isPRINT(*s))
431 sv_catpvn(sstr, s, 1);
433 sv_catpvs(sstr, "\\n");
435 sv_catpvs(sstr, "\\r");
437 sv_catpvs(sstr, "\\t");
439 sv_catpvs(sstr, "\\a");
441 sv_catpvs(sstr, "\\b");
443 sv_catpvs(sstr, "\\f");
444 else if (!perlstyle && *s == '\v')
445 sv_catpvs(sstr, "\\v");
448 /* Don't want promotion of a signed -1 char in sprintf args */
449 const unsigned char c = (unsigned char) *s;
450 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
452 /* XXX Add line breaks if string is long */
455 sv_catpvs(sstr, "\"");
462 SV *sstr = newSVpvs_flags("'", SVs_TEMP);
463 const char *s = SvPV_nolen(sv);
464 /* Don't want promotion of a signed -1 char in sprintf args */
465 const unsigned char c = (unsigned char) *s;
468 sv_catpvs(sstr, "\\'");
470 sv_catpvs(sstr, "\\\\");
472 sv_catpvn(sstr, s, 1);
474 sv_catpvs(sstr, "\\n");
476 sv_catpvs(sstr, "\\r");
478 sv_catpvs(sstr, "\\t");
480 sv_catpvs(sstr, "\\a");
482 sv_catpvs(sstr, "\\b");
484 sv_catpvs(sstr, "\\f");
486 sv_catpvs(sstr, "\\v");
488 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
489 sv_catpvs(sstr, "'");
493 #define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
494 #define PMOP_pmreplroot(o) o->op_pmreplrootu.op_pmreplroot
497 walkoptree(pTHX_ OP *o, const char *method, SV *ref)
502 const char *const classname = opclassnames[cc_opclass(aTHX_ o)];
505 /* Check that no-one has changed our reference, or is holding a reference
507 if (SvREFCNT(ref) == 1 && SvROK(ref) && SvTYPE(ref) == SVt_RV
508 && (object = SvRV(ref)) && SvREFCNT(object) == 1
509 && SvTYPE(object) == SVt_PVMG && SvIOK_only(object)
510 && !SvMAGICAL(object) && !SvMAGIC(object) && SvSTASH(object)) {
511 /* Looks good, so rebless it for the class we need: */
512 sv_bless(ref, gv_stashpv(classname, GV_ADD));
514 /* Need to make a new one. */
515 ref = sv_newmortal();
516 object = newSVrv(ref, classname);
518 sv_setiv(object, PTR2IV(o));
520 if (walkoptree_debug) {
524 perl_call_method("walkoptree_debug", G_DISCARD);
529 perl_call_method(method, G_DISCARD);
530 if (o && (o->op_flags & OPf_KIDS)) {
531 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
532 ref = walkoptree(aTHX_ kid, method, ref);
535 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
536 && (kid = PMOP_pmreplroot(cPMOPo)))
538 ref = walkoptree(aTHX_ kid, method, ref);
544 oplist(pTHX_ OP *o, SV **SP)
546 for(; o; o = o->op_next) {
550 XPUSHs(make_op_object(aTHX_ o));
551 switch (o->op_type) {
553 SP = oplist(aTHX_ PMOP_pmreplstart(cPMOPo), SP);
556 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
557 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
558 kid = kUNOP->op_first; /* pass rv2gv */
559 kid = kUNOP->op_first; /* pass leave */
560 SP = oplist(aTHX_ kid->op_next, SP);
564 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
566 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
569 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
570 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
571 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
579 typedef UNOP *B__UNOP;
580 typedef BINOP *B__BINOP;
581 typedef LOGOP *B__LOGOP;
582 typedef LISTOP *B__LISTOP;
583 typedef PMOP *B__PMOP;
584 typedef SVOP *B__SVOP;
585 typedef PADOP *B__PADOP;
586 typedef PVOP *B__PVOP;
587 typedef LOOP *B__LOOP;
595 #if PERL_VERSION >= 11
596 typedef SV *B__REGEXP;
608 typedef MAGIC *B__MAGIC;
610 typedef struct refcounted_he *B__RHE;
612 typedef PADLIST *B__PADLIST;
616 # define ASSIGN_COMMON_ALIAS(prefix, var) \
617 STMT_START { XSANY.any_i32 = offsetof(struct interpreter, prefix##var); } STMT_END
619 # define ASSIGN_COMMON_ALIAS(prefix, var) \
620 STMT_START { XSANY.any_ptr = (void *)&PL_##var; } STMT_END
623 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
625 static XSPROTO(intrpvar_sv_common); /* prototype to pass -Wmissing-prototypes */
626 static XSPROTO(intrpvar_sv_common)
632 croak_xs_usage(cv, "");
634 ret = *(SV **)(XSANY.any_i32 + (char *)my_perl);
636 ret = *(SV **)(XSANY.any_ptr);
638 ST(0) = make_sv_object(aTHX_ ret);
648 #define PADOFFSETp 0x4
652 /* Keep this last: */
653 #define op_offset_special 0x8
655 /* table that drives most of the B::*OP methods */
660 U8 type; /* if op_offset_special, access is handled on a case-by-case basis */
663 STR_WITH_LEN("next"), OPp, offsetof(struct op, op_next), /* 0*/
664 STR_WITH_LEN("sibling"), OPp, offsetof(struct op, op_sibling), /* 1*/
665 STR_WITH_LEN("targ"), PADOFFSETp, offsetof(struct op, op_targ), /* 2*/
666 STR_WITH_LEN("flags"), U8p, offsetof(struct op, op_flags), /* 3*/
667 STR_WITH_LEN("private"), U8p, offsetof(struct op, op_private), /* 4*/
668 STR_WITH_LEN("first"), OPp, offsetof(struct unop, op_first), /* 5*/
669 STR_WITH_LEN("last"), OPp, offsetof(struct binop, op_last), /* 6*/
670 STR_WITH_LEN("other"), OPp, offsetof(struct logop, op_other), /* 7*/
671 STR_WITH_LEN("pmreplstart"), op_offset_special, 0, /* 8*/
672 STR_WITH_LEN("redoop"), OPp, offsetof(struct loop, op_redoop), /* 9*/
673 STR_WITH_LEN("nextop"), OPp, offsetof(struct loop, op_nextop), /*10*/
674 STR_WITH_LEN("lastop"), OPp, offsetof(struct loop, op_lastop), /*11*/
675 STR_WITH_LEN("pmflags"), U32p, offsetof(struct pmop, op_pmflags), /*12*/
676 #if PERL_VERSION >= 17
677 STR_WITH_LEN("code_list"),OPp, offsetof(struct pmop, op_code_list),/*13*/
679 STR_WITH_LEN("code_list"),op_offset_special, 0,
681 STR_WITH_LEN("sv"), SVp, offsetof(struct svop, op_sv), /*14*/
682 STR_WITH_LEN("gv"), SVp, offsetof(struct svop, op_sv), /*15*/
683 STR_WITH_LEN("padix"), PADOFFSETp,offsetof(struct padop, op_padix),/*16*/
684 STR_WITH_LEN("cop_seq"), U32p, offsetof(struct cop, cop_seq), /*17*/
685 STR_WITH_LEN("line"), line_tp, offsetof(struct cop, cop_line), /*18*/
686 STR_WITH_LEN("hints"), U32p, offsetof(struct cop, cop_hints), /*19*/
688 STR_WITH_LEN("pmoffset"),IVp, offsetof(struct pmop, op_pmoffset),/*20*/
689 STR_WITH_LEN("filegv"), op_offset_special, 0, /*21*/
690 STR_WITH_LEN("file"), char_pp, offsetof(struct cop, cop_file), /*22*/
691 STR_WITH_LEN("stash"), op_offset_special, 0, /*23*/
692 # if PERL_VERSION < 17
693 STR_WITH_LEN("stashpv"), char_pp, offsetof(struct cop, cop_stashpv), /*24*/
694 STR_WITH_LEN("stashoff"),op_offset_special, 0, /*25*/
696 STR_WITH_LEN("stashpv"), op_offset_special, 0, /*24*/
697 STR_WITH_LEN("stashoff"),PADOFFSETp,offsetof(struct cop, cop_stashoff),/*25*/
700 STR_WITH_LEN("pmoffset"),op_offset_special, 0, /*20*/
701 STR_WITH_LEN("filegv"), SVp, offsetof(struct cop, cop_filegv), /*21*/
702 STR_WITH_LEN("file"), op_offset_special, 0, /*22*/
703 STR_WITH_LEN("stash"), SVp, offsetof(struct cop, cop_stash), /*23*/
704 STR_WITH_LEN("stashpv"), op_offset_special, 0, /*24*/
705 STR_WITH_LEN("stashoff"),op_offset_special, 0, /*25*/
707 STR_WITH_LEN("size"), op_offset_special, 0, /*26*/
708 STR_WITH_LEN("name"), op_offset_special, 0, /*27*/
709 STR_WITH_LEN("desc"), op_offset_special, 0, /*28*/
710 STR_WITH_LEN("ppaddr"), op_offset_special, 0, /*29*/
711 STR_WITH_LEN("type"), op_offset_special, 0, /*30*/
712 STR_WITH_LEN("opt"), op_offset_special, 0, /*31*/
713 STR_WITH_LEN("spare"), op_offset_special, 0, /*32*/
714 STR_WITH_LEN("children"),op_offset_special, 0, /*33*/
715 STR_WITH_LEN("pmreplroot"), op_offset_special, 0, /*34*/
716 STR_WITH_LEN("pmstashpv"), op_offset_special, 0, /*35*/
717 STR_WITH_LEN("pmstash"), op_offset_special, 0, /*36*/
718 STR_WITH_LEN("precomp"), op_offset_special, 0, /*37*/
719 STR_WITH_LEN("reflags"), op_offset_special, 0, /*38*/
720 STR_WITH_LEN("sv"), op_offset_special, 0, /*39*/
721 STR_WITH_LEN("gv"), op_offset_special, 0, /*40*/
722 STR_WITH_LEN("pv"), op_offset_special, 0, /*41*/
723 STR_WITH_LEN("label"), op_offset_special, 0, /*42*/
724 STR_WITH_LEN("arybase"), op_offset_special, 0, /*43*/
725 STR_WITH_LEN("warnings"),op_offset_special, 0, /*44*/
726 STR_WITH_LEN("io"), op_offset_special, 0, /*45*/
727 STR_WITH_LEN("hints_hash"),op_offset_special, 0, /*46*/
728 #if PERL_VERSION >= 17
729 STR_WITH_LEN("slabbed"), op_offset_special, 0, /*47*/
730 STR_WITH_LEN("savefree"),op_offset_special, 0, /*48*/
731 STR_WITH_LEN("static"), op_offset_special, 0, /*49*/
732 #if PERL_VERSION >= 19
733 STR_WITH_LEN("folded"), op_offset_special, 0, /*50*/
738 #include "const-c.inc"
740 MODULE = B PACKAGE = B
742 INCLUDE: const-xs.inc
749 const char *file = __FILE__;
751 specialsv_list[0] = Nullsv;
752 specialsv_list[1] = &PL_sv_undef;
753 specialsv_list[2] = &PL_sv_yes;
754 specialsv_list[3] = &PL_sv_no;
755 specialsv_list[4] = (SV *) pWARN_ALL;
756 specialsv_list[5] = (SV *) pWARN_NONE;
757 specialsv_list[6] = (SV *) pWARN_STD;
759 cv = newXS("B::init_av", intrpvar_sv_common, file);
760 ASSIGN_COMMON_ALIAS(I, initav);
761 cv = newXS("B::check_av", intrpvar_sv_common, file);
762 ASSIGN_COMMON_ALIAS(I, checkav_save);
763 cv = newXS("B::unitcheck_av", intrpvar_sv_common, file);
764 ASSIGN_COMMON_ALIAS(I, unitcheckav_save);
765 cv = newXS("B::begin_av", intrpvar_sv_common, file);
766 ASSIGN_COMMON_ALIAS(I, beginav_save);
767 cv = newXS("B::end_av", intrpvar_sv_common, file);
768 ASSIGN_COMMON_ALIAS(I, endav);
769 cv = newXS("B::main_cv", intrpvar_sv_common, file);
770 ASSIGN_COMMON_ALIAS(I, main_cv);
771 cv = newXS("B::inc_gv", intrpvar_sv_common, file);
772 ASSIGN_COMMON_ALIAS(I, incgv);
773 cv = newXS("B::defstash", intrpvar_sv_common, file);
774 ASSIGN_COMMON_ALIAS(I, defstash);
775 cv = newXS("B::curstash", intrpvar_sv_common, file);
776 ASSIGN_COMMON_ALIAS(I, curstash);
778 cv = newXS("B::formfeed", intrpvar_sv_common, file);
779 ASSIGN_COMMON_ALIAS(I, formfeed);
782 cv = newXS("B::regex_padav", intrpvar_sv_common, file);
783 ASSIGN_COMMON_ALIAS(I, regex_padav);
785 cv = newXS("B::warnhook", intrpvar_sv_common, file);
786 ASSIGN_COMMON_ALIAS(I, warnhook);
787 cv = newXS("B::diehook", intrpvar_sv_common, file);
788 ASSIGN_COMMON_ALIAS(I, diehook);
796 PUSHs(make_sv_object(aTHX_ GvSV(gv_fetchpvs("\f", GV_ADD, SVt_PV))));
803 RETVAL = PL_amagic_generation;
810 PADLIST *padlist = CvPADLIST(PL_main_cv ? PL_main_cv : PL_compcv);
814 SV * const rv = sv_newmortal();
815 sv_setiv(newSVrv(rv, padlist ? "B::PADLIST" : "B::NULL"),
820 PUSHs(make_sv_object(aTHX_ (SV *)padlist));
829 PUSHs(make_sv_object(aTHX_ ix > 1 ? &PL_sv_yes
830 : ix < 1 ? &PL_sv_undef
838 PUSHs(make_op_object(aTHX_ ix ? PL_main_start : PL_main_root));
845 RETVAL = ix ? PL_dowarn : PL_sub_generation;
850 walkoptree(op, method)
854 (void) walkoptree(aTHX_ op, method, &PL_sv_undef);
857 walkoptree_debug(...)
860 RETVAL = walkoptree_debug;
861 if (items > 0 && SvTRUE(ST(1)))
862 walkoptree_debug = 1;
866 #define address(sv) PTR2IV(sv)
877 croak("argument is not a reference");
878 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
887 ST(0) = sv_newmortal();
888 if (strncmp(name,"pp_",3) == 0)
890 for (i = 0; i < PL_maxo; i++)
892 if (strcmp(name, PL_op_name[i]) == 0)
898 sv_setiv(ST(0),result);
905 ST(0) = sv_newmortal();
906 if (opnum >= 0 && opnum < PL_maxo)
907 Perl_sv_setpvf(aTHX_ ST(0), "pp_%s", PL_op_name[opnum]);
915 const char *s = SvPVbyte(sv, len);
916 PERL_HASH(hash, s, len);
917 ST(0) = sv_2mortal(Perl_newSVpvf(aTHX_ "0x%"UVxf, (UV)hash));
919 #define cast_I32(foo) (I32)foo
941 PUSHs(ix == 2 ? cchar(aTHX_ sv) : cstring(aTHX_ sv, (bool)ix));
950 MODULE = B PACKAGE = B::OP
953 # The type checking code in B has always been identical for all OP types,
954 # irrespective of whether the action is actually defined on that OP.
968 B::PMOP::pmreplstart = 8
972 B::PMOP::pmflags = 12
973 B::PMOP::code_list = 13
980 B::PMOP::pmoffset = 20
985 B::COP::stashoff = 25
993 B::LISTOP::children = 33
994 B::PMOP::pmreplroot = 34
995 B::PMOP::pmstashpv = 35
996 B::PMOP::pmstash = 36
997 B::PMOP::precomp = 37
998 B::PMOP::reflags = 38
1003 B::COP::arybase = 43
1004 B::COP::warnings = 44
1006 B::COP::hints_hash = 46
1008 B::OP::savefree = 48
1014 if (ix < 0 || ix > 46)
1015 croak("Illegal alias %d for B::*OP::next", (int)ix);
1016 ret = get_overlay_object(aTHX_ o,
1017 op_methods[ix].name, op_methods[ix].namelen);
1023 /* handle non-direct field access */
1025 if (op_methods[ix].type == op_offset_special)
1027 case 8: /* pmreplstart */
1028 ret = make_op_object(aTHX_
1029 cPMOPo->op_type == OP_SUBST
1030 ? cPMOPo->op_pmstashstartu.op_pmreplstart
1035 case 21: /* filegv */
1036 ret = make_sv_object(aTHX_ (SV *)CopFILEGV((COP*)o));
1039 #ifndef USE_ITHREADS
1041 ret = sv_2mortal(newSVpv(CopFILE((COP*)o), 0));
1045 case 23: /* stash */
1046 ret = make_sv_object(aTHX_ (SV *)CopSTASH((COP*)o));
1049 #if PERL_VERSION >= 17 || !defined USE_ITHREADS
1050 case 24: /* stashpv */
1051 # if PERL_VERSION >= 17
1052 ret = sv_2mortal(CopSTASH((COP*)o)
1053 && SvTYPE(CopSTASH((COP*)o)) == SVt_PVHV
1054 ? newSVhek(HvNAME_HEK(CopSTASH((COP*)o)))
1057 ret = sv_2mortal(newSVpv(CopSTASHPV((COP*)o), 0));
1062 ret = sv_2mortal(newSVuv((UV)(opsizes[cc_opclass(aTHX_ o)])));
1066 ret = sv_2mortal(newSVpv(
1067 (char *)(ix == 28 ? OP_DESC(o) : OP_NAME(o)), 0));
1069 case 29: /* ppaddr */
1072 ret = sv_2mortal(Perl_newSVpvf(aTHX_ "PL_ppaddr[OP_%s]",
1073 PL_op_name[o->op_type]));
1074 for (i=13; (STRLEN)i < SvCUR(ret); ++i)
1075 SvPVX(ret)[i] = toUPPER(SvPVX(ret)[i]);
1080 case 32: /* spare */
1081 #if PERL_VERSION >= 17
1082 case 47: /* slabbed */
1083 case 48: /* savefree */
1084 case 49: /* static */
1085 #if PERL_VERSION >= 19
1086 case 50: /* folded */
1089 /* These are all bitfields, so we can't take their addresses */
1090 ret = sv_2mortal(newSVuv((UV)(
1091 ix == 30 ? o->op_type
1092 : ix == 31 ? o->op_opt
1093 : ix == 47 ? o->op_slabbed
1094 : ix == 48 ? o->op_savefree
1095 : ix == 49 ? o->op_static
1096 : ix == 50 ? o->op_folded
1099 case 33: /* children */
1103 for (kid = ((LISTOP*)o)->op_first; kid; kid = kid->op_sibling)
1105 ret = sv_2mortal(newSVuv(i));
1108 case 34: /* pmreplroot */
1109 if (cPMOPo->op_type == OP_PUSHRE) {
1111 ret = sv_newmortal();
1112 sv_setiv(ret, cPMOPo->op_pmreplrootu.op_pmtargetoff);
1114 GV *const target = cPMOPo->op_pmreplrootu.op_pmtargetgv;
1115 ret = sv_newmortal();
1116 sv_setiv(newSVrv(ret, target ?
1117 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1122 OP *const root = cPMOPo->op_pmreplrootu.op_pmreplroot;
1123 ret = make_op_object(aTHX_ root);
1127 case 35: /* pmstashpv */
1128 ret = sv_2mortal(newSVpv(PmopSTASHPV(cPMOPo),0));
1131 case 36: /* pmstash */
1132 ret = make_sv_object(aTHX_ (SV *) PmopSTASH(cPMOPo));
1135 case 37: /* precomp */
1136 case 38: /* reflags */
1138 REGEXP *rx = PM_GETRE(cPMOPo);
1139 ret = sv_newmortal();
1142 sv_setuv(ret, RX_EXTFLAGS(rx));
1145 sv_setpvn(ret, RX_PRECOMP(rx), RX_PRELEN(rx));
1152 /* It happens that the output typemaps for B::SV and B::GV
1153 * are identical. The "smarts" are in make_sv_object(),
1154 * which determines which class to use based on SvTYPE(),
1155 * rather than anything baked in at compile time. */
1156 if (cPADOPo->op_padix) {
1157 ret = PAD_SVl(cPADOPo->op_padix);
1158 if (ix == 40 && SvTYPE(ret) != SVt_PVGV)
1163 ret = make_sv_object(aTHX_ ret);
1166 /* OP_TRANS uses op_pv to point to a table of 256 or >=258
1167 * shorts whereas other PVOPs point to a null terminated
1169 if ( (cPVOPo->op_type == OP_TRANS
1170 || cPVOPo->op_type == OP_TRANSR) &&
1171 (cPVOPo->op_private & OPpTRANS_COMPLEMENT) &&
1172 !(cPVOPo->op_private & OPpTRANS_DELETE))
1174 const short* const tbl = (short*)cPVOPo->op_pv;
1175 const short entries = 257 + tbl[256];
1176 ret = newSVpvn_flags(cPVOPo->op_pv, entries * sizeof(short), SVs_TEMP);
1178 else if (cPVOPo->op_type == OP_TRANS || cPVOPo->op_type == OP_TRANSR) {
1179 ret = newSVpvn_flags(cPVOPo->op_pv, 256 * sizeof(short), SVs_TEMP);
1182 ret = newSVpvn_flags(cPVOPo->op_pv, strlen(cPVOPo->op_pv), SVs_TEMP);
1184 case 42: /* label */
1185 ret = sv_2mortal(newSVpv(CopLABEL(cCOPo),0));
1187 case 43: /* arybase */
1188 ret = sv_2mortal(newSVuv(0));
1190 case 44: /* warnings */
1191 ret = make_warnings_object(aTHX_ cCOPo);
1194 ret = make_cop_io_object(aTHX_ cCOPo);
1196 case 46: /* hints_hash */
1197 ret = sv_newmortal();
1198 sv_setiv(newSVrv(ret, "B::RHE"),
1199 PTR2IV(CopHINTHASH_get(cCOPo)));
1202 croak("method %s not implemented", op_methods[ix].name);
1204 /* do a direct structure offset lookup */
1205 const char *const ptr = (char *)o + op_methods[ix].offset;
1206 switch (op_methods[ix].type) {
1208 ret = make_op_object(aTHX_ *((OP **)ptr));
1211 ret = sv_2mortal(newSVuv(*((PADOFFSET*)ptr)));
1214 ret = sv_2mortal(newSVuv(*((U8*)ptr)));
1217 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1220 ret = make_sv_object(aTHX_ *((SV **)ptr));
1223 ret = sv_2mortal(newSVuv(*((line_t *)ptr)));
1226 ret = sv_2mortal(newSViv(*((IV*)ptr)));
1229 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1232 croak("Illegal type 0x%x for B::*OP::%s",
1233 (unsigned)op_methods[ix].type, op_methods[ix].name);
1244 SP = oplist(aTHX_ o, SP);
1247 MODULE = B PACKAGE = B::SV
1249 #define MAGICAL_FLAG_BITS (SVs_GMG|SVs_SMG|SVs_RMG)
1259 MAGICAL = MAGICAL_FLAG_BITS
1261 RETVAL = ix ? (SvFLAGS(sv) & (U32)ix) : SvREFCNT(sv);
1269 ST(0) = sv_2mortal(newRV(sv));
1272 MODULE = B PACKAGE = B::IV PREFIX = Sv
1278 MODULE = B PACKAGE = B::IV
1280 #define sv_SVp 0x00000
1281 #define sv_IVp 0x10000
1282 #define sv_UVp 0x20000
1283 #define sv_STRLENp 0x30000
1284 #define sv_U32p 0x40000
1285 #define sv_U8p 0x50000
1286 #define sv_char_pp 0x60000
1287 #define sv_NVp 0x70000
1288 #define sv_char_p 0x80000
1289 #define sv_SSize_tp 0x90000
1290 #define sv_I32p 0xA0000
1291 #define sv_U16p 0xB0000
1293 #define IV_ivx_ix sv_IVp | offsetof(struct xpviv, xiv_iv)
1294 #define IV_uvx_ix sv_UVp | offsetof(struct xpvuv, xuv_uv)
1295 #define NV_nvx_ix sv_NVp | offsetof(struct xpvnv, xnv_u.xnv_nv)
1297 #define NV_cop_seq_range_low_ix \
1298 sv_U32p | offsetof(struct xpvnv, xnv_u.xpad_cop_seq.xlow)
1299 #define NV_cop_seq_range_high_ix \
1300 sv_U32p | offsetof(struct xpvnv, xnv_u.xpad_cop_seq.xhigh)
1301 #define NV_parent_pad_index_ix \
1302 sv_U32p | offsetof(struct xpvnv, xnv_u.xpad_cop_seq.xlow)
1303 #define NV_parent_fakelex_flags_ix \
1304 sv_U32p | offsetof(struct xpvnv, xnv_u.xpad_cop_seq.xhigh)
1306 #define PV_cur_ix sv_STRLENp | offsetof(struct xpv, xpv_cur)
1307 #define PV_len_ix sv_STRLENp | offsetof(struct xpv, xpv_len)
1309 #define PVMG_stash_ix sv_SVp | offsetof(struct xpvmg, xmg_stash)
1311 #if PERL_VERSION > 18
1312 # define PVBM_useful_ix sv_I32p | offsetof(struct xpvgv, xnv_u.xbm_useful)
1313 #elif PERL_VERSION > 14
1314 # define PVBM_useful_ix sv_I32p | offsetof(struct xpvgv, xnv_u.xbm_s.xbm_useful)
1316 #define PVBM_useful_ix sv_I32p | offsetof(struct xpvgv, xiv_u.xivu_i32)
1319 #define PVLV_targoff_ix sv_U32p | offsetof(struct xpvlv, xlv_targoff)
1320 #define PVLV_targlen_ix sv_U32p | offsetof(struct xpvlv, xlv_targlen)
1321 #define PVLV_targ_ix sv_SVp | offsetof(struct xpvlv, xlv_targ)
1322 #define PVLV_type_ix sv_char_p | offsetof(struct xpvlv, xlv_type)
1324 #define PVGV_stash_ix sv_SVp | offsetof(struct xpvgv, xnv_u.xgv_stash)
1325 #define PVGV_flags_ix sv_STRLENp | offsetof(struct xpvgv, xpv_cur)
1326 #define PVIO_lines_ix sv_IVp | offsetof(struct xpvio, xiv_iv)
1328 #define PVIO_page_ix sv_IVp | offsetof(struct xpvio, xio_page)
1329 #define PVIO_page_len_ix sv_IVp | offsetof(struct xpvio, xio_page_len)
1330 #define PVIO_lines_left_ix sv_IVp | offsetof(struct xpvio, xio_lines_left)
1331 #define PVIO_top_name_ix sv_char_pp | offsetof(struct xpvio, xio_top_name)
1332 #define PVIO_top_gv_ix sv_SVp | offsetof(struct xpvio, xio_top_gv)
1333 #define PVIO_fmt_name_ix sv_char_pp | offsetof(struct xpvio, xio_fmt_name)
1334 #define PVIO_fmt_gv_ix sv_SVp | offsetof(struct xpvio, xio_fmt_gv)
1335 #define PVIO_bottom_name_ix sv_char_pp | offsetof(struct xpvio, xio_bottom_name)
1336 #define PVIO_bottom_gv_ix sv_SVp | offsetof(struct xpvio, xio_bottom_gv)
1337 #define PVIO_type_ix sv_char_p | offsetof(struct xpvio, xio_type)
1338 #define PVIO_flags_ix sv_U8p | offsetof(struct xpvio, xio_flags)
1340 #define PVAV_max_ix sv_SSize_tp | offsetof(struct xpvav, xav_max)
1342 #define PVCV_stash_ix sv_SVp | offsetof(struct xpvcv, xcv_stash)
1343 #if PERL_VERSION > 17 || (PERL_VERSION == 17 && PERL_SUBVERSION >= 3)
1344 # define PVCV_gv_ix sv_SVp | offsetof(struct xpvcv, xcv_gv_u.xcv_gv)
1346 # define PVCV_gv_ix sv_SVp | offsetof(struct xpvcv, xcv_gv)
1348 #define PVCV_file_ix sv_char_pp | offsetof(struct xpvcv, xcv_file)
1349 #define PVCV_outside_ix sv_SVp | offsetof(struct xpvcv, xcv_outside)
1350 #define PVCV_outside_seq_ix sv_U32p | offsetof(struct xpvcv, xcv_outside_seq)
1351 #define PVCV_flags_ix sv_U32p | offsetof(struct xpvcv, xcv_flags)
1353 #define PVHV_max_ix sv_STRLENp | offsetof(struct xpvhv, xhv_max)
1355 #if PERL_VERSION > 12
1356 #define PVHV_keys_ix sv_STRLENp | offsetof(struct xpvhv, xhv_keys)
1358 #define PVHV_keys_ix sv_IVp | offsetof(struct xpvhv, xhv_keys)
1361 # The type checking code in B has always been identical for all SV types,
1362 # irrespective of whether the action is actually defined on that SV.
1363 # We should fix this
1368 B::IV::IVX = IV_ivx_ix
1369 B::IV::UVX = IV_uvx_ix
1370 B::NV::NVX = NV_nvx_ix
1371 B::NV::COP_SEQ_RANGE_LOW = NV_cop_seq_range_low_ix
1372 B::NV::COP_SEQ_RANGE_HIGH = NV_cop_seq_range_high_ix
1373 B::NV::PARENT_PAD_INDEX = NV_parent_pad_index_ix
1374 B::NV::PARENT_FAKELEX_FLAGS = NV_parent_fakelex_flags_ix
1375 B::PV::CUR = PV_cur_ix
1376 B::PV::LEN = PV_len_ix
1377 B::PVMG::SvSTASH = PVMG_stash_ix
1378 B::PVLV::TARGOFF = PVLV_targoff_ix
1379 B::PVLV::TARGLEN = PVLV_targlen_ix
1380 B::PVLV::TARG = PVLV_targ_ix
1381 B::PVLV::TYPE = PVLV_type_ix
1382 B::GV::STASH = PVGV_stash_ix
1383 B::GV::GvFLAGS = PVGV_flags_ix
1384 B::BM::USEFUL = PVBM_useful_ix
1385 B::IO::LINES = PVIO_lines_ix
1386 B::IO::PAGE = PVIO_page_ix
1387 B::IO::PAGE_LEN = PVIO_page_len_ix
1388 B::IO::LINES_LEFT = PVIO_lines_left_ix
1389 B::IO::TOP_NAME = PVIO_top_name_ix
1390 B::IO::TOP_GV = PVIO_top_gv_ix
1391 B::IO::FMT_NAME = PVIO_fmt_name_ix
1392 B::IO::FMT_GV = PVIO_fmt_gv_ix
1393 B::IO::BOTTOM_NAME = PVIO_bottom_name_ix
1394 B::IO::BOTTOM_GV = PVIO_bottom_gv_ix
1395 B::IO::IoTYPE = PVIO_type_ix
1396 B::IO::IoFLAGS = PVIO_flags_ix
1397 B::AV::MAX = PVAV_max_ix
1398 B::CV::STASH = PVCV_stash_ix
1399 B::CV::FILE = PVCV_file_ix
1400 B::CV::OUTSIDE = PVCV_outside_ix
1401 B::CV::OUTSIDE_SEQ = PVCV_outside_seq_ix
1402 B::CV::CvFLAGS = PVCV_flags_ix
1403 B::HV::MAX = PVHV_max_ix
1404 B::HV::KEYS = PVHV_keys_ix
1409 ptr = (ix & 0xFFFF) + (char *)SvANY(sv);
1410 switch ((U8)(ix >> 16)) {
1411 case (U8)(sv_SVp >> 16):
1412 ret = make_sv_object(aTHX_ *((SV **)ptr));
1414 case (U8)(sv_IVp >> 16):
1415 ret = sv_2mortal(newSViv(*((IV *)ptr)));
1417 case (U8)(sv_UVp >> 16):
1418 ret = sv_2mortal(newSVuv(*((UV *)ptr)));
1420 case (U8)(sv_STRLENp >> 16):
1421 ret = sv_2mortal(newSVuv(*((STRLEN *)ptr)));
1423 case (U8)(sv_U32p >> 16):
1424 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
1426 case (U8)(sv_U8p >> 16):
1427 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
1429 case (U8)(sv_char_pp >> 16):
1430 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1432 case (U8)(sv_NVp >> 16):
1433 ret = sv_2mortal(newSVnv(*((NV *)ptr)));
1435 case (U8)(sv_char_p >> 16):
1436 ret = newSVpvn_flags((char *)ptr, 1, SVs_TEMP);
1438 case (U8)(sv_SSize_tp >> 16):
1439 ret = sv_2mortal(newSViv(*((SSize_t *)ptr)));
1441 case (U8)(sv_I32p >> 16):
1442 ret = sv_2mortal(newSVuv(*((I32 *)ptr)));
1444 case (U8)(sv_U16p >> 16):
1445 ret = sv_2mortal(newSVuv(*((U16 *)ptr)));
1448 croak("Illegal alias 0x%08x for B::*IVX", (unsigned)ix);
1460 ST(0) = boolSV((I32)SvIVX(sv) != SvIVX(sv));
1461 } else if (sizeof(IV) == 8) {
1463 const IV iv = SvIVX(sv);
1465 * The following way of spelling 32 is to stop compilers on
1466 * 32-bit architectures from moaning about the shift count
1467 * being >= the width of the type. Such architectures don't
1468 * reach this code anyway (unless sizeof(IV) > 8 but then
1469 * everything else breaks too so I'm not fussed at the moment).
1472 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1474 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1476 wp[1] = htonl(iv & 0xffffffff);
1477 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1479 U32 w = htonl((U32)SvIVX(sv));
1480 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1483 MODULE = B PACKAGE = B::NV PREFIX = Sv
1489 #if PERL_VERSION < 11
1491 MODULE = B PACKAGE = B::RV PREFIX = Sv
1497 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
1501 MODULE = B PACKAGE = B::REGEXP
1510 PUSHs(newSVpvn_flags(RX_PRECOMP(sv), RX_PRELEN(sv), SVs_TEMP));
1513 /* FIXME - can we code this method more efficiently? */
1519 MODULE = B PACKAGE = B::PV
1526 croak( "argument is not SvROK" );
1527 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
1542 #ifndef PERL_FBM_TABLE_OFFSET
1543 const MAGIC *const mg = mg_find(sv, PERL_MAGIC_bm);
1546 croak("argument to B::BM::TABLE is not a PVBM");
1551 /* Boyer-Moore table is just after string and its safety-margin \0 */
1552 p += len + PERL_FBM_TABLE_OFFSET;
1555 } else if (ix == 2) {
1556 /* This used to read 257. I think that that was buggy - should have
1557 been 258. (The "\0", the flags byte, and 256 for the table.)
1558 The only user of this method is B::Bytecode in B::PV::bsave.
1559 I'm guessing that nothing tested the runtime correctness of
1560 output of bytecompiled string constant arguments to index (etc).
1562 Note the start pointer is and has always been SvPVX(sv), not
1563 SvPVX(sv) + SvCUR(sv) PVBM was added in 651aa52ea1faa806, and
1564 first used by the compiler in 651aa52ea1faa806. It's used to
1565 get a "complete" dump of the buffer at SvPVX(), not just the
1566 PVBM table. This permits the generated bytecode to "load"
1569 5.15 and later store the BM table via MAGIC, so the compiler
1570 should handle this just fine without changes if PVBM now
1571 always returns the SvPVX() buffer. */
1574 ? RX_WRAPPED_const((REGEXP*)sv)
1577 p = SvPVX_const(sv);
1579 #ifdef PERL_FBM_TABLE_OFFSET
1580 len = SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0);
1586 p = isREGEXP(sv) ? RX_WRAPPED((REGEXP*)sv) : SvPVX(sv);
1591 } else if (SvPOK(sv)) {
1593 p = SvPVX_const(sv);
1597 else if (isREGEXP(sv)) {
1599 p = RX_WRAPPED_const((REGEXP*)sv);
1604 /* XXX for backward compatibility, but should fail */
1605 /* croak( "argument is not SvPOK" ); */
1608 ST(0) = newSVpvn_flags(p, len, SVs_TEMP | utf8);
1610 MODULE = B PACKAGE = B::PVMG
1615 MAGIC * mg = NO_INIT
1617 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1618 XPUSHs(make_mg_object(aTHX_ mg));
1620 MODULE = B PACKAGE = B::MAGIC
1637 XPUSHs(mg->mg_moremagic ? make_mg_object(aTHX_ mg->mg_moremagic)
1641 mPUSHu(mg->mg_private);
1644 PUSHs(newSVpvn_flags(&(mg->mg_type), 1, SVs_TEMP));
1647 mPUSHu(mg->mg_flags);
1653 PUSHs(make_sv_object(aTHX_ mg->mg_obj));
1657 if (mg->mg_len >= 0) {
1658 PUSHs(newSVpvn_flags(mg->mg_ptr, mg->mg_len, SVs_TEMP));
1659 } else if (mg->mg_len == HEf_SVKEY) {
1660 PUSHs(make_sv_object(aTHX_ (SV*)mg->mg_ptr));
1662 PUSHs(sv_newmortal());
1664 PUSHs(sv_newmortal());
1667 if(mg->mg_type == PERL_MAGIC_qr) {
1668 mPUSHi(PTR2IV(mg->mg_obj));
1670 croak("REGEX is only meaningful on r-magic");
1674 if (mg->mg_type == PERL_MAGIC_qr) {
1675 REGEXP *rx = (REGEXP *)mg->mg_obj;
1676 PUSHs(newSVpvn_flags(rx ? RX_PRECOMP(rx) : NULL,
1677 rx ? RX_PRELEN(rx) : 0, SVs_TEMP));
1679 croak( "precomp is only meaningful on r-magic" );
1684 MODULE = B PACKAGE = B::BM PREFIX = Bm
1694 MODULE = B PACKAGE = B::GV PREFIX = Gv
1703 ST(0) = sv_2mortal(newSVhek(!ix ? GvNAME_HEK(gv)
1704 : (ix == 1 ? GvFILE_HEK(gv)
1705 : HvNAME_HEK((HV *)gv))));
1714 RETVAL = isGV_with_GP(gv) ? TRUE : FALSE;
1716 RETVAL = GvGP(gv) == Null(GP*);
1725 #define GP_sv_ix (SVp << 16) | offsetof(struct gp, gp_sv)
1726 #define GP_io_ix (SVp << 16) | offsetof(struct gp, gp_io)
1727 #define GP_cv_ix (SVp << 16) | offsetof(struct gp, gp_cv)
1728 #define GP_cvgen_ix (U32p << 16) | offsetof(struct gp, gp_cvgen)
1729 #define GP_refcnt_ix (U32p << 16) | offsetof(struct gp, gp_refcnt)
1730 #define GP_hv_ix (SVp << 16) | offsetof(struct gp, gp_hv)
1731 #define GP_av_ix (SVp << 16) | offsetof(struct gp, gp_av)
1732 #define GP_form_ix (SVp << 16) | offsetof(struct gp, gp_form)
1733 #define GP_egv_ix (SVp << 16) | offsetof(struct gp, gp_egv)
1734 #define GP_line_ix (line_tp << 16) | offsetof(struct gp, gp_line)
1744 GvREFCNT = GP_refcnt_ix
1757 const GV *const gv = CvGV(cv);
1758 Perl_croak(aTHX_ "NULL gp in B::GV::%s", gv ? GvNAME(gv) : "???");
1760 ptr = (ix & 0xFFFF) + (char *)gp;
1761 switch ((U8)(ix >> 16)) {
1763 ret = make_sv_object(aTHX_ *((SV **)ptr));
1766 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1769 ret = sv_2mortal(newSVuv(*((line_t *)ptr)));
1772 croak("Illegal alias 0x%08x for B::*SV", (unsigned)ix);
1781 PUSHs(make_sv_object(aTHX_ (SV *)GvFILEGV(gv)));
1783 MODULE = B PACKAGE = B::IO PREFIX = Io
1793 if( strEQ( name, "stdin" ) ) {
1794 handle = PerlIO_stdin();
1796 else if( strEQ( name, "stdout" ) ) {
1797 handle = PerlIO_stdout();
1799 else if( strEQ( name, "stderr" ) ) {
1800 handle = PerlIO_stderr();
1803 croak( "Invalid value '%s'", name );
1805 RETVAL = handle == IoIFP(io);
1809 MODULE = B PACKAGE = B::AV PREFIX = Av
1819 if (AvFILL(av) >= 0) {
1820 SV **svp = AvARRAY(av);
1822 for (i = 0; i <= AvFILL(av); i++)
1823 XPUSHs(make_sv_object(aTHX_ svp[i]));
1831 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1832 XPUSHs(make_sv_object(aTHX_ (AvARRAY(av)[idx])));
1834 XPUSHs(make_sv_object(aTHX_ NULL));
1837 MODULE = B PACKAGE = B::FM PREFIX = Fm
1840 #define FmLINES(sv) 0
1846 MODULE = B PACKAGE = B::CV PREFIX = Cv
1858 PUSHs(make_op_object(aTHX_ CvISXSUB(cv) ? NULL
1859 : ix ? CvROOT(cv) : CvSTART(cv)));
1877 PUSHs(make_sv_object(aTHX_ (SV *)CvPADLIST(cv)));
1888 ST(0) = ix && CvCONST(cv)
1889 ? make_sv_object(aTHX_ (SV *)CvXSUBANY(cv).any_ptr)
1890 : sv_2mortal(newSViv(CvISXSUB(cv)
1891 ? (ix ? CvXSUBANY(cv).any_iv
1892 : PTR2IV(CvXSUB(cv)))
1899 PUSHs(make_sv_object(aTHX_ (SV *)cv_const_sv(cv)));
1905 ST(0) = make_sv_object(aTHX_ (SV*)CvGV(cv));
1907 #if PERL_VERSION > 17
1913 RETVAL = CvNAMED(cv) ? newSVhek(CvNAME_HEK(cv)) : &PL_sv_undef;
1919 MODULE = B PACKAGE = B::HV PREFIX = Hv
1933 if (HvUSEDKEYS(hv) > 0) {
1937 (void)hv_iterinit(hv);
1938 EXTEND(sp, HvUSEDKEYS(hv) * 2);
1939 while ((sv = hv_iternextsv(hv, &key, &len))) {
1941 PUSHs(make_sv_object(aTHX_ sv));
1945 MODULE = B PACKAGE = B::HE PREFIX = He
1953 PUSHs(make_sv_object(aTHX_ ix ? HeSVKEY_force(he) : HeVAL(he)));
1959 MODULE = B PACKAGE = B::RHE
1965 RETVAL = newRV( (SV*)cophh_2hv(h, 0) );
1972 MODULE = B PACKAGE = B::PADLIST PREFIX = Padlist
1979 PadlistARRAY(padlist)
1982 if (PadlistMAX(padlist) >= 0) {
1983 PAD **padp = PadlistARRAY(padlist);
1985 for (i = 0; i <= PadlistMAX(padlist); i++)
1986 XPUSHs(make_sv_object(aTHX_ (SV *)padp[i]));
1990 PadlistARRAYelt(padlist, idx)
1994 if (PadlistMAX(padlist) >= 0
1995 && idx <= PadlistMAX(padlist))
1996 XPUSHs(make_sv_object(aTHX_
1997 (SV *)PadlistARRAY(padlist)[idx]));
1999 XPUSHs(make_sv_object(aTHX_ NULL));
2002 PadlistREFCNT(padlist)
2005 RETVAL = PadlistREFCNT(padlist);