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 = newSVpvs("");
337 sv_setpvs(sstr, "0");
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_setpvs(sstr,"\"");
346 sv_catpvs(sstr, "\\\"");
348 sv_catpvs(sstr, "\\$");
350 sv_catpvs(sstr, "\\@");
353 if (strchr("nrftax\\",*(s+1)))
354 sv_catpvn(sstr, s++, 2);
356 sv_catpvs(sstr, "\\\\");
358 else /* should always be printable */
359 sv_catpvn(sstr, s, 1);
362 sv_catpvs(sstr, "\"");
369 const char *s = SvPV(sv, len);
370 sv_catpvs(sstr, "\"");
371 for (; len; len--, s++)
373 /* At least try a little for readability */
375 sv_catpvs(sstr, "\\\"");
377 sv_catpvs(sstr, "\\\\");
378 /* trigraphs - bleagh */
379 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
380 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", '?');
382 else if (perlstyle && *s == '$')
383 sv_catpvs(sstr, "\\$");
384 else if (perlstyle && *s == '@')
385 sv_catpvs(sstr, "\\@");
387 else if (isPRINT(*s))
389 else if (*s >= ' ' && *s < 127)
391 sv_catpvn(sstr, s, 1);
393 sv_catpvs(sstr, "\\n");
395 sv_catpvs(sstr, "\\r");
397 sv_catpvs(sstr, "\\t");
399 sv_catpvs(sstr, "\\a");
401 sv_catpvs(sstr, "\\b");
403 sv_catpvs(sstr, "\\f");
404 else if (!perlstyle && *s == '\v')
405 sv_catpvs(sstr, "\\v");
408 /* Don't want promotion of a signed -1 char in sprintf args */
409 const unsigned char c = (unsigned char) *s;
410 Perl_sv_catpvf(aTHX_ sstr, "\\%03o", c);
412 /* XXX Add line breaks if string is long */
414 sv_catpvs(sstr, "\"");
422 SV *sstr = newSVpvs("'");
423 const char *s = SvPV_nolen(sv);
426 sv_catpvs(sstr, "\\'");
428 sv_catpvs(sstr, "\\\\");
430 else if (isPRINT(*s))
432 else if (*s >= ' ' && *s < 127)
434 sv_catpvn(sstr, s, 1);
436 sv_catpvs(sstr, "\\n");
438 sv_catpvs(sstr, "\\r");
440 sv_catpvs(sstr, "\\t");
442 sv_catpvs(sstr, "\\a");
444 sv_catpvs(sstr, "\\b");
446 sv_catpvs(sstr, "\\f");
448 sv_catpvs(sstr, "\\v");
451 /* no trigraph support */
452 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
453 /* Don't want promotion of a signed -1 char in sprintf args */
454 unsigned char c = (unsigned char) *s;
455 const STRLEN oct_len = my_sprintf(escbuff, "\\%03o", c);
456 sv_catpvn(sstr, escbuff, oct_len);
458 sv_catpvs(sstr, "'");
462 #if PERL_VERSION >= 9
463 # define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart
464 # define PMOP_pmreplroot(o) o->op_pmreplrootu.op_pmreplroot
466 # define PMOP_pmreplstart(o) o->op_pmreplstart
467 # define PMOP_pmreplroot(o) o->op_pmreplroot
468 # define PMOP_pmpermflags(o) o->op_pmpermflags
469 # define PMOP_pmdynflags(o) o->op_pmdynflags
473 walkoptree(pTHX_ SV *opsv, const char *method)
480 croak("opsv is not a reference");
481 opsv = sv_mortalcopy(opsv);
482 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
483 if (walkoptree_debug) {
487 perl_call_method("walkoptree_debug", G_DISCARD);
492 perl_call_method(method, G_DISCARD);
493 if (o && (o->op_flags & OPf_KIDS)) {
494 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
495 /* Use the same opsv. Rely on methods not to mess it up. */
496 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
497 walkoptree(aTHX_ opsv, method);
500 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
501 && (kid = PMOP_pmreplroot(cPMOPo)))
503 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
504 walkoptree(aTHX_ opsv, method);
509 oplist(pTHX_ OP *o, SV **SP)
511 for(; o; o = o->op_next) {
513 #if PERL_VERSION >= 9
522 opsv = sv_newmortal();
523 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
525 switch (o->op_type) {
527 SP = oplist(aTHX_ PMOP_pmreplstart(cPMOPo), SP);
530 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
531 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
532 kid = kUNOP->op_first; /* pass rv2gv */
533 kid = kUNOP->op_first; /* pass leave */
534 SP = oplist(aTHX_ kid->op_next, SP);
538 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
540 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
543 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
544 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
545 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
553 typedef UNOP *B__UNOP;
554 typedef BINOP *B__BINOP;
555 typedef LOGOP *B__LOGOP;
556 typedef LISTOP *B__LISTOP;
557 typedef PMOP *B__PMOP;
558 typedef SVOP *B__SVOP;
559 typedef PADOP *B__PADOP;
560 typedef PVOP *B__PVOP;
561 typedef LOOP *B__LOOP;
569 #if PERL_VERSION >= 11
570 typedef SV *B__REGEXP;
582 typedef MAGIC *B__MAGIC;
584 #if PERL_VERSION >= 9
585 typedef struct refcounted_he *B__RHE;
588 #include "const-c.inc"
590 MODULE = B PACKAGE = B PREFIX = B_
592 INCLUDE: const-xs.inc
598 HV *stash = gv_stashpvs("B", GV_ADD);
599 AV *export_ok = perl_get_av("B::EXPORT_OK", GV_ADD);
601 specialsv_list[0] = Nullsv;
602 specialsv_list[1] = &PL_sv_undef;
603 specialsv_list[2] = &PL_sv_yes;
604 specialsv_list[3] = &PL_sv_no;
605 specialsv_list[4] = (SV *) pWARN_ALL;
606 specialsv_list[5] = (SV *) pWARN_NONE;
607 specialsv_list[6] = (SV *) pWARN_STD;
608 #if PERL_VERSION <= 8
609 # define OPpPAD_STATE 0
613 #define B_main_cv() PL_main_cv
614 #define B_init_av() PL_initav
615 #define B_inc_gv() PL_incgv
616 #define B_check_av() PL_checkav_save
618 # define B_unitcheck_av() PL_unitcheckav_save
620 # define B_unitcheck_av() NULL
622 #define B_begin_av() PL_beginav_save
623 #define B_end_av() PL_endav
624 #define B_main_root() PL_main_root
625 #define B_main_start() PL_main_start
626 #define B_amagic_generation() PL_amagic_generation
627 #define B_sub_generation() PL_sub_generation
628 #define B_defstash() PL_defstash
629 #define B_curstash() PL_curstash
630 #define B_dowarn() PL_dowarn
631 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
632 #define B_sv_undef() &PL_sv_undef
633 #define B_sv_yes() &PL_sv_yes
634 #define B_sv_no() &PL_sv_no
635 #define B_formfeed() PL_formfeed
637 #define B_regex_padav() PL_regex_padav
646 #if PERL_VERSION >= 9
679 B_amagic_generation()
711 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
716 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
718 MODULE = B PACKAGE = B
721 walkoptree(opsv, method)
725 walkoptree(aTHX_ opsv, method);
728 walkoptree_debug(...)
731 RETVAL = walkoptree_debug;
732 if (items > 0 && SvTRUE(ST(1)))
733 walkoptree_debug = 1;
737 #define address(sv) PTR2IV(sv)
748 croak("argument is not a reference");
749 RETVAL = (SV*)SvRV(sv);
760 ST(0) = sv_newmortal();
761 if (strncmp(name,"pp_",3) == 0)
763 for (i = 0; i < PL_maxo; i++)
765 if (strcmp(name, PL_op_name[i]) == 0)
771 sv_setiv(ST(0),result);
778 ST(0) = sv_newmortal();
779 if (opnum >= 0 && opnum < PL_maxo) {
780 sv_setpvs(ST(0), "pp_");
781 sv_catpv(ST(0), PL_op_name[opnum]);
790 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
791 const char *s = SvPV(sv, len);
792 PERL_HASH(hash, s, len);
793 len = my_sprintf(hexhash, "0x%"UVxf, (UV)hash);
794 ST(0) = newSVpvn_flags(hexhash, len, SVs_TEMP);
796 #define cast_I32(foo) (I32)foo
815 RETVAL = cstring(aTHX_ sv, 0);
823 RETVAL = cstring(aTHX_ sv, 1);
831 RETVAL = cchar(aTHX_ sv);
838 #if PERL_VERSION <= 8
839 # ifdef USE_5005THREADS
841 const STRLEN len = strlen(PL_threadsv_names);
844 for (i = 0; i < len; i++)
845 PUSHs(newSVpvn_flags(&PL_threadsv_names[i], 1, SVs_TEMP));
849 #define OP_next(o) o->op_next
850 #define OP_sibling(o) o->op_sibling
851 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
852 #define OP_targ(o) o->op_targ
853 #define OP_type(o) o->op_type
854 #if PERL_VERSION >= 9
855 # define OP_opt(o) o->op_opt
857 # define OP_seq(o) o->op_seq
859 #define OP_flags(o) o->op_flags
860 #define OP_private(o) o->op_private
861 #define OP_spare(o) o->op_spare
863 MODULE = B PACKAGE = B::OP PREFIX = OP_
869 RETVAL = opsizes[cc_opclass(aTHX_ o)];
885 RETVAL = (char *)PL_op_name[o->op_type];
895 SV *sv = sv_newmortal();
897 sv_setpvs(sv, "PL_ppaddr[OP_");
898 sv_catpv(sv, PL_op_name[o->op_type]);
899 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
900 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
916 #if PERL_VERSION >= 9
938 #if PERL_VERSION >= 9
950 SP = oplist(aTHX_ o, SP);
952 #define UNOP_first(o) o->op_first
954 MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
960 #define BINOP_last(o) o->op_last
962 MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
968 #define LOGOP_other(o) o->op_other
970 MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
976 MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
985 for (kid = o->op_first; kid; kid = kid->op_sibling)
991 #define PMOP_pmnext(o) o->op_pmnext
992 #define PMOP_pmregexp(o) PM_GETRE(o)
994 #define PMOP_pmoffset(o) o->op_pmoffset
995 #define PMOP_pmstashpv(o) PmopSTASHPV(o);
997 #define PMOP_pmstash(o) PmopSTASH(o);
999 #define PMOP_pmflags(o) o->op_pmflags
1001 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
1003 #if PERL_VERSION <= 8
1010 ST(0) = sv_newmortal();
1011 root = o->op_pmreplroot;
1012 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
1013 if (o->op_type == OP_PUSHRE) {
1014 # ifdef USE_ITHREADS
1015 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
1017 sv_setiv(newSVrv(ST(0), root ?
1018 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1023 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1032 ST(0) = sv_newmortal();
1033 if (o->op_type == OP_PUSHRE) {
1034 # ifdef USE_ITHREADS
1035 sv_setiv(ST(0), o->op_pmreplrootu.op_pmtargetoff);
1037 GV *const target = o->op_pmreplrootu.op_pmtargetgv;
1038 sv_setiv(newSVrv(ST(0), target ?
1039 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1044 OP *const root = o->op_pmreplrootu.op_pmreplroot;
1045 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)),
1055 #if PERL_VERSION < 9
1085 #if PERL_VERSION < 9
1100 REGEXP * rx = NO_INIT
1102 ST(0) = sv_newmortal();
1105 sv_setpvn(ST(0), RX_PRECOMP(rx), RX_PRELEN(rx));
1107 #if PERL_VERSION >= 9
1112 REGEXP * rx = NO_INIT
1114 ST(0) = sv_newmortal();
1117 sv_setuv(ST(0), RX_EXTFLAGS(rx));
1121 #define SVOP_sv(o) cSVOPo->op_sv
1122 #define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
1124 MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
1134 #define PADOP_padix(o) o->op_padix
1135 #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
1136 #define PADOP_gv(o) ((o->op_padix \
1137 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
1138 ? (GV*)PAD_SVl(o->op_padix) : (GV *)NULL)
1140 MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
1154 MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1161 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
1162 * whereas other PVOPs point to a null terminated string.
1164 if (o->op_type == OP_TRANS &&
1165 (o->op_private & OPpTRANS_COMPLEMENT) &&
1166 !(o->op_private & OPpTRANS_DELETE))
1168 const short* const tbl = (short*)o->op_pv;
1169 const short entries = 257 + tbl[256];
1170 ST(0) = newSVpvn_flags(o->op_pv, entries * sizeof(short), SVs_TEMP);
1172 else if (o->op_type == OP_TRANS) {
1173 ST(0) = newSVpvn_flags(o->op_pv, 256 * sizeof(short), SVs_TEMP);
1176 ST(0) = newSVpvn_flags(o->op_pv, strlen(o->op_pv), SVs_TEMP);
1178 #define LOOP_redoop(o) o->op_redoop
1179 #define LOOP_nextop(o) o->op_nextop
1180 #define LOOP_lastop(o) o->op_lastop
1182 MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1197 #define COP_label(o) CopLABEL(o)
1198 #define COP_stashpv(o) CopSTASHPV(o)
1199 #define COP_stash(o) CopSTASH(o)
1200 #define COP_file(o) CopFILE(o)
1201 #define COP_filegv(o) CopFILEGV(o)
1202 #define COP_cop_seq(o) o->cop_seq
1203 #define COP_arybase(o) CopARYBASE_get(o)
1204 #define COP_line(o) CopLINE(o)
1205 #define COP_hints(o) CopHINTS_get(o)
1206 #if PERL_VERSION < 9
1207 # define COP_warnings(o) o->cop_warnings
1208 # define COP_io(o) o->cop_io
1211 MODULE = B PACKAGE = B::COP PREFIX = COP_
1213 #if PERL_VERSION >= 11
1256 #if PERL_VERSION >= 9
1262 ST(0) = make_warnings_object(aTHX_ sv_newmortal(), o->cop_warnings);
1269 ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o);
1276 RETVAL = CopHINTHASH_get(o);
1296 MODULE = B PACKAGE = B::SV
1302 #define object_2svref(sv) sv
1309 MODULE = B PACKAGE = B::SV PREFIX = Sv
1331 MODULE = B PACKAGE = B::IV PREFIX = Sv
1346 MODULE = B PACKAGE = B::IV
1348 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1358 if (sizeof(IV) == 8) {
1360 const IV iv = SvIVX(sv);
1362 * The following way of spelling 32 is to stop compilers on
1363 * 32-bit architectures from moaning about the shift count
1364 * being >= the width of the type. Such architectures don't
1365 * reach this code anyway (unless sizeof(IV) > 8 but then
1366 * everything else breaks too so I'm not fussed at the moment).
1369 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1371 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1373 wp[1] = htonl(iv & 0xffffffff);
1374 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1376 U32 w = htonl((U32)SvIVX(sv));
1377 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1381 #if PERL_VERSION >= 11
1391 croak( "argument is not SvROK" );
1398 MODULE = B PACKAGE = B::NV PREFIX = Sv
1409 COP_SEQ_RANGE_LOW(sv)
1413 COP_SEQ_RANGE_HIGH(sv)
1417 PARENT_PAD_INDEX(sv)
1421 PARENT_FAKELEX_FLAGS(sv)
1424 #if PERL_VERSION < 11
1426 MODULE = B PACKAGE = B::RV PREFIX = Sv
1434 MODULE = B PACKAGE = B::PV PREFIX = Sv
1448 croak( "argument is not SvROK" );
1457 ST(0) = sv_newmortal();
1459 /* FIXME - we need a better way for B to identify PVs that are
1460 in the pads as variable names. */
1461 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1462 /* It claims to be longer than the space allocated for it -
1463 presuambly it's a variable name in the pad */
1464 sv_setpv(ST(0), SvPV_nolen_const(sv));
1466 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1468 SvFLAGS(ST(0)) |= SvUTF8(sv);
1471 /* XXX for backward compatibility, but should fail */
1472 /* croak( "argument is not SvPOK" ); */
1473 sv_setpvn(ST(0), NULL, 0);
1476 # This used to read 257. I think that that was buggy - should have been 258.
1477 # (The "\0", the flags byte, and 256 for the table. Not that anything
1478 # anywhere calls this method. NWC.
1483 ST(0) = sv_newmortal();
1484 sv_setpvn(ST(0), SvPVX_const(sv),
1485 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1496 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1501 MAGIC * mg = NO_INIT
1503 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1504 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
1506 MODULE = B PACKAGE = B::PVMG
1512 MODULE = B PACKAGE = B::REGEXP
1514 #if PERL_VERSION >= 11
1520 /* FIXME - can we code this method more efficiently? */
1521 RETVAL = PTR2IV(sv);
1529 RETVAL = newSVpvn( RX_PRECOMP(sv), RX_PRELEN(sv) );
1535 #define MgMOREMAGIC(mg) mg->mg_moremagic
1536 #define MgPRIVATE(mg) mg->mg_private
1537 #define MgTYPE(mg) mg->mg_type
1538 #define MgFLAGS(mg) mg->mg_flags
1539 #define MgOBJ(mg) mg->mg_obj
1540 #define MgLENGTH(mg) mg->mg_len
1541 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1543 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1549 if( MgMOREMAGIC(mg) ) {
1550 RETVAL = MgMOREMAGIC(mg);
1578 if(mg->mg_type == PERL_MAGIC_qr) {
1579 RETVAL = MgREGEX(mg);
1582 croak( "REGEX is only meaningful on r-magic" );
1591 if (mg->mg_type == PERL_MAGIC_qr) {
1592 REGEXP* rx = (REGEXP*)mg->mg_obj;
1595 RETVAL = newSVpvn( RX_PRECOMP(rx), RX_PRELEN(rx) );
1598 croak( "precomp is only meaningful on r-magic" );
1611 ST(0) = sv_newmortal();
1613 if (mg->mg_len >= 0){
1614 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1615 } else if (mg->mg_len == HEf_SVKEY) {
1616 ST(0) = make_sv_object(aTHX_
1617 sv_newmortal(), (SV*)mg->mg_ptr);
1621 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1639 MODULE = B PACKAGE = B::BM PREFIX = Bm
1656 STRLEN len = NO_INIT
1657 char * str = NO_INIT
1659 str = SvPV(sv, len);
1660 /* Boyer-Moore table is just after string and its safety-margin \0 */
1661 ST(0) = newSVpvn_flags(str + len + PERL_FBM_TABLE_OFFSET, 256, SVs_TEMP);
1663 MODULE = B PACKAGE = B::GV PREFIX = Gv
1669 #if PERL_VERSION >= 10
1670 ST(0) = sv_2mortal(newSVhek(GvNAME_HEK(gv)));
1672 ST(0) = newSVpvn_flags(GvNAME(gv), GvNAMELEN(gv), SVs_TEMP);
1679 RETVAL = GvGP(gv) == Null(GP*);
1687 #if PERL_VERSION >= 9
1688 RETVAL = isGV_with_GP(gv) ? TRUE : FALSE;
1690 RETVAL = TRUE; /* In 5.8 and earlier they all are. */
1715 RETVAL = (SV*)GvFORM(gv);
1751 MODULE = B PACKAGE = B::GV
1761 MODULE = B PACKAGE = B::IO PREFIX = Io
1803 #if PERL_VERSION <= 8
1818 if( strEQ( name, "stdin" ) ) {
1819 handle = PerlIO_stdin();
1821 else if( strEQ( name, "stdout" ) ) {
1822 handle = PerlIO_stdout();
1824 else if( strEQ( name, "stderr" ) ) {
1825 handle = PerlIO_stderr();
1828 croak( "Invalid value '%s'", name );
1830 RETVAL = handle == IoIFP(io);
1834 MODULE = B PACKAGE = B::IO
1844 MODULE = B PACKAGE = B::AV PREFIX = Av
1854 #if PERL_VERSION < 9
1857 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1869 if (AvFILL(av) >= 0) {
1870 SV **svp = AvARRAY(av);
1872 for (i = 0; i <= AvFILL(av); i++)
1873 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
1881 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1882 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1884 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1886 #if PERL_VERSION < 9
1888 MODULE = B PACKAGE = B::AV
1896 MODULE = B PACKAGE = B::FM PREFIX = Fm
1902 MODULE = B PACKAGE = B::CV PREFIX = Cv
1918 RETVAL = CvISXSUB(cv) ? NULL : ix ? CvROOT(cv) : CvSTART(cv);
1950 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1957 ST(0) = CvCONST(cv) ?
1958 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
1959 sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1961 MODULE = B PACKAGE = B::CV
1967 MODULE = B PACKAGE = B::CV PREFIX = cv_
1974 MODULE = B PACKAGE = B::HV PREFIX = Hv
1996 #if PERL_VERSION < 9
2008 if (HvKEYS(hv) > 0) {
2012 (void)hv_iterinit(hv);
2013 EXTEND(sp, HvKEYS(hv) * 2);
2014 while ((sv = hv_iternextsv(hv, &key, &len))) {
2016 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
2020 MODULE = B PACKAGE = B::HE PREFIX = He
2034 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
2036 #if PERL_VERSION >= 9
2042 RETVAL = newRV( (SV*)cophh_2hv(h, 0) );