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 OPpPAD_STATE 0
605 #define B_main_cv() PL_main_cv
606 #define B_init_av() PL_initav
607 #define B_inc_gv() PL_incgv
608 #define B_check_av() PL_checkav_save
610 # define B_unitcheck_av() PL_unitcheckav_save
612 # define B_unitcheck_av() NULL
614 #define B_begin_av() PL_beginav_save
615 #define B_end_av() PL_endav
616 #define B_main_root() PL_main_root
617 #define B_main_start() PL_main_start
618 #define B_amagic_generation() PL_amagic_generation
619 #define B_sub_generation() PL_sub_generation
620 #define B_defstash() PL_defstash
621 #define B_curstash() PL_curstash
622 #define B_dowarn() PL_dowarn
623 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
624 #define B_sv_undef() &PL_sv_undef
625 #define B_sv_yes() &PL_sv_yes
626 #define B_sv_no() &PL_sv_no
627 #define B_formfeed() PL_formfeed
629 #define B_regex_padav() PL_regex_padav
638 #if PERL_VERSION >= 9
671 B_amagic_generation()
703 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
708 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
710 MODULE = B PACKAGE = B
713 walkoptree(opsv, method)
717 walkoptree(aTHX_ opsv, method);
720 walkoptree_debug(...)
723 RETVAL = walkoptree_debug;
724 if (items > 0 && SvTRUE(ST(1)))
725 walkoptree_debug = 1;
729 #define address(sv) PTR2IV(sv)
740 croak("argument is not a reference");
741 RETVAL = (SV*)SvRV(sv);
752 ST(0) = sv_newmortal();
753 if (strncmp(name,"pp_",3) == 0)
755 for (i = 0; i < PL_maxo; i++)
757 if (strcmp(name, PL_op_name[i]) == 0)
763 sv_setiv(ST(0),result);
770 ST(0) = sv_newmortal();
771 if (opnum >= 0 && opnum < PL_maxo) {
772 sv_setpvn(ST(0), "pp_", 3);
773 sv_catpv(ST(0), PL_op_name[opnum]);
782 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
783 const char *s = SvPV(sv, len);
784 PERL_HASH(hash, s, len);
785 sprintf(hexhash, "0x%"UVxf, (UV)hash);
786 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
788 #define cast_I32(foo) (I32)foo
807 RETVAL = cstring(aTHX_ sv, 0);
815 RETVAL = cstring(aTHX_ sv, 1);
823 RETVAL = cchar(aTHX_ sv);
830 #if PERL_VERSION <= 8
831 # ifdef USE_5005THREADS
833 const STRLEN len = strlen(PL_threadsv_names);
836 for (i = 0; i < len; i++)
837 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
841 #define OP_next(o) o->op_next
842 #define OP_sibling(o) o->op_sibling
843 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
844 #define OP_targ(o) o->op_targ
845 #define OP_type(o) o->op_type
846 #if PERL_VERSION >= 9
847 # define OP_opt(o) o->op_opt
848 # define OP_static(o) o->op_static
850 # define OP_seq(o) o->op_seq
852 #define OP_flags(o) o->op_flags
853 #define OP_private(o) o->op_private
854 #define OP_spare(o) o->op_spare
856 MODULE = B PACKAGE = B::OP PREFIX = OP_
862 RETVAL = opsizes[cc_opclass(aTHX_ o)];
878 RETVAL = (char *)PL_op_name[o->op_type];
888 SV *sv = sv_newmortal();
890 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
891 sv_catpv(sv, PL_op_name[o->op_type]);
892 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
893 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
909 #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));
1374 MODULE = B PACKAGE = B::NV PREFIX = Sv
1385 COP_SEQ_RANGE_LOW(sv)
1389 COP_SEQ_RANGE_HIGH(sv)
1393 PARENT_PAD_INDEX(sv)
1397 PARENT_FAKELEX_FLAGS(sv)
1400 MODULE = B PACKAGE = B::RV PREFIX = Sv
1406 MODULE = B PACKAGE = B::PV PREFIX = Sv
1420 croak( "argument is not SvROK" );
1429 ST(0) = sv_newmortal();
1431 /* FIXME - we need a better way for B to identify PVs that are
1432 in the pads as variable names. */
1433 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1434 /* It claims to be longer than the space allocated for it -
1435 presuambly it's a variable name in the pad */
1436 sv_setpv(ST(0), SvPV_nolen_const(sv));
1438 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1440 SvFLAGS(ST(0)) |= SvUTF8(sv);
1443 /* XXX for backward compatibility, but should fail */
1444 /* croak( "argument is not SvPOK" ); */
1445 sv_setpvn(ST(0), NULL, 0);
1448 # This used to read 257. I think that that was buggy - should have been 258.
1449 # (The "\0", the flags byte, and 256 for the table. Not that anything
1450 # anywhere calls this method. NWC.
1455 ST(0) = sv_newmortal();
1456 sv_setpvn(ST(0), SvPVX_const(sv),
1457 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1468 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1473 MAGIC * mg = NO_INIT
1475 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1476 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
1478 MODULE = B PACKAGE = B::PVMG
1484 #define MgMOREMAGIC(mg) mg->mg_moremagic
1485 #define MgPRIVATE(mg) mg->mg_private
1486 #define MgTYPE(mg) mg->mg_type
1487 #define MgFLAGS(mg) mg->mg_flags
1488 #define MgOBJ(mg) mg->mg_obj
1489 #define MgLENGTH(mg) mg->mg_len
1490 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1492 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1498 if( MgMOREMAGIC(mg) ) {
1499 RETVAL = MgMOREMAGIC(mg);
1527 if(mg->mg_type == PERL_MAGIC_qr) {
1528 RETVAL = MgREGEX(mg);
1531 croak( "REGEX is only meaningful on r-magic" );
1540 if (mg->mg_type == PERL_MAGIC_qr) {
1541 REGEXP* rx = (REGEXP*)mg->mg_obj;
1544 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1547 croak( "precomp is only meaningful on r-magic" );
1560 ST(0) = sv_newmortal();
1562 if (mg->mg_len >= 0){
1563 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1564 } else if (mg->mg_len == HEf_SVKEY) {
1565 ST(0) = make_sv_object(aTHX_
1566 sv_newmortal(), (SV*)mg->mg_ptr);
1570 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1588 MODULE = B PACKAGE = B::BM PREFIX = Bm
1605 STRLEN len = NO_INIT
1606 char * str = NO_INIT
1608 str = SvPV(sv, len);
1609 /* Boyer-Moore table is just after string and its safety-margin \0 */
1610 ST(0) = sv_2mortal(newSVpvn(str + len + PERL_FBM_TABLE_OFFSET, 256));
1612 MODULE = B PACKAGE = B::GV PREFIX = Gv
1618 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
1624 RETVAL = GvGP(gv) == Null(GP*);
1648 RETVAL = (SV*)GvFORM(gv);
1684 MODULE = B PACKAGE = B::GV
1694 MODULE = B PACKAGE = B::IO PREFIX = Io
1747 if( strEQ( name, "stdin" ) ) {
1748 handle = PerlIO_stdin();
1750 else if( strEQ( name, "stdout" ) ) {
1751 handle = PerlIO_stdout();
1753 else if( strEQ( name, "stderr" ) ) {
1754 handle = PerlIO_stderr();
1757 croak( "Invalid value '%s'", name );
1759 RETVAL = handle == IoIFP(io);
1763 MODULE = B PACKAGE = B::IO
1773 MODULE = B PACKAGE = B::AV PREFIX = Av
1783 #if PERL_VERSION < 9
1786 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1798 if (AvFILL(av) >= 0) {
1799 SV **svp = AvARRAY(av);
1801 for (i = 0; i <= AvFILL(av); i++)
1802 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
1810 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1811 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1813 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1815 #if PERL_VERSION < 9
1817 MODULE = B PACKAGE = B::AV
1825 MODULE = B PACKAGE = B::FM PREFIX = Fm
1831 MODULE = B PACKAGE = B::CV PREFIX = Cv
1845 RETVAL = CvISXSUB(cv) ? NULL : CvSTART(cv);
1853 RETVAL = CvISXSUB(cv) ? NULL : CvROOT(cv);
1885 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1892 ST(0) = CvCONST(cv) ?
1893 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
1894 sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1896 MODULE = B PACKAGE = B::CV
1902 MODULE = B PACKAGE = B::CV PREFIX = cv_
1909 MODULE = B PACKAGE = B::HV PREFIX = Hv
1931 #if PERL_VERSION < 9
1943 if (HvKEYS(hv) > 0) {
1947 (void)hv_iterinit(hv);
1948 EXTEND(sp, HvKEYS(hv) * 2);
1949 while ((sv = hv_iternextsv(hv, &key, &len))) {
1950 PUSHs(newSVpvn(key, len));
1951 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
1955 MODULE = B PACKAGE = B::HE PREFIX = He
1969 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
1971 #if PERL_VERSION >= 9
1977 RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) );