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)];
239 make_sv_object(pTHX_ SV *arg, SV *sv)
241 const char *type = 0;
245 for (iv = 0; iv < sizeof(specialsv_list)/sizeof(SV*); iv++) {
246 if (sv == specialsv_list[iv]) {
252 type = svclassnames[SvTYPE(sv)];
255 sv_setiv(newSVrv(arg, type), iv);
259 #if PERL_VERSION >= 9
261 make_temp_object(pTHX_ SV *arg, SV *temp)
264 const char *const type = svclassnames[SvTYPE(temp)];
265 const IV iv = PTR2IV(temp);
267 target = newSVrv(arg, type);
268 sv_setiv(target, iv);
270 /* Need to keep our "temp" around as long as the target exists.
271 Simplest way seems to be to hang it from magic, and let that clear
272 it up. No vtable, so won't actually get in the way of anything. */
273 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
274 /* magic object has had its reference count increased, so we must drop
281 make_warnings_object(pTHX_ SV *arg, STRLEN *warnings)
283 const char *type = 0;
285 IV iv = sizeof(specialsv_list)/sizeof(SV*);
287 /* Counting down is deliberate. Before the split between make_sv_object
288 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
289 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
292 if ((SV*)warnings == specialsv_list[iv]) {
298 sv_setiv(newSVrv(arg, type), iv);
301 /* B assumes that warnings are a regular SV. Seems easier to keep it
302 happy by making them into a regular SV. */
303 return make_temp_object(aTHX_ arg,
304 newSVpvn((char *)(warnings + 1), *warnings));
309 make_cop_io_object(pTHX_ SV *arg, COP *cop)
311 SV *const value = newSV(0);
313 Perl_emulate_cop_io(aTHX_ cop, value);
316 return make_temp_object(aTHX_ arg, newSVsv(value));
319 return make_sv_object(aTHX_ arg, NULL);
325 make_mg_object(pTHX_ SV *arg, MAGIC *mg)
327 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
332 cstring(pTHX_ SV *sv, bool perlstyle)
334 SV *sstr = newSVpvn("", 0);
337 sv_setpvn(sstr, "0", 1);
338 else if (perlstyle && SvUTF8(sv)) {
339 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
340 const STRLEN len = SvCUR(sv);
341 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
342 sv_setpvn(sstr,"\"",1);
346 sv_catpvn(sstr, "\\\"", 2);
348 sv_catpvn(sstr, "\\$", 2);
350 sv_catpvn(sstr, "\\@", 2);
353 if (strchr("nrftax\\",*(s+1)))
354 sv_catpvn(sstr, s++, 2);
356 sv_catpvn(sstr, "\\\\", 2);
358 else /* should always be printable */
359 sv_catpvn(sstr, s, 1);
362 sv_catpv(sstr, "\"");
369 const char *s = SvPV(sv, len);
370 sv_catpv(sstr, "\"");
371 for (; len; len--, s++)
373 /* At least try a little for readability */
375 sv_catpv(sstr, "\\\"");
377 sv_catpv(sstr, "\\\\");
378 /* trigraphs - bleagh */
379 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
380 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
381 sprintf(escbuff, "\\%03o", '?');
382 sv_catpv(sstr, escbuff);
384 else if (perlstyle && *s == '$')
385 sv_catpv(sstr, "\\$");
386 else if (perlstyle && *s == '@')
387 sv_catpv(sstr, "\\@");
389 else if (isPRINT(*s))
391 else if (*s >= ' ' && *s < 127)
393 sv_catpvn(sstr, s, 1);
395 sv_catpv(sstr, "\\n");
397 sv_catpv(sstr, "\\r");
399 sv_catpv(sstr, "\\t");
401 sv_catpv(sstr, "\\a");
403 sv_catpv(sstr, "\\b");
405 sv_catpv(sstr, "\\f");
406 else if (!perlstyle && *s == '\v')
407 sv_catpv(sstr, "\\v");
410 /* Don't want promotion of a signed -1 char in sprintf args */
411 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
412 const unsigned char c = (unsigned char) *s;
413 sprintf(escbuff, "\\%03o", c);
414 sv_catpv(sstr, escbuff);
416 /* XXX Add line breaks if string is long */
418 sv_catpv(sstr, "\"");
426 SV *sstr = newSVpvn("'", 1);
427 const char *s = SvPV_nolen(sv);
430 sv_catpvn(sstr, "\\'", 2);
432 sv_catpvn(sstr, "\\\\", 2);
434 else if (isPRINT(*s))
436 else if (*s >= ' ' && *s < 127)
438 sv_catpvn(sstr, s, 1);
440 sv_catpvn(sstr, "\\n", 2);
442 sv_catpvn(sstr, "\\r", 2);
444 sv_catpvn(sstr, "\\t", 2);
446 sv_catpvn(sstr, "\\a", 2);
448 sv_catpvn(sstr, "\\b", 2);
450 sv_catpvn(sstr, "\\f", 2);
452 sv_catpvn(sstr, "\\v", 2);
455 /* no trigraph support */
456 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
457 /* Don't want promotion of a signed -1 char in sprintf args */
458 unsigned char c = (unsigned char) *s;
459 sprintf(escbuff, "\\%03o", c);
460 sv_catpv(sstr, escbuff);
462 sv_catpvn(sstr, "'", 1);
467 walkoptree(pTHX_ SV *opsv, const char *method)
474 croak("opsv is not a reference");
475 opsv = sv_mortalcopy(opsv);
476 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
477 if (walkoptree_debug) {
481 perl_call_method("walkoptree_debug", G_DISCARD);
486 perl_call_method(method, G_DISCARD);
487 if (o && (o->op_flags & OPf_KIDS)) {
488 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
489 /* Use the same opsv. Rely on methods not to mess it up. */
490 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
491 walkoptree(aTHX_ opsv, method);
494 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
495 #if PERL_VERSION >= 9
496 && (kid = cPMOPo->op_pmreplrootu.op_pmreplroot)
498 && (kid = cPMOPo->op_pmreplroot)
502 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
503 walkoptree(aTHX_ opsv, method);
508 oplist(pTHX_ OP *o, SV **SP)
510 for(; o; o = o->op_next) {
512 #if PERL_VERSION >= 9
521 opsv = sv_newmortal();
522 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
524 switch (o->op_type) {
526 #if PERL_VERSION >= 9
527 SP = oplist(aTHX_ cPMOPo->op_pmstashstartu.op_pmreplstart, SP);
529 SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP);
533 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
534 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
535 kid = kUNOP->op_first; /* pass rv2gv */
536 kid = kUNOP->op_first; /* pass leave */
537 SP = oplist(aTHX_ kid->op_next, SP);
541 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
543 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
546 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
547 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
548 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
556 typedef UNOP *B__UNOP;
557 typedef BINOP *B__BINOP;
558 typedef LOGOP *B__LOGOP;
559 typedef LISTOP *B__LISTOP;
560 typedef PMOP *B__PMOP;
561 typedef SVOP *B__SVOP;
562 typedef PADOP *B__PADOP;
563 typedef PVOP *B__PVOP;
564 typedef LOOP *B__LOOP;
582 typedef MAGIC *B__MAGIC;
584 #if PERL_VERSION >= 9
585 typedef struct refcounted_he *B__RHE;
588 MODULE = B PACKAGE = B PREFIX = B_
594 HV *stash = gv_stashpvn("B", 1, GV_ADD);
595 AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE);
597 specialsv_list[0] = Nullsv;
598 specialsv_list[1] = &PL_sv_undef;
599 specialsv_list[2] = &PL_sv_yes;
600 specialsv_list[3] = &PL_sv_no;
601 specialsv_list[4] = (SV *) pWARN_ALL;
602 specialsv_list[5] = (SV *) pWARN_NONE;
603 specialsv_list[6] = (SV *) pWARN_STD;
604 #if PERL_VERSION <= 8
605 # define OPpPAD_STATE 0
610 #define B_main_cv() PL_main_cv
611 #define B_init_av() PL_initav
612 #define B_inc_gv() PL_incgv
613 #define B_check_av() PL_checkav_save
615 # define B_unitcheck_av() PL_unitcheckav_save
617 # define B_unitcheck_av() NULL
619 #define B_begin_av() PL_beginav_save
620 #define B_end_av() PL_endav
621 #define B_main_root() PL_main_root
622 #define B_main_start() PL_main_start
623 #define B_amagic_generation() PL_amagic_generation
624 #define B_sub_generation() PL_sub_generation
625 #define B_defstash() PL_defstash
626 #define B_curstash() PL_curstash
627 #define B_dowarn() PL_dowarn
628 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
629 #define B_sv_undef() &PL_sv_undef
630 #define B_sv_yes() &PL_sv_yes
631 #define B_sv_no() &PL_sv_no
632 #define B_formfeed() PL_formfeed
634 #define B_regex_padav() PL_regex_padav
643 #if PERL_VERSION >= 9
676 B_amagic_generation()
708 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
713 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
715 MODULE = B PACKAGE = B
718 walkoptree(opsv, method)
722 walkoptree(aTHX_ opsv, method);
725 walkoptree_debug(...)
728 RETVAL = walkoptree_debug;
729 if (items > 0 && SvTRUE(ST(1)))
730 walkoptree_debug = 1;
734 #define address(sv) PTR2IV(sv)
745 croak("argument is not a reference");
746 RETVAL = (SV*)SvRV(sv);
757 ST(0) = sv_newmortal();
758 if (strncmp(name,"pp_",3) == 0)
760 for (i = 0; i < PL_maxo; i++)
762 if (strcmp(name, PL_op_name[i]) == 0)
768 sv_setiv(ST(0),result);
775 ST(0) = sv_newmortal();
776 if (opnum >= 0 && opnum < PL_maxo) {
777 sv_setpvn(ST(0), "pp_", 3);
778 sv_catpv(ST(0), PL_op_name[opnum]);
787 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
788 const char *s = SvPV(sv, len);
789 PERL_HASH(hash, s, len);
790 sprintf(hexhash, "0x%"UVxf, (UV)hash);
791 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
793 #define cast_I32(foo) (I32)foo
812 RETVAL = cstring(aTHX_ sv, 0);
820 RETVAL = cstring(aTHX_ sv, 1);
828 RETVAL = cchar(aTHX_ sv);
835 #if PERL_VERSION <= 8
836 # ifdef USE_5005THREADS
838 const STRLEN len = strlen(PL_threadsv_names);
841 for (i = 0; i < len; i++)
842 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
846 #define OP_next(o) o->op_next
847 #define OP_sibling(o) o->op_sibling
848 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
849 #define OP_targ(o) o->op_targ
850 #define OP_type(o) o->op_type
851 #if PERL_VERSION >= 9
852 # define OP_opt(o) o->op_opt
854 # define OP_seq(o) o->op_seq
856 #define OP_flags(o) o->op_flags
857 #define OP_private(o) o->op_private
858 #define OP_spare(o) o->op_spare
860 MODULE = B PACKAGE = B::OP PREFIX = OP_
866 RETVAL = opsizes[cc_opclass(aTHX_ o)];
882 RETVAL = (char *)PL_op_name[o->op_type];
892 SV *sv = sv_newmortal();
894 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
895 sv_catpv(sv, PL_op_name[o->op_type]);
896 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
897 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
913 #if PERL_VERSION >= 9
935 #if PERL_VERSION >= 9
947 SP = oplist(aTHX_ o, SP);
949 #define UNOP_first(o) o->op_first
951 MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
957 #define BINOP_last(o) o->op_last
959 MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
965 #define LOGOP_other(o) o->op_other
967 MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
973 MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
982 for (kid = o->op_first; kid; kid = kid->op_sibling)
988 #if PERL_VERSION >= 9
989 # define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
991 # define PMOP_pmreplstart(o) o->op_pmreplstart
992 # define PMOP_pmpermflags(o) o->op_pmpermflags
993 # define PMOP_pmdynflags(o) o->op_pmdynflags
995 #define PMOP_pmnext(o) o->op_pmnext
996 #define PMOP_pmregexp(o) PM_GETRE(o)
998 #define PMOP_pmoffset(o) o->op_pmoffset
999 #define PMOP_pmstashpv(o) PmopSTASHPV(o);
1001 #define PMOP_pmstash(o) PmopSTASH(o);
1003 #define PMOP_pmflags(o) o->op_pmflags
1005 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
1007 #if PERL_VERSION <= 8
1014 ST(0) = sv_newmortal();
1015 root = o->op_pmreplroot;
1016 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
1017 if (o->op_type == OP_PUSHRE) {
1018 # ifdef USE_ITHREADS
1019 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
1021 sv_setiv(newSVrv(ST(0), root ?
1022 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1027 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1036 ST(0) = sv_newmortal();
1037 if (o->op_type == OP_PUSHRE) {
1038 # ifdef USE_ITHREADS
1039 sv_setiv(ST(0), o->op_pmreplrootu.op_pmtargetoff);
1041 GV *const target = o->op_pmreplrootu.op_pmtargetgv;
1042 sv_setiv(newSVrv(ST(0), target ?
1043 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1048 OP *const root = o->op_pmreplrootu.op_pmreplroot;
1049 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)),
1059 #if PERL_VERSION < 9
1089 #if PERL_VERSION < 9
1104 REGEXP * rx = NO_INIT
1106 ST(0) = sv_newmortal();
1109 sv_setpvn(ST(0), rx->precomp, rx->prelen);
1111 #if PERL_VERSION >= 9
1116 REGEXP * rx = NO_INIT
1118 ST(0) = sv_newmortal();
1121 sv_setuv(ST(0), rx->extflags);
1125 #define SVOP_sv(o) cSVOPo->op_sv
1126 #define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
1128 MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
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) : Nullgv)
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) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1176 else if (o->op_type == OP_TRANS) {
1177 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1180 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
1182 #define LOOP_redoop(o) o->op_redoop
1183 #define LOOP_nextop(o) o->op_nextop
1184 #define LOOP_lastop(o) o->op_lastop
1186 MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1201 #define COP_label(o) o->cop_label
1202 #define COP_stashpv(o) CopSTASHPV(o)
1203 #define COP_stash(o) CopSTASH(o)
1204 #define COP_file(o) CopFILE(o)
1205 #define COP_filegv(o) CopFILEGV(o)
1206 #define COP_cop_seq(o) o->cop_seq
1207 #define COP_arybase(o) CopARYBASE_get(o)
1208 #define COP_line(o) CopLINE(o)
1209 #define COP_hints(o) CopHINTS_get(o)
1210 #if PERL_VERSION < 9
1211 # define COP_warnings(o) o->cop_warnings
1212 # define COP_io(o) o->cop_io
1215 MODULE = B PACKAGE = B::COP PREFIX = COP_
1250 #if PERL_VERSION >= 9
1256 ST(0) = make_warnings_object(aTHX_ sv_newmortal(), o->cop_warnings);
1263 ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o);
1270 RETVAL = o->cop_hints_hash;
1290 MODULE = B PACKAGE = B::SV
1296 #define object_2svref(sv) sv
1303 MODULE = B PACKAGE = B::SV PREFIX = Sv
1325 MODULE = B PACKAGE = B::IV PREFIX = Sv
1340 MODULE = B PACKAGE = B::IV
1342 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1352 if (sizeof(IV) == 8) {
1354 const IV iv = SvIVX(sv);
1356 * The following way of spelling 32 is to stop compilers on
1357 * 32-bit architectures from moaning about the shift count
1358 * being >= the width of the type. Such architectures don't
1359 * reach this code anyway (unless sizeof(IV) > 8 but then
1360 * everything else breaks too so I'm not fussed at the moment).
1363 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1365 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1367 wp[1] = htonl(iv & 0xffffffff);
1368 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
1370 U32 w = htonl((U32)SvIVX(sv));
1371 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
1375 #if PERL_VERSION >= 11
1385 croak( "argument is not SvROK" );
1392 MODULE = B PACKAGE = B::NV PREFIX = Sv
1403 COP_SEQ_RANGE_LOW(sv)
1407 COP_SEQ_RANGE_HIGH(sv)
1411 PARENT_PAD_INDEX(sv)
1415 PARENT_FAKELEX_FLAGS(sv)
1418 #if PERL_VERSION < 11
1420 MODULE = B PACKAGE = B::RV PREFIX = Sv
1428 MODULE = B PACKAGE = B::PV PREFIX = Sv
1442 croak( "argument is not SvROK" );
1451 ST(0) = sv_newmortal();
1453 /* FIXME - we need a better way for B to identify PVs that are
1454 in the pads as variable names. */
1455 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1456 /* It claims to be longer than the space allocated for it -
1457 presuambly it's a variable name in the pad */
1458 sv_setpv(ST(0), SvPV_nolen_const(sv));
1460 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1462 SvFLAGS(ST(0)) |= SvUTF8(sv);
1465 /* XXX for backward compatibility, but should fail */
1466 /* croak( "argument is not SvPOK" ); */
1467 sv_setpvn(ST(0), NULL, 0);
1470 # This used to read 257. I think that that was buggy - should have been 258.
1471 # (The "\0", the flags byte, and 256 for the table. Not that anything
1472 # anywhere calls this method. NWC.
1477 ST(0) = sv_newmortal();
1478 sv_setpvn(ST(0), SvPVX_const(sv),
1479 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1490 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1495 MAGIC * mg = NO_INIT
1497 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1498 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
1500 MODULE = B PACKAGE = B::PVMG
1506 #define MgMOREMAGIC(mg) mg->mg_moremagic
1507 #define MgPRIVATE(mg) mg->mg_private
1508 #define MgTYPE(mg) mg->mg_type
1509 #define MgFLAGS(mg) mg->mg_flags
1510 #define MgOBJ(mg) mg->mg_obj
1511 #define MgLENGTH(mg) mg->mg_len
1512 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1514 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1520 if( MgMOREMAGIC(mg) ) {
1521 RETVAL = MgMOREMAGIC(mg);
1549 if(mg->mg_type == PERL_MAGIC_qr) {
1550 RETVAL = MgREGEX(mg);
1553 croak( "REGEX is only meaningful on r-magic" );
1562 if (mg->mg_type == PERL_MAGIC_qr) {
1563 REGEXP* rx = (REGEXP*)mg->mg_obj;
1566 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1569 croak( "precomp is only meaningful on r-magic" );
1582 ST(0) = sv_newmortal();
1584 if (mg->mg_len >= 0){
1585 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1586 } else if (mg->mg_len == HEf_SVKEY) {
1587 ST(0) = make_sv_object(aTHX_
1588 sv_newmortal(), (SV*)mg->mg_ptr);
1592 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1610 MODULE = B PACKAGE = B::BM PREFIX = Bm
1627 STRLEN len = NO_INIT
1628 char * str = NO_INIT
1630 str = SvPV(sv, len);
1631 /* Boyer-Moore table is just after string and its safety-margin \0 */
1632 ST(0) = sv_2mortal(newSVpvn(str + len + PERL_FBM_TABLE_OFFSET, 256));
1634 MODULE = B PACKAGE = B::GV PREFIX = Gv
1640 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
1646 RETVAL = GvGP(gv) == Null(GP*);
1654 #if PERL_VERSION >= 9
1655 RETVAL = isGV_with_GP(gv) ? TRUE : FALSE;
1657 RETVAL = TRUE; /* In 5.8 and earlier they all are. */
1682 RETVAL = (SV*)GvFORM(gv);
1718 MODULE = B PACKAGE = B::GV
1728 MODULE = B PACKAGE = B::IO PREFIX = Io
1770 #if PERL_VERSION <= 8
1785 if( strEQ( name, "stdin" ) ) {
1786 handle = PerlIO_stdin();
1788 else if( strEQ( name, "stdout" ) ) {
1789 handle = PerlIO_stdout();
1791 else if( strEQ( name, "stderr" ) ) {
1792 handle = PerlIO_stderr();
1795 croak( "Invalid value '%s'", name );
1797 RETVAL = handle == IoIFP(io);
1801 MODULE = B PACKAGE = B::IO
1811 MODULE = B PACKAGE = B::AV PREFIX = Av
1821 #if PERL_VERSION < 9
1824 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1836 if (AvFILL(av) >= 0) {
1837 SV **svp = AvARRAY(av);
1839 for (i = 0; i <= AvFILL(av); i++)
1840 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
1848 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1849 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1851 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1853 #if PERL_VERSION < 9
1855 MODULE = B PACKAGE = B::AV
1863 MODULE = B PACKAGE = B::FM PREFIX = Fm
1869 MODULE = B PACKAGE = B::CV PREFIX = Cv
1883 RETVAL = CvISXSUB(cv) ? NULL : CvSTART(cv);
1891 RETVAL = CvISXSUB(cv) ? NULL : CvROOT(cv);
1923 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1930 ST(0) = CvCONST(cv) ?
1931 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
1932 sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1934 MODULE = B PACKAGE = B::CV
1940 MODULE = B PACKAGE = B::CV PREFIX = cv_
1947 MODULE = B PACKAGE = B::HV PREFIX = Hv
1969 #if PERL_VERSION < 9
1981 if (HvKEYS(hv) > 0) {
1985 (void)hv_iterinit(hv);
1986 EXTEND(sp, HvKEYS(hv) * 2);
1987 while ((sv = hv_iternextsv(hv, &key, &len))) {
1988 PUSHs(newSVpvn(key, len));
1989 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
1993 MODULE = B PACKAGE = B::HE PREFIX = He
2007 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
2009 #if PERL_VERSION >= 9
2015 RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) );