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));
834 #define OP_next(o) o->op_next
835 #define OP_sibling(o) o->op_sibling
836 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
837 #define OP_targ(o) o->op_targ
838 #define OP_type(o) o->op_type
839 #if PERL_VERSION >= 9
840 # define OP_opt(o) o->op_opt
842 # define OP_seq(o) o->op_seq
844 #define OP_flags(o) o->op_flags
845 #define OP_private(o) o->op_private
846 #define OP_spare(o) o->op_spare
848 MODULE = B PACKAGE = B::OP PREFIX = OP_
854 RETVAL = opsizes[cc_opclass(aTHX_ o)];
870 RETVAL = (char *)PL_op_name[o->op_type];
880 SV *sv = sv_newmortal();
882 sv_setpvs(sv, "PL_ppaddr[OP_");
883 sv_catpv(sv, PL_op_name[o->op_type]);
884 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
885 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
901 #if PERL_VERSION >= 9
923 #if PERL_VERSION >= 9
935 SP = oplist(aTHX_ o, SP);
937 #define UNOP_first(o) o->op_first
939 MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
945 #define BINOP_last(o) o->op_last
947 MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
953 #define LOGOP_other(o) o->op_other
955 MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
961 MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
970 for (kid = o->op_first; kid; kid = kid->op_sibling)
976 #define PMOP_pmnext(o) o->op_pmnext
977 #define PMOP_pmregexp(o) PM_GETRE(o)
979 #define PMOP_pmoffset(o) o->op_pmoffset
980 #define PMOP_pmstashpv(o) PmopSTASHPV(o);
982 #define PMOP_pmstash(o) PmopSTASH(o);
984 #define PMOP_pmflags(o) o->op_pmflags
986 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
988 #if PERL_VERSION <= 8
995 ST(0) = sv_newmortal();
996 root = o->op_pmreplroot;
997 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
998 if (o->op_type == OP_PUSHRE) {
1000 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
1002 sv_setiv(newSVrv(ST(0), root ?
1003 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1008 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1017 ST(0) = sv_newmortal();
1018 if (o->op_type == OP_PUSHRE) {
1019 # ifdef USE_ITHREADS
1020 sv_setiv(ST(0), o->op_pmreplrootu.op_pmtargetoff);
1022 GV *const target = o->op_pmreplrootu.op_pmtargetgv;
1023 sv_setiv(newSVrv(ST(0), target ?
1024 svclassnames[SvTYPE((SV*)target)] : "B::SV"),
1029 OP *const root = o->op_pmreplrootu.op_pmreplroot;
1030 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)),
1040 #if PERL_VERSION < 9
1070 #if PERL_VERSION < 9
1085 REGEXP * rx = NO_INIT
1087 ST(0) = sv_newmortal();
1090 sv_setpvn(ST(0), RX_PRECOMP(rx), RX_PRELEN(rx));
1092 #if PERL_VERSION >= 9
1097 REGEXP * rx = NO_INIT
1099 ST(0) = sv_newmortal();
1102 sv_setuv(ST(0), RX_EXTFLAGS(rx));
1106 #define SVOP_sv(o) cSVOPo->op_sv
1107 #define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
1109 MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
1119 #define PADOP_padix(o) o->op_padix
1120 #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
1121 #define PADOP_gv(o) ((o->op_padix \
1122 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
1123 ? (GV*)PAD_SVl(o->op_padix) : (GV *)NULL)
1125 MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
1139 MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1146 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
1147 * whereas other PVOPs point to a null terminated string.
1149 if (o->op_type == OP_TRANS &&
1150 (o->op_private & OPpTRANS_COMPLEMENT) &&
1151 !(o->op_private & OPpTRANS_DELETE))
1153 const short* const tbl = (short*)o->op_pv;
1154 const short entries = 257 + tbl[256];
1155 ST(0) = newSVpvn_flags(o->op_pv, entries * sizeof(short), SVs_TEMP);
1157 else if (o->op_type == OP_TRANS) {
1158 ST(0) = newSVpvn_flags(o->op_pv, 256 * sizeof(short), SVs_TEMP);
1161 ST(0) = newSVpvn_flags(o->op_pv, strlen(o->op_pv), SVs_TEMP);
1163 #define LOOP_redoop(o) o->op_redoop
1164 #define LOOP_nextop(o) o->op_nextop
1165 #define LOOP_lastop(o) o->op_lastop
1167 MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
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)
1191 #if PERL_VERSION < 9
1192 # define COP_warnings(o) o->cop_warnings
1193 # define COP_io(o) o->cop_io
1196 MODULE = B PACKAGE = B::COP PREFIX = COP_
1198 #if PERL_VERSION >= 11
1241 #if PERL_VERSION >= 9
1247 ST(0) = make_warnings_object(aTHX_ o->cop_warnings);
1254 ST(0) = make_cop_io_object(aTHX_ o);
1261 RETVAL = CopHINTHASH_get(o);
1281 MODULE = B PACKAGE = B::SV
1287 #define object_2svref(sv) sv
1294 MODULE = B PACKAGE = B::SV PREFIX = Sv
1316 MODULE = B PACKAGE = B::IV PREFIX = Sv
1331 MODULE = B PACKAGE = B::IV
1333 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1343 if (sizeof(IV) == 8) {
1345 const IV iv = SvIVX(sv);
1347 * The following way of spelling 32 is to stop compilers on
1348 * 32-bit architectures from moaning about the shift count
1349 * being >= the width of the type. Such architectures don't
1350 * reach this code anyway (unless sizeof(IV) > 8 but then
1351 * everything else breaks too so I'm not fussed at the moment).
1354 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1356 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1358 wp[1] = htonl(iv & 0xffffffff);
1359 ST(0) = newSVpvn_flags((char *)wp, 8, SVs_TEMP);
1361 U32 w = htonl((U32)SvIVX(sv));
1362 ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
1366 #if PERL_VERSION >= 11
1376 croak( "argument is not SvROK" );
1383 MODULE = B PACKAGE = B::NV PREFIX = Sv
1394 COP_SEQ_RANGE_LOW(sv)
1398 COP_SEQ_RANGE_HIGH(sv)
1402 PARENT_PAD_INDEX(sv)
1406 PARENT_FAKELEX_FLAGS(sv)
1409 #if PERL_VERSION < 11
1411 MODULE = B PACKAGE = B::RV PREFIX = Sv
1419 MODULE = B PACKAGE = B::PV PREFIX = Sv
1433 croak( "argument is not SvROK" );
1442 ST(0) = sv_newmortal();
1444 /* FIXME - we need a better way for B to identify PVs that are
1445 in the pads as variable names. */
1446 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1447 /* It claims to be longer than the space allocated for it -
1448 presuambly it's a variable name in the pad */
1449 sv_setpv(ST(0), SvPV_nolen_const(sv));
1451 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1453 SvFLAGS(ST(0)) |= SvUTF8(sv);
1456 /* XXX for backward compatibility, but should fail */
1457 /* croak( "argument is not SvPOK" ); */
1458 sv_setpvn(ST(0), NULL, 0);
1461 # This used to read 257. I think that that was buggy - should have been 258.
1462 # (The "\0", the flags byte, and 256 for the table. Not that anything
1463 # anywhere calls this method. NWC.
1468 ST(0) = sv_newmortal();
1469 sv_setpvn(ST(0), SvPVX_const(sv),
1470 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1481 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1486 MAGIC * mg = NO_INIT
1488 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1489 XPUSHs(make_mg_object(aTHX_ mg));
1491 MODULE = B PACKAGE = B::PVMG
1497 MODULE = B PACKAGE = B::REGEXP
1499 #if PERL_VERSION >= 11
1505 /* FIXME - can we code this method more efficiently? */
1506 RETVAL = PTR2IV(sv);
1514 RETVAL = newSVpvn( RX_PRECOMP(sv), RX_PRELEN(sv) );
1520 #define MgMOREMAGIC(mg) mg->mg_moremagic
1521 #define MgPRIVATE(mg) mg->mg_private
1522 #define MgTYPE(mg) mg->mg_type
1523 #define MgFLAGS(mg) mg->mg_flags
1524 #define MgOBJ(mg) mg->mg_obj
1525 #define MgLENGTH(mg) mg->mg_len
1526 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1528 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1534 if( MgMOREMAGIC(mg) ) {
1535 RETVAL = MgMOREMAGIC(mg);
1563 if(mg->mg_type == PERL_MAGIC_qr) {
1564 RETVAL = MgREGEX(mg);
1567 croak( "REGEX is only meaningful on r-magic" );
1576 if (mg->mg_type == PERL_MAGIC_qr) {
1577 REGEXP* rx = (REGEXP*)mg->mg_obj;
1580 RETVAL = newSVpvn( RX_PRECOMP(rx), RX_PRELEN(rx) );
1583 croak( "precomp is only meaningful on r-magic" );
1596 ST(0) = sv_newmortal();
1598 if (mg->mg_len >= 0){
1599 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1600 } else if (mg->mg_len == HEf_SVKEY) {
1601 ST(0) = make_sv_object(aTHX_ NULL, (SV*)mg->mg_ptr);
1605 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1623 MODULE = B PACKAGE = B::BM PREFIX = Bm
1640 STRLEN len = NO_INIT
1641 char * str = NO_INIT
1643 str = SvPV(sv, len);
1644 /* Boyer-Moore table is just after string and its safety-margin \0 */
1645 ST(0) = newSVpvn_flags(str + len + PERL_FBM_TABLE_OFFSET, 256, SVs_TEMP);
1647 MODULE = B PACKAGE = B::GV PREFIX = Gv
1653 #if PERL_VERSION >= 10
1654 ST(0) = sv_2mortal(newSVhek(GvNAME_HEK(gv)));
1656 ST(0) = newSVpvn_flags(GvNAME(gv), GvNAMELEN(gv), SVs_TEMP);
1663 RETVAL = GvGP(gv) == Null(GP*);
1671 #if PERL_VERSION >= 9
1672 RETVAL = isGV_with_GP(gv) ? TRUE : FALSE;
1674 RETVAL = TRUE; /* In 5.8 and earlier they all are. */
1699 RETVAL = (SV*)GvFORM(gv);
1735 MODULE = B PACKAGE = B::GV
1745 MODULE = B PACKAGE = B::IO PREFIX = Io
1787 #if PERL_VERSION <= 8
1802 if( strEQ( name, "stdin" ) ) {
1803 handle = PerlIO_stdin();
1805 else if( strEQ( name, "stdout" ) ) {
1806 handle = PerlIO_stdout();
1808 else if( strEQ( name, "stderr" ) ) {
1809 handle = PerlIO_stderr();
1812 croak( "Invalid value '%s'", name );
1814 RETVAL = handle == IoIFP(io);
1818 MODULE = B PACKAGE = B::IO
1828 MODULE = B PACKAGE = B::AV PREFIX = Av
1838 #if PERL_VERSION < 9
1841 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1853 if (AvFILL(av) >= 0) {
1854 SV **svp = AvARRAY(av);
1856 for (i = 0; i <= AvFILL(av); i++)
1857 XPUSHs(make_sv_object(aTHX_ NULL, svp[i]));
1865 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1866 XPUSHs(make_sv_object(aTHX_ NULL, (AvARRAY(av)[idx])));
1868 XPUSHs(make_sv_object(aTHX_ NULL, NULL));
1870 #if PERL_VERSION < 9
1872 MODULE = B PACKAGE = B::AV
1880 MODULE = B PACKAGE = B::FM PREFIX = Fm
1886 MODULE = B PACKAGE = B::CV PREFIX = Cv
1902 RETVAL = CvISXSUB(cv) ? NULL : ix ? CvROOT(cv) : CvSTART(cv);
1934 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1942 ? make_sv_object(aTHX_ NULL, (SV *)CvXSUBANY(cv).any_ptr)
1943 : sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1945 MODULE = B PACKAGE = B::CV
1951 MODULE = B PACKAGE = B::CV PREFIX = cv_
1958 MODULE = B PACKAGE = B::HV PREFIX = Hv
1980 #if PERL_VERSION < 9
1992 if (HvKEYS(hv) > 0) {
1996 (void)hv_iterinit(hv);
1997 EXTEND(sp, HvKEYS(hv) * 2);
1998 while ((sv = hv_iternextsv(hv, &key, &len))) {
2000 PUSHs(make_sv_object(aTHX_ NULL, sv));
2004 MODULE = B PACKAGE = B::HE PREFIX = He
2018 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
2020 #if PERL_VERSION >= 9
2026 RETVAL = newRV( (SV*)cophh_2hv(h, 0) );