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