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[] = {
66 static const char* const opclassnames[] = {
81 static const size_t opsizes[] = {
96 #define MY_CXT_KEY "B::_guts" XS_VERSION
99 int x_walkoptree_debug; /* Flag for walkoptree debug hook */
100 SV * x_specialsv_list[7];
105 #define walkoptree_debug (MY_CXT.x_walkoptree_debug)
106 #define specialsv_list (MY_CXT.x_specialsv_list)
109 cc_opclass(pTHX_ const OP *o)
115 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
117 if (o->op_type == OP_SASSIGN)
118 return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP);
120 if (o->op_type == OP_AELEMFAST) {
121 if (o->op_flags & OPf_SPECIAL)
132 if (o->op_type == OP_GV || o->op_type == OP_GVSV ||
133 o->op_type == OP_RCATLINE)
137 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
162 case OA_PVOP_OR_SVOP:
164 * Character translations (tr///) are usually a PVOP, keeping a
165 * pointer to a table of shorts used to look up translations.
166 * Under utf8, however, a simple table isn't practical; instead,
167 * the OP is an SVOP, and the SV is a reference to a swash
168 * (i.e., an RV pointing to an HV).
170 return (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
171 ? OPc_SVOP : OPc_PVOP;
179 case OA_BASEOP_OR_UNOP:
181 * UNI(OP_foo) in toke.c returns token UNI or FUNC1 depending on
182 * whether parens were seen. perly.y uses OPf_SPECIAL to
183 * signal whether a BASEOP had empty parens or none.
184 * Some other UNOPs are created later, though, so the best
185 * test is OPf_KIDS, which is set in newUNOP.
187 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
191 * The file stat OPs are created via UNI(OP_foo) in toke.c but use
192 * the OPf_REF flag to distinguish between OP types instead of the
193 * usual OPf_SPECIAL flag. As usual, if OPf_KIDS is set, then we
194 * return OPc_UNOP so that walkoptree can find our children. If
195 * OPf_KIDS is not set then we check OPf_REF. Without OPf_REF set
196 * (no argument to the operator) it's an OP; with OPf_REF set it's
197 * an SVOP (and op_sv is the GV for the filehandle argument).
199 return ((o->op_flags & OPf_KIDS) ? OPc_UNOP :
201 (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP);
203 (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP);
207 * next, last, redo, dump and goto use OPf_SPECIAL to indicate that a
208 * label was omitted (in which case it's a BASEOP) or else a term was
209 * seen. In this last case, all except goto are definitely PVOP but
210 * goto is either a PVOP (with an ordinary constant label), an UNOP
211 * with OPf_STACKED (with a non-constant non-sub) or an UNOP for
212 * OP_REFGEN (with goto &sub) in which case OPf_STACKED also seems to
215 if (o->op_flags & OPf_STACKED)
217 else if (o->op_flags & OPf_SPECIAL)
222 warn("can't determine class of operator %s, assuming BASEOP\n",
223 PL_op_name[o->op_type]);
228 cc_opclassname(pTHX_ const OP *o)
230 return (char *)opclassnames[cc_opclass(aTHX_ o)];
234 make_sv_object(pTHX_ SV *arg, SV *sv)
236 const char *type = 0;
240 for (iv = 0; iv < sizeof(specialsv_list)/sizeof(SV*); iv++) {
241 if (sv == specialsv_list[iv]) {
247 type = svclassnames[SvTYPE(sv)];
250 sv_setiv(newSVrv(arg, type), iv);
254 #if PERL_VERSION >= 9
256 make_temp_object(pTHX_ SV *arg, SV *temp)
259 const char *const type = svclassnames[SvTYPE(temp)];
260 const IV iv = PTR2IV(temp);
262 target = newSVrv(arg, type);
263 sv_setiv(target, iv);
265 /* Need to keep our "temp" around as long as the target exists.
266 Simplest way seems to be to hang it from magic, and let that clear
267 it up. No vtable, so won't actually get in the way of anything. */
268 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
269 /* magic object has had its reference count increased, so we must drop
276 make_warnings_object(pTHX_ SV *arg, STRLEN *warnings)
278 const char *type = 0;
280 IV iv = sizeof(specialsv_list)/sizeof(SV*);
282 /* Counting down is deliberate. Before the split between make_sv_object
283 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
284 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
287 if ((SV*)warnings == specialsv_list[iv]) {
293 sv_setiv(newSVrv(arg, type), iv);
296 /* B assumes that warnings are a regular SV. Seems easier to keep it
297 happy by making them into a regular SV. */
298 return make_temp_object(aTHX_ arg,
299 newSVpvn((char *)(warnings + 1), *warnings));
304 make_cop_io_object(pTHX_ SV *arg, COP *cop)
306 SV *const value = newSV(0);
308 Perl_emulate_cop_io(aTHX_ cop, value);
311 return make_temp_object(aTHX_ arg, newSVsv(value));
314 return make_sv_object(aTHX_ arg, NULL);
320 make_mg_object(pTHX_ SV *arg, MAGIC *mg)
322 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
327 cstring(pTHX_ SV *sv, bool perlstyle)
329 SV *sstr = newSVpvn("", 0);
332 sv_setpvn(sstr, "0", 1);
333 else if (perlstyle && SvUTF8(sv)) {
334 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
335 const STRLEN len = SvCUR(sv);
336 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
337 sv_setpvn(sstr,"\"",1);
341 sv_catpvn(sstr, "\\\"", 2);
343 sv_catpvn(sstr, "\\$", 2);
345 sv_catpvn(sstr, "\\@", 2);
348 if (strchr("nrftax\\",*(s+1)))
349 sv_catpvn(sstr, s++, 2);
351 sv_catpvn(sstr, "\\\\", 2);
353 else /* should always be printable */
354 sv_catpvn(sstr, s, 1);
357 sv_catpv(sstr, "\"");
364 const char *s = SvPV(sv, len);
365 sv_catpv(sstr, "\"");
366 for (; len; len--, s++)
368 /* At least try a little for readability */
370 sv_catpv(sstr, "\\\"");
372 sv_catpv(sstr, "\\\\");
373 /* trigraphs - bleagh */
374 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
375 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
376 sprintf(escbuff, "\\%03o", '?');
377 sv_catpv(sstr, escbuff);
379 else if (perlstyle && *s == '$')
380 sv_catpv(sstr, "\\$");
381 else if (perlstyle && *s == '@')
382 sv_catpv(sstr, "\\@");
384 else if (isPRINT(*s))
386 else if (*s >= ' ' && *s < 127)
388 sv_catpvn(sstr, s, 1);
390 sv_catpv(sstr, "\\n");
392 sv_catpv(sstr, "\\r");
394 sv_catpv(sstr, "\\t");
396 sv_catpv(sstr, "\\a");
398 sv_catpv(sstr, "\\b");
400 sv_catpv(sstr, "\\f");
401 else if (!perlstyle && *s == '\v')
402 sv_catpv(sstr, "\\v");
405 /* Don't want promotion of a signed -1 char in sprintf args */
406 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
407 const unsigned char c = (unsigned char) *s;
408 sprintf(escbuff, "\\%03o", c);
409 sv_catpv(sstr, escbuff);
411 /* XXX Add line breaks if string is long */
413 sv_catpv(sstr, "\"");
421 SV *sstr = newSVpvn("'", 1);
422 const char *s = SvPV_nolen(sv);
425 sv_catpvn(sstr, "\\'", 2);
427 sv_catpvn(sstr, "\\\\", 2);
429 else if (isPRINT(*s))
431 else if (*s >= ' ' && *s < 127)
433 sv_catpvn(sstr, s, 1);
435 sv_catpvn(sstr, "\\n", 2);
437 sv_catpvn(sstr, "\\r", 2);
439 sv_catpvn(sstr, "\\t", 2);
441 sv_catpvn(sstr, "\\a", 2);
443 sv_catpvn(sstr, "\\b", 2);
445 sv_catpvn(sstr, "\\f", 2);
447 sv_catpvn(sstr, "\\v", 2);
450 /* no trigraph support */
451 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
452 /* Don't want promotion of a signed -1 char in sprintf args */
453 unsigned char c = (unsigned char) *s;
454 sprintf(escbuff, "\\%03o", c);
455 sv_catpv(sstr, escbuff);
457 sv_catpvn(sstr, "'", 1);
462 walkoptree(pTHX_ SV *opsv, const char *method)
469 croak("opsv is not a reference");
470 opsv = sv_mortalcopy(opsv);
471 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
472 if (walkoptree_debug) {
476 perl_call_method("walkoptree_debug", G_DISCARD);
481 perl_call_method(method, G_DISCARD);
482 if (o && (o->op_flags & OPf_KIDS)) {
483 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
484 /* Use the same opsv. Rely on methods not to mess it up. */
485 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
486 walkoptree(aTHX_ opsv, method);
489 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
490 #if PERL_VERSION >= 9
491 && (kid = cPMOPo->op_pmreplrootu.op_pmreplroot)
493 && (kid = cPMOPo->op_pmreplroot)
497 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
498 walkoptree(aTHX_ opsv, method);
503 oplist(pTHX_ OP *o, SV **SP)
505 for(; o; o = o->op_next) {
507 #if PERL_VERSION >= 9
516 opsv = sv_newmortal();
517 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
519 switch (o->op_type) {
521 #if PERL_VERSION >= 9
522 SP = oplist(aTHX_ cPMOPo->op_pmstashstartu.op_pmreplstart, SP);
524 SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP);
528 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
529 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
530 kid = kUNOP->op_first; /* pass rv2gv */
531 kid = kUNOP->op_first; /* pass leave */
532 SP = oplist(aTHX_ kid->op_next, SP);
536 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
538 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
541 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
542 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
543 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
551 typedef UNOP *B__UNOP;
552 typedef BINOP *B__BINOP;
553 typedef LOGOP *B__LOGOP;
554 typedef LISTOP *B__LISTOP;
555 typedef PMOP *B__PMOP;
556 typedef SVOP *B__SVOP;
557 typedef PADOP *B__PADOP;
558 typedef PVOP *B__PVOP;
559 typedef LOOP *B__LOOP;
577 typedef MAGIC *B__MAGIC;
579 #if PERL_VERSION >= 9
580 typedef struct refcounted_he *B__RHE;
583 MODULE = B PACKAGE = B PREFIX = B_
589 HV *stash = gv_stashpvn("B", 1, GV_ADD);
590 AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE);
592 specialsv_list[0] = Nullsv;
593 specialsv_list[1] = &PL_sv_undef;
594 specialsv_list[2] = &PL_sv_yes;
595 specialsv_list[3] = &PL_sv_no;
596 specialsv_list[4] = (SV *) pWARN_ALL;
597 specialsv_list[5] = (SV *) pWARN_NONE;
598 specialsv_list[6] = (SV *) pWARN_STD;
599 #if PERL_VERSION <= 8
600 # define CVf_ASSERTION 0
601 # define OPpPAD_STATE 0
606 #define B_main_cv() PL_main_cv
607 #define B_init_av() PL_initav
608 #define B_inc_gv() PL_incgv
609 #define B_check_av() PL_checkav_save
611 # define B_unitcheck_av() PL_unitcheckav_save
613 # define B_unitcheck_av() NULL
615 #define B_begin_av() PL_beginav_save
616 #define B_end_av() PL_endav
617 #define B_main_root() PL_main_root
618 #define B_main_start() PL_main_start
619 #define B_amagic_generation() PL_amagic_generation
620 #define B_sub_generation() PL_sub_generation
621 #define B_defstash() PL_defstash
622 #define B_curstash() PL_curstash
623 #define B_dowarn() PL_dowarn
624 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
625 #define B_sv_undef() &PL_sv_undef
626 #define B_sv_yes() &PL_sv_yes
627 #define B_sv_no() &PL_sv_no
628 #define B_formfeed() PL_formfeed
630 #define B_regex_padav() PL_regex_padav
639 #if PERL_VERSION >= 9
672 B_amagic_generation()
704 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
709 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
711 MODULE = B PACKAGE = B
714 walkoptree(opsv, method)
718 walkoptree(aTHX_ opsv, method);
721 walkoptree_debug(...)
724 RETVAL = walkoptree_debug;
725 if (items > 0 && SvTRUE(ST(1)))
726 walkoptree_debug = 1;
730 #define address(sv) PTR2IV(sv)
741 croak("argument is not a reference");
742 RETVAL = (SV*)SvRV(sv);
753 ST(0) = sv_newmortal();
754 if (strncmp(name,"pp_",3) == 0)
756 for (i = 0; i < PL_maxo; i++)
758 if (strcmp(name, PL_op_name[i]) == 0)
764 sv_setiv(ST(0),result);
771 ST(0) = sv_newmortal();
772 if (opnum >= 0 && opnum < PL_maxo) {
773 sv_setpvn(ST(0), "pp_", 3);
774 sv_catpv(ST(0), PL_op_name[opnum]);
783 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
784 const char *s = SvPV(sv, len);
785 PERL_HASH(hash, s, len);
786 sprintf(hexhash, "0x%"UVxf, (UV)hash);
787 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
789 #define cast_I32(foo) (I32)foo
808 RETVAL = cstring(aTHX_ sv, 0);
816 RETVAL = cstring(aTHX_ sv, 1);
824 RETVAL = cchar(aTHX_ sv);
831 #if PERL_VERSION <= 8
832 # ifdef USE_5005THREADS
834 const STRLEN len = strlen(PL_threadsv_names);
837 for (i = 0; i < len; i++)
838 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
842 #define OP_next(o) o->op_next
843 #define OP_sibling(o) o->op_sibling
844 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
845 #define OP_targ(o) o->op_targ
846 #define OP_type(o) o->op_type
847 #if PERL_VERSION >= 9
848 # define OP_opt(o) o->op_opt
849 # define OP_static(o) o->op_static
851 # define OP_seq(o) o->op_seq
853 #define OP_flags(o) o->op_flags
854 #define OP_private(o) o->op_private
855 #define OP_spare(o) o->op_spare
857 MODULE = B PACKAGE = B::OP PREFIX = OP_
863 RETVAL = opsizes[cc_opclass(aTHX_ o)];
879 RETVAL = (char *)PL_op_name[o->op_type];
889 SV *sv = sv_newmortal();
891 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
892 sv_catpv(sv, PL_op_name[o->op_type]);
893 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
894 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
910 #if PERL_VERSION >= 9
936 #if PERL_VERSION >= 9
948 SP = oplist(aTHX_ o, SP);
950 #define UNOP_first(o) o->op_first
952 MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
958 #define BINOP_last(o) o->op_last
960 MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
966 #define LOGOP_other(o) o->op_other
968 MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
974 MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
983 for (kid = o->op_first; kid; kid = kid->op_sibling)
989 #if PERL_VERSION >= 9
990 # define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
992 # define PMOP_pmreplstart(o) o->op_pmreplstart
993 # define PMOP_pmpermflags(o) o->op_pmpermflags
994 # define PMOP_pmdynflags(o) o->op_pmdynflags
996 #define PMOP_pmnext(o) o->op_pmnext
997 #define PMOP_pmregexp(o) PM_GETRE(o)
999 #define PMOP_pmoffset(o) o->op_pmoffset
1000 #define PMOP_pmstashpv(o) PmopSTASHPV(o);
1002 #define PMOP_pmstash(o) PmopSTASH(o);
1004 #define PMOP_pmflags(o) o->op_pmflags
1006 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
1008 #if PERL_VERSION <= 8
1015 ST(0) = sv_newmortal();
1016 root = o->op_pmreplroot;
1017 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
1018 if (o->op_type == OP_PUSHRE) {
1019 # ifdef USE_ITHREADS
1020 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
1022 sv_setiv(newSVrv(ST(0), root ?
1023 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1028 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1037 ST(0) = sv_newmortal();
1038 if (o->op_type == OP_PUSHRE) {
1039 # ifdef USE_ITHREADS
1040 sv_setiv(ST(0), o->op_pmreplrootu.op_pmtargetoff);
1042 GV *const target = o->op_pmreplrootu.op_pmtargetgv;
1043 sv_setiv(newSVrv(ST(0), target ?
1044 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1049 OP *const root = o->op_pmreplrootu.op_pmreplroot;
1050 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)),
1060 #if PERL_VERSION < 9
1090 #if PERL_VERSION < 9
1105 REGEXP * rx = NO_INIT
1107 ST(0) = sv_newmortal();
1110 sv_setpvn(ST(0), rx->precomp, rx->prelen);
1112 #if PERL_VERSION >= 9
1117 REGEXP * rx = NO_INIT
1119 ST(0) = sv_newmortal();
1122 sv_setuv(ST(0), rx->extflags);
1126 #define SVOP_sv(o) cSVOPo->op_sv
1127 #define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
1129 MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
1139 #define PADOP_padix(o) o->op_padix
1140 #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
1141 #define PADOP_gv(o) ((o->op_padix \
1142 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
1143 ? (GV*)PAD_SVl(o->op_padix) : Nullgv)
1145 MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
1159 MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1166 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
1167 * whereas other PVOPs point to a null terminated string.
1169 if (o->op_type == OP_TRANS &&
1170 (o->op_private & OPpTRANS_COMPLEMENT) &&
1171 !(o->op_private & OPpTRANS_DELETE))
1173 const short* const tbl = (short*)o->op_pv;
1174 const short entries = 257 + tbl[256];
1175 ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1177 else if (o->op_type == OP_TRANS) {
1178 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1181 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
1183 #define LOOP_redoop(o) o->op_redoop
1184 #define LOOP_nextop(o) o->op_nextop
1185 #define LOOP_lastop(o) o->op_lastop
1187 MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1202 #define COP_label(o) o->cop_label
1203 #define COP_stashpv(o) CopSTASHPV(o)
1204 #define COP_stash(o) CopSTASH(o)
1205 #define COP_file(o) CopFILE(o)
1206 #define COP_filegv(o) CopFILEGV(o)
1207 #define COP_cop_seq(o) o->cop_seq
1208 #define COP_arybase(o) CopARYBASE_get(o)
1209 #define COP_line(o) CopLINE(o)
1210 #define COP_hints(o) CopHINTS_get(o)
1211 #if PERL_VERSION < 9
1212 # define COP_warnings(o) o->cop_warnings
1213 # define COP_io(o) o->cop_io
1216 MODULE = B PACKAGE = B::COP PREFIX = COP_
1251 #if PERL_VERSION >= 9
1257 ST(0) = make_warnings_object(aTHX_ sv_newmortal(), o->cop_warnings);
1264 ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o);
1271 RETVAL = o->cop_hints_hash;
1291 MODULE = B PACKAGE = B::SV
1297 #define object_2svref(sv) sv
1304 MODULE = B PACKAGE = B::SV PREFIX = Sv
1326 MODULE = B PACKAGE = B::IV PREFIX = Sv
1341 MODULE = B PACKAGE = B::IV
1343 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1353 if (sizeof(IV) == 8) {
1355 const IV iv = SvIVX(sv);
1357 * The following way of spelling 32 is to stop compilers on
1358 * 32-bit architectures from moaning about the shift count
1359 * being >= the width of the type. Such architectures don't
1360 * reach this code anyway (unless sizeof(IV) > 8 but then
1361 * everything else breaks too so I'm not fussed at the moment).
1364 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1366 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1368 wp[1] = htonl(iv & 0xffffffff);
1369 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
1371 U32 w = htonl((U32)SvIVX(sv));
1372 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
1375 MODULE = B PACKAGE = B::NV PREFIX = Sv
1386 COP_SEQ_RANGE_LOW(sv)
1390 COP_SEQ_RANGE_HIGH(sv)
1394 PARENT_PAD_INDEX(sv)
1398 PARENT_FAKELEX_FLAGS(sv)
1401 MODULE = B PACKAGE = B::RV PREFIX = Sv
1407 MODULE = B PACKAGE = B::PV PREFIX = Sv
1421 croak( "argument is not SvROK" );
1430 ST(0) = sv_newmortal();
1432 /* FIXME - we need a better way for B to identify PVs that are
1433 in the pads as variable names. */
1434 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1435 /* It claims to be longer than the space allocated for it -
1436 presuambly it's a variable name in the pad */
1437 sv_setpv(ST(0), SvPV_nolen_const(sv));
1439 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1441 SvFLAGS(ST(0)) |= SvUTF8(sv);
1444 /* XXX for backward compatibility, but should fail */
1445 /* croak( "argument is not SvPOK" ); */
1446 sv_setpvn(ST(0), NULL, 0);
1449 # This used to read 257. I think that that was buggy - should have been 258.
1450 # (The "\0", the flags byte, and 256 for the table. Not that anything
1451 # anywhere calls this method. NWC.
1456 ST(0) = sv_newmortal();
1457 sv_setpvn(ST(0), SvPVX_const(sv),
1458 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1469 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1474 MAGIC * mg = NO_INIT
1476 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1477 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
1479 MODULE = B PACKAGE = B::PVMG
1485 #define MgMOREMAGIC(mg) mg->mg_moremagic
1486 #define MgPRIVATE(mg) mg->mg_private
1487 #define MgTYPE(mg) mg->mg_type
1488 #define MgFLAGS(mg) mg->mg_flags
1489 #define MgOBJ(mg) mg->mg_obj
1490 #define MgLENGTH(mg) mg->mg_len
1491 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1493 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1499 if( MgMOREMAGIC(mg) ) {
1500 RETVAL = MgMOREMAGIC(mg);
1528 if(mg->mg_type == PERL_MAGIC_qr) {
1529 RETVAL = MgREGEX(mg);
1532 croak( "REGEX is only meaningful on r-magic" );
1541 if (mg->mg_type == PERL_MAGIC_qr) {
1542 REGEXP* rx = (REGEXP*)mg->mg_obj;
1545 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1548 croak( "precomp is only meaningful on r-magic" );
1561 ST(0) = sv_newmortal();
1563 if (mg->mg_len >= 0){
1564 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1565 } else if (mg->mg_len == HEf_SVKEY) {
1566 ST(0) = make_sv_object(aTHX_
1567 sv_newmortal(), (SV*)mg->mg_ptr);
1571 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1589 MODULE = B PACKAGE = B::BM PREFIX = Bm
1606 STRLEN len = NO_INIT
1607 char * str = NO_INIT
1609 str = SvPV(sv, len);
1610 /* Boyer-Moore table is just after string and its safety-margin \0 */
1611 ST(0) = sv_2mortal(newSVpvn(str + len + PERL_FBM_TABLE_OFFSET, 256));
1613 MODULE = B PACKAGE = B::GV PREFIX = Gv
1619 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
1625 RETVAL = GvGP(gv) == Null(GP*);
1649 RETVAL = (SV*)GvFORM(gv);
1685 MODULE = B PACKAGE = B::GV
1695 MODULE = B PACKAGE = B::IO PREFIX = Io
1748 if( strEQ( name, "stdin" ) ) {
1749 handle = PerlIO_stdin();
1751 else if( strEQ( name, "stdout" ) ) {
1752 handle = PerlIO_stdout();
1754 else if( strEQ( name, "stderr" ) ) {
1755 handle = PerlIO_stderr();
1758 croak( "Invalid value '%s'", name );
1760 RETVAL = handle == IoIFP(io);
1764 MODULE = B PACKAGE = B::IO
1774 MODULE = B PACKAGE = B::AV PREFIX = Av
1784 #if PERL_VERSION < 9
1787 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1799 if (AvFILL(av) >= 0) {
1800 SV **svp = AvARRAY(av);
1802 for (i = 0; i <= AvFILL(av); i++)
1803 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
1811 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1812 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1814 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1816 #if PERL_VERSION < 9
1818 MODULE = B PACKAGE = B::AV
1826 MODULE = B PACKAGE = B::FM PREFIX = Fm
1832 MODULE = B PACKAGE = B::CV PREFIX = Cv
1846 RETVAL = CvISXSUB(cv) ? NULL : CvSTART(cv);
1854 RETVAL = CvISXSUB(cv) ? NULL : CvROOT(cv);
1886 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1893 ST(0) = CvCONST(cv) ?
1894 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
1895 sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1897 MODULE = B PACKAGE = B::CV
1903 MODULE = B PACKAGE = B::CV PREFIX = cv_
1910 MODULE = B PACKAGE = B::HV PREFIX = Hv
1932 #if PERL_VERSION < 9
1944 if (HvKEYS(hv) > 0) {
1948 (void)hv_iterinit(hv);
1949 EXTEND(sp, HvKEYS(hv) * 2);
1950 while ((sv = hv_iternextsv(hv, &key, &len))) {
1951 PUSHs(newSVpvn(key, len));
1952 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
1956 MODULE = B PACKAGE = B::HE PREFIX = He
1970 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
1972 #if PERL_VERSION >= 9
1978 RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) );