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, GV_ADD);
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
592 # define OPpPAD_STATE 0
597 #define B_main_cv() PL_main_cv
598 #define B_init_av() PL_initav
599 #define B_inc_gv() PL_incgv
600 #define B_check_av() PL_checkav_save
602 # define B_unitcheck_av() PL_unitcheckav_save
604 # define B_unitcheck_av() NULL
606 #define B_begin_av() PL_beginav_save
607 #define B_end_av() PL_endav
608 #define B_main_root() PL_main_root
609 #define B_main_start() PL_main_start
610 #define B_amagic_generation() PL_amagic_generation
611 #define B_sub_generation() PL_sub_generation
612 #define B_defstash() PL_defstash
613 #define B_curstash() PL_curstash
614 #define B_dowarn() PL_dowarn
615 #define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
616 #define B_sv_undef() &PL_sv_undef
617 #define B_sv_yes() &PL_sv_yes
618 #define B_sv_no() &PL_sv_no
619 #define B_formfeed() PL_formfeed
621 #define B_regex_padav() PL_regex_padav
659 B_amagic_generation()
691 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
696 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
698 MODULE = B PACKAGE = B
701 walkoptree(opsv, method)
705 walkoptree(aTHX_ opsv, method);
708 walkoptree_debug(...)
711 RETVAL = walkoptree_debug;
712 if (items > 0 && SvTRUE(ST(1)))
713 walkoptree_debug = 1;
717 #define address(sv) PTR2IV(sv)
728 croak("argument is not a reference");
729 RETVAL = (SV*)SvRV(sv);
740 ST(0) = sv_newmortal();
741 if (strncmp(name,"pp_",3) == 0)
743 for (i = 0; i < PL_maxo; i++)
745 if (strcmp(name, PL_op_name[i]) == 0)
751 sv_setiv(ST(0),result);
758 ST(0) = sv_newmortal();
759 if (opnum >= 0 && opnum < PL_maxo) {
760 sv_setpvn(ST(0), "pp_", 3);
761 sv_catpv(ST(0), PL_op_name[opnum]);
770 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
771 const char *s = SvPV(sv, len);
772 PERL_HASH(hash, s, len);
773 sprintf(hexhash, "0x%"UVxf, (UV)hash);
774 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
776 #define cast_I32(foo) (I32)foo
795 RETVAL = cstring(aTHX_ sv, 0);
803 RETVAL = cstring(aTHX_ sv, 1);
811 RETVAL = cchar(aTHX_ sv);
818 #if PERL_VERSION <= 8
819 # ifdef USE_5005THREADS
821 const STRLEN len = strlen(PL_threadsv_names);
824 for (i = 0; i < len; i++)
825 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
829 #define OP_next(o) o->op_next
830 #define OP_sibling(o) o->op_sibling
831 #define OP_desc(o) (char *)PL_op_desc[o->op_type]
832 #define OP_targ(o) o->op_targ
833 #define OP_type(o) o->op_type
834 #if PERL_VERSION >= 9
835 # define OP_opt(o) o->op_opt
836 # define OP_static(o) o->op_static
838 # define OP_seq(o) o->op_seq
840 #define OP_flags(o) o->op_flags
841 #define OP_private(o) o->op_private
842 #define OP_spare(o) o->op_spare
844 MODULE = B PACKAGE = B::OP PREFIX = OP_
850 RETVAL = opsizes[cc_opclass(aTHX_ o)];
866 RETVAL = (char *)PL_op_name[o->op_type];
876 SV *sv = sv_newmortal();
878 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
879 sv_catpv(sv, PL_op_name[o->op_type]);
880 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
881 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
897 #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_pmreplroot(o) o->op_pmreplroot
977 #define PMOP_pmreplstart(o) o->op_pmreplstart
978 #define PMOP_pmnext(o) o->op_pmnext
979 #define PMOP_pmregexp(o) PM_GETRE(o)
981 #define PMOP_pmoffset(o) o->op_pmoffset
982 #define PMOP_pmstashpv(o) o->op_pmstashpv
984 #define PMOP_pmstash(o) o->op_pmstash
986 #define PMOP_pmflags(o) o->op_pmflags
987 #define PMOP_pmpermflags(o) o->op_pmpermflags
988 #define PMOP_pmdynflags(o) o->op_pmdynflags
990 MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
997 ST(0) = sv_newmortal();
998 root = o->op_pmreplroot;
999 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
1000 if (o->op_type == OP_PUSHRE) {
1002 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
1004 sv_setiv(newSVrv(ST(0), root ?
1005 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
1010 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
1054 REGEXP * rx = NO_INIT
1056 ST(0) = sv_newmortal();
1059 sv_setpvn(ST(0), rx->precomp, rx->prelen);
1061 #define SVOP_sv(o) cSVOPo->op_sv
1062 #define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
1064 MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
1074 #define PADOP_padix(o) o->op_padix
1075 #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
1076 #define PADOP_gv(o) ((o->op_padix \
1077 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
1078 ? (GV*)PAD_SVl(o->op_padix) : Nullgv)
1080 MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
1094 MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1101 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
1102 * whereas other PVOPs point to a null terminated string.
1104 if (o->op_type == OP_TRANS &&
1105 (o->op_private & OPpTRANS_COMPLEMENT) &&
1106 !(o->op_private & OPpTRANS_DELETE))
1108 const short* const tbl = (short*)o->op_pv;
1109 const short entries = 257 + tbl[256];
1110 ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1112 else if (o->op_type == OP_TRANS) {
1113 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1116 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
1118 #define LOOP_redoop(o) o->op_redoop
1119 #define LOOP_nextop(o) o->op_nextop
1120 #define LOOP_lastop(o) o->op_lastop
1122 MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1137 #define COP_label(o) o->cop_label
1138 #define COP_stashpv(o) CopSTASHPV(o)
1139 #define COP_stash(o) CopSTASH(o)
1140 #define COP_file(o) CopFILE(o)
1141 #define COP_filegv(o) CopFILEGV(o)
1142 #define COP_cop_seq(o) o->cop_seq
1143 #define COP_arybase(o) CopARYBASE_get(o)
1144 #define COP_line(o) CopLINE(o)
1145 #define COP_hints(o) CopHINTS_get(o)
1147 MODULE = B PACKAGE = B::COP PREFIX = COP_
1186 ST(0) = make_warnings_object(aTHX_ sv_newmortal(), o->cop_warnings);
1193 ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o);
1204 RETVAL = o->cop_hints_hash;
1208 MODULE = B PACKAGE = B::SV
1214 #define object_2svref(sv) sv
1221 MODULE = B PACKAGE = B::SV PREFIX = Sv
1243 MODULE = B PACKAGE = B::IV PREFIX = Sv
1258 MODULE = B PACKAGE = B::IV
1260 #define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1270 if (sizeof(IV) == 8) {
1272 const IV iv = SvIVX(sv);
1274 * The following way of spelling 32 is to stop compilers on
1275 * 32-bit architectures from moaning about the shift count
1276 * being >= the width of the type. Such architectures don't
1277 * reach this code anyway (unless sizeof(IV) > 8 but then
1278 * everything else breaks too so I'm not fussed at the moment).
1281 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1283 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1285 wp[1] = htonl(iv & 0xffffffff);
1286 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
1288 U32 w = htonl((U32)SvIVX(sv));
1289 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
1292 MODULE = B PACKAGE = B::NV PREFIX = Sv
1303 COP_SEQ_RANGE_LOW(sv)
1307 COP_SEQ_RANGE_HIGH(sv)
1311 PARENT_PAD_INDEX(sv)
1315 PARENT_FAKELEX_FLAGS(sv)
1318 MODULE = B PACKAGE = B::RV PREFIX = Sv
1324 MODULE = B PACKAGE = B::PV PREFIX = Sv
1338 croak( "argument is not SvROK" );
1347 ST(0) = sv_newmortal();
1349 /* FIXME - we need a better way for B to identify PVs that are
1350 in the pads as variable names. */
1351 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1352 /* It claims to be longer than the space allocated for it -
1353 presuambly it's a variable name in the pad */
1354 sv_setpv(ST(0), SvPV_nolen_const(sv));
1356 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1358 SvFLAGS(ST(0)) |= SvUTF8(sv);
1361 /* XXX for backward compatibility, but should fail */
1362 /* croak( "argument is not SvPOK" ); */
1363 sv_setpvn(ST(0), NULL, 0);
1366 # This used to read 257. I think that that was buggy - should have been 258.
1367 # (The "\0", the flags byte, and 256 for the table. Not that anything
1368 # anywhere calls this method. NWC.
1373 ST(0) = sv_newmortal();
1374 sv_setpvn(ST(0), SvPVX_const(sv),
1375 SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
1386 MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1391 MAGIC * mg = NO_INIT
1393 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
1394 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
1396 MODULE = B PACKAGE = B::PVMG
1402 #define MgMOREMAGIC(mg) mg->mg_moremagic
1403 #define MgPRIVATE(mg) mg->mg_private
1404 #define MgTYPE(mg) mg->mg_type
1405 #define MgFLAGS(mg) mg->mg_flags
1406 #define MgOBJ(mg) mg->mg_obj
1407 #define MgLENGTH(mg) mg->mg_len
1408 #define MgREGEX(mg) PTR2IV(mg->mg_obj)
1410 MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1416 if( MgMOREMAGIC(mg) ) {
1417 RETVAL = MgMOREMAGIC(mg);
1445 if(mg->mg_type == PERL_MAGIC_qr) {
1446 RETVAL = MgREGEX(mg);
1449 croak( "REGEX is only meaningful on r-magic" );
1458 if (mg->mg_type == PERL_MAGIC_qr) {
1459 REGEXP* rx = (REGEXP*)mg->mg_obj;
1462 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1465 croak( "precomp is only meaningful on r-magic" );
1478 ST(0) = sv_newmortal();
1480 if (mg->mg_len >= 0){
1481 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
1482 } else if (mg->mg_len == HEf_SVKEY) {
1483 ST(0) = make_sv_object(aTHX_
1484 sv_newmortal(), (SV*)mg->mg_ptr);
1488 MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1506 MODULE = B PACKAGE = B::BM PREFIX = Bm
1523 STRLEN len = NO_INIT
1524 char * str = NO_INIT
1526 str = SvPV(sv, len);
1527 /* Boyer-Moore table is just after string and its safety-margin \0 */
1528 ST(0) = sv_2mortal(newSVpvn(str + len + PERL_FBM_TABLE_OFFSET, 256));
1530 MODULE = B PACKAGE = B::GV PREFIX = Gv
1536 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
1542 RETVAL = GvGP(gv) == Null(GP*);
1566 RETVAL = (SV*)GvFORM(gv);
1602 MODULE = B PACKAGE = B::GV
1612 MODULE = B PACKAGE = B::IO PREFIX = Io
1665 if( strEQ( name, "stdin" ) ) {
1666 handle = PerlIO_stdin();
1668 else if( strEQ( name, "stdout" ) ) {
1669 handle = PerlIO_stdout();
1671 else if( strEQ( name, "stderr" ) ) {
1672 handle = PerlIO_stderr();
1675 croak( "Invalid value '%s'", name );
1677 RETVAL = handle == IoIFP(io);
1681 MODULE = B PACKAGE = B::IO
1691 MODULE = B PACKAGE = B::AV PREFIX = Av
1701 #if PERL_VERSION < 9
1704 #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1716 if (AvFILL(av) >= 0) {
1717 SV **svp = AvARRAY(av);
1719 for (i = 0; i <= AvFILL(av); i++)
1720 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
1728 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1729 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1731 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1733 #if PERL_VERSION < 9
1735 MODULE = B PACKAGE = B::AV
1743 MODULE = B PACKAGE = B::FM PREFIX = Fm
1749 MODULE = B PACKAGE = B::CV PREFIX = Cv
1763 RETVAL = CvISXSUB(cv) ? NULL : CvSTART(cv);
1771 RETVAL = CvISXSUB(cv) ? NULL : CvROOT(cv);
1803 ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0));
1810 ST(0) = CvCONST(cv) ?
1811 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
1812 sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0));
1814 MODULE = B PACKAGE = B::CV
1820 MODULE = B PACKAGE = B::CV PREFIX = cv_
1827 MODULE = B PACKAGE = B::HV PREFIX = Hv
1849 #if PERL_VERSION < 9
1861 if (HvKEYS(hv) > 0) {
1865 (void)hv_iterinit(hv);
1866 EXTEND(sp, HvKEYS(hv) * 2);
1867 while ((sv = hv_iternextsv(hv, &key, &len))) {
1868 PUSHs(newSVpvn(key, len));
1869 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
1873 MODULE = B PACKAGE = B::HE PREFIX = He
1887 MODULE = B PACKAGE = B::RHE PREFIX = RHE_
1893 RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) );