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
39 #if PERL_VERSION >= 11
71 static const char* const opclassnames[] = {
86 static const size_t opsizes[] = {
101 #define MY_CXT_KEY "B::_guts" XS_VERSION
104 int x_walkoptree_debug; /* Flag for walkoptree debug hook */
105 SV * x_specialsv_list[7];
110 #define walkoptree_debug (MY_CXT.x_walkoptree_debug)
111 #define specialsv_list (MY_CXT.x_specialsv_list)
114 cc_opclass(pTHX_ const OP *o)
120 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
122 if (o->op_type == OP_SASSIGN)
123 return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP);
125 if (o->op_type == OP_AELEMFAST) {
126 if (o->op_flags & OPf_SPECIAL)
137 if (o->op_type == OP_GV || o->op_type == OP_GVSV ||
138 o->op_type == OP_RCATLINE)
142 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
167 case OA_PVOP_OR_SVOP:
169 * Character translations (tr///) are usually a PVOP, keeping a
170 * pointer to a table of shorts used to look up translations.
171 * Under utf8, however, a simple table isn't practical; instead,
172 * the OP is an SVOP, and the SV is a reference to a swash
173 * (i.e., an RV pointing to an HV).
175 return (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
176 ? OPc_SVOP : OPc_PVOP;
184 case OA_BASEOP_OR_UNOP:
186 * UNI(OP_foo) in toke.c returns token UNI or FUNC1 depending on
187 * whether parens were seen. perly.y uses OPf_SPECIAL to
188 * signal whether a BASEOP had empty parens or none.
189 * Some other UNOPs are created later, though, so the best
190 * test is OPf_KIDS, which is set in newUNOP.
192 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
196 * The file stat OPs are created via UNI(OP_foo) in toke.c but use
197 * the OPf_REF flag to distinguish between OP types instead of the
198 * usual OPf_SPECIAL flag. As usual, if OPf_KIDS is set, then we
199 * return OPc_UNOP so that walkoptree can find our children. If
200 * OPf_KIDS is not set then we check OPf_REF. Without OPf_REF set
201 * (no argument to the operator) it's an OP; with OPf_REF set it's
202 * an SVOP (and op_sv is the GV for the filehandle argument).
204 return ((o->op_flags & OPf_KIDS) ? OPc_UNOP :
206 (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP);
208 (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP);
212 * next, last, redo, dump and goto use OPf_SPECIAL to indicate that a
213 * label was omitted (in which case it's a BASEOP) or else a term was
214 * seen. In this last case, all except goto are definitely PVOP but
215 * goto is either a PVOP (with an ordinary constant label), an UNOP
216 * with OPf_STACKED (with a non-constant non-sub) or an UNOP for
217 * OP_REFGEN (with goto &sub) in which case OPf_STACKED also seems to
220 if (o->op_flags & OPf_STACKED)
222 else if (o->op_flags & OPf_SPECIAL)
227 warn("can't determine class of operator %s, assuming BASEOP\n",
228 PL_op_name[o->op_type]);
233 cc_opclassname(pTHX_ const OP *o)
235 return (char *)opclassnames[cc_opclass(aTHX_ o)];
238 /* FIXME - figure out how to get the typemap to assign this to ST(0), rather
239 than creating a new mortal for ST(0) then passing it in as the first
242 make_sv_object(pTHX_ SV *arg, SV *sv)
244 const char *type = 0;
249 arg = sv_newmortal();
251 for (iv = 0; iv < sizeof(specialsv_list)/sizeof(SV*); iv++) {
252 if (sv == specialsv_list[iv]) {
258 type = svclassnames[SvTYPE(sv)];
261 sv_setiv(newSVrv(arg, type), iv);
265 #if PERL_VERSION >= 9
267 make_temp_object(pTHX_ SV *temp)
270 SV *arg = sv_newmortal();
271 const char *const type = svclassnames[SvTYPE(temp)];
272 const IV iv = PTR2IV(temp);
274 target = newSVrv(arg, type);
275 sv_setiv(target, iv);
277 /* Need to keep our "temp" around as long as the target exists.
278 Simplest way seems to be to hang it from magic, and let that clear
279 it up. No vtable, so won't actually get in the way of anything. */
280 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
281 /* magic object has had its reference count increased, so we must drop
288 make_warnings_object(pTHX_ STRLEN *warnings)
290 const char *type = 0;
292 IV iv = sizeof(specialsv_list)/sizeof(SV*);
294 /* Counting down is deliberate. Before the split between make_sv_object
295 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
296 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
299 if ((SV*)warnings == specialsv_list[iv]) {
305 SV *arg = sv_newmortal();
306 sv_setiv(newSVrv(arg, type), iv);
309 /* B assumes that warnings are a regular SV. Seems easier to keep it
310 happy by making them into a regular SV. */
311 return make_temp_object(aTHX_ newSVpvn((char *)(warnings + 1), *warnings));
316 make_cop_io_object(pTHX_ COP *cop)
318 SV *const value = newSV(0);
320 Perl_emulate_cop_io(aTHX_ cop, value);
323 return make_sv_object(aTHX_ NULL, value);
326 return make_sv_object(aTHX_ NULL, NULL);
332 make_mg_object(pTHX_ MAGIC *mg)
334 SV *arg = sv_newmortal();
335 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
340 cstring(pTHX_ SV *sv, bool perlstyle)
345 return newSVpvs_flags("0", SVs_TEMP);
347 sstr = newSVpvs_flags("\"", SVs_TEMP);
349 if (perlstyle && SvUTF8(sv)) {
350 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
351 const STRLEN len = SvCUR(sv);
352 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
356 sv_catpvs(sstr, "\\\"");
358 sv_catpvs(sstr, "\\$");
360 sv_catpvs(sstr, "\\@");
363 if (strchr("nrftax\\",*(s+1)))
364 sv_catpvn(sstr, s++, 2);
366 sv_catpvs(sstr, "\\\\");
368 else /* should always be printable */
369 sv_catpvn(sstr, s, 1);
377 const char *s = SvPV(sv, len);
378 for (; len; len--, s++)
380 /* At least try a little for readability */
382 sv_catpvs(sstr, "\\\"");
384 sv_catpvs(sstr, "\\\\");
385 /* trigraphs - bleagh */
386 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
387 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", '?');
389 else if (perlstyle && *s == '$')
390 sv_catpvs(sstr, "\\$");
391 else if (perlstyle && *s == '@')
392 sv_catpvs(sstr, "\\@");
394 else if (isPRINT(*s))
396 else if (*s >= ' ' && *s < 127)
398 sv_catpvn(sstr, s, 1);
400 sv_catpvs(sstr, "\\n");
402 sv_catpvs(sstr, "\\r");
404 sv_catpvs(sstr, "\\t");
406 sv_catpvs(sstr, "\\a");
408 sv_catpvs(sstr, "\\b");
410 sv_catpvs(sstr, "\\f");
411 else if (!perlstyle && *s == '\v')
412 sv_catpvs(sstr, "\\v");
415 /* Don't want promotion of a signed -1 char in sprintf args */
416 const unsigned char c = (unsigned char) *s;
417 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
419 /* XXX Add line breaks if string is long */
422 sv_catpvs(sstr, "\"");
429 SV *sstr = newSVpvs_flags("'", SVs_TEMP);
430 const char *s = SvPV_nolen(sv);
431 /* Don't want promotion of a signed -1 char in sprintf args */
432 const unsigned char c = (unsigned char) *s;
435 sv_catpvs(sstr, "\\'");
437 sv_catpvs(sstr, "\\\\");
441 else if (c >= ' ' && c < 127)
443 sv_catpvn(sstr, s, 1);
445 sv_catpvs(sstr, "\\n");
447 sv_catpvs(sstr, "\\r");
449 sv_catpvs(sstr, "\\t");
451 sv_catpvs(sstr, "\\a");
453 sv_catpvs(sstr, "\\b");
455 sv_catpvs(sstr, "\\f");
457 sv_catpvs(sstr, "\\v");
459 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
460 sv_catpvs(sstr, "'");
464 #if PERL_VERSION >= 9
465 # define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
466 # define PMOP_pmreplroot(o) o->op_pmreplrootu.op_pmreplroot
468 # define PMOP_pmreplstart(o) o->op_pmreplstart
469 # define PMOP_pmreplroot(o) o->op_pmreplroot
470 # define PMOP_pmpermflags(o) o->op_pmpermflags
471 # define PMOP_pmdynflags(o) o->op_pmdynflags
475 walkoptree(pTHX_ SV *opsv, const char *method)
482 croak("opsv is not a reference");
483 opsv = sv_mortalcopy(opsv);
484 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
485 if (walkoptree_debug) {
489 perl_call_method("walkoptree_debug", G_DISCARD);
494 perl_call_method(method, G_DISCARD);
495 if (o && (o->op_flags & OPf_KIDS)) {
496 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
497 /* Use the same opsv. Rely on methods not to mess it up. */
498 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
499 walkoptree(aTHX_ opsv, method);
502 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
503 && (kid = PMOP_pmreplroot(cPMOPo)))
505 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
506 walkoptree(aTHX_ opsv, method);
511 oplist(pTHX_ OP *o, SV **SP)
513 for(; o; o = o->op_next) {
515 #if PERL_VERSION >= 9
524 opsv = sv_newmortal();
525 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
527 switch (o->op_type) {
529 SP = oplist(aTHX_ PMOP_pmreplstart(cPMOPo), SP);
532 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
533 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
534 kid = kUNOP->op_first; /* pass rv2gv */
535 kid = kUNOP->op_first; /* pass leave */
536 SP = oplist(aTHX_ kid->op_next, SP);
540 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
542 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
545 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
546 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
547 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
555 typedef UNOP *B__UNOP;
556 typedef BINOP *B__BINOP;
557 typedef LOGOP *B__LOGOP;
558 typedef LISTOP *B__LISTOP;
559 typedef PMOP *B__PMOP;
560 typedef SVOP *B__SVOP;
561 typedef PADOP *B__PADOP;
562 typedef PVOP *B__PVOP;
563 typedef LOOP *B__LOOP;
571 #if PERL_VERSION >= 11
572 typedef SV *B__REGEXP;
584 typedef MAGIC *B__MAGIC;
586 #if PERL_VERSION >= 9
587 typedef struct refcounted_he *B__RHE;
590 #include "const-c.inc"
592 MODULE = B PACKAGE = B PREFIX = B_
594 INCLUDE: const-xs.inc
600 HV *stash = gv_stashpvs("B", GV_ADD);
601 AV *export_ok = perl_get_av("B::EXPORT_OK", GV_ADD);
603 specialsv_list[0] = Nullsv;
604 specialsv_list[1] = &PL_sv_undef;
605 specialsv_list[2] = &PL_sv_yes;
606 specialsv_list[3] = &PL_sv_no;
607 specialsv_list[4] = (SV *) pWARN_ALL;
608 specialsv_list[5] = (SV *) pWARN_NONE;
609 specialsv_list[6] = (SV *) pWARN_STD;
610 #if PERL_VERSION <= 8
611 # define OPpPAD_STATE 0
615 #define B_main_cv() PL_main_cv
616 #define B_init_av() PL_initav
617 #define B_inc_gv() PL_incgv
618 #define B_check_av() PL_checkav_save
620 # define B_unitcheck_av() PL_unitcheckav_save
622 # define B_unitcheck_av() NULL
624 #define B_begin_av() PL_beginav_save
625 #define B_end_av() PL_endav
626 #define B_main_root() PL_main_root
627 #define B_main_start() PL_main_start
628 #define B_amagic_generation() PL_amagic_generation
629 #define B_sub_generation() PL_sub_generation
630 #define B_defstash() PL_defstash
631 #define B_curstash() PL_curstash
632 #define B_dowarn() PL_dowarn
633 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
634 #define B_sv_undef() &PL_sv_undef
635 #define B_sv_yes() &PL_sv_yes
636 #define B_sv_no() &PL_sv_no
637 #define B_formfeed() PL_formfeed
639 #define B_regex_padav() PL_regex_padav
648 #if PERL_VERSION >= 9
681 B_amagic_generation()
713 ST(0) = make_sv_object(aTHX_ NULL, PL_warnhook);
718 ST(0) = make_sv_object(aTHX_ NULL, PL_diehook);
720 MODULE = B PACKAGE = B
723 walkoptree(opsv, method)
727 walkoptree(aTHX_ opsv, method);
730 walkoptree_debug(...)
733 RETVAL = walkoptree_debug;
734 if (items > 0 && SvTRUE(ST(1)))
735 walkoptree_debug = 1;
739 #define address(sv) PTR2IV(sv)
750 croak("argument is not a reference");
751 RETVAL = (SV*)SvRV(sv);
762 ST(0) = sv_newmortal();
763 if (strncmp(name,"pp_",3) == 0)
765 for (i = 0; i < PL_maxo; i++)
767 if (strcmp(name, PL_op_name[i]) == 0)
773 sv_setiv(ST(0),result);
780 ST(0) = sv_newmortal();
781 if (opnum >= 0 && opnum < PL_maxo) {
782 sv_setpvs(ST(0), "pp_");
783 sv_catpv(ST(0), PL_op_name[opnum]);
792 const char *s = SvPVbyte(sv, len);
793 PERL_HASH(hash, s, len);
794 ST(0) = sv_2mortal(Perl_newSVpvf(aTHX_ "0x%"UVxf, (UV)hash));
796 #define cast_I32(foo) (I32)foo
818 PUSHs(ix == 2 ? cchar(aTHX_ sv) : cstring(aTHX_ sv, ix));
823 #if PERL_VERSION <= 8
824 # ifdef USE_5005THREADS
826 const STRLEN len = strlen(PL_threadsv_names);
829 for (i = 0; i < len; i++)
830 PUSHs(newSVpvn_flags(&PL_threadsv_names[i], 1, SVs_TEMP));
835 #define PADOFFSETp 0x10000
841 #define OP_next_ix OPp | offsetof(struct op, op_next)
842 #define OP_sibling_ix OPp | offsetof(struct op, op_sibling)
843 #define UNOP_first_ix OPp | offsetof(struct unop, op_first)
844 #define BINOP_last_ix OPp | offsetof(struct binop, op_last)
845 #define LOGOP_other_ix OPp | offsetof(struct logop, op_other)
846 #if PERL_VERSION >= 9
847 # define PMOP_pmreplstart_ix \
848 OPp | offsetof(struct pmop, op_pmstashstartu.op_pmreplstart)
850 # define PMOP_pmreplstart_ix OPp | offsetof(struct pmop, op_pmreplstart)
852 #define LOOP_redoop_ix OPp | offsetof(struct loop, op_redoop)
853 #define LOOP_nextop_ix OPp | offsetof(struct loop, op_nextop)
854 #define LOOP_lastop_ix OPp | offsetof(struct loop, op_lastop)
856 #define OP_targ_ix PADOFFSETp | offsetof(struct op, op_targ)
857 #define OP_flags_ix U8p | offsetof(struct op, op_flags)
858 #define OP_private_ix U8p | offsetof(struct op, op_private)
860 #define PMOP_pmflags_ix U32p | offsetof(struct pmop, op_pmflags)
863 #define PMOP_pmoffset_ix IVp | offsetof(struct pmop, op_pmoffset)
866 # Yes, B::SV::sv and B::SV::gv really do end up generating identical code.
867 #define SVOP_sv_ix SVp | offsetof(struct svop, op_sv)
868 #define SVOP_gv_ix SVp | offsetof(struct svop, op_sv)
870 MODULE = B PACKAGE = B::OP PREFIX = OP_
876 RETVAL = opsizes[cc_opclass(aTHX_ o)];
880 # The type checking code in B has always been identical for all OP types,
881 # irrespective of whether the action is actually defined on that OP.
887 B::OP::next = OP_next_ix
888 B::OP::sibling = OP_sibling_ix
889 B::OP::targ = OP_targ_ix
890 B::OP::flags = OP_flags_ix
891 B::OP::private = OP_private_ix
892 B::UNOP::first = UNOP_first_ix
893 B::BINOP::last = BINOP_last_ix
894 B::LOGOP::other = LOGOP_other_ix
895 B::PMOP::pmreplstart = PMOP_pmreplstart_ix
896 B::LOOP::redoop = LOOP_redoop_ix
897 B::LOOP::nextop = LOOP_nextop_ix
898 B::LOOP::lastop = LOOP_lastop_ix
899 B::PMOP::pmflags = PMOP_pmflags_ix
900 B::SVOP::sv = SVOP_sv_ix
901 B::SVOP::gv = SVOP_gv_ix
906 ptr = (ix & 0xFFFF) + (char *)o;
907 switch ((U8)(ix >> 16)) {
908 case (U8)(OPp >> 16):
910 OP *const o2 = *((OP **)ptr);
911 ret = sv_newmortal();
912 sv_setiv(newSVrv(ret, cc_opclassname(aTHX_ o2)), PTR2IV(o2));
915 case (U8)(PADOFFSETp >> 16):
916 ret = sv_2mortal(newSVuv(*((PADOFFSET*)ptr)));
918 case (U8)(U8p >> 16):
919 ret = sv_2mortal(newSVuv(*((U8*)ptr)));
921 case (U8)(U32p >> 16):
922 ret = sv_2mortal(newSVuv(*((U32*)ptr)));
924 case (U8)(SVp >> 16):
925 ret = make_sv_object(aTHX_ NULL, *((SV **)ptr));
928 case (U8)(IVp >> 16):
929 ret = sv_2mortal(newSViv(*((IV*)ptr)));
942 RETVAL = (char *)(ix ? PL_op_desc : PL_op_name)[o->op_type];
951 SV *sv = newSVpvs_flags("PL_ppaddr[OP_", SVs_TEMP);
953 sv_catpv(sv, PL_op_name[o->op_type]);
954 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
955 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
959 #if PERL_VERSION >= 9
960 # These 3 are all bitfields, so we can't take their addresses.
973 RETVAL = o->op_spare;
1005 SP = oplist(aTHX_ o, SP);
1007 MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
1016 for (kid = o->op_first; kid; kid = kid->op_sibling)
1022 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
1024 #if PERL_VERSION <= 8
1031 ST(0) = sv_newmortal();
1032 root = o->op_pmreplroot;
1033 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
1034 if (o->op_type == OP_PUSHRE) {
1035 # ifdef USE_ITHREADS
1036 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
1038 sv_setiv(newSVrv(ST(0), root ?
1039 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1044 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1053 ST(0) = sv_newmortal();
1054 if (o->op_type == OP_PUSHRE) {
1055 # ifdef USE_ITHREADS
1056 sv_setiv(ST(0), o->op_pmreplrootu.op_pmtargetoff);
1058 GV *const target = o->op_pmreplrootu.op_pmtargetgv;
1059 sv_setiv(newSVrv(ST(0), target ?
1060 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1065 OP *const root = o->op_pmreplrootu.op_pmreplroot;
1066 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)),
1073 #define PMOP_pmstashpv(o) PmopSTASHPV(o);
1080 #define PMOP_pmstash(o) PmopSTASH(o);
1088 #if PERL_VERSION < 9
1089 #define PMOP_pmnext(o) o->op_pmnext
1113 ST(0) = sv_newmortal();
1115 #if PERL_VERSION >= 9
1117 sv_setuv(ST(0), RX_EXTFLAGS(rx));
1121 sv_setpvn(ST(0), RX_PRECOMP(rx), RX_PRELEN(rx));
1129 cv = newXS("B::PMOP::pmoffset", XS_B__OP_next, __FILE__);
1130 XSANY.any_i32 = PMOP_pmoffset_ix;
1132 #if PERL_VERSION >= 9
1133 cv = newXS("B::PMOP::reflags", XS_B__PMOP_precomp, __FILE__);
1138 #define PADOP_padix(o) o->op_padix
1139 #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
1140 #define PADOP_gv(o) ((o->op_padix \
1141 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
1142 ? (GV*)PAD_SVl(o->op_padix) : (GV *)NULL)
1144 MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
1158 MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1165 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
1166 * whereas other PVOPs point to a null terminated string.
1168 if (o->op_type == OP_TRANS &&
1169 (o->op_private & OPpTRANS_COMPLEMENT) &&
1170 !(o->op_private & OPpTRANS_DELETE))
1172 const short* const tbl = (short*)o->op_pv;
1173 const short entries = 257 + tbl[256];
1174 ST(0) = newSVpvn_flags(o->op_pv, entries * sizeof(short), SVs_TEMP);
1176 else if (o->op_type == OP_TRANS) {
1177 ST(0) = newSVpvn_flags(o->op_pv, 256 * sizeof(short), SVs_TEMP);
1180 ST(0) = newSVpvn_flags(o->op_pv, strlen(o->op_pv), SVs_TEMP);
1182 #define COP_label(o) CopLABEL(o)
1183 #define COP_stashpv(o) CopSTASHPV(o)
1184 #define COP_stash(o) CopSTASH(o)
1185 #define COP_file(o) CopFILE(o)
1186 #define COP_filegv(o) CopFILEGV(o)
1187 #define COP_cop_seq(o) o->cop_seq
1188 #define COP_arybase(o) CopARYBASE_get(o)
1189 #define COP_line(o) CopLINE(o)
1190 #define COP_hints(o) CopHINTS_get(o)
1192 MODULE = B PACKAGE = B::COP PREFIX = COP_
1231 #if PERL_VERSION >= 9
1232 ST(0) = make_warnings_object(aTHX_ o->cop_warnings);
1234 ST(0) = make_sv_object(aTHX_ NULL, o->cop_warnings);
1242 #if PERL_VERSION >= 9
1243 ST(0) = make_cop_io_object(aTHX_ o);
1245 ST(0) = make_sv_object(aTHX_ NULL, o->cop_io);
1249 #if PERL_VERSION >= 9
1255 RETVAL = CopHINTHASH_get(o);
1265 MODULE = B PACKAGE = B::SV
1267 #define MAGICAL_FLAG_BITS (SVs_GMG|SVs_SMG|SVs_RMG)
1277 MAGICAL = MAGICAL_FLAG_BITS
1279 RETVAL = ix ? (SvFLAGS(sv) & (U32)ix) : SvREFCNT(sv);
1287 ST(0) = sv_2mortal(newRV(sv));
1290 MODULE = B PACKAGE = B::IV PREFIX = Sv
1305 MODULE = B PACKAGE = B::IV
1307 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1317 if (sizeof(IV) == 8) {
1319 const IV iv = SvIVX(sv);
1321 * The following way of spelling 32 is to stop compilers on
1322 * 32-bit architectures from moaning about the shift count
1323 * being >= the width of the type. Such architectures don't
1324 * reach this code anyway (unless sizeof(IV) > 8 but then
1325 * everything else breaks too so I'm not fussed at the moment).
1328 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1330 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1332 wp[1] = htonl(iv & 0xffffffff);
1333 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1335 U32 w = htonl((U32)SvIVX(sv));
1336 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1339 #if PERL_VERSION >= 11
1340 # The input typemap checking makes no distinction between different SV types,
1341 # so the XS body will generate the same C code, despite the different XS
1342 # "types". So there is no change in behaviour from doing newXS like this,
1343 # compared with the old approach of having a (near) duplicate XS body.
1344 # We should fix the typemap checking.
1347 newXS("B::IV::RV", XS_B__PV_RV, __FILE__);
1351 MODULE = B PACKAGE = B::NV PREFIX = Sv
1362 COP_SEQ_RANGE_LOW(sv)
1366 COP_SEQ_RANGE_HIGH(sv)
1370 PARENT_PAD_INDEX(sv)
1374 PARENT_FAKELEX_FLAGS(sv)
1377 #if PERL_VERSION < 11
1379 MODULE = B PACKAGE = B::RV PREFIX = Sv
1387 MODULE = B PACKAGE = B::PV PREFIX = Sv
1401 croak( "argument is not SvROK" );
1411 STRLEN len = SvCUR(sv);
1412 const char *p = SvPVX_const(sv);
1413 #if PERL_VERSION < 10
1414 /* Before 5.10 (well 931b58fb28fa5ca7), PAD_COMPNAME_GEN was stored
1415 in SvCUR(), which meant we had to attempt this special casing
1416 to avoid tripping up over variable names in the pads. */
1417 if((SvLEN(sv) && len >= SvLEN(sv))) {
1418 /* It claims to be longer than the space allocated for it -
1419 presuambly it's a variable name in the pad */
1423 ST(0) = newSVpvn_flags(p, len, SVs_TEMP | SvUTF8(sv));
1426 /* XXX for backward compatibility, but should fail */
1427 /* croak( "argument is not SvPOK" ); */
1428 ST(0) = sv_newmortal();
1431 # This used to read 257. I think that that was buggy - should have been 258.
1432 # (The "\0", the flags byte, and 256 for the table. Not that anything
1433 # anywhere calls this method. NWC.
1438 ST(0) = newSVpvn_flags(SvPVX_const(sv),
1439 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0),
1451 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1456 MAGIC * mg = NO_INIT
1458 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1459 XPUSHs(make_mg_object(aTHX_ mg));
1461 MODULE = B PACKAGE = B::PVMG
1467 MODULE = B PACKAGE = B::REGEXP
1469 #if PERL_VERSION >= 11
1475 /* FIXME - can we code this method more efficiently? */
1476 RETVAL = PTR2IV(sv);
1484 RETVAL = newSVpvn( RX_PRECOMP(sv), RX_PRELEN(sv) );
1490 #define MgMOREMAGIC(mg) mg->mg_moremagic
1491 #define MgPRIVATE(mg) mg->mg_private
1492 #define MgTYPE(mg) mg->mg_type
1493 #define MgFLAGS(mg) mg->mg_flags
1494 #define MgOBJ(mg) mg->mg_obj
1495 #define MgLENGTH(mg) mg->mg_len
1496 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1498 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1504 if( MgMOREMAGIC(mg) ) {
1505 RETVAL = MgMOREMAGIC(mg);
1533 if(mg->mg_type == PERL_MAGIC_qr) {
1534 RETVAL = MgREGEX(mg);
1537 croak( "REGEX is only meaningful on r-magic" );
1546 if (mg->mg_type == PERL_MAGIC_qr) {
1547 REGEXP* rx = (REGEXP*)mg->mg_obj;
1550 RETVAL = newSVpvn( RX_PRECOMP(rx), RX_PRELEN(rx) );
1553 croak( "precomp is only meaningful on r-magic" );
1567 if (mg->mg_len >= 0){
1568 ST(0) = newSVpvn_flags(mg->mg_ptr, mg->mg_len, SVs_TEMP);
1569 } else if (mg->mg_len == HEf_SVKEY) {
1570 ST(0) = make_sv_object(aTHX_ NULL, (SV*)mg->mg_ptr);
1572 ST(0) = sv_newmortal();
1574 ST(0) = sv_newmortal();
1576 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1594 MODULE = B PACKAGE = B::BM PREFIX = Bm
1611 STRLEN len = NO_INIT
1612 char * str = NO_INIT
1614 str = SvPV(sv, len);
1615 /* Boyer-Moore table is just after string and its safety-margin \0 */
1616 ST(0) = newSVpvn_flags(str + len + PERL_FBM_TABLE_OFFSET, 256, SVs_TEMP);
1618 MODULE = B PACKAGE = B::GV PREFIX = Gv
1624 #if PERL_VERSION >= 10
1625 ST(0) = sv_2mortal(newSVhek(GvNAME_HEK(gv)));
1627 ST(0) = newSVpvn_flags(GvNAME(gv), GvNAMELEN(gv), SVs_TEMP);
1637 #if PERL_VERSION >= 9
1638 RETVAL = isGV_with_GP(gv) ? TRUE : FALSE;
1640 RETVAL = TRUE; /* In 5.8 and earlier they all are. */
1643 RETVAL = GvGP(gv) == Null(GP*);
1668 RETVAL = (SV*)GvFORM(gv);
1704 MODULE = B PACKAGE = B::GV
1714 MODULE = B PACKAGE = B::IO PREFIX = Io
1756 #if PERL_VERSION <= 8
1771 if( strEQ( name, "stdin" ) ) {
1772 handle = PerlIO_stdin();
1774 else if( strEQ( name, "stdout" ) ) {
1775 handle = PerlIO_stdout();
1777 else if( strEQ( name, "stderr" ) ) {
1778 handle = PerlIO_stderr();
1781 croak( "Invalid value '%s'", name );
1783 RETVAL = handle == IoIFP(io);
1787 MODULE = B PACKAGE = B::IO
1797 MODULE = B PACKAGE = B::AV PREFIX = Av
1811 if (AvFILL(av) >= 0) {
1812 SV **svp = AvARRAY(av);
1814 for (i = 0; i <= AvFILL(av); i++)
1815 XPUSHs(make_sv_object(aTHX_ NULL, svp[i]));
1823 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1824 XPUSHs(make_sv_object(aTHX_ NULL, (AvARRAY(av)[idx])));
1826 XPUSHs(make_sv_object(aTHX_ NULL, NULL));
1828 #if PERL_VERSION < 9
1830 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1836 MODULE = B PACKAGE = B::AV
1844 MODULE = B PACKAGE = B::FM PREFIX = Fm
1850 MODULE = B PACKAGE = B::CV PREFIX = Cv
1866 RETVAL = CvISXSUB(cv) ? NULL : ix ? CvROOT(cv) : CvSTART(cv);
1898 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1906 ? make_sv_object(aTHX_ NULL, (SV *)CvXSUBANY(cv).any_ptr)
1907 : sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1909 MODULE = B PACKAGE = B::CV
1915 MODULE = B PACKAGE = B::CV PREFIX = cv_
1922 MODULE = B PACKAGE = B::HV PREFIX = Hv
1944 #if PERL_VERSION < 9
1956 if (HvKEYS(hv) > 0) {
1960 (void)hv_iterinit(hv);
1961 EXTEND(sp, HvKEYS(hv) * 2);
1962 while ((sv = hv_iternextsv(hv, &key, &len))) {
1964 PUSHs(make_sv_object(aTHX_ NULL, sv));
1968 MODULE = B PACKAGE = B::HE PREFIX = He
1982 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
1984 #if PERL_VERSION >= 9
1990 RETVAL = newRV( (SV*)cophh_2hv(h, 0) );