This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove PMROOT and replace it with a small shell script. Er, magic.
[perl5.git] / ext / B / B.xs
CommitLineData
a8a597b2
MB
1/* B.xs
2 *
3 * Copyright (c) 1996 Malcolm Beattie
4 *
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.
7 *
8 */
9
c5be433b 10#define PERL_NO_GET_CONTEXT
a8a597b2
MB
11#include "EXTERN.h"
12#include "perl.h"
13#include "XSUB.h"
a8a597b2 14
51aa15f3
GS
15#ifdef PerlIO
16typedef PerlIO * InputStream;
17#else
18typedef FILE * InputStream;
19#endif
20
21
27da23d5 22static const char* const svclassnames[] = {
a8a597b2
MB
23 "B::NULL",
24 "B::IV",
25 "B::NV",
26 "B::RV",
27 "B::PV",
28 "B::PVIV",
29 "B::PVNV",
30 "B::PVMG",
31 "B::BM",
7252851f 32#if PERL_VERSION >= 9
4ce457a6 33 "B::GV",
7252851f 34#endif
a8a597b2
MB
35 "B::PVLV",
36 "B::AV",
37 "B::HV",
38 "B::CV",
7252851f
NC
39#if PERL_VERSION <= 8
40 "B::GV",
41#endif
a8a597b2
MB
42 "B::FM",
43 "B::IO",
44};
45
46typedef enum {
47 OPc_NULL, /* 0 */
48 OPc_BASEOP, /* 1 */
49 OPc_UNOP, /* 2 */
50 OPc_BINOP, /* 3 */
51 OPc_LOGOP, /* 4 */
1a67a97c
SM
52 OPc_LISTOP, /* 5 */
53 OPc_PMOP, /* 6 */
54 OPc_SVOP, /* 7 */
7934575e 55 OPc_PADOP, /* 8 */
1a67a97c 56 OPc_PVOP, /* 9 */
651aa52e
AE
57 OPc_LOOP, /* 10 */
58 OPc_COP /* 11 */
a8a597b2
MB
59} opclass;
60
27da23d5 61static const char* const opclassnames[] = {
a8a597b2
MB
62 "B::NULL",
63 "B::OP",
64 "B::UNOP",
65 "B::BINOP",
66 "B::LOGOP",
a8a597b2
MB
67 "B::LISTOP",
68 "B::PMOP",
69 "B::SVOP",
7934575e 70 "B::PADOP",
a8a597b2 71 "B::PVOP",
a8a597b2
MB
72 "B::LOOP",
73 "B::COP"
74};
75
27da23d5 76static const size_t opsizes[] = {
651aa52e
AE
77 0,
78 sizeof(OP),
79 sizeof(UNOP),
80 sizeof(BINOP),
81 sizeof(LOGOP),
82 sizeof(LISTOP),
83 sizeof(PMOP),
84 sizeof(SVOP),
85 sizeof(PADOP),
86 sizeof(PVOP),
87 sizeof(LOOP),
88 sizeof(COP)
89};
90
df3728a2 91#define MY_CXT_KEY "B::_guts" XS_VERSION
a8a597b2 92
89ca4ac7
JH
93typedef struct {
94 int x_walkoptree_debug; /* Flag for walkoptree debug hook */
b326da91 95 SV * x_specialsv_list[7];
89ca4ac7
JH
96} my_cxt_t;
97
98START_MY_CXT
99
100#define walkoptree_debug (MY_CXT.x_walkoptree_debug)
101#define specialsv_list (MY_CXT.x_specialsv_list)
e8edd1e6 102
a8a597b2 103static opclass
cea2e8a9 104cc_opclass(pTHX_ OP *o)
a8a597b2
MB
105{
106 if (!o)
107 return OPc_NULL;
108
109 if (o->op_type == 0)
110 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
111
112 if (o->op_type == OP_SASSIGN)
113 return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP);
114
18228111 115#ifdef USE_ITHREADS
31b49ad4
SM
116 if (o->op_type == OP_GV || o->op_type == OP_GVSV ||
117 o->op_type == OP_AELEMFAST || o->op_type == OP_RCATLINE)
18228111
GS
118 return OPc_PADOP;
119#endif
120
22c35a8c 121 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
a8a597b2
MB
122 case OA_BASEOP:
123 return OPc_BASEOP;
124
125 case OA_UNOP:
126 return OPc_UNOP;
127
128 case OA_BINOP:
129 return OPc_BINOP;
130
131 case OA_LOGOP:
132 return OPc_LOGOP;
133
a8a597b2
MB
134 case OA_LISTOP:
135 return OPc_LISTOP;
136
137 case OA_PMOP:
138 return OPc_PMOP;
139
140 case OA_SVOP:
141 return OPc_SVOP;
142
7934575e
GS
143 case OA_PADOP:
144 return OPc_PADOP;
a8a597b2 145
293d3ffa
SM
146 case OA_PVOP_OR_SVOP:
147 /*
148 * Character translations (tr///) are usually a PVOP, keeping a
149 * pointer to a table of shorts used to look up translations.
150 * Under utf8, however, a simple table isn't practical; instead,
151 * the OP is an SVOP, and the SV is a reference to a swash
152 * (i.e., an RV pointing to an HV).
153 */
154 return (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
155 ? OPc_SVOP : OPc_PVOP;
a8a597b2
MB
156
157 case OA_LOOP:
158 return OPc_LOOP;
159
160 case OA_COP:
161 return OPc_COP;
162
163 case OA_BASEOP_OR_UNOP:
164 /*
165 * UNI(OP_foo) in toke.c returns token UNI or FUNC1 depending on
45f6cd40
SM
166 * whether parens were seen. perly.y uses OPf_SPECIAL to
167 * signal whether a BASEOP had empty parens or none.
168 * Some other UNOPs are created later, though, so the best
169 * test is OPf_KIDS, which is set in newUNOP.
a8a597b2 170 */
45f6cd40 171 return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP;
a8a597b2
MB
172
173 case OA_FILESTATOP:
174 /*
175 * The file stat OPs are created via UNI(OP_foo) in toke.c but use
176 * the OPf_REF flag to distinguish between OP types instead of the
177 * usual OPf_SPECIAL flag. As usual, if OPf_KIDS is set, then we
178 * return OPc_UNOP so that walkoptree can find our children. If
179 * OPf_KIDS is not set then we check OPf_REF. Without OPf_REF set
180 * (no argument to the operator) it's an OP; with OPf_REF set it's
7934575e 181 * an SVOP (and op_sv is the GV for the filehandle argument).
a8a597b2
MB
182 */
183 return ((o->op_flags & OPf_KIDS) ? OPc_UNOP :
93865851
GS
184#ifdef USE_ITHREADS
185 (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP);
186#else
7934575e 187 (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP);
93865851 188#endif
a8a597b2
MB
189 case OA_LOOPEXOP:
190 /*
191 * next, last, redo, dump and goto use OPf_SPECIAL to indicate that a
192 * label was omitted (in which case it's a BASEOP) or else a term was
193 * seen. In this last case, all except goto are definitely PVOP but
194 * goto is either a PVOP (with an ordinary constant label), an UNOP
195 * with OPf_STACKED (with a non-constant non-sub) or an UNOP for
196 * OP_REFGEN (with goto &sub) in which case OPf_STACKED also seems to
197 * get set.
198 */
199 if (o->op_flags & OPf_STACKED)
200 return OPc_UNOP;
201 else if (o->op_flags & OPf_SPECIAL)
202 return OPc_BASEOP;
203 else
204 return OPc_PVOP;
205 }
206 warn("can't determine class of operator %s, assuming BASEOP\n",
22c35a8c 207 PL_op_name[o->op_type]);
a8a597b2
MB
208 return OPc_BASEOP;
209}
210
211static char *
cea2e8a9 212cc_opclassname(pTHX_ OP *o)
a8a597b2 213{
27da23d5 214 return (char *)opclassnames[cc_opclass(aTHX_ o)];
a8a597b2
MB
215}
216
217static SV *
cea2e8a9 218make_sv_object(pTHX_ SV *arg, SV *sv)
a8a597b2 219{
27da23d5 220 const char *type = 0;
a8a597b2 221 IV iv;
89ca4ac7 222 dMY_CXT;
a8a597b2 223
e8edd1e6
TH
224 for (iv = 0; iv < sizeof(specialsv_list)/sizeof(SV*); iv++) {
225 if (sv == specialsv_list[iv]) {
a8a597b2
MB
226 type = "B::SPECIAL";
227 break;
228 }
229 }
230 if (!type) {
231 type = svclassnames[SvTYPE(sv)];
56431972 232 iv = PTR2IV(sv);
a8a597b2
MB
233 }
234 sv_setiv(newSVrv(arg, type), iv);
235 return arg;
236}
237
238static SV *
cea2e8a9 239make_mg_object(pTHX_ SV *arg, MAGIC *mg)
a8a597b2 240{
56431972 241 sv_setiv(newSVrv(arg, "B::MAGIC"), PTR2IV(mg));
a8a597b2
MB
242 return arg;
243}
244
245static SV *
52ad86de 246cstring(pTHX_ SV *sv, bool perlstyle)
a8a597b2 247{
79cb57f6 248 SV *sstr = newSVpvn("", 0);
a8a597b2
MB
249 STRLEN len;
250 char *s;
b326da91 251 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
a8a597b2
MB
252
253 if (!SvOK(sv))
254 sv_setpvn(sstr, "0", 1);
d79a7a3d
RGS
255 else if (perlstyle && SvUTF8(sv))
256 {
257 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
258 len = SvCUR(sv);
259 s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
c69006e4 260 sv_setpvn(sstr,"\"",1);
d79a7a3d
RGS
261 while (*s)
262 {
263 if (*s == '"')
264 sv_catpv(sstr, "\\\"");
265 else if (*s == '$')
266 sv_catpv(sstr, "\\$");
267 else if (*s == '@')
268 sv_catpv(sstr, "\\@");
269 else if (*s == '\\')
270 {
271 if (strchr("nrftax\\",*(s+1)))
272 sv_catpvn(sstr, s++, 2);
273 else
274 sv_catpv(sstr, "\\\\");
275 }
276 else /* should always be printable */
277 sv_catpvn(sstr, s, 1);
278 ++s;
279 }
280 sv_catpv(sstr, "\"");
281 return sstr;
282 }
a8a597b2
MB
283 else
284 {
285 /* XXX Optimise? */
286 s = SvPV(sv, len);
287 sv_catpv(sstr, "\"");
288 for (; len; len--, s++)
289 {
290 /* At least try a little for readability */
291 if (*s == '"')
292 sv_catpv(sstr, "\\\"");
293 else if (*s == '\\')
294 sv_catpv(sstr, "\\\\");
b326da91 295 /* trigraphs - bleagh */
52ad86de 296 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?')
b326da91
MB
297 {
298 sprintf(escbuff, "\\%03o", '?');
299 sv_catpv(sstr, escbuff);
300 }
52ad86de
JH
301 else if (perlstyle && *s == '$')
302 sv_catpv(sstr, "\\$");
303 else if (perlstyle && *s == '@')
304 sv_catpv(sstr, "\\@");
ce561ef2
JH
305#ifdef EBCDIC
306 else if (isPRINT(*s))
307#else
308 else if (*s >= ' ' && *s < 127)
309#endif /* EBCDIC */
a8a597b2
MB
310 sv_catpvn(sstr, s, 1);
311 else if (*s == '\n')
312 sv_catpv(sstr, "\\n");
313 else if (*s == '\r')
314 sv_catpv(sstr, "\\r");
315 else if (*s == '\t')
316 sv_catpv(sstr, "\\t");
317 else if (*s == '\a')
318 sv_catpv(sstr, "\\a");
319 else if (*s == '\b')
320 sv_catpv(sstr, "\\b");
321 else if (*s == '\f')
322 sv_catpv(sstr, "\\f");
52ad86de 323 else if (!perlstyle && *s == '\v')
a8a597b2
MB
324 sv_catpv(sstr, "\\v");
325 else
326 {
a8a597b2
MB
327 /* Don't want promotion of a signed -1 char in sprintf args */
328 unsigned char c = (unsigned char) *s;
329 sprintf(escbuff, "\\%03o", c);
330 sv_catpv(sstr, escbuff);
331 }
332 /* XXX Add line breaks if string is long */
333 }
334 sv_catpv(sstr, "\"");
335 }
336 return sstr;
337}
338
339static SV *
cea2e8a9 340cchar(pTHX_ SV *sv)
a8a597b2 341{
79cb57f6 342 SV *sstr = newSVpvn("'", 1);
2d8e6c8d
GS
343 STRLEN n_a;
344 char *s = SvPV(sv, n_a);
a8a597b2
MB
345
346 if (*s == '\'')
347 sv_catpv(sstr, "\\'");
348 else if (*s == '\\')
349 sv_catpv(sstr, "\\\\");
ce561ef2 350#ifdef EBCDIC
133b4094 351 else if (isPRINT(*s))
ce561ef2
JH
352#else
353 else if (*s >= ' ' && *s < 127)
354#endif /* EBCDIC */
a8a597b2
MB
355 sv_catpvn(sstr, s, 1);
356 else if (*s == '\n')
357 sv_catpv(sstr, "\\n");
358 else if (*s == '\r')
359 sv_catpv(sstr, "\\r");
360 else if (*s == '\t')
361 sv_catpv(sstr, "\\t");
362 else if (*s == '\a')
363 sv_catpv(sstr, "\\a");
364 else if (*s == '\b')
365 sv_catpv(sstr, "\\b");
366 else if (*s == '\f')
367 sv_catpv(sstr, "\\f");
368 else if (*s == '\v')
369 sv_catpv(sstr, "\\v");
370 else
371 {
372 /* no trigraph support */
373 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
374 /* Don't want promotion of a signed -1 char in sprintf args */
375 unsigned char c = (unsigned char) *s;
376 sprintf(escbuff, "\\%03o", c);
377 sv_catpv(sstr, escbuff);
378 }
379 sv_catpv(sstr, "'");
380 return sstr;
381}
382
a8a597b2 383void
cea2e8a9 384walkoptree(pTHX_ SV *opsv, char *method)
a8a597b2
MB
385{
386 dSP;
f3be9b72 387 OP *o, *kid;
89ca4ac7
JH
388 dMY_CXT;
389
a8a597b2
MB
390 if (!SvROK(opsv))
391 croak("opsv is not a reference");
392 opsv = sv_mortalcopy(opsv);
56431972 393 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
a8a597b2
MB
394 if (walkoptree_debug) {
395 PUSHMARK(sp);
396 XPUSHs(opsv);
397 PUTBACK;
398 perl_call_method("walkoptree_debug", G_DISCARD);
399 }
400 PUSHMARK(sp);
401 XPUSHs(opsv);
402 PUTBACK;
403 perl_call_method(method, G_DISCARD);
404 if (o && (o->op_flags & OPf_KIDS)) {
a8a597b2
MB
405 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
406 /* Use the same opsv. Rely on methods not to mess it up. */
56431972 407 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
cea2e8a9 408 walkoptree(aTHX_ opsv, method);
a8a597b2
MB
409 }
410 }
5464c149 411 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
f3be9b72
RGS
412 && (kid = cPMOPo->op_pmreplroot))
413 {
5464c149 414 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
f3be9b72
RGS
415 walkoptree(aTHX_ opsv, method);
416 }
a8a597b2
MB
417}
418
1df34986
AE
419SV **
420oplist(pTHX_ OP *o, SV **SP)
421{
422 for(; o; o = o->op_next) {
423 SV *opsv;
7252851f
NC
424#if PERL_VERSION >= 9
425 if (o->op_opt == 0)
1df34986 426 break;
2814eb74 427 o->op_opt = 0;
7252851f
NC
428#else
429 if (o->op_seq == 0)
430 break;
431 o->op_seq = 0;
432#endif
1df34986
AE
433 opsv = sv_newmortal();
434 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
435 XPUSHs(opsv);
436 switch (o->op_type) {
437 case OP_SUBST:
438 SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP);
439 continue;
440 case OP_SORT:
f66c782a 441 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
1df34986
AE
442 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
443 kid = kUNOP->op_first; /* pass rv2gv */
444 kid = kUNOP->op_first; /* pass leave */
f66c782a 445 SP = oplist(aTHX_ kid->op_next, SP);
1df34986
AE
446 }
447 continue;
448 }
449 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
450 case OA_LOGOP:
451 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
452 break;
453 case OA_LOOP:
454 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
455 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
456 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
457 break;
458 }
459 }
460 return SP;
461}
462
a8a597b2
MB
463typedef OP *B__OP;
464typedef UNOP *B__UNOP;
465typedef BINOP *B__BINOP;
466typedef LOGOP *B__LOGOP;
a8a597b2
MB
467typedef LISTOP *B__LISTOP;
468typedef PMOP *B__PMOP;
469typedef SVOP *B__SVOP;
7934575e 470typedef PADOP *B__PADOP;
a8a597b2
MB
471typedef PVOP *B__PVOP;
472typedef LOOP *B__LOOP;
473typedef COP *B__COP;
474
475typedef SV *B__SV;
476typedef SV *B__IV;
477typedef SV *B__PV;
478typedef SV *B__NV;
479typedef SV *B__PVMG;
480typedef SV *B__PVLV;
481typedef SV *B__BM;
482typedef SV *B__RV;
1df34986 483typedef SV *B__FM;
a8a597b2
MB
484typedef AV *B__AV;
485typedef HV *B__HV;
486typedef CV *B__CV;
487typedef GV *B__GV;
488typedef IO *B__IO;
489
490typedef MAGIC *B__MAGIC;
491
492MODULE = B PACKAGE = B PREFIX = B_
493
494PROTOTYPES: DISABLE
495
496BOOT:
4c1f658f
NIS
497{
498 HV *stash = gv_stashpvn("B", 1, TRUE);
499 AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE);
89ca4ac7 500 MY_CXT_INIT;
e8edd1e6
TH
501 specialsv_list[0] = Nullsv;
502 specialsv_list[1] = &PL_sv_undef;
503 specialsv_list[2] = &PL_sv_yes;
504 specialsv_list[3] = &PL_sv_no;
059a8bb7
JH
505 specialsv_list[4] = pWARN_ALL;
506 specialsv_list[5] = pWARN_NONE;
b326da91 507 specialsv_list[6] = pWARN_STD;
f5ba1307 508#if PERL_VERSION <= 8
7252851f
NC
509# define CVf_ASSERTION 0
510#endif
4c1f658f
NIS
511#include "defsubs.h"
512}
a8a597b2 513
3280af22 514#define B_main_cv() PL_main_cv
31d7d75a 515#define B_init_av() PL_initav
651aa52e 516#define B_inc_gv() PL_incgv
ece599bd 517#define B_check_av() PL_checkav_save
059a8bb7
JH
518#define B_begin_av() PL_beginav_save
519#define B_end_av() PL_endav
3280af22
NIS
520#define B_main_root() PL_main_root
521#define B_main_start() PL_main_start
56eca212 522#define B_amagic_generation() PL_amagic_generation
651aa52e
AE
523#define B_defstash() PL_defstash
524#define B_curstash() PL_curstash
525#define B_dowarn() PL_dowarn
3280af22
NIS
526#define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
527#define B_sv_undef() &PL_sv_undef
528#define B_sv_yes() &PL_sv_yes
529#define B_sv_no() &PL_sv_no
1df34986 530#define B_formfeed() PL_formfeed
9d2bbe64
MB
531#ifdef USE_ITHREADS
532#define B_regex_padav() PL_regex_padav
533#endif
a8a597b2 534
31d7d75a
NIS
535B::AV
536B_init_av()
537
059a8bb7 538B::AV
ece599bd
RGS
539B_check_av()
540
541B::AV
059a8bb7
JH
542B_begin_av()
543
544B::AV
545B_end_av()
546
651aa52e
AE
547B::GV
548B_inc_gv()
549
9d2bbe64
MB
550#ifdef USE_ITHREADS
551
552B::AV
553B_regex_padav()
554
555#endif
556
a8a597b2
MB
557B::CV
558B_main_cv()
559
560B::OP
561B_main_root()
562
563B::OP
564B_main_start()
565
56eca212
GS
566long
567B_amagic_generation()
568
a8a597b2
MB
569B::AV
570B_comppadlist()
571
572B::SV
573B_sv_undef()
574
575B::SV
576B_sv_yes()
577
578B::SV
579B_sv_no()
580
651aa52e
AE
581B::HV
582B_curstash()
583
584B::HV
585B_defstash()
a8a597b2 586
651aa52e
AE
587U8
588B_dowarn()
589
1df34986
AE
590B::SV
591B_formfeed()
592
651aa52e
AE
593void
594B_warnhook()
595 CODE:
596 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
597
598void
599B_diehook()
600 CODE:
601 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
602
603MODULE = B PACKAGE = B
a8a597b2
MB
604
605void
606walkoptree(opsv, method)
607 SV * opsv
608 char * method
cea2e8a9
GS
609 CODE:
610 walkoptree(aTHX_ opsv, method);
a8a597b2
MB
611
612int
613walkoptree_debug(...)
614 CODE:
89ca4ac7 615 dMY_CXT;
a8a597b2
MB
616 RETVAL = walkoptree_debug;
617 if (items > 0 && SvTRUE(ST(1)))
618 walkoptree_debug = 1;
619 OUTPUT:
620 RETVAL
621
56431972 622#define address(sv) PTR2IV(sv)
a8a597b2
MB
623
624IV
625address(sv)
626 SV * sv
627
628B::SV
629svref_2object(sv)
630 SV * sv
631 CODE:
632 if (!SvROK(sv))
633 croak("argument is not a reference");
634 RETVAL = (SV*)SvRV(sv);
635 OUTPUT:
0cc1d052
NIS
636 RETVAL
637
638void
639opnumber(name)
640char * name
641CODE:
642{
643 int i;
644 IV result = -1;
645 ST(0) = sv_newmortal();
646 if (strncmp(name,"pp_",3) == 0)
647 name += 3;
648 for (i = 0; i < PL_maxo; i++)
649 {
650 if (strcmp(name, PL_op_name[i]) == 0)
651 {
652 result = i;
653 break;
654 }
655 }
656 sv_setiv(ST(0),result);
657}
a8a597b2
MB
658
659void
660ppname(opnum)
661 int opnum
662 CODE:
663 ST(0) = sv_newmortal();
3280af22 664 if (opnum >= 0 && opnum < PL_maxo) {
a8a597b2 665 sv_setpvn(ST(0), "pp_", 3);
22c35a8c 666 sv_catpv(ST(0), PL_op_name[opnum]);
a8a597b2
MB
667 }
668
669void
670hash(sv)
671 SV * sv
672 CODE:
673 char *s;
674 STRLEN len;
675 U32 hash = 0;
faccc32b 676 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
a8a597b2 677 s = SvPV(sv, len);
c32d3395 678 PERL_HASH(hash, s, len);
faccc32b 679 sprintf(hexhash, "0x%"UVxf, (UV)hash);
a8a597b2
MB
680 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
681
682#define cast_I32(foo) (I32)foo
683IV
684cast_I32(i)
685 IV i
686
687void
688minus_c()
689 CODE:
3280af22 690 PL_minus_c = TRUE;
a8a597b2 691
059a8bb7
JH
692void
693save_BEGINs()
694 CODE:
aefff11f 695 PL_savebegin = TRUE;
059a8bb7 696
a8a597b2
MB
697SV *
698cstring(sv)
699 SV * sv
cea2e8a9 700 CODE:
52ad86de
JH
701 RETVAL = cstring(aTHX_ sv, 0);
702 OUTPUT:
703 RETVAL
704
705SV *
706perlstring(sv)
707 SV * sv
708 CODE:
709 RETVAL = cstring(aTHX_ sv, 1);
cea2e8a9
GS
710 OUTPUT:
711 RETVAL
a8a597b2
MB
712
713SV *
714cchar(sv)
715 SV * sv
cea2e8a9
GS
716 CODE:
717 RETVAL = cchar(aTHX_ sv);
718 OUTPUT:
719 RETVAL
a8a597b2
MB
720
721void
722threadsv_names()
723 PPCODE:
f5ba1307
NC
724#if PERL_VERSION <= 8
725# ifdef USE_5005THREADS
726 int i;
727 STRLEN len = strlen(PL_threadsv_names);
728
729 EXTEND(sp, len);
730 for (i = 0; i < len; i++)
731 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
732# endif
733#endif
a8a597b2
MB
734
735#define OP_next(o) o->op_next
736#define OP_sibling(o) o->op_sibling
27da23d5 737#define OP_desc(o) (char *)PL_op_desc[o->op_type]
a8a597b2
MB
738#define OP_targ(o) o->op_targ
739#define OP_type(o) o->op_type
7252851f
NC
740#if PERL_VERSION >= 9
741# define OP_opt(o) o->op_opt
742# define OP_static(o) o->op_static
743#else
744# define OP_seq(o) o->op_seq
745#endif
a8a597b2
MB
746#define OP_flags(o) o->op_flags
747#define OP_private(o) o->op_private
a60ba18b 748#define OP_spare(o) o->op_spare
a8a597b2
MB
749
750MODULE = B PACKAGE = B::OP PREFIX = OP_
751
651aa52e
AE
752size_t
753OP_size(o)
754 B::OP o
755 CODE:
756 RETVAL = opsizes[cc_opclass(aTHX_ o)];
757 OUTPUT:
758 RETVAL
759
a8a597b2
MB
760B::OP
761OP_next(o)
762 B::OP o
763
764B::OP
765OP_sibling(o)
766 B::OP o
767
768char *
3f872cb9
GS
769OP_name(o)
770 B::OP o
771 CODE:
27da23d5 772 RETVAL = (char *)PL_op_name[o->op_type];
8063af02
DM
773 OUTPUT:
774 RETVAL
3f872cb9
GS
775
776
8063af02 777void
a8a597b2
MB
778OP_ppaddr(o)
779 B::OP o
dc333d64
GS
780 PREINIT:
781 int i;
782 SV *sv = sv_newmortal();
a8a597b2 783 CODE:
dc333d64
GS
784 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
785 sv_catpv(sv, PL_op_name[o->op_type]);
7c436af3 786 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
dc333d64
GS
787 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
788 sv_catpv(sv, "]");
789 ST(0) = sv;
a8a597b2
MB
790
791char *
792OP_desc(o)
793 B::OP o
794
7934575e 795PADOFFSET
a8a597b2
MB
796OP_targ(o)
797 B::OP o
798
799U16
800OP_type(o)
801 B::OP o
802
7252851f
NC
803#if PERL_VERSION >= 9
804
2814eb74
PJ
805U8
806OP_opt(o)
807 B::OP o
808
809U8
810OP_static(o)
a8a597b2
MB
811 B::OP o
812
7252851f
NC
813#else
814
815U16
816OP_seq(o)
817 B::OP o
818
819#endif
820
a8a597b2
MB
821U8
822OP_flags(o)
823 B::OP o
824
825U8
826OP_private(o)
827 B::OP o
828
7252851f
NC
829#if PERL_VERSION >= 9
830
a60ba18b
JC
831U8
832OP_spare(o)
833 B::OP o
834
7252851f
NC
835#endif
836
1df34986
AE
837void
838OP_oplist(o)
839 B::OP o
840 PPCODE:
841 SP = oplist(aTHX_ o, SP);
842
a8a597b2
MB
843#define UNOP_first(o) o->op_first
844
845MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
846
847B::OP
848UNOP_first(o)
849 B::UNOP o
850
851#define BINOP_last(o) o->op_last
852
853MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
854
855B::OP
856BINOP_last(o)
857 B::BINOP o
858
859#define LOGOP_other(o) o->op_other
860
861MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
862
863B::OP
864LOGOP_other(o)
865 B::LOGOP o
866
a8a597b2
MB
867MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
868
c03c2844
SM
869U32
870LISTOP_children(o)
871 B::LISTOP o
872 OP * kid = NO_INIT
873 int i = NO_INIT
874 CODE:
c03c2844
SM
875 i = 0;
876 for (kid = o->op_first; kid; kid = kid->op_sibling)
877 i++;
8063af02
DM
878 RETVAL = i;
879 OUTPUT:
880 RETVAL
c03c2844 881
a8a597b2
MB
882#define PMOP_pmreplroot(o) o->op_pmreplroot
883#define PMOP_pmreplstart(o) o->op_pmreplstart
884#define PMOP_pmnext(o) o->op_pmnext
aaa362c4 885#define PMOP_pmregexp(o) PM_GETRE(o)
9d2bbe64
MB
886#ifdef USE_ITHREADS
887#define PMOP_pmoffset(o) o->op_pmoffset
651aa52e
AE
888#define PMOP_pmstashpv(o) o->op_pmstashpv
889#else
890#define PMOP_pmstash(o) o->op_pmstash
9d2bbe64 891#endif
a8a597b2
MB
892#define PMOP_pmflags(o) o->op_pmflags
893#define PMOP_pmpermflags(o) o->op_pmpermflags
9d2bbe64 894#define PMOP_pmdynflags(o) o->op_pmdynflags
a8a597b2
MB
895
896MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
897
898void
899PMOP_pmreplroot(o)
900 B::PMOP o
901 OP * root = NO_INIT
902 CODE:
903 ST(0) = sv_newmortal();
904 root = o->op_pmreplroot;
905 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
906 if (o->op_type == OP_PUSHRE) {
9d2bbe64
MB
907#ifdef USE_ITHREADS
908 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
909#else
a8a597b2
MB
910 sv_setiv(newSVrv(ST(0), root ?
911 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
56431972 912 PTR2IV(root));
9d2bbe64 913#endif
a8a597b2
MB
914 }
915 else {
56431972 916 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
a8a597b2
MB
917 }
918
919B::OP
920PMOP_pmreplstart(o)
921 B::PMOP o
922
923B::PMOP
924PMOP_pmnext(o)
925 B::PMOP o
926
9d2bbe64
MB
927#ifdef USE_ITHREADS
928
929IV
930PMOP_pmoffset(o)
931 B::PMOP o
932
651aa52e
AE
933char*
934PMOP_pmstashpv(o)
935 B::PMOP o
936
937#else
938
939B::HV
940PMOP_pmstash(o)
941 B::PMOP o
942
9d2bbe64
MB
943#endif
944
6e21dc91 945U32
a8a597b2
MB
946PMOP_pmflags(o)
947 B::PMOP o
948
6e21dc91 949U32
a8a597b2
MB
950PMOP_pmpermflags(o)
951 B::PMOP o
952
9d2bbe64
MB
953U8
954PMOP_pmdynflags(o)
955 B::PMOP o
956
a8a597b2
MB
957void
958PMOP_precomp(o)
959 B::PMOP o
960 REGEXP * rx = NO_INIT
961 CODE:
962 ST(0) = sv_newmortal();
aaa362c4 963 rx = PM_GETRE(o);
a8a597b2
MB
964 if (rx)
965 sv_setpvn(ST(0), rx->precomp, rx->prelen);
966
ac33dcd1
JH
967#define SVOP_sv(o) cSVOPo->op_sv
968#define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
a8a597b2
MB
969
970MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
971
a8a597b2
MB
972B::SV
973SVOP_sv(o)
974 B::SVOP o
975
f22444f5 976B::GV
065a1863
GS
977SVOP_gv(o)
978 B::SVOP o
979
7934575e 980#define PADOP_padix(o) o->op_padix
dd2155a4 981#define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
7934575e 982#define PADOP_gv(o) ((o->op_padix \
dd2155a4
DM
983 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
984 ? (GV*)PAD_SVl(o->op_padix) : Nullgv)
a8a597b2 985
7934575e
GS
986MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
987
988PADOFFSET
989PADOP_padix(o)
990 B::PADOP o
991
992B::SV
993PADOP_sv(o)
994 B::PADOP o
a8a597b2
MB
995
996B::GV
7934575e
GS
997PADOP_gv(o)
998 B::PADOP o
a8a597b2
MB
999
1000MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
1001
1002void
1003PVOP_pv(o)
1004 B::PVOP o
1005 CODE:
1006 /*
bec89253 1007 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
a8a597b2
MB
1008 * whereas other PVOPs point to a null terminated string.
1009 */
bec89253
RH
1010 if (o->op_type == OP_TRANS &&
1011 (o->op_private & OPpTRANS_COMPLEMENT) &&
1012 !(o->op_private & OPpTRANS_DELETE))
1013 {
1014 short* tbl = (short*)o->op_pv;
1015 short entries = 257 + tbl[256];
1016 ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1017 }
1018 else if (o->op_type == OP_TRANS) {
1019 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1020 }
1021 else
1022 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
a8a597b2
MB
1023
1024#define LOOP_redoop(o) o->op_redoop
1025#define LOOP_nextop(o) o->op_nextop
1026#define LOOP_lastop(o) o->op_lastop
1027
1028MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1029
1030
1031B::OP
1032LOOP_redoop(o)
1033 B::LOOP o
1034
1035B::OP
1036LOOP_nextop(o)
1037 B::LOOP o
1038
1039B::OP
1040LOOP_lastop(o)
1041 B::LOOP o
1042
1043#define COP_label(o) o->cop_label
11faa288
GS
1044#define COP_stashpv(o) CopSTASHPV(o)
1045#define COP_stash(o) CopSTASH(o)
57843af0 1046#define COP_file(o) CopFILE(o)
1df34986 1047#define COP_filegv(o) CopFILEGV(o)
a8a597b2
MB
1048#define COP_cop_seq(o) o->cop_seq
1049#define COP_arybase(o) o->cop_arybase
57843af0 1050#define COP_line(o) CopLINE(o)
b295d113 1051#define COP_warnings(o) o->cop_warnings
6e6a1aef 1052#define COP_io(o) o->cop_io
a8a597b2
MB
1053
1054MODULE = B PACKAGE = B::COP PREFIX = COP_
1055
1056char *
1057COP_label(o)
1058 B::COP o
1059
11faa288
GS
1060char *
1061COP_stashpv(o)
1062 B::COP o
1063
a8a597b2
MB
1064B::HV
1065COP_stash(o)
1066 B::COP o
1067
57843af0
GS
1068char *
1069COP_file(o)
a8a597b2
MB
1070 B::COP o
1071
1df34986
AE
1072B::GV
1073COP_filegv(o)
1074 B::COP o
1075
1076
a8a597b2
MB
1077U32
1078COP_cop_seq(o)
1079 B::COP o
1080
1081I32
1082COP_arybase(o)
1083 B::COP o
1084
8bafa735 1085U32
a8a597b2
MB
1086COP_line(o)
1087 B::COP o
1088
b295d113
TH
1089B::SV
1090COP_warnings(o)
1091 B::COP o
1092
6e6a1aef
RGS
1093B::SV
1094COP_io(o)
1095 B::COP o
1096
651aa52e
AE
1097MODULE = B PACKAGE = B::SV
1098
1099U32
1100SvTYPE(sv)
1101 B::SV sv
1102
429a5ce7
SM
1103#define object_2svref(sv) sv
1104#define SVREF SV *
1105
1106SVREF
1107object_2svref(sv)
1108 B::SV sv
1109
a8a597b2
MB
1110MODULE = B PACKAGE = B::SV PREFIX = Sv
1111
1112U32
1113SvREFCNT(sv)
1114 B::SV sv
1115
1116U32
1117SvFLAGS(sv)
1118 B::SV sv
1119
651aa52e
AE
1120U32
1121SvPOK(sv)
1122 B::SV sv
1123
1124U32
1125SvROK(sv)
1126 B::SV sv
1127
1128U32
1129SvMAGICAL(sv)
1130 B::SV sv
1131
a8a597b2
MB
1132MODULE = B PACKAGE = B::IV PREFIX = Sv
1133
1134IV
1135SvIV(sv)
1136 B::IV sv
1137
1138IV
1139SvIVX(sv)
1140 B::IV sv
1141
0ca04487
VB
1142UV
1143SvUVX(sv)
1144 B::IV sv
1145
1146
a8a597b2
MB
1147MODULE = B PACKAGE = B::IV
1148
1149#define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1150
1151int
1152needs64bits(sv)
1153 B::IV sv
1154
1155void
1156packiv(sv)
1157 B::IV sv
1158 CODE:
1159 if (sizeof(IV) == 8) {
1160 U32 wp[2];
1161 IV iv = SvIVX(sv);
1162 /*
1163 * The following way of spelling 32 is to stop compilers on
1164 * 32-bit architectures from moaning about the shift count
1165 * being >= the width of the type. Such architectures don't
1166 * reach this code anyway (unless sizeof(IV) > 8 but then
1167 * everything else breaks too so I'm not fussed at the moment).
1168 */
42718184
RB
1169#ifdef UV_IS_QUAD
1170 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1171#else
1172 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1173#endif
a8a597b2 1174 wp[1] = htonl(iv & 0xffffffff);
79cb57f6 1175 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
a8a597b2
MB
1176 } else {
1177 U32 w = htonl((U32)SvIVX(sv));
79cb57f6 1178 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
a8a597b2
MB
1179 }
1180
1181MODULE = B PACKAGE = B::NV PREFIX = Sv
1182
76ef7183 1183NV
a8a597b2
MB
1184SvNV(sv)
1185 B::NV sv
1186
76ef7183 1187NV
a8a597b2
MB
1188SvNVX(sv)
1189 B::NV sv
1190
1191MODULE = B PACKAGE = B::RV PREFIX = Sv
1192
1193B::SV
1194SvRV(sv)
1195 B::RV sv
1196
1197MODULE = B PACKAGE = B::PV PREFIX = Sv
1198
0b40bd6d
RH
1199char*
1200SvPVX(sv)
1201 B::PV sv
1202
b326da91
MB
1203B::SV
1204SvRV(sv)
1205 B::PV sv
1206 CODE:
1207 if( SvROK(sv) ) {
1208 RETVAL = SvRV(sv);
1209 }
1210 else {
1211 croak( "argument is not SvROK" );
1212 }
1213 OUTPUT:
1214 RETVAL
1215
a8a597b2
MB
1216void
1217SvPV(sv)
1218 B::PV sv
1219 CODE:
b326da91 1220 ST(0) = sv_newmortal();
9d2bbe64 1221 if( SvPOK(sv) ) {
b326da91
MB
1222 sv_setpvn(ST(0), SvPVX(sv), SvCUR(sv));
1223 SvFLAGS(ST(0)) |= SvUTF8(sv);
1224 }
1225 else {
1226 /* XXX for backward compatibility, but should fail */
1227 /* croak( "argument is not SvPOK" ); */
1228 sv_setpvn(ST(0), NULL, 0);
1229 }
a8a597b2 1230
651aa52e
AE
1231void
1232SvPVBM(sv)
1233 B::PV sv
1234 CODE:
1235 ST(0) = sv_newmortal();
1236 sv_setpvn(ST(0), SvPVX(sv),
1237 SvCUR(sv) + (SvTYPE(sv) == SVt_PVBM ? 257 : 0));
1238
1239
445a12f6
DM
1240STRLEN
1241SvLEN(sv)
1242 B::PV sv
1243
1244STRLEN
1245SvCUR(sv)
1246 B::PV sv
1247
a8a597b2
MB
1248MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1249
1250void
1251SvMAGIC(sv)
1252 B::PVMG sv
1253 MAGIC * mg = NO_INIT
1254 PPCODE:
1255 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
cea2e8a9 1256 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
a8a597b2
MB
1257
1258MODULE = B PACKAGE = B::PVMG
1259
1260B::HV
1261SvSTASH(sv)
1262 B::PVMG sv
1263
1264#define MgMOREMAGIC(mg) mg->mg_moremagic
1265#define MgPRIVATE(mg) mg->mg_private
1266#define MgTYPE(mg) mg->mg_type
1267#define MgFLAGS(mg) mg->mg_flags
1268#define MgOBJ(mg) mg->mg_obj
88b39979 1269#define MgLENGTH(mg) mg->mg_len
bde7177d 1270#define MgREGEX(mg) PTR2IV(mg->mg_obj)
a8a597b2
MB
1271
1272MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1273
1274B::MAGIC
1275MgMOREMAGIC(mg)
1276 B::MAGIC mg
c5f0f3aa
RGS
1277 CODE:
1278 if( MgMOREMAGIC(mg) ) {
1279 RETVAL = MgMOREMAGIC(mg);
1280 }
1281 else {
1282 XSRETURN_UNDEF;
1283 }
1284 OUTPUT:
1285 RETVAL
a8a597b2
MB
1286
1287U16
1288MgPRIVATE(mg)
1289 B::MAGIC mg
1290
1291char
1292MgTYPE(mg)
1293 B::MAGIC mg
1294
1295U8
1296MgFLAGS(mg)
1297 B::MAGIC mg
1298
1299B::SV
1300MgOBJ(mg)
1301 B::MAGIC mg
b326da91 1302
9d2bbe64
MB
1303IV
1304MgREGEX(mg)
1305 B::MAGIC mg
1306 CODE:
1307 if( mg->mg_type == 'r' ) {
1308 RETVAL = MgREGEX(mg);
1309 }
1310 else {
1311 croak( "REGEX is only meaningful on r-magic" );
1312 }
1313 OUTPUT:
1314 RETVAL
1315
b326da91
MB
1316SV*
1317precomp(mg)
1318 B::MAGIC mg
1319 CODE:
1320 if (mg->mg_type == 'r') {
1321 REGEXP* rx = (REGEXP*)mg->mg_obj;
1322 if( rx )
1323 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1324 }
1325 else {
1326 croak( "precomp is only meaningful on r-magic" );
1327 }
1328 OUTPUT:
1329 RETVAL
a8a597b2 1330
88b39979
VB
1331I32
1332MgLENGTH(mg)
1333 B::MAGIC mg
1334
a8a597b2
MB
1335void
1336MgPTR(mg)
1337 B::MAGIC mg
1338 CODE:
1339 ST(0) = sv_newmortal();
88b39979
VB
1340 if (mg->mg_ptr){
1341 if (mg->mg_len >= 0){
1342 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
651aa52e
AE
1343 } else if (mg->mg_len == HEf_SVKEY) {
1344 ST(0) = make_sv_object(aTHX_
1345 sv_newmortal(), (SV*)mg->mg_ptr);
88b39979
VB
1346 }
1347 }
a8a597b2
MB
1348
1349MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1350
1351U32
1352LvTARGOFF(sv)
1353 B::PVLV sv
1354
1355U32
1356LvTARGLEN(sv)
1357 B::PVLV sv
1358
1359char
1360LvTYPE(sv)
1361 B::PVLV sv
1362
1363B::SV
1364LvTARG(sv)
1365 B::PVLV sv
1366
1367MODULE = B PACKAGE = B::BM PREFIX = Bm
1368
1369I32
1370BmUSEFUL(sv)
1371 B::BM sv
1372
1373U16
1374BmPREVIOUS(sv)
1375 B::BM sv
1376
1377U8
1378BmRARE(sv)
1379 B::BM sv
1380
1381void
1382BmTABLE(sv)
1383 B::BM sv
1384 STRLEN len = NO_INIT
1385 char * str = NO_INIT
1386 CODE:
1387 str = SvPV(sv, len);
1388 /* Boyer-Moore table is just after string and its safety-margin \0 */
79cb57f6 1389 ST(0) = sv_2mortal(newSVpvn(str + len + 1, 256));
a8a597b2
MB
1390
1391MODULE = B PACKAGE = B::GV PREFIX = Gv
1392
1393void
1394GvNAME(gv)
1395 B::GV gv
1396 CODE:
79cb57f6 1397 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
a8a597b2 1398
87d7fd28
GS
1399bool
1400is_empty(gv)
1401 B::GV gv
1402 CODE:
1403 RETVAL = GvGP(gv) == Null(GP*);
1404 OUTPUT:
1405 RETVAL
1406
651aa52e
AE
1407void*
1408GvGP(gv)
1409 B::GV gv
1410
a8a597b2
MB
1411B::HV
1412GvSTASH(gv)
1413 B::GV gv
1414
1415B::SV
1416GvSV(gv)
1417 B::GV gv
1418
1419B::IO
1420GvIO(gv)
1421 B::GV gv
1422
1df34986 1423B::FM
a8a597b2
MB
1424GvFORM(gv)
1425 B::GV gv
1df34986
AE
1426 CODE:
1427 RETVAL = (SV*)GvFORM(gv);
1428 OUTPUT:
1429 RETVAL
a8a597b2
MB
1430
1431B::AV
1432GvAV(gv)
1433 B::GV gv
1434
1435B::HV
1436GvHV(gv)
1437 B::GV gv
1438
1439B::GV
1440GvEGV(gv)
1441 B::GV gv
1442
1443B::CV
1444GvCV(gv)
1445 B::GV gv
1446
1447U32
1448GvCVGEN(gv)
1449 B::GV gv
1450
8bafa735 1451U32
a8a597b2
MB
1452GvLINE(gv)
1453 B::GV gv
1454
b195d487
GS
1455char *
1456GvFILE(gv)
1457 B::GV gv
1458
a8a597b2
MB
1459B::GV
1460GvFILEGV(gv)
1461 B::GV gv
1462
1463MODULE = B PACKAGE = B::GV
1464
1465U32
1466GvREFCNT(gv)
1467 B::GV gv
1468
1469U8
1470GvFLAGS(gv)
1471 B::GV gv
1472
1473MODULE = B PACKAGE = B::IO PREFIX = Io
1474
1475long
1476IoLINES(io)
1477 B::IO io
1478
1479long
1480IoPAGE(io)
1481 B::IO io
1482
1483long
1484IoPAGE_LEN(io)
1485 B::IO io
1486
1487long
1488IoLINES_LEFT(io)
1489 B::IO io
1490
1491char *
1492IoTOP_NAME(io)
1493 B::IO io
1494
1495B::GV
1496IoTOP_GV(io)
1497 B::IO io
1498
1499char *
1500IoFMT_NAME(io)
1501 B::IO io
1502
1503B::GV
1504IoFMT_GV(io)
1505 B::IO io
1506
1507char *
1508IoBOTTOM_NAME(io)
1509 B::IO io
1510
1511B::GV
1512IoBOTTOM_GV(io)
1513 B::IO io
1514
1515short
1516IoSUBPROCESS(io)
1517 B::IO io
1518
b326da91
MB
1519bool
1520IsSTD(io,name)
1521 B::IO io
1522 char* name
1523 PREINIT:
1524 PerlIO* handle = 0;
1525 CODE:
1526 if( strEQ( name, "stdin" ) ) {
1527 handle = PerlIO_stdin();
1528 }
1529 else if( strEQ( name, "stdout" ) ) {
1530 handle = PerlIO_stdout();
1531 }
1532 else if( strEQ( name, "stderr" ) ) {
1533 handle = PerlIO_stderr();
1534 }
1535 else {
1536 croak( "Invalid value '%s'", name );
1537 }
1538 RETVAL = handle == IoIFP(io);
1539 OUTPUT:
1540 RETVAL
1541
a8a597b2
MB
1542MODULE = B PACKAGE = B::IO
1543
1544char
1545IoTYPE(io)
1546 B::IO io
1547
1548U8
1549IoFLAGS(io)
1550 B::IO io
1551
1552MODULE = B PACKAGE = B::AV PREFIX = Av
1553
1554SSize_t
1555AvFILL(av)
1556 B::AV av
1557
1558SSize_t
1559AvMAX(av)
1560 B::AV av
1561
1562#define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1563
1564IV
1565AvOFF(av)
1566 B::AV av
1567
1568void
1569AvARRAY(av)
1570 B::AV av
1571 PPCODE:
1572 if (AvFILL(av) >= 0) {
1573 SV **svp = AvARRAY(av);
1574 I32 i;
1575 for (i = 0; i <= AvFILL(av); i++)
cea2e8a9 1576 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
a8a597b2
MB
1577 }
1578
429a5ce7
SM
1579void
1580AvARRAYelt(av, idx)
1581 B::AV av
1582 int idx
1583 PPCODE:
1584 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1585 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1586 else
1587 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1588
1df34986
AE
1589MODULE = B PACKAGE = B::FM PREFIX = Fm
1590
1591IV
1592FmLINES(form)
1593 B::FM form
1594
a8a597b2
MB
1595MODULE = B PACKAGE = B::CV PREFIX = Cv
1596
651aa52e
AE
1597U32
1598CvCONST(cv)
1599 B::CV cv
1600
a8a597b2
MB
1601B::HV
1602CvSTASH(cv)
1603 B::CV cv
1604
1605B::OP
1606CvSTART(cv)
1607 B::CV cv
1608
1609B::OP
1610CvROOT(cv)
1611 B::CV cv
1612
1613B::GV
1614CvGV(cv)
1615 B::CV cv
1616
57843af0
GS
1617char *
1618CvFILE(cv)
1619 B::CV cv
1620
a8a597b2
MB
1621long
1622CvDEPTH(cv)
1623 B::CV cv
1624
1625B::AV
1626CvPADLIST(cv)
1627 B::CV cv
1628
1629B::CV
1630CvOUTSIDE(cv)
1631 B::CV cv
1632
a3985cdc
DM
1633U32
1634CvOUTSIDE_SEQ(cv)
1635 B::CV cv
1636
a8a597b2
MB
1637void
1638CvXSUB(cv)
1639 B::CV cv
1640 CODE:
56431972 1641 ST(0) = sv_2mortal(newSViv(PTR2IV(CvXSUB(cv))));
a8a597b2
MB
1642
1643
1644void
1645CvXSUBANY(cv)
1646 B::CV cv
1647 CODE:
b326da91 1648 ST(0) = CvCONST(cv) ?
07409e01 1649 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
651aa52e 1650 sv_2mortal(newSViv(CvXSUBANY(cv).any_iv));
a8a597b2 1651
5cfd8ad4
VB
1652MODULE = B PACKAGE = B::CV
1653
6aaf4108 1654U16
5cfd8ad4
VB
1655CvFLAGS(cv)
1656 B::CV cv
1657
de3f1649
JT
1658MODULE = B PACKAGE = B::CV PREFIX = cv_
1659
1660B::SV
1661cv_const_sv(cv)
1662 B::CV cv
1663
5cfd8ad4 1664
a8a597b2
MB
1665MODULE = B PACKAGE = B::HV PREFIX = Hv
1666
1667STRLEN
1668HvFILL(hv)
1669 B::HV hv
1670
1671STRLEN
1672HvMAX(hv)
1673 B::HV hv
1674
1675I32
1676HvKEYS(hv)
1677 B::HV hv
1678
1679I32
1680HvRITER(hv)
1681 B::HV hv
1682
1683char *
1684HvNAME(hv)
1685 B::HV hv
1686
a8a597b2
MB
1687void
1688HvARRAY(hv)
1689 B::HV hv
1690 PPCODE:
1691 if (HvKEYS(hv) > 0) {
1692 SV *sv;
1693 char *key;
1694 I32 len;
1695 (void)hv_iterinit(hv);
1696 EXTEND(sp, HvKEYS(hv) * 2);
8063af02 1697 while ((sv = hv_iternextsv(hv, &key, &len))) {
79cb57f6 1698 PUSHs(newSVpvn(key, len));
cea2e8a9 1699 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
a8a597b2
MB
1700 }
1701 }