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[] = {
43 static const char* const opclassnames[] = {
60 static const size_t opsizes[] = {
77 #define MY_CXT_KEY "B::_guts" XS_VERSION
80 SV * x_specialsv_list[8];
81 int x_walkoptree_debug; /* Flag for walkoptree debug hook */
86 #define walkoptree_debug (MY_CXT.x_walkoptree_debug)
87 #define specialsv_list (MY_CXT.x_specialsv_list)
90 static void B_init_my_cxt(pTHX_ my_cxt_t * cxt) {
91 cxt->x_specialsv_list[0] = Nullsv;
92 cxt->x_specialsv_list[1] = &PL_sv_undef;
93 cxt->x_specialsv_list[2] = &PL_sv_yes;
94 cxt->x_specialsv_list[3] = &PL_sv_no;
95 cxt->x_specialsv_list[4] = (SV *) pWARN_ALL;
96 cxt->x_specialsv_list[5] = (SV *) pWARN_NONE;
97 cxt->x_specialsv_list[6] = (SV *) pWARN_STD;
98 cxt->x_specialsv_list[7] = &PL_sv_zero;
103 make_op_object(pTHX_ const OP *o)
105 SV *opsv = sv_newmortal();
106 sv_setiv(newSVrv(opsv, opclassnames[op_class(o)]), PTR2IV(o));
112 get_overlay_object(pTHX_ const OP *o, const char * const name, U32 namelen)
117 SV *sv =get_sv("B::overlay", 0);
118 if (!sv || !SvROK(sv))
121 if (SvTYPE(sv) != SVt_PVHV)
123 key = newSViv(PTR2IV(o));
124 he = hv_fetch_ent((HV*)sv, key, 0, 0);
129 if (!sv || !SvROK(sv))
132 if (SvTYPE(sv) != SVt_PVHV)
134 svp = hv_fetch((HV*)sv, name, namelen, 0);
143 make_sv_object(pTHX_ SV *sv)
145 SV *const arg = sv_newmortal();
146 const char *type = 0;
150 for (iv = 0; iv < (IV)(sizeof(specialsv_list)/sizeof(SV*)); iv++) {
151 if (sv == specialsv_list[iv]) {
157 type = svclassnames[SvTYPE(sv)];
160 sv_setiv(newSVrv(arg, type), iv);
165 make_temp_object(pTHX_ SV *temp)
168 SV *arg = sv_newmortal();
169 const char *const type = svclassnames[SvTYPE(temp)];
170 const IV iv = PTR2IV(temp);
172 target = newSVrv(arg, type);
173 sv_setiv(target, iv);
175 /* Need to keep our "temp" around as long as the target exists.
176 Simplest way seems to be to hang it from magic, and let that clear
177 it up. No vtable, so won't actually get in the way of anything. */
178 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
179 /* magic object has had its reference count increased, so we must drop
186 make_warnings_object(pTHX_ const COP *const cop)
188 const STRLEN *const warnings = cop->cop_warnings;
189 const char *type = 0;
191 IV iv = sizeof(specialsv_list)/sizeof(SV*);
193 /* Counting down is deliberate. Before the split between make_sv_object
194 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
195 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
198 if ((SV*)warnings == specialsv_list[iv]) {
204 SV *arg = sv_newmortal();
205 sv_setiv(newSVrv(arg, type), iv);
208 /* B assumes that warnings are a regular SV. Seems easier to keep it
209 happy by making them into a regular SV. */
210 return make_temp_object(aTHX_ newSVpvn((char *)(warnings + 1), *warnings));
215 make_cop_io_object(pTHX_ COP *cop)
217 SV *const value = newSV(0);
219 Perl_emulate_cop_io(aTHX_ cop, value);
222 return make_sv_object(aTHX_ value);
225 return make_sv_object(aTHX_ NULL);
230 make_mg_object(pTHX_ MAGIC *mg)
232 SV *arg = sv_newmortal();
233 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
238 cstring(pTHX_ SV *sv, bool perlstyle)
243 return newSVpvs_flags("0", SVs_TEMP);
245 sstr = newSVpvs_flags("\"", SVs_TEMP);
247 if (perlstyle && SvUTF8(sv)) {
248 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
249 const STRLEN len = SvCUR(sv);
250 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
254 sv_catpvs(sstr, "\\\"");
256 sv_catpvs(sstr, "\\$");
258 sv_catpvs(sstr, "\\@");
261 if (strchr("nrftax\\",*(s+1)))
262 sv_catpvn(sstr, s++, 2);
264 sv_catpvs(sstr, "\\\\");
266 else /* should always be printable */
267 sv_catpvn(sstr, s, 1);
275 const char *s = SvPV(sv, len);
276 for (; len; len--, s++)
278 /* At least try a little for readability */
280 sv_catpvs(sstr, "\\\"");
282 sv_catpvs(sstr, "\\\\");
283 /* trigraphs - bleagh */
284 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
285 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", '?');
287 else if (perlstyle && *s == '$')
288 sv_catpvs(sstr, "\\$");
289 else if (perlstyle && *s == '@')
290 sv_catpvs(sstr, "\\@");
291 else if (isPRINT(*s))
292 sv_catpvn(sstr, s, 1);
294 sv_catpvs(sstr, "\\n");
296 sv_catpvs(sstr, "\\r");
298 sv_catpvs(sstr, "\\t");
300 sv_catpvs(sstr, "\\a");
302 sv_catpvs(sstr, "\\b");
304 sv_catpvs(sstr, "\\f");
305 else if (!perlstyle && *s == '\v')
306 sv_catpvs(sstr, "\\v");
309 /* Don't want promotion of a signed -1 char in sprintf args */
310 const unsigned char c = (unsigned char) *s;
311 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
313 /* XXX Add line breaks if string is long */
316 sv_catpvs(sstr, "\"");
323 SV *sstr = newSVpvs_flags("'", SVs_TEMP);
324 const char *s = SvPV_nolen(sv);
325 /* Don't want promotion of a signed -1 char in sprintf args */
326 const unsigned char c = (unsigned char) *s;
329 sv_catpvs(sstr, "\\'");
331 sv_catpvs(sstr, "\\\\");
333 sv_catpvn(sstr, s, 1);
335 sv_catpvs(sstr, "\\n");
337 sv_catpvs(sstr, "\\r");
339 sv_catpvs(sstr, "\\t");
341 sv_catpvs(sstr, "\\a");
343 sv_catpvs(sstr, "\\b");
345 sv_catpvs(sstr, "\\f");
347 sv_catpvs(sstr, "\\v");
349 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
350 sv_catpvs(sstr, "'");
354 #define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
355 #define PMOP_pmreplroot(o) o->op_pmreplrootu.op_pmreplroot
358 walkoptree(pTHX_ OP *o, const char *method, SV *ref)
363 const char *const classname = opclassnames[op_class(o)];
366 /* Check that no-one has changed our reference, or is holding a reference
368 if (SvREFCNT(ref) == 1 && SvROK(ref) && SvTYPE(ref) == SVt_RV
369 && (object = SvRV(ref)) && SvREFCNT(object) == 1
370 && SvTYPE(object) == SVt_PVMG && SvIOK_only(object)
371 && !SvMAGICAL(object) && !SvMAGIC(object) && SvSTASH(object)) {
372 /* Looks good, so rebless it for the class we need: */
373 sv_bless(ref, gv_stashpv(classname, GV_ADD));
375 /* Need to make a new one. */
376 ref = sv_newmortal();
377 object = newSVrv(ref, classname);
379 sv_setiv(object, PTR2IV(o));
381 if (walkoptree_debug) {
385 perl_call_method("walkoptree_debug", G_DISCARD);
390 perl_call_method(method, G_DISCARD);
391 if (o && (o->op_flags & OPf_KIDS)) {
392 for (kid = ((UNOP*)o)->op_first; kid; kid = OpSIBLING(kid)) {
393 ref = walkoptree(aTHX_ kid, method, ref);
396 if (o && (op_class(o) == OPclass_PMOP) && o->op_type != OP_SPLIT
397 && (kid = PMOP_pmreplroot(cPMOPo)))
399 ref = walkoptree(aTHX_ kid, method, ref);
405 oplist(pTHX_ OP *o, SV **SP)
407 for(; o; o = o->op_next) {
411 XPUSHs(make_op_object(aTHX_ o));
412 switch (o->op_type) {
414 SP = oplist(aTHX_ PMOP_pmreplstart(cPMOPo), SP);
417 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
418 OP *kid = OpSIBLING(cLISTOPo->op_first); /* pass pushmark */
419 kid = kUNOP->op_first; /* pass rv2gv */
420 kid = kUNOP->op_first; /* pass leave */
421 SP = oplist(aTHX_ kid->op_next, SP);
425 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
427 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
430 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
431 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
432 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
440 typedef UNOP *B__UNOP;
441 typedef BINOP *B__BINOP;
442 typedef LOGOP *B__LOGOP;
443 typedef LISTOP *B__LISTOP;
444 typedef PMOP *B__PMOP;
445 typedef SVOP *B__SVOP;
446 typedef PADOP *B__PADOP;
447 typedef PVOP *B__PVOP;
448 typedef LOOP *B__LOOP;
450 typedef METHOP *B__METHOP;
457 typedef SV *B__REGEXP;
468 typedef MAGIC *B__MAGIC;
470 typedef struct refcounted_he *B__RHE;
471 typedef PADLIST *B__PADLIST;
472 typedef PADNAMELIST *B__PADNAMELIST;
473 typedef PADNAME *B__PADNAME;
477 # define ASSIGN_COMMON_ALIAS(prefix, var) \
478 STMT_START { XSANY.any_i32 = STRUCT_OFFSET(struct interpreter, prefix##var); } STMT_END
480 # define ASSIGN_COMMON_ALIAS(prefix, var) \
481 STMT_START { XSANY.any_ptr = (void *)&PL_##var; } STMT_END
484 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
486 static XSPROTO(intrpvar_sv_common); /* prototype to pass -Wmissing-prototypes */
487 static XSPROTO(intrpvar_sv_common)
493 croak_xs_usage(cv, "");
495 ret = *(SV **)(XSANY.any_i32 + (char *)my_perl);
497 ret = *(SV **)(XSANY.any_ptr);
499 ST(0) = make_sv_object(aTHX_ ret);
509 #define PADOFFSETp 0x4
513 /* Keep this last: */
514 #define op_offset_special 0x8
516 /* table that drives most of the B::*OP methods */
518 static const struct OP_methods {
521 U8 type; /* if op_offset_special, access is handled on a case-by-case basis */
524 { STR_WITH_LEN("next"), OPp, STRUCT_OFFSET(struct op, op_next), },/* 0*/
525 { STR_WITH_LEN("sibling"), op_offset_special, 0, },/* 1*/
526 { STR_WITH_LEN("targ"), PADOFFSETp, STRUCT_OFFSET(struct op, op_targ), },/* 2*/
527 { STR_WITH_LEN("flags"), U8p, STRUCT_OFFSET(struct op, op_flags), },/* 3*/
528 { STR_WITH_LEN("private"), U8p, STRUCT_OFFSET(struct op, op_private), },/* 4*/
529 { STR_WITH_LEN("first"), OPp, STRUCT_OFFSET(struct unop, op_first), },/* 5*/
530 { STR_WITH_LEN("last"), OPp, STRUCT_OFFSET(struct binop, op_last), },/* 6*/
531 { STR_WITH_LEN("other"), OPp, STRUCT_OFFSET(struct logop, op_other), },/* 7*/
532 { STR_WITH_LEN("pmreplstart"), op_offset_special, 0, },/* 8*/
533 { STR_WITH_LEN("redoop"), OPp, STRUCT_OFFSET(struct loop, op_redoop), },/* 9*/
534 { STR_WITH_LEN("nextop"), OPp, STRUCT_OFFSET(struct loop, op_nextop), },/*10*/
535 { STR_WITH_LEN("lastop"), OPp, STRUCT_OFFSET(struct loop, op_lastop), },/*11*/
536 { STR_WITH_LEN("pmflags"), U32p, STRUCT_OFFSET(struct pmop, op_pmflags),},/*12*/
537 { STR_WITH_LEN("code_list"),OPp, STRUCT_OFFSET(struct pmop, op_code_list),},/*13*/
538 { STR_WITH_LEN("sv"), SVp, STRUCT_OFFSET(struct svop, op_sv), },/*14*/
539 { STR_WITH_LEN("gv"), SVp, STRUCT_OFFSET(struct svop, op_sv), },/*15*/
540 { STR_WITH_LEN("padix"), PADOFFSETp,STRUCT_OFFSET(struct padop, op_padix),},/*16*/
541 { STR_WITH_LEN("cop_seq"), U32p, STRUCT_OFFSET(struct cop, cop_seq), },/*17*/
542 { STR_WITH_LEN("line"), line_tp, STRUCT_OFFSET(struct cop, cop_line), },/*18*/
543 { STR_WITH_LEN("hints"), U32p, STRUCT_OFFSET(struct cop, cop_hints), },/*19*/
545 { STR_WITH_LEN("pmoffset"),IVp, STRUCT_OFFSET(struct pmop, op_pmoffset),},/*20*/
546 { STR_WITH_LEN("filegv"), op_offset_special, 0, },/*21*/
547 { STR_WITH_LEN("file"), char_pp, STRUCT_OFFSET(struct cop, cop_file), },/*22*/
548 { STR_WITH_LEN("stash"), op_offset_special, 0, },/*23*/
549 { STR_WITH_LEN("stashpv"), op_offset_special, 0, },/*24*/
550 { STR_WITH_LEN("stashoff"),PADOFFSETp,STRUCT_OFFSET(struct cop,cop_stashoff),},/*25*/
552 { STR_WITH_LEN("pmoffset"),op_offset_special, 0, },/*20*/
553 { STR_WITH_LEN("filegv"), SVp, STRUCT_OFFSET(struct cop, cop_filegv),},/*21*/
554 { STR_WITH_LEN("file"), op_offset_special, 0, },/*22*/
555 { STR_WITH_LEN("stash"), SVp, STRUCT_OFFSET(struct cop, cop_stash), },/*23*/
556 { STR_WITH_LEN("stashpv"), op_offset_special, 0, },/*24*/
557 { STR_WITH_LEN("stashoff"),op_offset_special, 0, },/*25*/
559 { STR_WITH_LEN("size"), op_offset_special, 0, },/*26*/
560 { STR_WITH_LEN("name"), op_offset_special, 0, },/*27*/
561 { STR_WITH_LEN("desc"), op_offset_special, 0, },/*28*/
562 { STR_WITH_LEN("ppaddr"), op_offset_special, 0, },/*29*/
563 { STR_WITH_LEN("type"), op_offset_special, 0, },/*30*/
564 { STR_WITH_LEN("opt"), op_offset_special, 0, },/*31*/
565 { STR_WITH_LEN("spare"), op_offset_special, 0, },/*32*/
566 { STR_WITH_LEN("children"),op_offset_special, 0, },/*33*/
567 { STR_WITH_LEN("pmreplroot"), op_offset_special, 0, },/*34*/
568 { STR_WITH_LEN("pmstashpv"), op_offset_special, 0, },/*35*/
569 { STR_WITH_LEN("pmstash"), op_offset_special, 0, },/*36*/
570 { STR_WITH_LEN("precomp"), op_offset_special, 0, },/*37*/
571 { STR_WITH_LEN("reflags"), op_offset_special, 0, },/*38*/
572 { STR_WITH_LEN("sv"), op_offset_special, 0, },/*39*/
573 { STR_WITH_LEN("gv"), op_offset_special, 0, },/*40*/
574 { STR_WITH_LEN("pv"), op_offset_special, 0, },/*41*/
575 { STR_WITH_LEN("label"), op_offset_special, 0, },/*42*/
576 { STR_WITH_LEN("arybase"), op_offset_special, 0, },/*43*/
577 { STR_WITH_LEN("warnings"),op_offset_special, 0, },/*44*/
578 { STR_WITH_LEN("io"), op_offset_special, 0, },/*45*/
579 { STR_WITH_LEN("hints_hash"),op_offset_special, 0, },/*46*/
580 { STR_WITH_LEN("slabbed"), op_offset_special, 0, },/*47*/
581 { STR_WITH_LEN("savefree"),op_offset_special, 0, },/*48*/
582 { STR_WITH_LEN("static"), op_offset_special, 0, },/*49*/
583 { STR_WITH_LEN("folded"), op_offset_special, 0, },/*50*/
584 { STR_WITH_LEN("moresib"), op_offset_special, 0, },/*51*/
585 { STR_WITH_LEN("parent"), op_offset_special, 0, },/*52*/
586 { STR_WITH_LEN("first"), op_offset_special, 0, },/*53*/
587 { STR_WITH_LEN("meth_sv"), op_offset_special, 0, },/*54*/
588 { STR_WITH_LEN("pmregexp"),op_offset_special, 0, },/*55*/
590 { STR_WITH_LEN("rclass"), op_offset_special, 0, },/*56*/
592 { STR_WITH_LEN("rclass"), op_offset_special, 0, },/*56*/
596 #include "const-c.inc"
598 MODULE = B PACKAGE = B
600 INCLUDE: const-xs.inc
607 const char *file = __FILE__;
610 B_init_my_cxt(aTHX_ &(MY_CXT));
611 cv = newXS("B::init_av", intrpvar_sv_common, file);
612 ASSIGN_COMMON_ALIAS(I, initav);
613 cv = newXS("B::check_av", intrpvar_sv_common, file);
614 ASSIGN_COMMON_ALIAS(I, checkav_save);
615 cv = newXS("B::unitcheck_av", intrpvar_sv_common, file);
616 ASSIGN_COMMON_ALIAS(I, unitcheckav_save);
617 cv = newXS("B::begin_av", intrpvar_sv_common, file);
618 ASSIGN_COMMON_ALIAS(I, beginav_save);
619 cv = newXS("B::end_av", intrpvar_sv_common, file);
620 ASSIGN_COMMON_ALIAS(I, endav);
621 cv = newXS("B::main_cv", intrpvar_sv_common, file);
622 ASSIGN_COMMON_ALIAS(I, main_cv);
623 cv = newXS("B::inc_gv", intrpvar_sv_common, file);
624 ASSIGN_COMMON_ALIAS(I, incgv);
625 cv = newXS("B::defstash", intrpvar_sv_common, file);
626 ASSIGN_COMMON_ALIAS(I, defstash);
627 cv = newXS("B::curstash", intrpvar_sv_common, file);
628 ASSIGN_COMMON_ALIAS(I, curstash);
630 cv = newXS("B::regex_padav", intrpvar_sv_common, file);
631 ASSIGN_COMMON_ALIAS(I, regex_padav);
633 cv = newXS("B::warnhook", intrpvar_sv_common, file);
634 ASSIGN_COMMON_ALIAS(I, warnhook);
635 cv = newXS("B::diehook", intrpvar_sv_common, file);
636 ASSIGN_COMMON_ALIAS(I, diehook);
637 sv = get_sv("B::OP::does_parent", GV_ADDMULTI);
638 #ifdef PERL_OP_PARENT
639 sv_setsv(sv, &PL_sv_yes);
641 sv_setsv(sv, &PL_sv_no);
648 PUSHs(make_sv_object(aTHX_ GvSV(gv_fetchpvs("\f", GV_ADD, SVt_PV))));
653 RETVAL = PL_amagic_generation;
660 PADLIST *padlist = CvPADLIST(PL_main_cv ? PL_main_cv : PL_compcv);
663 SV * const rv = sv_newmortal();
664 sv_setiv(newSVrv(rv, padlist ? "B::PADLIST" : "B::NULL"),
675 PUSHs(make_sv_object(aTHX_ ix > 1 ? &PL_sv_yes
676 : ix < 1 ? &PL_sv_undef
684 PUSHs(make_op_object(aTHX_ ix ? PL_main_start : PL_main_root));
691 RETVAL = ix ? PL_dowarn : PL_sub_generation;
696 walkoptree(op, method)
700 (void) walkoptree(aTHX_ op, method, &PL_sv_undef);
703 walkoptree_debug(...)
706 RETVAL = walkoptree_debug;
707 if (items > 0 && SvTRUE(ST(1)))
708 walkoptree_debug = 1;
712 #define address(sv) PTR2IV(sv)
723 croak("argument is not a reference");
724 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
733 ST(0) = sv_newmortal();
734 if (strBEGINs(name,"pp_"))
736 for (i = 0; i < PL_maxo; i++)
738 if (strEQ(name, PL_op_name[i]))
744 sv_setiv(ST(0),result);
751 ST(0) = sv_newmortal();
752 if (opnum >= 0 && opnum < PL_maxo)
753 Perl_sv_setpvf(aTHX_ ST(0), "pp_%s", PL_op_name[opnum]);
761 const char *s = SvPVbyte(sv, len);
762 PERL_HASH(hash, s, len);
763 ST(0) = sv_2mortal(Perl_newSVpvf(aTHX_ "0x%" UVxf, (UV)hash));
765 #define cast_I32(foo) (I32)foo
787 PUSHs(ix == 2 ? cchar(aTHX_ sv) : cstring(aTHX_ sv, (bool)ix));
798 PUTBACK; /* some vars go out of scope now in machine code */
801 B_init_my_cxt(aTHX_ &(MY_CXT));
803 return; /* dont execute another implied XSPP PUTBACK */
807 MODULE = B PACKAGE = B::OP
810 # The type checking code in B has always been identical for all OP types,
811 # irrespective of whether the action is actually defined on that OP.
825 B::PMOP::pmreplstart = 8
829 B::PMOP::pmflags = 12
830 B::PMOP::code_list = 13
837 B::PMOP::pmoffset = 20
842 B::COP::stashoff = 25
850 B::LISTOP::children = 33
851 B::PMOP::pmreplroot = 34
852 B::PMOP::pmstashpv = 35
853 B::PMOP::pmstash = 36
854 B::PMOP::precomp = 37
855 B::PMOP::reflags = 38
861 B::COP::warnings = 44
863 B::COP::hints_hash = 46
870 B::METHOP::first = 53
871 B::METHOP::meth_sv = 54
872 B::PMOP::pmregexp = 55
873 B::METHOP::rclass = 56
877 if (ix < 0 || (U32)ix >= C_ARRAY_LENGTH(op_methods))
878 croak("Illegal alias %d for B::*OP::next", (int)ix);
879 ret = get_overlay_object(aTHX_ o,
880 op_methods[ix].name, op_methods[ix].namelen);
886 /* handle non-direct field access */
888 if (op_methods[ix].type == op_offset_special)
890 case 1: /* B::OP::op_sibling */
891 ret = make_op_object(aTHX_ OpSIBLING(o));
894 case 8: /* B::PMOP::pmreplstart */
895 ret = make_op_object(aTHX_
896 cPMOPo->op_type == OP_SUBST
897 ? cPMOPo->op_pmstashstartu.op_pmreplstart
902 case 21: /* B::COP::filegv */
903 ret = make_sv_object(aTHX_ (SV *)CopFILEGV((COP*)o));
907 case 22: /* B::COP::file */
908 ret = sv_2mortal(newSVpv(CopFILE((COP*)o), 0));
912 case 23: /* B::COP::stash */
913 ret = make_sv_object(aTHX_ (SV *)CopSTASH((COP*)o));
916 case 24: /* B::COP::stashpv */
917 ret = sv_2mortal(CopSTASH((COP*)o)
918 && SvTYPE(CopSTASH((COP*)o)) == SVt_PVHV
919 ? newSVhek(HvNAME_HEK(CopSTASH((COP*)o)))
922 case 26: /* B::OP::size */
923 ret = sv_2mortal(newSVuv((UV)(opsizes[op_class(o)])));
925 case 27: /* B::OP::name */
926 case 28: /* B::OP::desc */
927 ret = sv_2mortal(newSVpv(
928 (char *)(ix == 28 ? OP_DESC(o) : OP_NAME(o)), 0));
930 case 29: /* B::OP::ppaddr */
933 ret = sv_2mortal(Perl_newSVpvf(aTHX_ "PL_ppaddr[OP_%s]",
934 PL_op_name[o->op_type]));
935 for (i=13; (STRLEN)i < SvCUR(ret); ++i)
936 SvPVX(ret)[i] = toUPPER(SvPVX(ret)[i]);
939 case 30: /* B::OP::type */
940 case 31: /* B::OP::opt */
941 case 32: /* B::OP::spare */
942 case 47: /* B::OP::slabbed */
943 case 48: /* B::OP::savefree */
944 case 49: /* B::OP::static */
945 case 50: /* B::OP::folded */
946 case 51: /* B::OP::moresib */
947 /* These are all bitfields, so we can't take their addresses */
948 ret = sv_2mortal(newSVuv((UV)(
949 ix == 30 ? o->op_type
950 : ix == 31 ? o->op_opt
951 : ix == 47 ? o->op_slabbed
952 : ix == 48 ? o->op_savefree
953 : ix == 49 ? o->op_static
954 : ix == 50 ? o->op_folded
955 : ix == 51 ? o->op_moresib
958 case 33: /* B::LISTOP::children */
962 for (kid = ((LISTOP*)o)->op_first; kid; kid = OpSIBLING(kid))
964 ret = sv_2mortal(newSVuv(i));
967 case 34: /* B::PMOP::pmreplroot */
968 if (cPMOPo->op_type == OP_SPLIT) {
969 ret = sv_newmortal();
971 if (o->op_private & OPpSPLIT_LEX)
973 sv_setiv(ret, cPMOPo->op_pmreplrootu.op_pmtargetoff);
976 GV *const target = cPMOPo->op_pmreplrootu.op_pmtargetgv;
977 sv_setiv(newSVrv(ret, target ?
978 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
984 OP *const root = cPMOPo->op_pmreplrootu.op_pmreplroot;
985 ret = make_op_object(aTHX_ root);
989 case 35: /* B::PMOP::pmstashpv */
990 ret = sv_2mortal(newSVpv(PmopSTASHPV(cPMOPo),0));
993 case 36: /* B::PMOP::pmstash */
994 ret = make_sv_object(aTHX_ (SV *) PmopSTASH(cPMOPo));
997 case 37: /* B::PMOP::precomp */
998 case 38: /* B::PMOP::reflags */
1000 REGEXP *rx = PM_GETRE(cPMOPo);
1001 ret = sv_newmortal();
1004 sv_setuv(ret, RX_EXTFLAGS(rx));
1007 sv_setpvn(ret, RX_PRECOMP(rx), RX_PRELEN(rx));
1014 case 39: /* B::PADOP::sv */
1015 case 40: /* B::PADOP::gv */
1016 /* PADOPs should only be created on threaded builds.
1017 * They don't have an sv or gv field, just an op_padix
1018 * field. Leave it to the caller to retrieve padix
1019 * and look up th value in the pad. Don't do it here,
1020 * becuase PL_curpad is the pad of the caller, not the
1021 * pad of the sub the op is part of */
1022 ret = make_sv_object(aTHX_ NULL);
1024 case 41: /* B::PVOP::pv */
1025 /* OP_TRANS uses op_pv to point to a OPtrans_map or
1026 * OPtrans_map_ex struct, whereas other PVOPs point to a
1027 * null terminated string. For trans, for now just return the
1028 * whole struct as a string and let the caller unpack() it */
1029 if ( cPVOPo->op_type == OP_TRANS
1030 || cPVOPo->op_type == OP_TRANSR)
1032 const OPtrans_map_ex * const extbl =
1033 (OPtrans_map_ex*)cPVOPo->op_pv;
1034 char *end = (char*)(&(extbl->map[256]));
1035 if (cPVOPo->op_private & OPpTRANS_COMPLEMENT) {
1036 short excess_len = extbl->excess_len;
1037 end = (char*)(&(extbl->map_ex[excess_len]));
1039 ret = newSVpvn_flags(cPVOPo->op_pv,
1044 ret = newSVpvn_flags(cPVOPo->op_pv, strlen(cPVOPo->op_pv), SVs_TEMP);
1046 case 42: /* B::COP::label */
1047 ret = sv_2mortal(newSVpv(CopLABEL(cCOPo),0));
1049 case 43: /* B::COP::arybase */
1050 ret = sv_2mortal(newSVuv(0));
1052 case 44: /* B::COP::warnings */
1053 ret = make_warnings_object(aTHX_ cCOPo);
1055 case 45: /* B::COP::io */
1056 ret = make_cop_io_object(aTHX_ cCOPo);
1058 case 46: /* B::COP::hints_hash */
1059 ret = sv_newmortal();
1060 sv_setiv(newSVrv(ret, "B::RHE"),
1061 PTR2IV(CopHINTHASH_get(cCOPo)));
1063 case 52: /* B::OP::parent */
1064 #ifdef PERL_OP_PARENT
1065 ret = make_op_object(aTHX_ op_parent(o));
1067 ret = make_op_object(aTHX_ NULL);
1070 case 53: /* B::METHOP::first */
1071 /* METHOP struct has an op_first/op_meth_sv union
1072 * as its first extra field. How to interpret the
1073 * union depends on the op type. For the purposes of
1074 * B, we treat it as a struct with both fields present,
1075 * where one of the fields always happens to be null
1076 * (i.e. we return NULL in preference to croaking with
1077 * 'method not implemented').
1079 ret = make_op_object(aTHX_
1080 o->op_type == OP_METHOD
1081 ? cMETHOPx(o)->op_u.op_first : NULL);
1083 case 54: /* B::METHOP::meth_sv */
1084 /* see comment above about METHOP */
1085 ret = make_sv_object(aTHX_
1086 o->op_type == OP_METHOD
1087 ? NULL : cMETHOPx(o)->op_u.op_meth_sv);
1089 case 55: /* B::PMOP::pmregexp */
1090 ret = make_sv_object(aTHX_ (SV *)PM_GETRE(cPMOPo));
1092 case 56: /* B::METHOP::rclass */
1094 ret = sv_2mortal(newSVuv(
1095 (o->op_type == OP_METHOD_REDIR ||
1096 o->op_type == OP_METHOD_REDIR_SUPER) ?
1097 cMETHOPx(o)->op_rclass_targ : 0
1100 ret = make_sv_object(aTHX_
1101 (o->op_type == OP_METHOD_REDIR ||
1102 o->op_type == OP_METHOD_REDIR_SUPER) ?
1103 cMETHOPx(o)->op_rclass_sv : NULL
1108 croak("method %s not implemented", op_methods[ix].name);
1110 /* do a direct structure offset lookup */
1111 const char *const ptr = (char *)o + op_methods[ix].offset;
1112 switch (op_methods[ix].type) {
1114 ret = make_op_object(aTHX_ *((OP **)ptr));
1117 ret = sv_2mortal(newSVuv(*((PADOFFSET*)ptr)));
1120 ret = sv_2mortal(newSVuv(*((U8*)ptr)));
1123 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1126 ret = make_sv_object(aTHX_ *((SV **)ptr));
1129 ret = sv_2mortal(newSVuv(*((line_t *)ptr)));
1132 ret = sv_2mortal(newSViv(*((IV*)ptr)));
1135 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1138 croak("Illegal type 0x%x for B::*OP::%s",
1139 (unsigned)op_methods[ix].type, op_methods[ix].name);
1150 SP = oplist(aTHX_ o, SP);
1154 MODULE = B PACKAGE = B::UNOP_AUX
1156 # UNOP_AUX class ops are like UNOPs except that they have an extra
1157 # op_aux pointer that points to an array of UNOP_AUX_item unions.
1158 # Element -1 of the array contains the length
1161 # return a string representation of op_aux where possible The op's CV is
1162 # needed as an extra arg to allow GVs and SVs moved into the pad to be
1173 aux = cUNOP_AUXo->op_aux;
1174 switch (o->op_type) {
1175 case OP_MULTICONCAT:
1176 ret = multiconcat_stringify(o);
1180 ret = multideref_stringify(o, cv);
1184 ret = sv_2mortal(Perl_newSVpvf(aTHX_ "%" IVdf,
1189 ret = Perl_newSVpvf(aTHX_ "%" IVdf ",%" IVdf, aux[0].iv, aux[1].iv);
1191 Perl_sv_catpvf(aTHX_ ret, ",%c", (char)aux[2].iv);
1192 ret = sv_2mortal(ret);
1196 ret = sv_2mortal(newSVpvn("", 0));
1203 # Return the contents of the op_aux array as a list of IV/GV/etc objects.
1204 # How to interpret each array element is op-dependent. The op's CV is
1205 # needed as an extra arg to allow GVs and SVs which have been moved into
1206 # the pad to be accessed okay.
1215 PERL_UNUSED_VAR(cv); /* not needed on unthreaded builds */
1216 aux = cUNOP_AUXo->op_aux;
1217 switch (o->op_type) {
1219 XSRETURN(0); /* by default, an empty list */
1222 XPUSHs(sv_2mortal(newSViv(PTR2IV(aux))));
1228 PUSHs(sv_2mortal(newSViv(aux[0].iv)));
1229 PUSHs(sv_2mortal(newSViv(aux[1].iv)));
1230 PUSHs(sv_2mortal(aux[2].iv ? Perl_newSVpvf(aTHX_ "%c",
1231 (char)aux[2].iv) : &PL_sv_no));
1234 case OP_MULTICONCAT:
1241 UNOP_AUX_item *lens;
1243 /* return (nargs, const string, segment len 0, 1, 2, ...) */
1245 /* if this changes, this block of code probably needs fixing */
1246 assert(PERL_MULTICONCAT_HEADER_SIZE == 5);
1247 nargs = aux[PERL_MULTICONCAT_IX_NARGS].ssize;
1248 EXTEND(SP, ((SSize_t)(2 + (nargs+1))));
1249 PUSHs(sv_2mortal(newSViv((IV)nargs)));
1251 p = aux[PERL_MULTICONCAT_IX_PLAIN_PV].pv;
1252 len = aux[PERL_MULTICONCAT_IX_PLAIN_LEN].ssize;
1254 p = aux[PERL_MULTICONCAT_IX_UTF8_PV].pv;
1255 len = aux[PERL_MULTICONCAT_IX_UTF8_LEN].ssize;
1258 sv = newSVpvn(p, len);
1259 SvFLAGS(sv) |= utf8;
1260 PUSHs(sv_2mortal(sv));
1262 lens = aux + PERL_MULTICONCAT_IX_LENGTHS;
1263 nargs++; /* loop (nargs+1) times */
1265 U8 *p = (U8*)SvPVX(sv);
1267 SSize_t bytes = lens->ssize;
1272 /* return char lengths rather than byte lengths */
1273 chars = utf8_length(p, p + bytes);
1277 PUSHs(sv_2mortal(newSViv(chars)));
1282 PUSHs(sv_2mortal(newSViv(lens->ssize)));
1291 # define ITEM_SV(item) *av_fetch(comppad, (item)->pad_offset, FALSE);
1293 # define ITEM_SV(item) UNOP_AUX_item_sv(item)
1296 UNOP_AUX_item *items = cUNOP_AUXo->op_aux;
1297 UV actions = items->uv;
1298 UV len = items[-1].uv;
1301 bool is_hash = FALSE;
1303 PADLIST * const padlist = CvPADLIST(cv);
1304 PAD *comppad = PadlistARRAY(padlist)[1];
1307 /* len should never be big enough to truncate or wrap */
1308 assert(len <= SSize_t_MAX);
1309 EXTEND(SP, (SSize_t)len);
1310 PUSHs(sv_2mortal(newSViv(actions)));
1313 switch (actions & MDEREF_ACTION_MASK) {
1316 actions = (++items)->uv;
1317 PUSHs(sv_2mortal(newSVuv(actions)));
1319 NOT_REACHED; /* NOTREACHED */
1321 case MDEREF_HV_padhv_helem:
1324 case MDEREF_AV_padav_aelem:
1325 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1327 NOT_REACHED; /* NOTREACHED */
1329 case MDEREF_HV_gvhv_helem:
1332 case MDEREF_AV_gvav_aelem:
1333 sv = ITEM_SV(++items);
1334 PUSHs(make_sv_object(aTHX_ sv));
1336 NOT_REACHED; /* NOTREACHED */
1338 case MDEREF_HV_gvsv_vivify_rv2hv_helem:
1341 case MDEREF_AV_gvsv_vivify_rv2av_aelem:
1342 sv = ITEM_SV(++items);
1343 PUSHs(make_sv_object(aTHX_ sv));
1344 goto do_vivify_rv2xv_elem;
1345 NOT_REACHED; /* NOTREACHED */
1347 case MDEREF_HV_padsv_vivify_rv2hv_helem:
1350 case MDEREF_AV_padsv_vivify_rv2av_aelem:
1351 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1352 goto do_vivify_rv2xv_elem;
1353 NOT_REACHED; /* NOTREACHED */
1355 case MDEREF_HV_pop_rv2hv_helem:
1356 case MDEREF_HV_vivify_rv2hv_helem:
1359 do_vivify_rv2xv_elem:
1360 case MDEREF_AV_pop_rv2av_aelem:
1361 case MDEREF_AV_vivify_rv2av_aelem:
1363 switch (actions & MDEREF_INDEX_MASK) {
1364 case MDEREF_INDEX_none:
1367 case MDEREF_INDEX_const:
1369 sv = ITEM_SV(++items);
1370 PUSHs(make_sv_object(aTHX_ sv));
1373 PUSHs(sv_2mortal(newSViv((++items)->iv)));
1375 case MDEREF_INDEX_padsv:
1376 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1378 case MDEREF_INDEX_gvsv:
1379 sv = ITEM_SV(++items);
1380 PUSHs(make_sv_object(aTHX_ sv));
1383 if (actions & MDEREF_FLAG_last)
1390 actions >>= MDEREF_SHIFT;
1394 } /* OP_MULTIDEREF */
1399 MODULE = B PACKAGE = B::SV
1401 #define MAGICAL_FLAG_BITS (SVs_GMG|SVs_SMG|SVs_RMG)
1411 MAGICAL = MAGICAL_FLAG_BITS
1413 RETVAL = ix ? (SvFLAGS(sv) & (U32)ix) : SvREFCNT(sv);
1421 ST(0) = sv_2mortal(newRV(sv));
1424 MODULE = B PACKAGE = B::IV PREFIX = Sv
1430 MODULE = B PACKAGE = B::IV
1432 #define sv_SVp 0x00000
1433 #define sv_IVp 0x10000
1434 #define sv_UVp 0x20000
1435 #define sv_STRLENp 0x30000
1436 #define sv_U32p 0x40000
1437 #define sv_U8p 0x50000
1438 #define sv_char_pp 0x60000
1439 #define sv_NVp 0x70000
1440 #define sv_char_p 0x80000
1441 #define sv_SSize_tp 0x90000
1442 #define sv_I32p 0xA0000
1443 #define sv_U16p 0xB0000
1445 #define IV_ivx_ix sv_IVp | STRUCT_OFFSET(struct xpviv, xiv_iv)
1446 #define IV_uvx_ix sv_UVp | STRUCT_OFFSET(struct xpvuv, xuv_uv)
1447 #define NV_nvx_ix sv_NVp | STRUCT_OFFSET(struct xpvnv, xnv_u.xnv_nv)
1449 #define PV_cur_ix sv_STRLENp | STRUCT_OFFSET(struct xpv, xpv_cur)
1450 #define PV_len_ix sv_STRLENp | STRUCT_OFFSET(struct xpv, xpv_len)
1452 #define PVMG_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvmg, xmg_stash)
1454 #define PVBM_useful_ix sv_IVp | STRUCT_OFFSET(struct xpviv, xiv_u.xivu_iv)
1456 #define PVLV_targoff_ix sv_U32p | STRUCT_OFFSET(struct xpvlv, xlv_targoff)
1457 #define PVLV_targlen_ix sv_U32p | STRUCT_OFFSET(struct xpvlv, xlv_targlen)
1458 #define PVLV_targ_ix sv_SVp | STRUCT_OFFSET(struct xpvlv, xlv_targ)
1459 #define PVLV_type_ix sv_char_p | STRUCT_OFFSET(struct xpvlv, xlv_type)
1461 #define PVGV_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvgv, xnv_u.xgv_stash)
1462 #define PVGV_flags_ix sv_STRLENp | STRUCT_OFFSET(struct xpvgv, xpv_cur)
1463 #define PVIO_lines_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xiv_iv)
1465 #define PVIO_page_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_page)
1466 #define PVIO_page_len_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_page_len)
1467 #define PVIO_lines_left_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_lines_left)
1468 #define PVIO_top_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_top_name)
1469 #define PVIO_top_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_top_gv)
1470 #define PVIO_fmt_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_fmt_name)
1471 #define PVIO_fmt_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_fmt_gv)
1472 #define PVIO_bottom_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_bottom_name)
1473 #define PVIO_bottom_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_bottom_gv)
1474 #define PVIO_type_ix sv_char_p | STRUCT_OFFSET(struct xpvio, xio_type)
1475 #define PVIO_flags_ix sv_U8p | STRUCT_OFFSET(struct xpvio, xio_flags)
1477 #define PVAV_max_ix sv_SSize_tp | STRUCT_OFFSET(struct xpvav, xav_max)
1479 #define PVCV_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_stash)
1480 #define PVCV_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_gv_u.xcv_gv)
1481 #define PVCV_file_ix sv_char_pp | STRUCT_OFFSET(struct xpvcv, xcv_file)
1482 #define PVCV_outside_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_outside)
1483 #define PVCV_outside_seq_ix sv_U32p | STRUCT_OFFSET(struct xpvcv, xcv_outside_seq)
1484 #define PVCV_flags_ix sv_U32p | STRUCT_OFFSET(struct xpvcv, xcv_flags)
1486 #define PVHV_max_ix sv_STRLENp | STRUCT_OFFSET(struct xpvhv, xhv_max)
1487 #define PVHV_keys_ix sv_STRLENp | STRUCT_OFFSET(struct xpvhv, xhv_keys)
1489 # The type checking code in B has always been identical for all SV types,
1490 # irrespective of whether the action is actually defined on that SV.
1491 # We should fix this
1496 B::IV::IVX = IV_ivx_ix
1497 B::IV::UVX = IV_uvx_ix
1498 B::NV::NVX = NV_nvx_ix
1499 B::PV::CUR = PV_cur_ix
1500 B::PV::LEN = PV_len_ix
1501 B::PVMG::SvSTASH = PVMG_stash_ix
1502 B::PVLV::TARGOFF = PVLV_targoff_ix
1503 B::PVLV::TARGLEN = PVLV_targlen_ix
1504 B::PVLV::TARG = PVLV_targ_ix
1505 B::PVLV::TYPE = PVLV_type_ix
1506 B::GV::STASH = PVGV_stash_ix
1507 B::GV::GvFLAGS = PVGV_flags_ix
1508 B::BM::USEFUL = PVBM_useful_ix
1509 B::IO::LINES = PVIO_lines_ix
1510 B::IO::PAGE = PVIO_page_ix
1511 B::IO::PAGE_LEN = PVIO_page_len_ix
1512 B::IO::LINES_LEFT = PVIO_lines_left_ix
1513 B::IO::TOP_NAME = PVIO_top_name_ix
1514 B::IO::TOP_GV = PVIO_top_gv_ix
1515 B::IO::FMT_NAME = PVIO_fmt_name_ix
1516 B::IO::FMT_GV = PVIO_fmt_gv_ix
1517 B::IO::BOTTOM_NAME = PVIO_bottom_name_ix
1518 B::IO::BOTTOM_GV = PVIO_bottom_gv_ix
1519 B::IO::IoTYPE = PVIO_type_ix
1520 B::IO::IoFLAGS = PVIO_flags_ix
1521 B::AV::MAX = PVAV_max_ix
1522 B::CV::STASH = PVCV_stash_ix
1523 B::CV::FILE = PVCV_file_ix
1524 B::CV::OUTSIDE = PVCV_outside_ix
1525 B::CV::OUTSIDE_SEQ = PVCV_outside_seq_ix
1526 B::CV::CvFLAGS = PVCV_flags_ix
1527 B::HV::MAX = PVHV_max_ix
1528 B::HV::KEYS = PVHV_keys_ix
1533 ptr = (ix & 0xFFFF) + (char *)SvANY(sv);
1534 switch ((U8)(ix >> 16)) {
1535 case (U8)(sv_SVp >> 16):
1536 ret = make_sv_object(aTHX_ *((SV **)ptr));
1538 case (U8)(sv_IVp >> 16):
1539 ret = sv_2mortal(newSViv(*((IV *)ptr)));
1541 case (U8)(sv_UVp >> 16):
1542 ret = sv_2mortal(newSVuv(*((UV *)ptr)));
1544 case (U8)(sv_STRLENp >> 16):
1545 ret = sv_2mortal(newSVuv(*((STRLEN *)ptr)));
1547 case (U8)(sv_U32p >> 16):
1548 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
1550 case (U8)(sv_U8p >> 16):
1551 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
1553 case (U8)(sv_char_pp >> 16):
1554 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1556 case (U8)(sv_NVp >> 16):
1557 ret = sv_2mortal(newSVnv(*((NV *)ptr)));
1559 case (U8)(sv_char_p >> 16):
1560 ret = newSVpvn_flags((char *)ptr, 1, SVs_TEMP);
1562 case (U8)(sv_SSize_tp >> 16):
1563 ret = sv_2mortal(newSViv(*((SSize_t *)ptr)));
1565 case (U8)(sv_I32p >> 16):
1566 ret = sv_2mortal(newSVuv(*((I32 *)ptr)));
1568 case (U8)(sv_U16p >> 16):
1569 ret = sv_2mortal(newSVuv(*((U16 *)ptr)));
1572 croak("Illegal alias 0x%08x for B::*IVX", (unsigned)ix);
1584 ST(0) = boolSV((I32)SvIVX(sv) != SvIVX(sv));
1585 } else if (sizeof(IV) == 8) {
1587 const IV iv = SvIVX(sv);
1589 * The following way of spelling 32 is to stop compilers on
1590 * 32-bit architectures from moaning about the shift count
1591 * being >= the width of the type. Such architectures don't
1592 * reach this code anyway (unless sizeof(IV) > 8 but then
1593 * everything else breaks too so I'm not fussed at the moment).
1596 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1598 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1600 wp[1] = htonl(iv & 0xffffffff);
1601 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1603 U32 w = htonl((U32)SvIVX(sv));
1604 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1607 MODULE = B PACKAGE = B::NV PREFIX = Sv
1613 MODULE = B PACKAGE = B::REGEXP
1624 PUSHs(newSVpvn_flags(RX_PRECOMP(sv), RX_PRELEN(sv), SVs_TEMP));
1625 } else if (ix == 2) {
1626 PUSHs(make_sv_object(aTHX_ (SV *)ReANY(sv)->qr_anoncv));
1630 PUSHu(RX_COMPFLAGS(sv));
1632 /* FIXME - can we code this method more efficiently? */
1636 MODULE = B PACKAGE = B::PV
1643 croak( "argument is not SvROK" );
1644 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
1659 const MAGIC *const mg = mg_find(sv, PERL_MAGIC_bm);
1662 croak("argument to B::BM::TABLE is not a PVBM");
1665 } else if (ix == 2) {
1666 /* This used to read 257. I think that that was buggy - should have
1667 been 258. (The "\0", the flags byte, and 256 for the table.)
1668 The only user of this method is B::Bytecode in B::PV::bsave.
1669 I'm guessing that nothing tested the runtime correctness of
1670 output of bytecompiled string constant arguments to index (etc).
1672 Note the start pointer is and has always been SvPVX(sv), not
1673 SvPVX(sv) + SvCUR(sv) PVBM was added in 651aa52ea1faa806, and
1674 first used by the compiler in 651aa52ea1faa806. It's used to
1675 get a "complete" dump of the buffer at SvPVX(), not just the
1676 PVBM table. This permits the generated bytecode to "load"
1679 5.15 and later store the BM table via MAGIC, so the compiler
1680 should handle this just fine without changes if PVBM now
1681 always returns the SvPVX() buffer. */
1683 ? RX_WRAPPED_const((REGEXP*)sv)
1687 p = isREGEXP(sv) ? RX_WRAPPED((REGEXP*)sv) : SvPVX(sv);
1689 } else if (SvPOK(sv)) {
1691 p = SvPVX_const(sv);
1693 } else if (isREGEXP(sv)) {
1695 p = RX_WRAPPED_const((REGEXP*)sv);
1698 /* XXX for backward compatibility, but should fail */
1699 /* croak( "argument is not SvPOK" ); */
1702 ST(0) = newSVpvn_flags(p, len, SVs_TEMP | utf8);
1704 MODULE = B PACKAGE = B::PVMG
1709 MAGIC * mg = NO_INIT
1711 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1712 XPUSHs(make_mg_object(aTHX_ mg));
1714 MODULE = B PACKAGE = B::MAGIC
1731 XPUSHs(mg->mg_moremagic ? make_mg_object(aTHX_ mg->mg_moremagic)
1735 mPUSHu(mg->mg_private);
1738 PUSHs(newSVpvn_flags(&(mg->mg_type), 1, SVs_TEMP));
1741 mPUSHu(mg->mg_flags);
1747 PUSHs(make_sv_object(aTHX_ mg->mg_obj));
1751 if (mg->mg_len >= 0) {
1752 PUSHs(newSVpvn_flags(mg->mg_ptr, mg->mg_len, SVs_TEMP));
1753 } else if (mg->mg_len == HEf_SVKEY) {
1754 PUSHs(make_sv_object(aTHX_ (SV*)mg->mg_ptr));
1756 PUSHs(sv_newmortal());
1758 PUSHs(sv_newmortal());
1761 if(mg->mg_type == PERL_MAGIC_qr) {
1762 mPUSHi(PTR2IV(mg->mg_obj));
1764 croak("REGEX is only meaningful on r-magic");
1768 if (mg->mg_type == PERL_MAGIC_qr) {
1769 REGEXP *rx = (REGEXP *)mg->mg_obj;
1770 PUSHs(newSVpvn_flags(rx ? RX_PRECOMP(rx) : NULL,
1771 rx ? RX_PRELEN(rx) : 0, SVs_TEMP));
1773 croak( "precomp is only meaningful on r-magic" );
1778 MODULE = B PACKAGE = B::BM PREFIX = Bm
1784 PERL_UNUSED_VAR(sv);
1785 RETVAL = BmPREVIOUS(sv);
1794 PERL_UNUSED_VAR(sv);
1795 RETVAL = BmRARE(sv);
1800 MODULE = B PACKAGE = B::GV PREFIX = Gv
1809 ST(0) = sv_2mortal(newSVhek(!ix ? GvNAME_HEK(gv)
1810 : (ix == 1 ? GvFILE_HEK(gv)
1811 : HvNAME_HEK((HV *)gv))));
1820 RETVAL = cBOOL(isGV_with_GP(gv));
1822 RETVAL = GvGP(gv) == Null(GP*);
1831 #define GP_sv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_sv)
1832 #define GP_io_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_io)
1833 #define GP_cv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_cv)
1834 #define GP_cvgen_ix (U32p << 16) | STRUCT_OFFSET(struct gp, gp_cvgen)
1835 #define GP_refcnt_ix (U32p << 16) | STRUCT_OFFSET(struct gp, gp_refcnt)
1836 #define GP_hv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_hv)
1837 #define GP_av_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_av)
1838 #define GP_form_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_form)
1839 #define GP_egv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_egv)
1849 GvREFCNT = GP_refcnt_ix
1861 const GV *const gv = CvGV(cv);
1862 Perl_croak(aTHX_ "NULL gp in B::GV::%s", gv ? GvNAME(gv) : "???");
1864 ptr = (ix & 0xFFFF) + (char *)gp;
1865 switch ((U8)(ix >> 16)) {
1867 ret = make_sv_object(aTHX_ *((SV **)ptr));
1870 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1873 croak("Illegal alias 0x%08x for B::*SV", (unsigned)ix);
1890 PUSHs(make_sv_object(aTHX_ (SV *)GvFILEGV(gv)));
1892 MODULE = B PACKAGE = B::IO PREFIX = Io
1902 if( strEQ( name, "stdin" ) ) {
1903 handle = PerlIO_stdin();
1905 else if( strEQ( name, "stdout" ) ) {
1906 handle = PerlIO_stdout();
1908 else if( strEQ( name, "stderr" ) ) {
1909 handle = PerlIO_stderr();
1912 croak( "Invalid value '%s'", name );
1914 RETVAL = handle == IoIFP(io);
1918 MODULE = B PACKAGE = B::AV PREFIX = Av
1928 if (AvFILL(av) >= 0) {
1929 SV **svp = AvARRAY(av);
1931 for (i = 0; i <= AvFILL(av); i++)
1932 XPUSHs(make_sv_object(aTHX_ svp[i]));
1940 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1941 XPUSHs(make_sv_object(aTHX_ (AvARRAY(av)[idx])));
1943 XPUSHs(make_sv_object(aTHX_ NULL));
1946 MODULE = B PACKAGE = B::FM PREFIX = Fm
1952 PERL_UNUSED_VAR(format);
1958 MODULE = B PACKAGE = B::CV PREFIX = Cv
1970 PUSHs(make_op_object(aTHX_ CvISXSUB(cv) ? NULL
1971 : ix ? CvROOT(cv) : CvSTART(cv)));
1981 RETVAL = CvISXSUB(cv) ? NULL : CvPADLIST(cv);
1989 RETVAL = newSVuv(CvISXSUB(cv) ? PTR2UV(CvHSCXT(cv)) : 0);
1999 ST(0) = ix && CvCONST(cv)
2000 ? make_sv_object(aTHX_ (SV *)CvXSUBANY(cv).any_ptr)
2001 : sv_2mortal(newSViv(CvISXSUB(cv)
2002 ? (ix ? CvXSUBANY(cv).any_iv
2003 : PTR2IV(CvXSUB(cv)))
2010 PUSHs(make_sv_object(aTHX_ (SV *)cv_const_sv(cv)));
2016 ST(0) = make_sv_object(aTHX_ (SV*)CvGV(cv));
2022 RETVAL = CvNAMED(cv) ? newSVhek(CvNAME_HEK(cv)) : &PL_sv_undef;
2026 MODULE = B PACKAGE = B::HV PREFIX = Hv
2040 if (HvUSEDKEYS(hv) > 0) {
2042 SSize_t extend_size;
2043 (void)hv_iterinit(hv);
2044 /* 2*HvUSEDKEYS() should never be big enough to truncate or wrap */
2045 assert(HvUSEDKEYS(hv) <= (SSize_t_MAX >> 1));
2046 extend_size = (SSize_t)HvUSEDKEYS(hv) * 2;
2047 EXTEND(sp, extend_size);
2048 while ((he = hv_iternext(hv))) {
2050 mPUSHs(HeSVKEY(he));
2051 } else if (HeKUTF8(he)) {
2052 PUSHs(newSVpvn_flags(HeKEY(he), HeKLEN(he), SVf_UTF8|SVs_TEMP));
2054 mPUSHp(HeKEY(he), HeKLEN(he));
2056 PUSHs(make_sv_object(aTHX_ HeVAL(he)));
2060 MODULE = B PACKAGE = B::HE PREFIX = He
2068 PUSHs(make_sv_object(aTHX_ ix ? HeSVKEY_force(he) : HeVAL(he)));
2074 MODULE = B PACKAGE = B::RHE
2080 RETVAL = newRV_noinc( (SV*)cophh_2hv(h, 0) );
2085 MODULE = B PACKAGE = B::PADLIST PREFIX = Padlist
2090 ALIAS: B::PADNAMELIST::MAX = 0
2092 PERL_UNUSED_VAR(ix);
2093 RETVAL = PadlistMAX(padlist);
2098 PadlistNAMES(padlist)
2102 PadlistARRAY(padlist)
2105 if (PadlistMAX(padlist) >= 0) {
2107 PAD **padp = PadlistARRAY(padlist);
2109 sv_setiv(newSVrv(TARG, PadlistNAMES(padlist)
2112 PTR2IV(PadlistNAMES(padlist)));
2114 for (i = 1; i <= PadlistMAX(padlist); i++)
2115 XPUSHs(make_sv_object(aTHX_ (SV *)padp[i]));
2119 PadlistARRAYelt(padlist, idx)
2123 if (idx < 0 || idx > PadlistMAX(padlist))
2124 XPUSHs(make_sv_object(aTHX_ NULL));
2127 PUSHMARK(PL_stack_sp-1);
2128 XS_B__PADLIST_NAMES(aTHX_ cv);
2132 XPUSHs(make_sv_object(aTHX_
2133 (SV *)PadlistARRAY(padlist)[idx]));
2136 PadlistREFCNT(padlist)
2139 PERL_UNUSED_VAR(padlist);
2140 RETVAL = PadlistREFCNT(padlist);
2144 MODULE = B PACKAGE = B::PADNAMELIST PREFIX = Padnamelist
2147 PadnamelistARRAY(pnl)
2150 if (PadnamelistMAX(pnl) >= 0) {
2151 PADNAME **padp = PadnamelistARRAY(pnl);
2153 for (; i <= PadnamelistMAX(pnl); i++)
2155 SV *rv = sv_newmortal();
2156 sv_setiv(newSVrv(rv,padp[i] ? "B::PADNAME" : "B::SPECIAL"),
2163 PadnamelistARRAYelt(pnl, idx)
2167 if (idx < 0 || idx > PadnamelistMAX(pnl))
2170 RETVAL = PadnamelistARRAY(pnl)[idx];
2174 MODULE = B PACKAGE = B::PADNAME PREFIX = Padname
2176 #define PN_type_ix \
2177 sv_SVp | STRUCT_OFFSET(struct padname,xpadn_type_u.xpadn_typestash)
2178 #define PN_ourstash_ix \
2179 sv_SVp | STRUCT_OFFSET(struct padname,xpadn_ourstash)
2181 sv_U8p | STRUCT_OFFSET(struct padname,xpadn_len)
2182 #define PN_refcnt_ix \
2183 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_refcnt)
2184 #define PN_cop_seq_range_low_ix \
2185 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_low)
2186 #define PN_cop_seq_range_high_ix \
2187 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_high)
2188 #define PNL_refcnt_ix \
2189 sv_U32p | STRUCT_OFFSET(struct padnamelist, xpadnl_refcnt)
2191 sv_U32p | STRUCT_OFFSET(struct padlist, xpadl_id)
2192 #define PL_outid_ix \
2193 sv_U32p | STRUCT_OFFSET(struct padlist, xpadl_outid)
2200 B::PADNAME::TYPE = PN_type_ix
2201 B::PADNAME::OURSTASH = PN_ourstash_ix
2202 B::PADNAME::LEN = PN_len_ix
2203 B::PADNAME::REFCNT = PN_refcnt_ix
2204 B::PADNAME::COP_SEQ_RANGE_LOW = PN_cop_seq_range_low_ix
2205 B::PADNAME::COP_SEQ_RANGE_HIGH = PN_cop_seq_range_high_ix
2206 B::PADNAMELIST::REFCNT = PNL_refcnt_ix
2207 B::PADLIST::id = PL_id_ix
2208 B::PADLIST::outid = PL_outid_ix
2213 ptr = (ix & 0xFFFF) + (char *)pn;
2214 switch ((U8)(ix >> 16)) {
2215 case (U8)(sv_SVp >> 16):
2216 ret = make_sv_object(aTHX_ *((SV **)ptr));
2218 case (U8)(sv_U32p >> 16):
2219 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
2221 case (U8)(sv_U8p >> 16):
2222 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
2236 PERL_UNUSED_ARG(RETVAL);
2237 sv_setpvn(TARG, PadnamePV(pn), PadnameLEN(pn));
2243 /* Uses less memory than an ALIAS. */
2244 GV *gv = gv_fetchpvs("B::PADNAME::TYPE", 1, SVt_PVGV);
2245 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::SvSTASH",1,SVt_PVGV),(SV *)gv);
2246 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PROTOCV",1,SVt_PVGV),(SV *)gv);
2247 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PVX",1,SVt_PVGV),
2248 (SV *)gv_fetchpvs("B::PADNAME::PV" ,1,SVt_PVGV));
2249 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PARENT_PAD_INDEX" ,1,SVt_PVGV),
2250 (SV *)gv_fetchpvs("B::PADNAME::COP_SEQ_RANGE_LOW",1,
2252 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PARENT_FAKELEX_FLAGS",1,
2254 (SV *)gv_fetchpvs("B::PADNAME::COP_SEQ_RANGE_HIGH" ,1,
2262 RETVAL = PadnameFLAGS(pn);
2263 /* backward-compatibility hack, which should be removed if the
2264 flags field becomes large enough to hold SVf_FAKE (and
2265 PADNAMEt_OUTER should be renumbered to match SVf_FAKE) */
2266 STATIC_ASSERT_STMT(SVf_FAKE >= 1<<(sizeof(PadnameFLAGS((B__PADNAME)NULL)) * 8));
2267 if (PadnameOUTER(pn))