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);
255 make_temp_object(pTHX_ SV *arg, SV *temp)
258 const char *const type = svclassnames[SvTYPE(temp)];
259 const IV iv = PTR2IV(temp);
261 target = newSVrv(arg, type);
262 sv_setiv(target, iv);
264 /* Need to keep our "temp" around as long as the target exists.
265 Simplest way seems to be to hang it from magic, and let that clear
266 it up. No vtable, so won't actually get in the way of anything. */
267 sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0);
268 /* magic object has had its reference count increased, so we must drop
275 make_warnings_object(pTHX_ SV *arg, STRLEN *warnings)
277 const char *type = 0;
279 IV iv = sizeof(specialsv_list)/sizeof(SV*);
281 /* Counting down is deliberate. Before the split between make_sv_object
282 and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD
283 were both 0, so you could never get a B::SPECIAL for pWARN_STD */
286 if ((SV*)warnings == specialsv_list[iv]) {
292 sv_setiv(newSVrv(arg, type), iv);
295 /* B assumes that warnings are a regular SV. Seems easier to keep it
296 happy by making them into a regular SV. */
297 return make_temp_object(aTHX_ arg,
298 newSVpvn((char *)(warnings + 1), *warnings));
303 make_cop_io_object(pTHX_ SV *arg, COP *cop)
305 if (CopHINTS_get(cop) & HINT_LEXICAL_IO) {
306 /* I feel you should be able to simply SvREFCNT_inc the return value
307 from this, but if you do (and restore the line
308 my $ioix = $cop->io->ix;
309 in B::COP::bsave in Bytecode.pm, then you get errors about
310 "attempt to free temp prematurely ... during global destruction.
311 The SV's flags are consistent with the error, but quite how the
312 temp escaped from the save stack is not clear. */
313 SV *value = Perl_refcounted_he_fetch(aTHX_ cop->cop_hints_hash,
315 return make_temp_object(aTHX_ arg, newSVsv(value));
317 return make_sv_object(aTHX_ arg, NULL);
322 make_mg_object(pTHX_ SV *arg, MAGIC *mg)
324 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
329 cstring(pTHX_ SV *sv, bool perlstyle)
331 SV *sstr = newSVpvn("", 0);
334 sv_setpvn(sstr, "0", 1);
335 else if (perlstyle && SvUTF8(sv)) {
336 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
337 const STRLEN len = SvCUR(sv);
338 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
339 sv_setpvn(sstr,"\"",1);
343 sv_catpvn(sstr, "\\\"", 2);
345 sv_catpvn(sstr, "\\$", 2);
347 sv_catpvn(sstr, "\\@", 2);
350 if (strchr("nrftax\\",*(s+1)))
351 sv_catpvn(sstr, s++, 2);
353 sv_catpvn(sstr, "\\\\", 2);
355 else /* should always be printable */
356 sv_catpvn(sstr, s, 1);
359 sv_catpv(sstr, "\"");
366 const char *s = SvPV(sv, len);
367 sv_catpv(sstr, "\"");
368 for (; len; len--, s++)
370 /* At least try a little for readability */
372 sv_catpv(sstr, "\\\"");
374 sv_catpv(sstr, "\\\\");
375 /* trigraphs - bleagh */
376 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
377 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
378 sprintf(escbuff, "\\%03o", '?');
379 sv_catpv(sstr, escbuff);
381 else if (perlstyle && *s == '$')
382 sv_catpv(sstr, "\\$");
383 else if (perlstyle && *s == '@')
384 sv_catpv(sstr, "\\@");
386 else if (isPRINT(*s))
388 else if (*s >= ' ' && *s < 127)
390 sv_catpvn(sstr, s, 1);
392 sv_catpv(sstr, "\\n");
394 sv_catpv(sstr, "\\r");
396 sv_catpv(sstr, "\\t");
398 sv_catpv(sstr, "\\a");
400 sv_catpv(sstr, "\\b");
402 sv_catpv(sstr, "\\f");
403 else if (!perlstyle && *s == '\v')
404 sv_catpv(sstr, "\\v");
407 /* Don't want promotion of a signed -1 char in sprintf args */
408 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
409 const unsigned char c = (unsigned char) *s;
410 sprintf(escbuff, "\\%03o", c);
411 sv_catpv(sstr, escbuff);
413 /* XXX Add line breaks if string is long */
415 sv_catpv(sstr, "\"");
423 SV *sstr = newSVpvn("'", 1);
424 const char *s = SvPV_nolen(sv);
427 sv_catpvn(sstr, "\\'", 2);
429 sv_catpvn(sstr, "\\\\", 2);
431 else if (isPRINT(*s))
433 else if (*s >= ' ' && *s < 127)
435 sv_catpvn(sstr, s, 1);
437 sv_catpvn(sstr, "\\n", 2);
439 sv_catpvn(sstr, "\\r", 2);
441 sv_catpvn(sstr, "\\t", 2);
443 sv_catpvn(sstr, "\\a", 2);
445 sv_catpvn(sstr, "\\b", 2);
447 sv_catpvn(sstr, "\\f", 2);
449 sv_catpvn(sstr, "\\v", 2);
452 /* no trigraph support */
453 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
454 /* Don't want promotion of a signed -1 char in sprintf args */
455 unsigned char c = (unsigned char) *s;
456 sprintf(escbuff, "\\%03o", c);
457 sv_catpv(sstr, escbuff);
459 sv_catpvn(sstr, "'", 1);
464 walkoptree(pTHX_ SV *opsv, const char *method)
471 croak("opsv is not a reference");
472 opsv = sv_mortalcopy(opsv);
473 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
474 if (walkoptree_debug) {
478 perl_call_method("walkoptree_debug", G_DISCARD);
483 perl_call_method(method, G_DISCARD);
484 if (o && (o->op_flags & OPf_KIDS)) {
485 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
486 /* Use the same opsv. Rely on methods not to mess it up. */
487 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
488 walkoptree(aTHX_ opsv, method);
491 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
492 && (kid = cPMOPo->op_pmreplroot))
494 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
495 walkoptree(aTHX_ opsv, method);
500 oplist(pTHX_ OP *o, SV **SP)
502 for(; o; o = o->op_next) {
504 #if PERL_VERSION >= 9
513 opsv = sv_newmortal();
514 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
516 switch (o->op_type) {
518 SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP);
521 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
522 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
523 kid = kUNOP->op_first; /* pass rv2gv */
524 kid = kUNOP->op_first; /* pass leave */
525 SP = oplist(aTHX_ kid->op_next, SP);
529 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
531 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
534 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
535 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
536 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
544 typedef UNOP *B__UNOP;
545 typedef BINOP *B__BINOP;
546 typedef LOGOP *B__LOGOP;
547 typedef LISTOP *B__LISTOP;
548 typedef PMOP *B__PMOP;
549 typedef SVOP *B__SVOP;
550 typedef PADOP *B__PADOP;
551 typedef PVOP *B__PVOP;
552 typedef LOOP *B__LOOP;
570 typedef MAGIC *B__MAGIC;
572 typedef struct refcounted_he *B__RHE;
574 MODULE = B PACKAGE = B PREFIX = B_
580 HV *stash = gv_stashpvn("B", 1, TRUE);
581 AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE);
583 specialsv_list[0] = Nullsv;
584 specialsv_list[1] = &PL_sv_undef;
585 specialsv_list[2] = &PL_sv_yes;
586 specialsv_list[3] = &PL_sv_no;
587 specialsv_list[4] = (SV *) pWARN_ALL;
588 specialsv_list[5] = (SV *) pWARN_NONE;
589 specialsv_list[6] = (SV *) pWARN_STD;
590 #if PERL_VERSION <= 8
591 # define CVf_ASSERTION 0
596 #define B_main_cv() PL_main_cv
597 #define B_init_av() PL_initav
598 #define B_inc_gv() PL_incgv
599 #define B_check_av() PL_checkav_save
600 #define B_unitcheck_av() PL_unitcheckav_save
601 #define B_begin_av() PL_beginav_save
602 #define B_end_av() PL_endav
603 #define B_main_root() PL_main_root
604 #define B_main_start() PL_main_start
605 #define B_amagic_generation() PL_amagic_generation
606 #define B_sub_generation() PL_sub_generation
607 #define B_defstash() PL_defstash
608 #define B_curstash() PL_curstash
609 #define B_dowarn() PL_dowarn
610 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
611 #define B_sv_undef() &PL_sv_undef
612 #define B_sv_yes() &PL_sv_yes
613 #define B_sv_no() &PL_sv_no
614 #define B_formfeed() PL_formfeed
616 #define B_regex_padav() PL_regex_padav
654 B_amagic_generation()
686 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
691 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
693 MODULE = B PACKAGE = B
696 walkoptree(opsv, method)
700 walkoptree(aTHX_ opsv, method);
703 walkoptree_debug(...)
706 RETVAL = walkoptree_debug;
707 if (items > 0 && SvTRUE(ST(1)))
708 walkoptree_debug = 1;
712 #define address(sv) PTR2IV(sv)
723 croak("argument is not a reference");
724 RETVAL = (SV*)SvRV(sv);
735 ST(0) = sv_newmortal();
736 if (strncmp(name,"pp_",3) == 0)
738 for (i = 0; i < PL_maxo; i++)
740 if (strcmp(name, PL_op_name[i]) == 0)
746 sv_setiv(ST(0),result);
753 ST(0) = sv_newmortal();
754 if (opnum >= 0 && opnum < PL_maxo) {
755 sv_setpvn(ST(0), "pp_", 3);
756 sv_catpv(ST(0), PL_op_name[opnum]);
765 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
766 const char *s = SvPV(sv, len);
767 PERL_HASH(hash, s, len);
768 sprintf(hexhash, "0x%"UVxf, (UV)hash);
769 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
771 #define cast_I32(foo) (I32)foo
790 RETVAL = cstring(aTHX_ sv, 0);
798 RETVAL = cstring(aTHX_ sv, 1);
806 RETVAL = cchar(aTHX_ sv);
813 #if PERL_VERSION <= 8
814 # ifdef USE_5005THREADS
816 const STRLEN len = strlen(PL_threadsv_names);
819 for (i = 0; i < len; i++)
820 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
824 #define OP_next(o) o->op_next
825 #define OP_sibling(o) o->op_sibling
826 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
827 #define OP_targ(o) o->op_targ
828 #define OP_type(o) o->op_type
829 #if PERL_VERSION >= 9
830 # define OP_opt(o) o->op_opt
831 # define OP_static(o) o->op_static
833 # define OP_seq(o) o->op_seq
835 #define OP_flags(o) o->op_flags
836 #define OP_private(o) o->op_private
837 #define OP_spare(o) o->op_spare
839 MODULE = B PACKAGE = B::OP PREFIX = OP_
845 RETVAL = opsizes[cc_opclass(aTHX_ o)];
861 RETVAL = (char *)PL_op_name[o->op_type];
871 SV *sv = sv_newmortal();
873 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
874 sv_catpv(sv, PL_op_name[o->op_type]);
875 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
876 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
892 #if PERL_VERSION >= 9
918 #if PERL_VERSION >= 9
930 SP = oplist(aTHX_ o, SP);
932 #define UNOP_first(o) o->op_first
934 MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
940 #define BINOP_last(o) o->op_last
942 MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
948 #define LOGOP_other(o) o->op_other
950 MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
956 MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
965 for (kid = o->op_first; kid; kid = kid->op_sibling)
971 #define PMOP_pmreplroot(o) o->op_pmreplroot
972 #define PMOP_pmreplstart(o) o->op_pmreplstart
973 #define PMOP_pmnext(o) o->op_pmnext
974 #define PMOP_pmregexp(o) PM_GETRE(o)
976 #define PMOP_pmoffset(o) o->op_pmoffset
977 #define PMOP_pmstashpv(o) o->op_pmstashpv
979 #define PMOP_pmstash(o) o->op_pmstash
981 #define PMOP_pmflags(o) o->op_pmflags
982 #define PMOP_pmpermflags(o) o->op_pmpermflags
983 #define PMOP_pmdynflags(o) o->op_pmdynflags
985 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
992 ST(0) = sv_newmortal();
993 root = o->op_pmreplroot;
994 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
995 if (o->op_type == OP_PUSHRE) {
997 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
999 sv_setiv(newSVrv(ST(0), root ?
1000 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1005 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1049 REGEXP * rx = NO_INIT
1051 ST(0) = sv_newmortal();
1054 sv_setpvn(ST(0), rx->precomp, rx->prelen);
1056 #define SVOP_sv(o) cSVOPo->op_sv
1057 #define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
1059 MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
1069 #define PADOP_padix(o) o->op_padix
1070 #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
1071 #define PADOP_gv(o) ((o->op_padix \
1072 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
1073 ? (GV*)PAD_SVl(o->op_padix) : Nullgv)
1075 MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
1089 MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1096 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
1097 * whereas other PVOPs point to a null terminated string.
1099 if (o->op_type == OP_TRANS &&
1100 (o->op_private & OPpTRANS_COMPLEMENT) &&
1101 !(o->op_private & OPpTRANS_DELETE))
1103 const short* const tbl = (short*)o->op_pv;
1104 const short entries = 257 + tbl[256];
1105 ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1107 else if (o->op_type == OP_TRANS) {
1108 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1111 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
1113 #define LOOP_redoop(o) o->op_redoop
1114 #define LOOP_nextop(o) o->op_nextop
1115 #define LOOP_lastop(o) o->op_lastop
1117 MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1132 #define COP_label(o) o->cop_label
1133 #define COP_stashpv(o) CopSTASHPV(o)
1134 #define COP_stash(o) CopSTASH(o)
1135 #define COP_file(o) CopFILE(o)
1136 #define COP_filegv(o) CopFILEGV(o)
1137 #define COP_cop_seq(o) o->cop_seq
1138 #define COP_arybase(o) CopARYBASE_get(o)
1139 #define COP_line(o) CopLINE(o)
1140 #define COP_hints(o) CopHINTS_get(o)
1142 MODULE = B PACKAGE = B::COP PREFIX = COP_
1181 ST(0) = make_warnings_object(aTHX_ sv_newmortal(), o->cop_warnings);
1188 ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o);
1199 RETVAL = o->cop_hints_hash;
1203 MODULE = B PACKAGE = B::SV
1209 #define object_2svref(sv) sv
1216 MODULE = B PACKAGE = B::SV PREFIX = Sv
1238 MODULE = B PACKAGE = B::IV PREFIX = Sv
1253 MODULE = B PACKAGE = B::IV
1255 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1265 if (sizeof(IV) == 8) {
1267 const IV iv = SvIVX(sv);
1269 * The following way of spelling 32 is to stop compilers on
1270 * 32-bit architectures from moaning about the shift count
1271 * being >= the width of the type. Such architectures don't
1272 * reach this code anyway (unless sizeof(IV) > 8 but then
1273 * everything else breaks too so I'm not fussed at the moment).
1276 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1278 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1280 wp[1] = htonl(iv & 0xffffffff);
1281 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
1283 U32 w = htonl((U32)SvIVX(sv));
1284 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
1287 MODULE = B PACKAGE = B::NV PREFIX = Sv
1297 MODULE = B PACKAGE = B::RV PREFIX = Sv
1303 MODULE = B PACKAGE = B::PV PREFIX = Sv
1317 croak( "argument is not SvROK" );
1326 ST(0) = sv_newmortal();
1328 /* FIXME - we need a better way for B to identify PVs that are
1329 in the pads as variable names. */
1330 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1331 /* It claims to be longer than the space allocated for it -
1332 presuambly it's a variable name in the pad */
1333 sv_setpv(ST(0), SvPV_nolen_const(sv));
1335 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1337 SvFLAGS(ST(0)) |= SvUTF8(sv);
1340 /* XXX for backward compatibility, but should fail */
1341 /* croak( "argument is not SvPOK" ); */
1342 sv_setpvn(ST(0), NULL, 0);
1345 # This used to read 257. I think that that was buggy - should have been 258.
1346 # (The "\0", the flags byte, and 256 for the table. Not that anything
1347 # anywhere calls this method. NWC.
1352 ST(0) = sv_newmortal();
1353 sv_setpvn(ST(0), SvPVX_const(sv),
1354 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1365 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1370 MAGIC * mg = NO_INIT
1372 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1373 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
1375 MODULE = B PACKAGE = B::PVMG
1381 #define MgMOREMAGIC(mg) mg->mg_moremagic
1382 #define MgPRIVATE(mg) mg->mg_private
1383 #define MgTYPE(mg) mg->mg_type
1384 #define MgFLAGS(mg) mg->mg_flags
1385 #define MgOBJ(mg) mg->mg_obj
1386 #define MgLENGTH(mg) mg->mg_len
1387 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1389 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1395 if( MgMOREMAGIC(mg) ) {
1396 RETVAL = MgMOREMAGIC(mg);
1424 if(mg->mg_type == PERL_MAGIC_qr) {
1425 RETVAL = MgREGEX(mg);
1428 croak( "REGEX is only meaningful on r-magic" );
1437 if (mg->mg_type == PERL_MAGIC_qr) {
1438 REGEXP* rx = (REGEXP*)mg->mg_obj;
1441 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1444 croak( "precomp is only meaningful on r-magic" );
1457 ST(0) = sv_newmortal();
1459 if (mg->mg_len >= 0){
1460 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1461 } else if (mg->mg_len == HEf_SVKEY) {
1462 ST(0) = make_sv_object(aTHX_
1463 sv_newmortal(), (SV*)mg->mg_ptr);
1467 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1485 MODULE = B PACKAGE = B::BM PREFIX = Bm
1502 STRLEN len = NO_INIT
1503 char * str = NO_INIT
1505 str = SvPV(sv, len);
1506 /* Boyer-Moore table is just after string and its safety-margin \0 */
1507 ST(0) = sv_2mortal(newSVpvn(str + len + PERL_FBM_TABLE_OFFSET, 256));
1509 MODULE = B PACKAGE = B::GV PREFIX = Gv
1515 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
1521 RETVAL = GvGP(gv) == Null(GP*);
1545 RETVAL = (SV*)GvFORM(gv);
1581 MODULE = B PACKAGE = B::GV
1591 MODULE = B PACKAGE = B::IO PREFIX = Io
1644 if( strEQ( name, "stdin" ) ) {
1645 handle = PerlIO_stdin();
1647 else if( strEQ( name, "stdout" ) ) {
1648 handle = PerlIO_stdout();
1650 else if( strEQ( name, "stderr" ) ) {
1651 handle = PerlIO_stderr();
1654 croak( "Invalid value '%s'", name );
1656 RETVAL = handle == IoIFP(io);
1660 MODULE = B PACKAGE = B::IO
1670 MODULE = B PACKAGE = B::AV PREFIX = Av
1680 #if PERL_VERSION < 9
1683 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1695 if (AvFILL(av) >= 0) {
1696 SV **svp = AvARRAY(av);
1698 for (i = 0; i <= AvFILL(av); i++)
1699 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
1707 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1708 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1710 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1712 #if PERL_VERSION < 9
1714 MODULE = B PACKAGE = B::AV
1722 MODULE = B PACKAGE = B::FM PREFIX = Fm
1728 MODULE = B PACKAGE = B::CV PREFIX = Cv
1742 RETVAL = CvISXSUB(cv) ? NULL : CvSTART(cv);
1750 RETVAL = CvISXSUB(cv) ? NULL : CvROOT(cv);
1782 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1789 ST(0) = CvCONST(cv) ?
1790 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
1791 sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1793 MODULE = B PACKAGE = B::CV
1799 MODULE = B PACKAGE = B::CV PREFIX = cv_
1806 MODULE = B PACKAGE = B::HV PREFIX = Hv
1828 #if PERL_VERSION < 9
1840 if (HvKEYS(hv) > 0) {
1844 (void)hv_iterinit(hv);
1845 EXTEND(sp, HvKEYS(hv) * 2);
1846 while ((sv = hv_iternextsv(hv, &key, &len))) {
1847 PUSHs(newSVpvn(key, len));
1848 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
1852 MODULE = B PACKAGE = B::HE PREFIX = He
1866 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
1872 RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) );