This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
lib/bigint.pm tiny typo fix
[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",
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
61static char *opclassnames[] = {
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
651aa52e
AE
76static size_t opsizes[] = {
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{
cea2e8a9 214 return opclassnames[cc_opclass(aTHX_ o)];
a8a597b2
MB
215}
216
217static SV *
cea2e8a9 218make_sv_object(pTHX_ SV *arg, SV *sv)
a8a597b2
MB
219{
220 char *type = 0;
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);
260 sv_setpv(sstr,"\"");
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 }
f3be9b72
RGS
411 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP)
412 && (kid = cPMOPo->op_pmreplroot))
413 {
414 sv_setiv(newSVrv(opsv, opclassnames[OPc_PMOP]), PTR2IV(kid));
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;
7252851f
NC
508#if PERL_VERSION <= 9
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:
a8a597b2
MB
724
725
726#define OP_next(o) o->op_next
727#define OP_sibling(o) o->op_sibling
22c35a8c 728#define OP_desc(o) PL_op_desc[o->op_type]
a8a597b2
MB
729#define OP_targ(o) o->op_targ
730#define OP_type(o) o->op_type
7252851f
NC
731#if PERL_VERSION >= 9
732# define OP_opt(o) o->op_opt
733# define OP_static(o) o->op_static
734#else
735# define OP_seq(o) o->op_seq
736#endif
a8a597b2
MB
737#define OP_flags(o) o->op_flags
738#define OP_private(o) o->op_private
a60ba18b 739#define OP_spare(o) o->op_spare
a8a597b2
MB
740
741MODULE = B PACKAGE = B::OP PREFIX = OP_
742
651aa52e
AE
743size_t
744OP_size(o)
745 B::OP o
746 CODE:
747 RETVAL = opsizes[cc_opclass(aTHX_ o)];
748 OUTPUT:
749 RETVAL
750
a8a597b2
MB
751B::OP
752OP_next(o)
753 B::OP o
754
755B::OP
756OP_sibling(o)
757 B::OP o
758
759char *
3f872cb9
GS
760OP_name(o)
761 B::OP o
762 CODE:
8063af02
DM
763 RETVAL = PL_op_name[o->op_type];
764 OUTPUT:
765 RETVAL
3f872cb9
GS
766
767
8063af02 768void
a8a597b2
MB
769OP_ppaddr(o)
770 B::OP o
dc333d64
GS
771 PREINIT:
772 int i;
773 SV *sv = sv_newmortal();
a8a597b2 774 CODE:
dc333d64
GS
775 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
776 sv_catpv(sv, PL_op_name[o->op_type]);
7c436af3 777 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
dc333d64
GS
778 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
779 sv_catpv(sv, "]");
780 ST(0) = sv;
a8a597b2
MB
781
782char *
783OP_desc(o)
784 B::OP o
785
7934575e 786PADOFFSET
a8a597b2
MB
787OP_targ(o)
788 B::OP o
789
790U16
791OP_type(o)
792 B::OP o
793
7252851f
NC
794#if PERL_VERSION >= 9
795
2814eb74
PJ
796U8
797OP_opt(o)
798 B::OP o
799
800U8
801OP_static(o)
a8a597b2
MB
802 B::OP o
803
7252851f
NC
804#else
805
806U16
807OP_seq(o)
808 B::OP o
809
810#endif
811
a8a597b2
MB
812U8
813OP_flags(o)
814 B::OP o
815
816U8
817OP_private(o)
818 B::OP o
819
7252851f
NC
820#if PERL_VERSION >= 9
821
a60ba18b
JC
822U8
823OP_spare(o)
824 B::OP o
825
7252851f
NC
826#endif
827
1df34986
AE
828void
829OP_oplist(o)
830 B::OP o
831 PPCODE:
832 SP = oplist(aTHX_ o, SP);
833
a8a597b2
MB
834#define UNOP_first(o) o->op_first
835
836MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
837
838B::OP
839UNOP_first(o)
840 B::UNOP o
841
842#define BINOP_last(o) o->op_last
843
844MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
845
846B::OP
847BINOP_last(o)
848 B::BINOP o
849
850#define LOGOP_other(o) o->op_other
851
852MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
853
854B::OP
855LOGOP_other(o)
856 B::LOGOP o
857
a8a597b2
MB
858MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
859
c03c2844
SM
860U32
861LISTOP_children(o)
862 B::LISTOP o
863 OP * kid = NO_INIT
864 int i = NO_INIT
865 CODE:
c03c2844
SM
866 i = 0;
867 for (kid = o->op_first; kid; kid = kid->op_sibling)
868 i++;
8063af02
DM
869 RETVAL = i;
870 OUTPUT:
871 RETVAL
c03c2844 872
a8a597b2
MB
873#define PMOP_pmreplroot(o) o->op_pmreplroot
874#define PMOP_pmreplstart(o) o->op_pmreplstart
875#define PMOP_pmnext(o) o->op_pmnext
aaa362c4 876#define PMOP_pmregexp(o) PM_GETRE(o)
9d2bbe64
MB
877#ifdef USE_ITHREADS
878#define PMOP_pmoffset(o) o->op_pmoffset
651aa52e
AE
879#define PMOP_pmstashpv(o) o->op_pmstashpv
880#else
881#define PMOP_pmstash(o) o->op_pmstash
9d2bbe64 882#endif
a8a597b2
MB
883#define PMOP_pmflags(o) o->op_pmflags
884#define PMOP_pmpermflags(o) o->op_pmpermflags
9d2bbe64 885#define PMOP_pmdynflags(o) o->op_pmdynflags
a8a597b2
MB
886
887MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
888
889void
890PMOP_pmreplroot(o)
891 B::PMOP o
892 OP * root = NO_INIT
893 CODE:
894 ST(0) = sv_newmortal();
895 root = o->op_pmreplroot;
896 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
897 if (o->op_type == OP_PUSHRE) {
9d2bbe64
MB
898#ifdef USE_ITHREADS
899 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
900#else
a8a597b2
MB
901 sv_setiv(newSVrv(ST(0), root ?
902 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
56431972 903 PTR2IV(root));
9d2bbe64 904#endif
a8a597b2
MB
905 }
906 else {
56431972 907 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
a8a597b2
MB
908 }
909
910B::OP
911PMOP_pmreplstart(o)
912 B::PMOP o
913
914B::PMOP
915PMOP_pmnext(o)
916 B::PMOP o
917
9d2bbe64
MB
918#ifdef USE_ITHREADS
919
920IV
921PMOP_pmoffset(o)
922 B::PMOP o
923
651aa52e
AE
924char*
925PMOP_pmstashpv(o)
926 B::PMOP o
927
928#else
929
930B::HV
931PMOP_pmstash(o)
932 B::PMOP o
933
9d2bbe64
MB
934#endif
935
6e21dc91 936U32
a8a597b2
MB
937PMOP_pmflags(o)
938 B::PMOP o
939
6e21dc91 940U32
a8a597b2
MB
941PMOP_pmpermflags(o)
942 B::PMOP o
943
9d2bbe64
MB
944U8
945PMOP_pmdynflags(o)
946 B::PMOP o
947
a8a597b2
MB
948void
949PMOP_precomp(o)
950 B::PMOP o
951 REGEXP * rx = NO_INIT
952 CODE:
953 ST(0) = sv_newmortal();
aaa362c4 954 rx = PM_GETRE(o);
a8a597b2
MB
955 if (rx)
956 sv_setpvn(ST(0), rx->precomp, rx->prelen);
957
ac33dcd1
JH
958#define SVOP_sv(o) cSVOPo->op_sv
959#define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
a8a597b2
MB
960
961MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
962
a8a597b2
MB
963B::SV
964SVOP_sv(o)
965 B::SVOP o
966
f22444f5 967B::GV
065a1863
GS
968SVOP_gv(o)
969 B::SVOP o
970
7934575e 971#define PADOP_padix(o) o->op_padix
dd2155a4 972#define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
7934575e 973#define PADOP_gv(o) ((o->op_padix \
dd2155a4
DM
974 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
975 ? (GV*)PAD_SVl(o->op_padix) : Nullgv)
a8a597b2 976
7934575e
GS
977MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
978
979PADOFFSET
980PADOP_padix(o)
981 B::PADOP o
982
983B::SV
984PADOP_sv(o)
985 B::PADOP o
a8a597b2
MB
986
987B::GV
7934575e
GS
988PADOP_gv(o)
989 B::PADOP o
a8a597b2
MB
990
991MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
992
993void
994PVOP_pv(o)
995 B::PVOP o
996 CODE:
997 /*
bec89253 998 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
a8a597b2
MB
999 * whereas other PVOPs point to a null terminated string.
1000 */
bec89253
RH
1001 if (o->op_type == OP_TRANS &&
1002 (o->op_private & OPpTRANS_COMPLEMENT) &&
1003 !(o->op_private & OPpTRANS_DELETE))
1004 {
1005 short* tbl = (short*)o->op_pv;
1006 short entries = 257 + tbl[256];
1007 ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1008 }
1009 else if (o->op_type == OP_TRANS) {
1010 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1011 }
1012 else
1013 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
a8a597b2
MB
1014
1015#define LOOP_redoop(o) o->op_redoop
1016#define LOOP_nextop(o) o->op_nextop
1017#define LOOP_lastop(o) o->op_lastop
1018
1019MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1020
1021
1022B::OP
1023LOOP_redoop(o)
1024 B::LOOP o
1025
1026B::OP
1027LOOP_nextop(o)
1028 B::LOOP o
1029
1030B::OP
1031LOOP_lastop(o)
1032 B::LOOP o
1033
1034#define COP_label(o) o->cop_label
11faa288
GS
1035#define COP_stashpv(o) CopSTASHPV(o)
1036#define COP_stash(o) CopSTASH(o)
57843af0 1037#define COP_file(o) CopFILE(o)
1df34986 1038#define COP_filegv(o) CopFILEGV(o)
a8a597b2
MB
1039#define COP_cop_seq(o) o->cop_seq
1040#define COP_arybase(o) o->cop_arybase
57843af0 1041#define COP_line(o) CopLINE(o)
b295d113 1042#define COP_warnings(o) o->cop_warnings
6e6a1aef 1043#define COP_io(o) o->cop_io
a8a597b2
MB
1044
1045MODULE = B PACKAGE = B::COP PREFIX = COP_
1046
1047char *
1048COP_label(o)
1049 B::COP o
1050
11faa288
GS
1051char *
1052COP_stashpv(o)
1053 B::COP o
1054
a8a597b2
MB
1055B::HV
1056COP_stash(o)
1057 B::COP o
1058
57843af0
GS
1059char *
1060COP_file(o)
a8a597b2
MB
1061 B::COP o
1062
1df34986
AE
1063B::GV
1064COP_filegv(o)
1065 B::COP o
1066
1067
a8a597b2
MB
1068U32
1069COP_cop_seq(o)
1070 B::COP o
1071
1072I32
1073COP_arybase(o)
1074 B::COP o
1075
8bafa735 1076U32
a8a597b2
MB
1077COP_line(o)
1078 B::COP o
1079
b295d113
TH
1080B::SV
1081COP_warnings(o)
1082 B::COP o
1083
6e6a1aef
RGS
1084B::SV
1085COP_io(o)
1086 B::COP o
1087
651aa52e
AE
1088MODULE = B PACKAGE = B::SV
1089
1090U32
1091SvTYPE(sv)
1092 B::SV sv
1093
429a5ce7
SM
1094#define object_2svref(sv) sv
1095#define SVREF SV *
1096
1097SVREF
1098object_2svref(sv)
1099 B::SV sv
1100
a8a597b2
MB
1101MODULE = B PACKAGE = B::SV PREFIX = Sv
1102
1103U32
1104SvREFCNT(sv)
1105 B::SV sv
1106
1107U32
1108SvFLAGS(sv)
1109 B::SV sv
1110
651aa52e
AE
1111U32
1112SvPOK(sv)
1113 B::SV sv
1114
1115U32
1116SvROK(sv)
1117 B::SV sv
1118
1119U32
1120SvMAGICAL(sv)
1121 B::SV sv
1122
a8a597b2
MB
1123MODULE = B PACKAGE = B::IV PREFIX = Sv
1124
1125IV
1126SvIV(sv)
1127 B::IV sv
1128
1129IV
1130SvIVX(sv)
1131 B::IV sv
1132
0ca04487
VB
1133UV
1134SvUVX(sv)
1135 B::IV sv
1136
1137
a8a597b2
MB
1138MODULE = B PACKAGE = B::IV
1139
1140#define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1141
1142int
1143needs64bits(sv)
1144 B::IV sv
1145
1146void
1147packiv(sv)
1148 B::IV sv
1149 CODE:
1150 if (sizeof(IV) == 8) {
1151 U32 wp[2];
1152 IV iv = SvIVX(sv);
1153 /*
1154 * The following way of spelling 32 is to stop compilers on
1155 * 32-bit architectures from moaning about the shift count
1156 * being >= the width of the type. Such architectures don't
1157 * reach this code anyway (unless sizeof(IV) > 8 but then
1158 * everything else breaks too so I'm not fussed at the moment).
1159 */
42718184
RB
1160#ifdef UV_IS_QUAD
1161 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1162#else
1163 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1164#endif
a8a597b2 1165 wp[1] = htonl(iv & 0xffffffff);
79cb57f6 1166 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
a8a597b2
MB
1167 } else {
1168 U32 w = htonl((U32)SvIVX(sv));
79cb57f6 1169 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
a8a597b2
MB
1170 }
1171
1172MODULE = B PACKAGE = B::NV PREFIX = Sv
1173
76ef7183 1174NV
a8a597b2
MB
1175SvNV(sv)
1176 B::NV sv
1177
76ef7183 1178NV
a8a597b2
MB
1179SvNVX(sv)
1180 B::NV sv
1181
1182MODULE = B PACKAGE = B::RV PREFIX = Sv
1183
1184B::SV
1185SvRV(sv)
1186 B::RV sv
1187
1188MODULE = B PACKAGE = B::PV PREFIX = Sv
1189
0b40bd6d
RH
1190char*
1191SvPVX(sv)
1192 B::PV sv
1193
b326da91
MB
1194B::SV
1195SvRV(sv)
1196 B::PV sv
1197 CODE:
1198 if( SvROK(sv) ) {
1199 RETVAL = SvRV(sv);
1200 }
1201 else {
1202 croak( "argument is not SvROK" );
1203 }
1204 OUTPUT:
1205 RETVAL
1206
a8a597b2
MB
1207void
1208SvPV(sv)
1209 B::PV sv
1210 CODE:
b326da91 1211 ST(0) = sv_newmortal();
9d2bbe64 1212 if( SvPOK(sv) ) {
b326da91
MB
1213 sv_setpvn(ST(0), SvPVX(sv), SvCUR(sv));
1214 SvFLAGS(ST(0)) |= SvUTF8(sv);
1215 }
1216 else {
1217 /* XXX for backward compatibility, but should fail */
1218 /* croak( "argument is not SvPOK" ); */
1219 sv_setpvn(ST(0), NULL, 0);
1220 }
a8a597b2 1221
651aa52e
AE
1222void
1223SvPVBM(sv)
1224 B::PV sv
1225 CODE:
1226 ST(0) = sv_newmortal();
1227 sv_setpvn(ST(0), SvPVX(sv),
1228 SvCUR(sv) + (SvTYPE(sv) == SVt_PVBM ? 257 : 0));
1229
1230
445a12f6
DM
1231STRLEN
1232SvLEN(sv)
1233 B::PV sv
1234
1235STRLEN
1236SvCUR(sv)
1237 B::PV sv
1238
a8a597b2
MB
1239MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1240
1241void
1242SvMAGIC(sv)
1243 B::PVMG sv
1244 MAGIC * mg = NO_INIT
1245 PPCODE:
1246 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
cea2e8a9 1247 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
a8a597b2
MB
1248
1249MODULE = B PACKAGE = B::PVMG
1250
1251B::HV
1252SvSTASH(sv)
1253 B::PVMG sv
1254
1255#define MgMOREMAGIC(mg) mg->mg_moremagic
1256#define MgPRIVATE(mg) mg->mg_private
1257#define MgTYPE(mg) mg->mg_type
1258#define MgFLAGS(mg) mg->mg_flags
1259#define MgOBJ(mg) mg->mg_obj
88b39979 1260#define MgLENGTH(mg) mg->mg_len
bde7177d 1261#define MgREGEX(mg) PTR2IV(mg->mg_obj)
a8a597b2
MB
1262
1263MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1264
1265B::MAGIC
1266MgMOREMAGIC(mg)
1267 B::MAGIC mg
c5f0f3aa
RGS
1268 CODE:
1269 if( MgMOREMAGIC(mg) ) {
1270 RETVAL = MgMOREMAGIC(mg);
1271 }
1272 else {
1273 XSRETURN_UNDEF;
1274 }
1275 OUTPUT:
1276 RETVAL
a8a597b2
MB
1277
1278U16
1279MgPRIVATE(mg)
1280 B::MAGIC mg
1281
1282char
1283MgTYPE(mg)
1284 B::MAGIC mg
1285
1286U8
1287MgFLAGS(mg)
1288 B::MAGIC mg
1289
1290B::SV
1291MgOBJ(mg)
1292 B::MAGIC mg
b326da91 1293
9d2bbe64
MB
1294IV
1295MgREGEX(mg)
1296 B::MAGIC mg
1297 CODE:
1298 if( mg->mg_type == 'r' ) {
1299 RETVAL = MgREGEX(mg);
1300 }
1301 else {
1302 croak( "REGEX is only meaningful on r-magic" );
1303 }
1304 OUTPUT:
1305 RETVAL
1306
b326da91
MB
1307SV*
1308precomp(mg)
1309 B::MAGIC mg
1310 CODE:
1311 if (mg->mg_type == 'r') {
1312 REGEXP* rx = (REGEXP*)mg->mg_obj;
1313 if( rx )
1314 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1315 }
1316 else {
1317 croak( "precomp is only meaningful on r-magic" );
1318 }
1319 OUTPUT:
1320 RETVAL
a8a597b2 1321
88b39979
VB
1322I32
1323MgLENGTH(mg)
1324 B::MAGIC mg
1325
a8a597b2
MB
1326void
1327MgPTR(mg)
1328 B::MAGIC mg
1329 CODE:
1330 ST(0) = sv_newmortal();
88b39979
VB
1331 if (mg->mg_ptr){
1332 if (mg->mg_len >= 0){
1333 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
651aa52e
AE
1334 } else if (mg->mg_len == HEf_SVKEY) {
1335 ST(0) = make_sv_object(aTHX_
1336 sv_newmortal(), (SV*)mg->mg_ptr);
88b39979
VB
1337 }
1338 }
a8a597b2
MB
1339
1340MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1341
1342U32
1343LvTARGOFF(sv)
1344 B::PVLV sv
1345
1346U32
1347LvTARGLEN(sv)
1348 B::PVLV sv
1349
1350char
1351LvTYPE(sv)
1352 B::PVLV sv
1353
1354B::SV
1355LvTARG(sv)
1356 B::PVLV sv
1357
1358MODULE = B PACKAGE = B::BM PREFIX = Bm
1359
1360I32
1361BmUSEFUL(sv)
1362 B::BM sv
1363
1364U16
1365BmPREVIOUS(sv)
1366 B::BM sv
1367
1368U8
1369BmRARE(sv)
1370 B::BM sv
1371
1372void
1373BmTABLE(sv)
1374 B::BM sv
1375 STRLEN len = NO_INIT
1376 char * str = NO_INIT
1377 CODE:
1378 str = SvPV(sv, len);
1379 /* Boyer-Moore table is just after string and its safety-margin \0 */
79cb57f6 1380 ST(0) = sv_2mortal(newSVpvn(str + len + 1, 256));
a8a597b2
MB
1381
1382MODULE = B PACKAGE = B::GV PREFIX = Gv
1383
1384void
1385GvNAME(gv)
1386 B::GV gv
1387 CODE:
79cb57f6 1388 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
a8a597b2 1389
87d7fd28
GS
1390bool
1391is_empty(gv)
1392 B::GV gv
1393 CODE:
1394 RETVAL = GvGP(gv) == Null(GP*);
1395 OUTPUT:
1396 RETVAL
1397
651aa52e
AE
1398void*
1399GvGP(gv)
1400 B::GV gv
1401
a8a597b2
MB
1402B::HV
1403GvSTASH(gv)
1404 B::GV gv
1405
1406B::SV
1407GvSV(gv)
1408 B::GV gv
1409
1410B::IO
1411GvIO(gv)
1412 B::GV gv
1413
1df34986 1414B::FM
a8a597b2
MB
1415GvFORM(gv)
1416 B::GV gv
1df34986
AE
1417 CODE:
1418 RETVAL = (SV*)GvFORM(gv);
1419 OUTPUT:
1420 RETVAL
a8a597b2
MB
1421
1422B::AV
1423GvAV(gv)
1424 B::GV gv
1425
1426B::HV
1427GvHV(gv)
1428 B::GV gv
1429
1430B::GV
1431GvEGV(gv)
1432 B::GV gv
1433
1434B::CV
1435GvCV(gv)
1436 B::GV gv
1437
1438U32
1439GvCVGEN(gv)
1440 B::GV gv
1441
8bafa735 1442U32
a8a597b2
MB
1443GvLINE(gv)
1444 B::GV gv
1445
b195d487
GS
1446char *
1447GvFILE(gv)
1448 B::GV gv
1449
a8a597b2
MB
1450B::GV
1451GvFILEGV(gv)
1452 B::GV gv
1453
1454MODULE = B PACKAGE = B::GV
1455
1456U32
1457GvREFCNT(gv)
1458 B::GV gv
1459
1460U8
1461GvFLAGS(gv)
1462 B::GV gv
1463
1464MODULE = B PACKAGE = B::IO PREFIX = Io
1465
1466long
1467IoLINES(io)
1468 B::IO io
1469
1470long
1471IoPAGE(io)
1472 B::IO io
1473
1474long
1475IoPAGE_LEN(io)
1476 B::IO io
1477
1478long
1479IoLINES_LEFT(io)
1480 B::IO io
1481
1482char *
1483IoTOP_NAME(io)
1484 B::IO io
1485
1486B::GV
1487IoTOP_GV(io)
1488 B::IO io
1489
1490char *
1491IoFMT_NAME(io)
1492 B::IO io
1493
1494B::GV
1495IoFMT_GV(io)
1496 B::IO io
1497
1498char *
1499IoBOTTOM_NAME(io)
1500 B::IO io
1501
1502B::GV
1503IoBOTTOM_GV(io)
1504 B::IO io
1505
1506short
1507IoSUBPROCESS(io)
1508 B::IO io
1509
b326da91
MB
1510bool
1511IsSTD(io,name)
1512 B::IO io
1513 char* name
1514 PREINIT:
1515 PerlIO* handle = 0;
1516 CODE:
1517 if( strEQ( name, "stdin" ) ) {
1518 handle = PerlIO_stdin();
1519 }
1520 else if( strEQ( name, "stdout" ) ) {
1521 handle = PerlIO_stdout();
1522 }
1523 else if( strEQ( name, "stderr" ) ) {
1524 handle = PerlIO_stderr();
1525 }
1526 else {
1527 croak( "Invalid value '%s'", name );
1528 }
1529 RETVAL = handle == IoIFP(io);
1530 OUTPUT:
1531 RETVAL
1532
a8a597b2
MB
1533MODULE = B PACKAGE = B::IO
1534
1535char
1536IoTYPE(io)
1537 B::IO io
1538
1539U8
1540IoFLAGS(io)
1541 B::IO io
1542
1543MODULE = B PACKAGE = B::AV PREFIX = Av
1544
1545SSize_t
1546AvFILL(av)
1547 B::AV av
1548
1549SSize_t
1550AvMAX(av)
1551 B::AV av
1552
1553#define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off
1554
1555IV
1556AvOFF(av)
1557 B::AV av
1558
1559void
1560AvARRAY(av)
1561 B::AV av
1562 PPCODE:
1563 if (AvFILL(av) >= 0) {
1564 SV **svp = AvARRAY(av);
1565 I32 i;
1566 for (i = 0; i <= AvFILL(av); i++)
cea2e8a9 1567 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
a8a597b2
MB
1568 }
1569
429a5ce7
SM
1570void
1571AvARRAYelt(av, idx)
1572 B::AV av
1573 int idx
1574 PPCODE:
1575 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1576 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1577 else
1578 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
1579
1580
a8a597b2
MB
1581MODULE = B PACKAGE = B::AV
1582
1583U8
1584AvFLAGS(av)
1585 B::AV av
1586
1df34986
AE
1587MODULE = B PACKAGE = B::FM PREFIX = Fm
1588
1589IV
1590FmLINES(form)
1591 B::FM form
1592
a8a597b2
MB
1593MODULE = B PACKAGE = B::CV PREFIX = Cv
1594
651aa52e
AE
1595U32
1596CvCONST(cv)
1597 B::CV cv
1598
a8a597b2
MB
1599B::HV
1600CvSTASH(cv)
1601 B::CV cv
1602
1603B::OP
1604CvSTART(cv)
1605 B::CV cv
1606
1607B::OP
1608CvROOT(cv)
1609 B::CV cv
1610
1611B::GV
1612CvGV(cv)
1613 B::CV cv
1614
57843af0
GS
1615char *
1616CvFILE(cv)
1617 B::CV cv
1618
a8a597b2
MB
1619long
1620CvDEPTH(cv)
1621 B::CV cv
1622
1623B::AV
1624CvPADLIST(cv)
1625 B::CV cv
1626
1627B::CV
1628CvOUTSIDE(cv)
1629 B::CV cv
1630
a3985cdc
DM
1631U32
1632CvOUTSIDE_SEQ(cv)
1633 B::CV cv
1634
a8a597b2
MB
1635void
1636CvXSUB(cv)
1637 B::CV cv
1638 CODE:
56431972 1639 ST(0) = sv_2mortal(newSViv(PTR2IV(CvXSUB(cv))));
a8a597b2
MB
1640
1641
1642void
1643CvXSUBANY(cv)
1644 B::CV cv
1645 CODE:
b326da91 1646 ST(0) = CvCONST(cv) ?
651aa52e
AE
1647 make_sv_object(aTHX_ sv_newmortal(),CvXSUBANY(cv).any_ptr) :
1648 sv_2mortal(newSViv(CvXSUBANY(cv).any_iv));
a8a597b2 1649
5cfd8ad4
VB
1650MODULE = B PACKAGE = B::CV
1651
6aaf4108 1652U16
5cfd8ad4
VB
1653CvFLAGS(cv)
1654 B::CV cv
1655
de3f1649
JT
1656MODULE = B PACKAGE = B::CV PREFIX = cv_
1657
1658B::SV
1659cv_const_sv(cv)
1660 B::CV cv
1661
5cfd8ad4 1662
a8a597b2
MB
1663MODULE = B PACKAGE = B::HV PREFIX = Hv
1664
1665STRLEN
1666HvFILL(hv)
1667 B::HV hv
1668
1669STRLEN
1670HvMAX(hv)
1671 B::HV hv
1672
1673I32
1674HvKEYS(hv)
1675 B::HV hv
1676
1677I32
1678HvRITER(hv)
1679 B::HV hv
1680
1681char *
1682HvNAME(hv)
1683 B::HV hv
1684
1685B::PMOP
1686HvPMROOT(hv)
1687 B::HV hv
1688
1689void
1690HvARRAY(hv)
1691 B::HV hv
1692 PPCODE:
1693 if (HvKEYS(hv) > 0) {
1694 SV *sv;
1695 char *key;
1696 I32 len;
1697 (void)hv_iterinit(hv);
1698 EXTEND(sp, HvKEYS(hv) * 2);
8063af02 1699 while ((sv = hv_iternextsv(hv, &key, &len))) {
79cb57f6 1700 PUSHs(newSVpvn(key, len));
cea2e8a9 1701 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
a8a597b2
MB
1702 }
1703 }