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;
472 typedef PADLIST *B__PADLIST;
474 typedef PADNAMELIST *B__PADNAMELIST;
475 typedef PADNAME *B__PADNAME;
479 # define ASSIGN_COMMON_ALIAS(prefix, var) \
480 STMT_START { XSANY.any_i32 = STRUCT_OFFSET(struct interpreter, prefix##var); } STMT_END
482 # define ASSIGN_COMMON_ALIAS(prefix, var) \
483 STMT_START { XSANY.any_ptr = (void *)&PL_##var; } STMT_END
486 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
488 static XSPROTO(intrpvar_sv_common); /* prototype to pass -Wmissing-prototypes */
489 static XSPROTO(intrpvar_sv_common)
495 croak_xs_usage(cv, "");
497 ret = *(SV **)(XSANY.any_i32 + (char *)my_perl);
499 ret = *(SV **)(XSANY.any_ptr);
501 ST(0) = make_sv_object(aTHX_ ret);
511 #define PADOFFSETp 0x4
515 /* Keep this last: */
516 #define op_offset_special 0x8
518 /* table that drives most of the B::*OP methods */
520 static const struct OP_methods {
523 U8 type; /* if op_offset_special, access is handled on a case-by-case basis */
526 { STR_WITH_LEN("next"), OPp, STRUCT_OFFSET(struct op, op_next), },/* 0*/
527 { STR_WITH_LEN("sibling"), op_offset_special, 0, },/* 1*/
528 { STR_WITH_LEN("targ"), PADOFFSETp, STRUCT_OFFSET(struct op, op_targ), },/* 2*/
529 { STR_WITH_LEN("flags"), U8p, STRUCT_OFFSET(struct op, op_flags), },/* 3*/
530 { STR_WITH_LEN("private"), U8p, STRUCT_OFFSET(struct op, op_private), },/* 4*/
531 { STR_WITH_LEN("first"), OPp, STRUCT_OFFSET(struct unop, op_first), },/* 5*/
532 { STR_WITH_LEN("last"), OPp, STRUCT_OFFSET(struct binop, op_last), },/* 6*/
533 { STR_WITH_LEN("other"), OPp, STRUCT_OFFSET(struct logop, op_other), },/* 7*/
534 { STR_WITH_LEN("pmreplstart"), op_offset_special, 0, },/* 8*/
535 { STR_WITH_LEN("redoop"), OPp, STRUCT_OFFSET(struct loop, op_redoop), },/* 9*/
536 { STR_WITH_LEN("nextop"), OPp, STRUCT_OFFSET(struct loop, op_nextop), },/*10*/
537 { STR_WITH_LEN("lastop"), OPp, STRUCT_OFFSET(struct loop, op_lastop), },/*11*/
538 { STR_WITH_LEN("pmflags"), U32p, STRUCT_OFFSET(struct pmop, op_pmflags),},/*12*/
539 { STR_WITH_LEN("code_list"),OPp, STRUCT_OFFSET(struct pmop, op_code_list),},/*13*/
540 { STR_WITH_LEN("sv"), SVp, STRUCT_OFFSET(struct svop, op_sv), },/*14*/
541 { STR_WITH_LEN("gv"), SVp, STRUCT_OFFSET(struct svop, op_sv), },/*15*/
542 { STR_WITH_LEN("padix"), PADOFFSETp,STRUCT_OFFSET(struct padop, op_padix),},/*16*/
543 { STR_WITH_LEN("cop_seq"), U32p, STRUCT_OFFSET(struct cop, cop_seq), },/*17*/
544 { STR_WITH_LEN("line"), line_tp, STRUCT_OFFSET(struct cop, cop_line), },/*18*/
545 { STR_WITH_LEN("hints"), U32p, STRUCT_OFFSET(struct cop, cop_hints), },/*19*/
547 { STR_WITH_LEN("pmoffset"),IVp, STRUCT_OFFSET(struct pmop, op_pmoffset),},/*20*/
548 { STR_WITH_LEN("filegv"), op_offset_special, 0, },/*21*/
549 { STR_WITH_LEN("file"), char_pp, STRUCT_OFFSET(struct cop, cop_file), },/*22*/
550 { STR_WITH_LEN("stash"), op_offset_special, 0, },/*23*/
551 { STR_WITH_LEN("stashpv"), op_offset_special, 0, },/*24*/
552 { STR_WITH_LEN("stashoff"),PADOFFSETp,STRUCT_OFFSET(struct cop,cop_stashoff),},/*25*/
554 { STR_WITH_LEN("pmoffset"),op_offset_special, 0, },/*20*/
555 { STR_WITH_LEN("filegv"), SVp, STRUCT_OFFSET(struct cop, cop_filegv),},/*21*/
556 { STR_WITH_LEN("file"), op_offset_special, 0, },/*22*/
557 { STR_WITH_LEN("stash"), SVp, STRUCT_OFFSET(struct cop, cop_stash), },/*23*/
558 { STR_WITH_LEN("stashpv"), op_offset_special, 0, },/*24*/
559 { STR_WITH_LEN("stashoff"),op_offset_special, 0, },/*25*/
561 { STR_WITH_LEN("size"), op_offset_special, 0, },/*26*/
562 { STR_WITH_LEN("name"), op_offset_special, 0, },/*27*/
563 { STR_WITH_LEN("desc"), op_offset_special, 0, },/*28*/
564 { STR_WITH_LEN("ppaddr"), op_offset_special, 0, },/*29*/
565 { STR_WITH_LEN("type"), op_offset_special, 0, },/*30*/
566 { STR_WITH_LEN("opt"), op_offset_special, 0, },/*31*/
567 { STR_WITH_LEN("spare"), op_offset_special, 0, },/*32*/
568 { STR_WITH_LEN("children"),op_offset_special, 0, },/*33*/
569 { STR_WITH_LEN("pmreplroot"), op_offset_special, 0, },/*34*/
570 { STR_WITH_LEN("pmstashpv"), op_offset_special, 0, },/*35*/
571 { STR_WITH_LEN("pmstash"), op_offset_special, 0, },/*36*/
572 { STR_WITH_LEN("precomp"), op_offset_special, 0, },/*37*/
573 { STR_WITH_LEN("reflags"), op_offset_special, 0, },/*38*/
574 { STR_WITH_LEN("sv"), op_offset_special, 0, },/*39*/
575 { STR_WITH_LEN("gv"), op_offset_special, 0, },/*40*/
576 { STR_WITH_LEN("pv"), op_offset_special, 0, },/*41*/
577 { STR_WITH_LEN("label"), op_offset_special, 0, },/*42*/
578 { STR_WITH_LEN("arybase"), op_offset_special, 0, },/*43*/
579 { STR_WITH_LEN("warnings"),op_offset_special, 0, },/*44*/
580 { STR_WITH_LEN("io"), op_offset_special, 0, },/*45*/
581 { STR_WITH_LEN("hints_hash"),op_offset_special, 0, },/*46*/
582 { STR_WITH_LEN("slabbed"), op_offset_special, 0, },/*47*/
583 { STR_WITH_LEN("savefree"),op_offset_special, 0, },/*48*/
584 { STR_WITH_LEN("static"), op_offset_special, 0, },/*49*/
585 { STR_WITH_LEN("folded"), op_offset_special, 0, },/*50*/
586 { STR_WITH_LEN("moresib"), op_offset_special, 0, },/*51*/
587 { STR_WITH_LEN("parent"), op_offset_special, 0, },/*52*/
588 { STR_WITH_LEN("first"), op_offset_special, 0, },/*53*/
589 { STR_WITH_LEN("meth_sv"), op_offset_special, 0, },/*54*/
590 { STR_WITH_LEN("pmregexp"),op_offset_special, 0, },/*55*/
592 { STR_WITH_LEN("rclass"), op_offset_special, 0, },/*56*/
594 { STR_WITH_LEN("rclass"), op_offset_special, 0, },/*56*/
598 #include "const-c.inc"
600 MODULE = B PACKAGE = B
602 INCLUDE: const-xs.inc
609 const char *file = __FILE__;
612 B_init_my_cxt(aTHX_ &(MY_CXT));
613 cv = newXS("B::init_av", intrpvar_sv_common, file);
614 ASSIGN_COMMON_ALIAS(I, initav);
615 cv = newXS("B::check_av", intrpvar_sv_common, file);
616 ASSIGN_COMMON_ALIAS(I, checkav_save);
617 cv = newXS("B::unitcheck_av", intrpvar_sv_common, file);
618 ASSIGN_COMMON_ALIAS(I, unitcheckav_save);
619 cv = newXS("B::begin_av", intrpvar_sv_common, file);
620 ASSIGN_COMMON_ALIAS(I, beginav_save);
621 cv = newXS("B::end_av", intrpvar_sv_common, file);
622 ASSIGN_COMMON_ALIAS(I, endav);
623 cv = newXS("B::main_cv", intrpvar_sv_common, file);
624 ASSIGN_COMMON_ALIAS(I, main_cv);
625 cv = newXS("B::inc_gv", intrpvar_sv_common, file);
626 ASSIGN_COMMON_ALIAS(I, incgv);
627 cv = newXS("B::defstash", intrpvar_sv_common, file);
628 ASSIGN_COMMON_ALIAS(I, defstash);
629 cv = newXS("B::curstash", intrpvar_sv_common, file);
630 ASSIGN_COMMON_ALIAS(I, curstash);
632 cv = newXS("B::formfeed", intrpvar_sv_common, file);
633 ASSIGN_COMMON_ALIAS(I, formfeed);
636 cv = newXS("B::regex_padav", intrpvar_sv_common, file);
637 ASSIGN_COMMON_ALIAS(I, regex_padav);
639 cv = newXS("B::warnhook", intrpvar_sv_common, file);
640 ASSIGN_COMMON_ALIAS(I, warnhook);
641 cv = newXS("B::diehook", intrpvar_sv_common, file);
642 ASSIGN_COMMON_ALIAS(I, diehook);
643 sv = get_sv("B::OP::does_parent", GV_ADDMULTI);
644 #ifdef PERL_OP_PARENT
645 sv_setsv(sv, &PL_sv_yes);
647 sv_setsv(sv, &PL_sv_no);
656 PUSHs(make_sv_object(aTHX_ GvSV(gv_fetchpvs("\f", GV_ADD, SVt_PV))));
663 RETVAL = PL_amagic_generation;
670 PADLIST *padlist = CvPADLIST(PL_main_cv ? PL_main_cv : PL_compcv);
674 SV * const rv = sv_newmortal();
675 sv_setiv(newSVrv(rv, padlist ? "B::PADLIST" : "B::NULL"),
680 PUSHs(make_sv_object(aTHX_ (SV *)padlist));
689 PUSHs(make_sv_object(aTHX_ ix > 1 ? &PL_sv_yes
690 : ix < 1 ? &PL_sv_undef
698 PUSHs(make_op_object(aTHX_ ix ? PL_main_start : PL_main_root));
705 RETVAL = ix ? PL_dowarn : PL_sub_generation;
710 walkoptree(op, method)
714 (void) walkoptree(aTHX_ op, method, &PL_sv_undef);
717 walkoptree_debug(...)
720 RETVAL = walkoptree_debug;
721 if (items > 0 && SvTRUE(ST(1)))
722 walkoptree_debug = 1;
726 #define address(sv) PTR2IV(sv)
737 croak("argument is not a reference");
738 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
747 ST(0) = sv_newmortal();
748 if (strBEGINs(name,"pp_"))
750 for (i = 0; i < PL_maxo; i++)
752 if (strEQ(name, PL_op_name[i]))
758 sv_setiv(ST(0),result);
765 ST(0) = sv_newmortal();
766 if (opnum >= 0 && opnum < PL_maxo)
767 Perl_sv_setpvf(aTHX_ ST(0), "pp_%s", PL_op_name[opnum]);
775 const char *s = SvPVbyte(sv, len);
776 PERL_HASH(hash, s, len);
777 ST(0) = sv_2mortal(Perl_newSVpvf(aTHX_ "0x%" UVxf, (UV)hash));
779 #define cast_I32(foo) (I32)foo
801 PUSHs(ix == 2 ? cchar(aTHX_ sv) : cstring(aTHX_ sv, (bool)ix));
812 PUTBACK; /* some vars go out of scope now in machine code */
815 B_init_my_cxt(aTHX_ &(MY_CXT));
817 return; /* dont execute another implied XSPP PUTBACK */
821 MODULE = B PACKAGE = B::OP
824 # The type checking code in B has always been identical for all OP types,
825 # irrespective of whether the action is actually defined on that OP.
839 B::PMOP::pmreplstart = 8
843 B::PMOP::pmflags = 12
844 B::PMOP::code_list = 13
851 B::PMOP::pmoffset = 20
856 B::COP::stashoff = 25
864 B::LISTOP::children = 33
865 B::PMOP::pmreplroot = 34
866 B::PMOP::pmstashpv = 35
867 B::PMOP::pmstash = 36
868 B::PMOP::precomp = 37
869 B::PMOP::reflags = 38
875 B::COP::warnings = 44
877 B::COP::hints_hash = 46
884 B::METHOP::first = 53
885 B::METHOP::meth_sv = 54
886 B::PMOP::pmregexp = 55
887 B::METHOP::rclass = 56
891 if (ix < 0 || (U32)ix >= C_ARRAY_LENGTH(op_methods))
892 croak("Illegal alias %d for B::*OP::next", (int)ix);
893 ret = get_overlay_object(aTHX_ o,
894 op_methods[ix].name, op_methods[ix].namelen);
900 /* handle non-direct field access */
902 if (op_methods[ix].type == op_offset_special)
904 case 1: /* B::OP::op_sibling */
905 ret = make_op_object(aTHX_ OpSIBLING(o));
908 case 8: /* B::PMOP::pmreplstart */
909 ret = make_op_object(aTHX_
910 cPMOPo->op_type == OP_SUBST
911 ? cPMOPo->op_pmstashstartu.op_pmreplstart
916 case 21: /* B::COP::filegv */
917 ret = make_sv_object(aTHX_ (SV *)CopFILEGV((COP*)o));
921 case 22: /* B::COP::file */
922 ret = sv_2mortal(newSVpv(CopFILE((COP*)o), 0));
926 case 23: /* B::COP::stash */
927 ret = make_sv_object(aTHX_ (SV *)CopSTASH((COP*)o));
930 case 24: /* B::COP::stashpv */
931 ret = sv_2mortal(CopSTASH((COP*)o)
932 && SvTYPE(CopSTASH((COP*)o)) == SVt_PVHV
933 ? newSVhek(HvNAME_HEK(CopSTASH((COP*)o)))
936 case 26: /* B::OP::size */
937 ret = sv_2mortal(newSVuv((UV)(opsizes[op_class(o)])));
939 case 27: /* B::OP::name */
940 case 28: /* B::OP::desc */
941 ret = sv_2mortal(newSVpv(
942 (char *)(ix == 28 ? OP_DESC(o) : OP_NAME(o)), 0));
944 case 29: /* B::OP::ppaddr */
947 ret = sv_2mortal(Perl_newSVpvf(aTHX_ "PL_ppaddr[OP_%s]",
948 PL_op_name[o->op_type]));
949 for (i=13; (STRLEN)i < SvCUR(ret); ++i)
950 SvPVX(ret)[i] = toUPPER(SvPVX(ret)[i]);
953 case 30: /* B::OP::type */
954 case 31: /* B::OP::opt */
955 case 32: /* B::OP::spare */
956 case 47: /* B::OP::slabbed */
957 case 48: /* B::OP::savefree */
958 case 49: /* B::OP::static */
959 case 50: /* B::OP::folded */
960 case 51: /* B::OP::moresib */
961 /* These are all bitfields, so we can't take their addresses */
962 ret = sv_2mortal(newSVuv((UV)(
963 ix == 30 ? o->op_type
964 : ix == 31 ? o->op_opt
965 : ix == 47 ? o->op_slabbed
966 : ix == 48 ? o->op_savefree
967 : ix == 49 ? o->op_static
968 : ix == 50 ? o->op_folded
969 : ix == 51 ? o->op_moresib
972 case 33: /* B::LISTOP::children */
976 for (kid = ((LISTOP*)o)->op_first; kid; kid = OpSIBLING(kid))
978 ret = sv_2mortal(newSVuv(i));
981 case 34: /* B::PMOP::pmreplroot */
982 if (cPMOPo->op_type == OP_SPLIT) {
983 ret = sv_newmortal();
985 if (o->op_private & OPpSPLIT_LEX)
987 sv_setiv(ret, cPMOPo->op_pmreplrootu.op_pmtargetoff);
990 GV *const target = cPMOPo->op_pmreplrootu.op_pmtargetgv;
991 sv_setiv(newSVrv(ret, target ?
992 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
998 OP *const root = cPMOPo->op_pmreplrootu.op_pmreplroot;
999 ret = make_op_object(aTHX_ root);
1003 case 35: /* B::PMOP::pmstashpv */
1004 ret = sv_2mortal(newSVpv(PmopSTASHPV(cPMOPo),0));
1007 case 36: /* B::PMOP::pmstash */
1008 ret = make_sv_object(aTHX_ (SV *) PmopSTASH(cPMOPo));
1011 case 37: /* B::PMOP::precomp */
1012 case 38: /* B::PMOP::reflags */
1014 REGEXP *rx = PM_GETRE(cPMOPo);
1015 ret = sv_newmortal();
1018 sv_setuv(ret, RX_EXTFLAGS(rx));
1021 sv_setpvn(ret, RX_PRECOMP(rx), RX_PRELEN(rx));
1028 case 39: /* B::PADOP::sv */
1029 case 40: /* B::PADOP::gv */
1030 /* PADOPs should only be created on threaded builds.
1031 * They don't have an sv or gv field, just an op_padix
1032 * field. Leave it to the caller to retrieve padix
1033 * and look up th value in the pad. Don't do it here,
1034 * becuase PL_curpad is the pad of the caller, not the
1035 * pad of the sub the op is part of */
1036 ret = make_sv_object(aTHX_ NULL);
1038 case 41: /* B::PVOP::pv */
1039 /* OP_TRANS uses op_pv to point to a table of 256 or >=258
1040 * shorts whereas other PVOPs point to a null terminated
1042 if ( (cPVOPo->op_type == OP_TRANS
1043 || cPVOPo->op_type == OP_TRANSR) &&
1044 (cPVOPo->op_private & OPpTRANS_COMPLEMENT) &&
1045 !(cPVOPo->op_private & OPpTRANS_DELETE))
1047 const short* const tbl = (short*)cPVOPo->op_pv;
1048 const short entries = 257 + tbl[256];
1049 ret = newSVpvn_flags(cPVOPo->op_pv, entries * sizeof(short), SVs_TEMP);
1051 else if (cPVOPo->op_type == OP_TRANS || cPVOPo->op_type == OP_TRANSR) {
1052 ret = newSVpvn_flags(cPVOPo->op_pv, 256 * sizeof(short), SVs_TEMP);
1055 ret = newSVpvn_flags(cPVOPo->op_pv, strlen(cPVOPo->op_pv), SVs_TEMP);
1057 case 42: /* B::COP::label */
1058 ret = sv_2mortal(newSVpv(CopLABEL(cCOPo),0));
1060 case 43: /* B::COP::arybase */
1061 ret = sv_2mortal(newSVuv(0));
1063 case 44: /* B::COP::warnings */
1064 ret = make_warnings_object(aTHX_ cCOPo);
1066 case 45: /* B::COP::io */
1067 ret = make_cop_io_object(aTHX_ cCOPo);
1069 case 46: /* B::COP::hints_hash */
1070 ret = sv_newmortal();
1071 sv_setiv(newSVrv(ret, "B::RHE"),
1072 PTR2IV(CopHINTHASH_get(cCOPo)));
1074 case 52: /* B::OP::parent */
1075 #ifdef PERL_OP_PARENT
1076 ret = make_op_object(aTHX_ op_parent(o));
1078 ret = make_op_object(aTHX_ NULL);
1081 case 53: /* B::METHOP::first */
1082 /* METHOP struct has an op_first/op_meth_sv union
1083 * as its first extra field. How to interpret the
1084 * union depends on the op type. For the purposes of
1085 * B, we treat it as a struct with both fields present,
1086 * where one of the fields always happens to be null
1087 * (i.e. we return NULL in preference to croaking with
1088 * 'method not implemented').
1090 ret = make_op_object(aTHX_
1091 o->op_type == OP_METHOD
1092 ? cMETHOPx(o)->op_u.op_first : NULL);
1094 case 54: /* B::METHOP::meth_sv */
1095 /* see comment above about METHOP */
1096 ret = make_sv_object(aTHX_
1097 o->op_type == OP_METHOD
1098 ? NULL : cMETHOPx(o)->op_u.op_meth_sv);
1100 case 55: /* B::PMOP::pmregexp */
1101 ret = make_sv_object(aTHX_ (SV *)PM_GETRE(cPMOPo));
1103 case 56: /* B::METHOP::rclass */
1105 ret = sv_2mortal(newSVuv(
1106 (o->op_type == OP_METHOD_REDIR ||
1107 o->op_type == OP_METHOD_REDIR_SUPER) ?
1108 cMETHOPx(o)->op_rclass_targ : 0
1111 ret = make_sv_object(aTHX_
1112 (o->op_type == OP_METHOD_REDIR ||
1113 o->op_type == OP_METHOD_REDIR_SUPER) ?
1114 cMETHOPx(o)->op_rclass_sv : NULL
1119 croak("method %s not implemented", op_methods[ix].name);
1121 /* do a direct structure offset lookup */
1122 const char *const ptr = (char *)o + op_methods[ix].offset;
1123 switch (op_methods[ix].type) {
1125 ret = make_op_object(aTHX_ *((OP **)ptr));
1128 ret = sv_2mortal(newSVuv(*((PADOFFSET*)ptr)));
1131 ret = sv_2mortal(newSVuv(*((U8*)ptr)));
1134 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1137 ret = make_sv_object(aTHX_ *((SV **)ptr));
1140 ret = sv_2mortal(newSVuv(*((line_t *)ptr)));
1143 ret = sv_2mortal(newSViv(*((IV*)ptr)));
1146 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1149 croak("Illegal type 0x%x for B::*OP::%s",
1150 (unsigned)op_methods[ix].type, op_methods[ix].name);
1161 SP = oplist(aTHX_ o, SP);
1165 MODULE = B PACKAGE = B::UNOP_AUX
1167 # UNOP_AUX class ops are like UNOPs except that they have an extra
1168 # op_aux pointer that points to an array of UNOP_AUX_item unions.
1169 # Element -1 of the array contains the length
1172 # return a string representation of op_aux where possible The op's CV is
1173 # needed as an extra arg to allow GVs and SVs moved into the pad to be
1184 aux = cUNOP_AUXo->op_aux;
1185 switch (o->op_type) {
1186 case OP_MULTICONCAT:
1187 ret = multiconcat_stringify(o);
1191 ret = multideref_stringify(o, cv);
1195 ret = sv_2mortal(Perl_newSVpvf(aTHX_ "%" IVdf,
1200 ret = Perl_newSVpvf(aTHX_ "%" IVdf ",%" IVdf, aux[0].iv, aux[1].iv);
1202 Perl_sv_catpvf(aTHX_ ret, ",%c", (char)aux[2].iv);
1203 ret = sv_2mortal(ret);
1207 ret = sv_2mortal(newSVpvn("", 0));
1214 # Return the contents of the op_aux array as a list of IV/GV/etc objects.
1215 # How to interpret each array element is op-dependent. The op's CV is
1216 # needed as an extra arg to allow GVs and SVs which have been moved into
1217 # the pad to be accessed okay.
1226 PERL_UNUSED_VAR(cv); /* not needed on unthreaded builds */
1227 aux = cUNOP_AUXo->op_aux;
1228 switch (o->op_type) {
1230 XSRETURN(0); /* by default, an empty list */
1233 XPUSHs(sv_2mortal(newSViv(PTR2IV(aux))));
1239 PUSHs(sv_2mortal(newSViv(aux[0].iv)));
1240 PUSHs(sv_2mortal(newSViv(aux[1].iv)));
1241 PUSHs(sv_2mortal(aux[2].iv ? Perl_newSVpvf(aTHX_ "%c",
1242 (char)aux[2].iv) : &PL_sv_no));
1245 case OP_MULTICONCAT:
1247 UV nargs = aux[0].uv;
1252 UNOP_AUX_item *lens;
1254 /* return (nargs, const string, segment len 0, 1, 2, ...) */
1256 /* if this changes, this block of code probably needs fixing */
1257 assert(PERL_MULTICONCAT_HEADER_SIZE == 5);
1258 nargs = aux[PERL_MULTICONCAT_IX_NARGS].uv;
1259 EXTEND(SP, ((SSize_t)(2 + (nargs+1))));
1260 PUSHs(sv_2mortal(newSViv(nargs)));
1262 p = aux[PERL_MULTICONCAT_IX_PLAIN_PV].pv;
1263 len = aux[PERL_MULTICONCAT_IX_PLAIN_LEN].size;
1265 p = aux[PERL_MULTICONCAT_IX_UTF8_PV].pv;
1266 len = aux[PERL_MULTICONCAT_IX_UTF8_LEN].size;
1269 sv = newSVpvn(p, len);
1270 SvFLAGS(sv) |= utf8;
1271 PUSHs(sv_2mortal(sv));
1273 lens = aux + PERL_MULTICONCAT_IX_LENGTHS;
1274 nargs++; /* loop (nargs+1) times */
1276 U8 *p = (U8*)SvPVX(sv);
1278 SSize_t bytes = lens->size;
1283 /* return char lengths rather than byte lengths */
1284 chars = utf8_length(p, p + bytes);
1288 PUSHs(sv_2mortal(newSViv(chars)));
1293 PUSHs(sv_2mortal(newSViv(lens->size)));
1302 # define ITEM_SV(item) *av_fetch(comppad, (item)->pad_offset, FALSE);
1304 # define ITEM_SV(item) UNOP_AUX_item_sv(item)
1307 UNOP_AUX_item *items = cUNOP_AUXo->op_aux;
1308 UV actions = items->uv;
1309 UV len = items[-1].uv;
1312 bool is_hash = FALSE;
1314 PADLIST * const padlist = CvPADLIST(cv);
1315 PAD *comppad = PadlistARRAY(padlist)[1];
1318 /* len should never be big enough to truncate or wrap */
1319 assert(len <= SSize_t_MAX);
1320 EXTEND(SP, (SSize_t)len);
1321 PUSHs(sv_2mortal(newSViv(actions)));
1324 switch (actions & MDEREF_ACTION_MASK) {
1327 actions = (++items)->uv;
1328 PUSHs(sv_2mortal(newSVuv(actions)));
1330 NOT_REACHED; /* NOTREACHED */
1332 case MDEREF_HV_padhv_helem:
1335 case MDEREF_AV_padav_aelem:
1336 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1338 NOT_REACHED; /* NOTREACHED */
1340 case MDEREF_HV_gvhv_helem:
1343 case MDEREF_AV_gvav_aelem:
1344 sv = ITEM_SV(++items);
1345 PUSHs(make_sv_object(aTHX_ sv));
1347 NOT_REACHED; /* NOTREACHED */
1349 case MDEREF_HV_gvsv_vivify_rv2hv_helem:
1352 case MDEREF_AV_gvsv_vivify_rv2av_aelem:
1353 sv = ITEM_SV(++items);
1354 PUSHs(make_sv_object(aTHX_ sv));
1355 goto do_vivify_rv2xv_elem;
1356 NOT_REACHED; /* NOTREACHED */
1358 case MDEREF_HV_padsv_vivify_rv2hv_helem:
1361 case MDEREF_AV_padsv_vivify_rv2av_aelem:
1362 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1363 goto do_vivify_rv2xv_elem;
1364 NOT_REACHED; /* NOTREACHED */
1366 case MDEREF_HV_pop_rv2hv_helem:
1367 case MDEREF_HV_vivify_rv2hv_helem:
1370 do_vivify_rv2xv_elem:
1371 case MDEREF_AV_pop_rv2av_aelem:
1372 case MDEREF_AV_vivify_rv2av_aelem:
1374 switch (actions & MDEREF_INDEX_MASK) {
1375 case MDEREF_INDEX_none:
1378 case MDEREF_INDEX_const:
1380 sv = ITEM_SV(++items);
1381 PUSHs(make_sv_object(aTHX_ sv));
1384 PUSHs(sv_2mortal(newSViv((++items)->iv)));
1386 case MDEREF_INDEX_padsv:
1387 PUSHs(sv_2mortal(newSVuv((++items)->pad_offset)));
1389 case MDEREF_INDEX_gvsv:
1390 sv = ITEM_SV(++items);
1391 PUSHs(make_sv_object(aTHX_ sv));
1394 if (actions & MDEREF_FLAG_last)
1401 actions >>= MDEREF_SHIFT;
1405 } /* OP_MULTIDEREF */
1410 MODULE = B PACKAGE = B::SV
1412 #define MAGICAL_FLAG_BITS (SVs_GMG|SVs_SMG|SVs_RMG)
1422 MAGICAL = MAGICAL_FLAG_BITS
1424 RETVAL = ix ? (SvFLAGS(sv) & (U32)ix) : SvREFCNT(sv);
1432 ST(0) = sv_2mortal(newRV(sv));
1435 MODULE = B PACKAGE = B::IV PREFIX = Sv
1441 MODULE = B PACKAGE = B::IV
1443 #define sv_SVp 0x00000
1444 #define sv_IVp 0x10000
1445 #define sv_UVp 0x20000
1446 #define sv_STRLENp 0x30000
1447 #define sv_U32p 0x40000
1448 #define sv_U8p 0x50000
1449 #define sv_char_pp 0x60000
1450 #define sv_NVp 0x70000
1451 #define sv_char_p 0x80000
1452 #define sv_SSize_tp 0x90000
1453 #define sv_I32p 0xA0000
1454 #define sv_U16p 0xB0000
1456 #define IV_ivx_ix sv_IVp | STRUCT_OFFSET(struct xpviv, xiv_iv)
1457 #define IV_uvx_ix sv_UVp | STRUCT_OFFSET(struct xpvuv, xuv_uv)
1458 #define NV_nvx_ix sv_NVp | STRUCT_OFFSET(struct xpvnv, xnv_u.xnv_nv)
1460 #define PV_cur_ix sv_STRLENp | STRUCT_OFFSET(struct xpv, xpv_cur)
1461 #define PV_len_ix sv_STRLENp | STRUCT_OFFSET(struct xpv, xpv_len)
1463 #define PVMG_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvmg, xmg_stash)
1465 #define PVBM_useful_ix sv_IVp | STRUCT_OFFSET(struct xpviv, xiv_u.xivu_iv)
1467 #define PVLV_targoff_ix sv_U32p | STRUCT_OFFSET(struct xpvlv, xlv_targoff)
1468 #define PVLV_targlen_ix sv_U32p | STRUCT_OFFSET(struct xpvlv, xlv_targlen)
1469 #define PVLV_targ_ix sv_SVp | STRUCT_OFFSET(struct xpvlv, xlv_targ)
1470 #define PVLV_type_ix sv_char_p | STRUCT_OFFSET(struct xpvlv, xlv_type)
1472 #define PVGV_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvgv, xnv_u.xgv_stash)
1473 #define PVGV_flags_ix sv_STRLENp | STRUCT_OFFSET(struct xpvgv, xpv_cur)
1474 #define PVIO_lines_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xiv_iv)
1476 #define PVIO_page_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_page)
1477 #define PVIO_page_len_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_page_len)
1478 #define PVIO_lines_left_ix sv_IVp | STRUCT_OFFSET(struct xpvio, xio_lines_left)
1479 #define PVIO_top_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_top_name)
1480 #define PVIO_top_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_top_gv)
1481 #define PVIO_fmt_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_fmt_name)
1482 #define PVIO_fmt_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_fmt_gv)
1483 #define PVIO_bottom_name_ix sv_char_pp | STRUCT_OFFSET(struct xpvio, xio_bottom_name)
1484 #define PVIO_bottom_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvio, xio_bottom_gv)
1485 #define PVIO_type_ix sv_char_p | STRUCT_OFFSET(struct xpvio, xio_type)
1486 #define PVIO_flags_ix sv_U8p | STRUCT_OFFSET(struct xpvio, xio_flags)
1488 #define PVAV_max_ix sv_SSize_tp | STRUCT_OFFSET(struct xpvav, xav_max)
1490 #define PVCV_stash_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_stash)
1491 #define PVCV_gv_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_gv_u.xcv_gv)
1492 #define PVCV_file_ix sv_char_pp | STRUCT_OFFSET(struct xpvcv, xcv_file)
1493 #define PVCV_outside_ix sv_SVp | STRUCT_OFFSET(struct xpvcv, xcv_outside)
1494 #define PVCV_outside_seq_ix sv_U32p | STRUCT_OFFSET(struct xpvcv, xcv_outside_seq)
1495 #define PVCV_flags_ix sv_U32p | STRUCT_OFFSET(struct xpvcv, xcv_flags)
1497 #define PVHV_max_ix sv_STRLENp | STRUCT_OFFSET(struct xpvhv, xhv_max)
1498 #define PVHV_keys_ix sv_STRLENp | STRUCT_OFFSET(struct xpvhv, xhv_keys)
1500 # The type checking code in B has always been identical for all SV types,
1501 # irrespective of whether the action is actually defined on that SV.
1502 # We should fix this
1507 B::IV::IVX = IV_ivx_ix
1508 B::IV::UVX = IV_uvx_ix
1509 B::NV::NVX = NV_nvx_ix
1510 B::PV::CUR = PV_cur_ix
1511 B::PV::LEN = PV_len_ix
1512 B::PVMG::SvSTASH = PVMG_stash_ix
1513 B::PVLV::TARGOFF = PVLV_targoff_ix
1514 B::PVLV::TARGLEN = PVLV_targlen_ix
1515 B::PVLV::TARG = PVLV_targ_ix
1516 B::PVLV::TYPE = PVLV_type_ix
1517 B::GV::STASH = PVGV_stash_ix
1518 B::GV::GvFLAGS = PVGV_flags_ix
1519 B::BM::USEFUL = PVBM_useful_ix
1520 B::IO::LINES = PVIO_lines_ix
1521 B::IO::PAGE = PVIO_page_ix
1522 B::IO::PAGE_LEN = PVIO_page_len_ix
1523 B::IO::LINES_LEFT = PVIO_lines_left_ix
1524 B::IO::TOP_NAME = PVIO_top_name_ix
1525 B::IO::TOP_GV = PVIO_top_gv_ix
1526 B::IO::FMT_NAME = PVIO_fmt_name_ix
1527 B::IO::FMT_GV = PVIO_fmt_gv_ix
1528 B::IO::BOTTOM_NAME = PVIO_bottom_name_ix
1529 B::IO::BOTTOM_GV = PVIO_bottom_gv_ix
1530 B::IO::IoTYPE = PVIO_type_ix
1531 B::IO::IoFLAGS = PVIO_flags_ix
1532 B::AV::MAX = PVAV_max_ix
1533 B::CV::STASH = PVCV_stash_ix
1534 B::CV::FILE = PVCV_file_ix
1535 B::CV::OUTSIDE = PVCV_outside_ix
1536 B::CV::OUTSIDE_SEQ = PVCV_outside_seq_ix
1537 B::CV::CvFLAGS = PVCV_flags_ix
1538 B::HV::MAX = PVHV_max_ix
1539 B::HV::KEYS = PVHV_keys_ix
1544 ptr = (ix & 0xFFFF) + (char *)SvANY(sv);
1545 switch ((U8)(ix >> 16)) {
1546 case (U8)(sv_SVp >> 16):
1547 ret = make_sv_object(aTHX_ *((SV **)ptr));
1549 case (U8)(sv_IVp >> 16):
1550 ret = sv_2mortal(newSViv(*((IV *)ptr)));
1552 case (U8)(sv_UVp >> 16):
1553 ret = sv_2mortal(newSVuv(*((UV *)ptr)));
1555 case (U8)(sv_STRLENp >> 16):
1556 ret = sv_2mortal(newSVuv(*((STRLEN *)ptr)));
1558 case (U8)(sv_U32p >> 16):
1559 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
1561 case (U8)(sv_U8p >> 16):
1562 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
1564 case (U8)(sv_char_pp >> 16):
1565 ret = sv_2mortal(newSVpv(*((char **)ptr), 0));
1567 case (U8)(sv_NVp >> 16):
1568 ret = sv_2mortal(newSVnv(*((NV *)ptr)));
1570 case (U8)(sv_char_p >> 16):
1571 ret = newSVpvn_flags((char *)ptr, 1, SVs_TEMP);
1573 case (U8)(sv_SSize_tp >> 16):
1574 ret = sv_2mortal(newSViv(*((SSize_t *)ptr)));
1576 case (U8)(sv_I32p >> 16):
1577 ret = sv_2mortal(newSVuv(*((I32 *)ptr)));
1579 case (U8)(sv_U16p >> 16):
1580 ret = sv_2mortal(newSVuv(*((U16 *)ptr)));
1583 croak("Illegal alias 0x%08x for B::*IVX", (unsigned)ix);
1595 ST(0) = boolSV((I32)SvIVX(sv) != SvIVX(sv));
1596 } else if (sizeof(IV) == 8) {
1598 const IV iv = SvIVX(sv);
1600 * The following way of spelling 32 is to stop compilers on
1601 * 32-bit architectures from moaning about the shift count
1602 * being >= the width of the type. Such architectures don't
1603 * reach this code anyway (unless sizeof(IV) > 8 but then
1604 * everything else breaks too so I'm not fussed at the moment).
1607 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1609 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1611 wp[1] = htonl(iv & 0xffffffff);
1612 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1614 U32 w = htonl((U32)SvIVX(sv));
1615 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1618 MODULE = B PACKAGE = B::NV PREFIX = Sv
1624 MODULE = B PACKAGE = B::REGEXP
1635 PUSHs(newSVpvn_flags(RX_PRECOMP(sv), RX_PRELEN(sv), SVs_TEMP));
1636 } else if (ix == 2) {
1637 PUSHs(make_sv_object(aTHX_ (SV *)ReANY(sv)->qr_anoncv));
1641 PUSHu(RX_COMPFLAGS(sv));
1643 /* FIXME - can we code this method more efficiently? */
1647 MODULE = B PACKAGE = B::PV
1654 croak( "argument is not SvROK" );
1655 PUSHs(make_sv_object(aTHX_ SvRV(sv)));
1670 #ifndef PERL_FBM_TABLE_OFFSET
1671 const MAGIC *const mg = mg_find(sv, PERL_MAGIC_bm);
1674 croak("argument to B::BM::TABLE is not a PVBM");
1679 /* Boyer-Moore table is just after string and its safety-margin \0 */
1680 p += len + PERL_FBM_TABLE_OFFSET;
1683 } else if (ix == 2) {
1684 /* This used to read 257. I think that that was buggy - should have
1685 been 258. (The "\0", the flags byte, and 256 for the table.)
1686 The only user of this method is B::Bytecode in B::PV::bsave.
1687 I'm guessing that nothing tested the runtime correctness of
1688 output of bytecompiled string constant arguments to index (etc).
1690 Note the start pointer is and has always been SvPVX(sv), not
1691 SvPVX(sv) + SvCUR(sv) PVBM was added in 651aa52ea1faa806, and
1692 first used by the compiler in 651aa52ea1faa806. It's used to
1693 get a "complete" dump of the buffer at SvPVX(), not just the
1694 PVBM table. This permits the generated bytecode to "load"
1697 5.15 and later store the BM table via MAGIC, so the compiler
1698 should handle this just fine without changes if PVBM now
1699 always returns the SvPVX() buffer. */
1702 ? RX_WRAPPED_const((REGEXP*)sv)
1705 p = SvPVX_const(sv);
1707 #ifdef PERL_FBM_TABLE_OFFSET
1708 len = SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0);
1714 p = isREGEXP(sv) ? RX_WRAPPED((REGEXP*)sv) : SvPVX(sv);
1719 } else if (SvPOK(sv)) {
1721 p = SvPVX_const(sv);
1725 else if (isREGEXP(sv)) {
1727 p = RX_WRAPPED_const((REGEXP*)sv);
1732 /* XXX for backward compatibility, but should fail */
1733 /* croak( "argument is not SvPOK" ); */
1736 ST(0) = newSVpvn_flags(p, len, SVs_TEMP | utf8);
1738 MODULE = B PACKAGE = B::PVMG
1743 MAGIC * mg = NO_INIT
1745 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1746 XPUSHs(make_mg_object(aTHX_ mg));
1748 MODULE = B PACKAGE = B::MAGIC
1765 XPUSHs(mg->mg_moremagic ? make_mg_object(aTHX_ mg->mg_moremagic)
1769 mPUSHu(mg->mg_private);
1772 PUSHs(newSVpvn_flags(&(mg->mg_type), 1, SVs_TEMP));
1775 mPUSHu(mg->mg_flags);
1781 PUSHs(make_sv_object(aTHX_ mg->mg_obj));
1785 if (mg->mg_len >= 0) {
1786 PUSHs(newSVpvn_flags(mg->mg_ptr, mg->mg_len, SVs_TEMP));
1787 } else if (mg->mg_len == HEf_SVKEY) {
1788 PUSHs(make_sv_object(aTHX_ (SV*)mg->mg_ptr));
1790 PUSHs(sv_newmortal());
1792 PUSHs(sv_newmortal());
1795 if(mg->mg_type == PERL_MAGIC_qr) {
1796 mPUSHi(PTR2IV(mg->mg_obj));
1798 croak("REGEX is only meaningful on r-magic");
1802 if (mg->mg_type == PERL_MAGIC_qr) {
1803 REGEXP *rx = (REGEXP *)mg->mg_obj;
1804 PUSHs(newSVpvn_flags(rx ? RX_PRECOMP(rx) : NULL,
1805 rx ? RX_PRELEN(rx) : 0, SVs_TEMP));
1807 croak( "precomp is only meaningful on r-magic" );
1812 MODULE = B PACKAGE = B::BM PREFIX = Bm
1818 PERL_UNUSED_VAR(sv);
1819 RETVAL = BmPREVIOUS(sv);
1828 PERL_UNUSED_VAR(sv);
1829 RETVAL = BmRARE(sv);
1834 MODULE = B PACKAGE = B::GV PREFIX = Gv
1843 ST(0) = sv_2mortal(newSVhek(!ix ? GvNAME_HEK(gv)
1844 : (ix == 1 ? GvFILE_HEK(gv)
1845 : HvNAME_HEK((HV *)gv))));
1854 RETVAL = cBOOL(isGV_with_GP(gv));
1856 RETVAL = GvGP(gv) == Null(GP*);
1865 #define GP_sv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_sv)
1866 #define GP_io_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_io)
1867 #define GP_cv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_cv)
1868 #define GP_cvgen_ix (U32p << 16) | STRUCT_OFFSET(struct gp, gp_cvgen)
1869 #define GP_refcnt_ix (U32p << 16) | STRUCT_OFFSET(struct gp, gp_refcnt)
1870 #define GP_hv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_hv)
1871 #define GP_av_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_av)
1872 #define GP_form_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_form)
1873 #define GP_egv_ix (SVp << 16) | STRUCT_OFFSET(struct gp, gp_egv)
1883 GvREFCNT = GP_refcnt_ix
1895 const GV *const gv = CvGV(cv);
1896 Perl_croak(aTHX_ "NULL gp in B::GV::%s", gv ? GvNAME(gv) : "???");
1898 ptr = (ix & 0xFFFF) + (char *)gp;
1899 switch ((U8)(ix >> 16)) {
1901 ret = make_sv_object(aTHX_ *((SV **)ptr));
1904 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
1907 croak("Illegal alias 0x%08x for B::*SV", (unsigned)ix);
1924 PUSHs(make_sv_object(aTHX_ (SV *)GvFILEGV(gv)));
1926 MODULE = B PACKAGE = B::IO PREFIX = Io
1936 if( strEQ( name, "stdin" ) ) {
1937 handle = PerlIO_stdin();
1939 else if( strEQ( name, "stdout" ) ) {
1940 handle = PerlIO_stdout();
1942 else if( strEQ( name, "stderr" ) ) {
1943 handle = PerlIO_stderr();
1946 croak( "Invalid value '%s'", name );
1948 RETVAL = handle == IoIFP(io);
1952 MODULE = B PACKAGE = B::AV PREFIX = Av
1962 if (AvFILL(av) >= 0) {
1963 SV **svp = AvARRAY(av);
1965 for (i = 0; i <= AvFILL(av); i++)
1966 XPUSHs(make_sv_object(aTHX_ svp[i]));
1974 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1975 XPUSHs(make_sv_object(aTHX_ (AvARRAY(av)[idx])));
1977 XPUSHs(make_sv_object(aTHX_ NULL));
1980 MODULE = B PACKAGE = B::FM PREFIX = Fm
1986 PERL_UNUSED_VAR(format);
1992 MODULE = B PACKAGE = B::CV PREFIX = Cv
2004 PUSHs(make_op_object(aTHX_ CvISXSUB(cv) ? NULL
2005 : ix ? CvROOT(cv) : CvSTART(cv)));
2017 RETVAL = CvISXSUB(cv) ? NULL : CvPADLIST(cv);
2027 PUSHs(make_sv_object(aTHX_ (SV *)CvPADLIST(cv)));
2036 RETVAL = newSVuv(CvISXSUB(cv) ? PTR2UV(CvHSCXT(cv)) : 0);
2046 ST(0) = ix && CvCONST(cv)
2047 ? make_sv_object(aTHX_ (SV *)CvXSUBANY(cv).any_ptr)
2048 : sv_2mortal(newSViv(CvISXSUB(cv)
2049 ? (ix ? CvXSUBANY(cv).any_iv
2050 : PTR2IV(CvXSUB(cv)))
2057 PUSHs(make_sv_object(aTHX_ (SV *)cv_const_sv(cv)));
2063 ST(0) = make_sv_object(aTHX_ (SV*)CvGV(cv));
2069 RETVAL = CvNAMED(cv) ? newSVhek(CvNAME_HEK(cv)) : &PL_sv_undef;
2073 MODULE = B PACKAGE = B::HV PREFIX = Hv
2087 if (HvUSEDKEYS(hv) > 0) {
2089 SSize_t extend_size;
2090 (void)hv_iterinit(hv);
2091 /* 2*HvUSEDKEYS() should never be big enough to truncate or wrap */
2092 assert(HvUSEDKEYS(hv) <= (SSize_t_MAX >> 1));
2093 extend_size = (SSize_t)HvUSEDKEYS(hv) * 2;
2094 EXTEND(sp, extend_size);
2095 while ((he = hv_iternext(hv))) {
2097 mPUSHs(HeSVKEY(he));
2098 } else if (HeKUTF8(he)) {
2099 PUSHs(newSVpvn_flags(HeKEY(he), HeKLEN(he), SVf_UTF8|SVs_TEMP));
2101 mPUSHp(HeKEY(he), HeKLEN(he));
2103 PUSHs(make_sv_object(aTHX_ HeVAL(he)));
2107 MODULE = B PACKAGE = B::HE PREFIX = He
2115 PUSHs(make_sv_object(aTHX_ ix ? HeSVKEY_force(he) : HeVAL(he)));
2121 MODULE = B PACKAGE = B::RHE
2127 RETVAL = newRV_noinc( (SV*)cophh_2hv(h, 0) );
2134 MODULE = B PACKAGE = B::PADLIST PREFIX = Padlist
2139 ALIAS: B::PADNAMELIST::MAX = 0
2141 PERL_UNUSED_VAR(ix);
2142 RETVAL = PadlistMAX(padlist);
2147 PadlistNAMES(padlist)
2151 PadlistARRAY(padlist)
2154 if (PadlistMAX(padlist) >= 0) {
2156 PAD **padp = PadlistARRAY(padlist);
2158 sv_setiv(newSVrv(TARG, PadlistNAMES(padlist)
2161 PTR2IV(PadlistNAMES(padlist)));
2163 for (i = 1; i <= PadlistMAX(padlist); i++)
2164 XPUSHs(make_sv_object(aTHX_ (SV *)padp[i]));
2168 PadlistARRAYelt(padlist, idx)
2172 if (idx < 0 || idx > PadlistMAX(padlist))
2173 XPUSHs(make_sv_object(aTHX_ NULL));
2176 PUSHMARK(PL_stack_sp-1);
2177 XS_B__PADLIST_NAMES(aTHX_ cv);
2181 XPUSHs(make_sv_object(aTHX_
2182 (SV *)PadlistARRAY(padlist)[idx]));
2185 PadlistREFCNT(padlist)
2188 PERL_UNUSED_VAR(padlist);
2189 RETVAL = PadlistREFCNT(padlist);
2195 MODULE = B PACKAGE = B::PADNAMELIST PREFIX = Padnamelist
2198 PadnamelistARRAY(pnl)
2201 if (PadnamelistMAX(pnl) >= 0) {
2202 PADNAME **padp = PadnamelistARRAY(pnl);
2204 for (; i <= PadnamelistMAX(pnl); i++)
2206 SV *rv = sv_newmortal();
2207 sv_setiv(newSVrv(rv,padp[i] ? "B::PADNAME" : "B::SPECIAL"),
2214 PadnamelistARRAYelt(pnl, idx)
2218 if (idx < 0 || idx > PadnamelistMAX(pnl))
2221 RETVAL = PadnamelistARRAY(pnl)[idx];
2225 MODULE = B PACKAGE = B::PADNAME PREFIX = Padname
2227 #define PN_type_ix \
2228 sv_SVp | STRUCT_OFFSET(struct padname,xpadn_type_u.xpadn_typestash)
2229 #define PN_ourstash_ix \
2230 sv_SVp | STRUCT_OFFSET(struct padname,xpadn_ourstash)
2232 sv_U8p | STRUCT_OFFSET(struct padname,xpadn_len)
2233 #define PN_refcnt_ix \
2234 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_refcnt)
2235 #define PN_cop_seq_range_low_ix \
2236 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_low)
2237 #define PN_cop_seq_range_high_ix \
2238 sv_U32p | STRUCT_OFFSET(struct padname, xpadn_high)
2239 #define PNL_refcnt_ix \
2240 sv_U32p | STRUCT_OFFSET(struct padnamelist, xpadnl_refcnt)
2242 sv_U32p | STRUCT_OFFSET(struct padlist, xpadl_id)
2243 #define PL_outid_ix \
2244 sv_U32p | STRUCT_OFFSET(struct padlist, xpadl_outid)
2251 B::PADNAME::TYPE = PN_type_ix
2252 B::PADNAME::OURSTASH = PN_ourstash_ix
2253 B::PADNAME::LEN = PN_len_ix
2254 B::PADNAME::REFCNT = PN_refcnt_ix
2255 B::PADNAME::COP_SEQ_RANGE_LOW = PN_cop_seq_range_low_ix
2256 B::PADNAME::COP_SEQ_RANGE_HIGH = PN_cop_seq_range_high_ix
2257 B::PADNAMELIST::REFCNT = PNL_refcnt_ix
2258 B::PADLIST::id = PL_id_ix
2259 B::PADLIST::outid = PL_outid_ix
2264 ptr = (ix & 0xFFFF) + (char *)pn;
2265 switch ((U8)(ix >> 16)) {
2266 case (U8)(sv_SVp >> 16):
2267 ret = make_sv_object(aTHX_ *((SV **)ptr));
2269 case (U8)(sv_U32p >> 16):
2270 ret = sv_2mortal(newSVuv(*((U32 *)ptr)));
2272 case (U8)(sv_U8p >> 16):
2273 ret = sv_2mortal(newSVuv(*((U8 *)ptr)));
2287 PERL_UNUSED_ARG(RETVAL);
2288 sv_setpvn(TARG, PadnamePV(pn), PadnameLEN(pn));
2294 /* Uses less memory than an ALIAS. */
2295 GV *gv = gv_fetchpvs("B::PADNAME::TYPE", 1, SVt_PVGV);
2296 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::SvSTASH",1,SVt_PVGV),(SV *)gv);
2297 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PROTOCV",1,SVt_PVGV),(SV *)gv);
2298 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PVX",1,SVt_PVGV),
2299 (SV *)gv_fetchpvs("B::PADNAME::PV" ,1,SVt_PVGV));
2300 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PARENT_PAD_INDEX" ,1,SVt_PVGV),
2301 (SV *)gv_fetchpvs("B::PADNAME::COP_SEQ_RANGE_LOW",1,
2303 sv_setsv((SV *)gv_fetchpvs("B::PADNAME::PARENT_FAKELEX_FLAGS",1,
2305 (SV *)gv_fetchpvs("B::PADNAME::COP_SEQ_RANGE_HIGH" ,1,
2313 RETVAL = PadnameFLAGS(pn);
2314 /* backward-compatibility hack, which should be removed if the
2315 flags field becomes large enough to hold SVf_FAKE (and
2316 PADNAMEt_OUTER should be renumbered to match SVf_FAKE) */
2317 STATIC_ASSERT_STMT(SVf_FAKE >= 1<<(sizeof(PadnameFLAGS((B__PADNAME)NULL)) * 8));
2318 if (PadnameOUTER(pn))