This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
'[at]' should be '@'
[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
5d7488b2 104cc_opclass(pTHX_ const 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 *
5d7488b2 212cc_opclassname(pTHX_ const 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
250 if (!SvOK(sv))
251 sv_setpvn(sstr, "0", 1);
5d7488b2 252 else if (perlstyle && SvUTF8(sv)) {
d79a7a3d 253 SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */
5d7488b2
AL
254 const STRLEN len = SvCUR(sv);
255 const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ);
c69006e4 256 sv_setpvn(sstr,"\"",1);
d79a7a3d
RGS
257 while (*s)
258 {
259 if (*s == '"')
5d7488b2 260 sv_catpvn(sstr, "\\\"", 2);
d79a7a3d 261 else if (*s == '$')
5d7488b2 262 sv_catpvn(sstr, "\\$", 2);
d79a7a3d 263 else if (*s == '@')
5d7488b2 264 sv_catpvn(sstr, "\\@", 2);
d79a7a3d
RGS
265 else if (*s == '\\')
266 {
267 if (strchr("nrftax\\",*(s+1)))
268 sv_catpvn(sstr, s++, 2);
269 else
5d7488b2 270 sv_catpvn(sstr, "\\\\", 2);
d79a7a3d
RGS
271 }
272 else /* should always be printable */
273 sv_catpvn(sstr, s, 1);
274 ++s;
275 }
276 sv_catpv(sstr, "\"");
277 return sstr;
278 }
a8a597b2
MB
279 else
280 {
281 /* XXX Optimise? */
5d7488b2
AL
282 STRLEN len;
283 const char *s = SvPV(sv, len);
a8a597b2
MB
284 sv_catpv(sstr, "\"");
285 for (; len; len--, s++)
286 {
287 /* At least try a little for readability */
288 if (*s == '"')
289 sv_catpv(sstr, "\\\"");
290 else if (*s == '\\')
291 sv_catpv(sstr, "\\\\");
b326da91 292 /* trigraphs - bleagh */
5d7488b2
AL
293 else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') {
294 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
b326da91
MB
295 sprintf(escbuff, "\\%03o", '?');
296 sv_catpv(sstr, escbuff);
297 }
52ad86de
JH
298 else if (perlstyle && *s == '$')
299 sv_catpv(sstr, "\\$");
300 else if (perlstyle && *s == '@')
301 sv_catpv(sstr, "\\@");
ce561ef2
JH
302#ifdef EBCDIC
303 else if (isPRINT(*s))
304#else
305 else if (*s >= ' ' && *s < 127)
306#endif /* EBCDIC */
a8a597b2
MB
307 sv_catpvn(sstr, s, 1);
308 else if (*s == '\n')
309 sv_catpv(sstr, "\\n");
310 else if (*s == '\r')
311 sv_catpv(sstr, "\\r");
312 else if (*s == '\t')
313 sv_catpv(sstr, "\\t");
314 else if (*s == '\a')
315 sv_catpv(sstr, "\\a");
316 else if (*s == '\b')
317 sv_catpv(sstr, "\\b");
318 else if (*s == '\f')
319 sv_catpv(sstr, "\\f");
52ad86de 320 else if (!perlstyle && *s == '\v')
a8a597b2
MB
321 sv_catpv(sstr, "\\v");
322 else
323 {
a8a597b2 324 /* Don't want promotion of a signed -1 char in sprintf args */
5d7488b2
AL
325 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
326 const unsigned char c = (unsigned char) *s;
a8a597b2
MB
327 sprintf(escbuff, "\\%03o", c);
328 sv_catpv(sstr, escbuff);
329 }
330 /* XXX Add line breaks if string is long */
331 }
332 sv_catpv(sstr, "\"");
333 }
334 return sstr;
335}
336
337static SV *
cea2e8a9 338cchar(pTHX_ SV *sv)
a8a597b2 339{
79cb57f6 340 SV *sstr = newSVpvn("'", 1);
5d7488b2 341 const char *s = SvPV_nolen(sv);
a8a597b2
MB
342
343 if (*s == '\'')
5d7488b2 344 sv_catpvn(sstr, "\\'", 2);
a8a597b2 345 else if (*s == '\\')
5d7488b2 346 sv_catpvn(sstr, "\\\\", 2);
ce561ef2 347#ifdef EBCDIC
133b4094 348 else if (isPRINT(*s))
ce561ef2
JH
349#else
350 else if (*s >= ' ' && *s < 127)
351#endif /* EBCDIC */
a8a597b2
MB
352 sv_catpvn(sstr, s, 1);
353 else if (*s == '\n')
5d7488b2 354 sv_catpvn(sstr, "\\n", 2);
a8a597b2 355 else if (*s == '\r')
5d7488b2 356 sv_catpvn(sstr, "\\r", 2);
a8a597b2 357 else if (*s == '\t')
5d7488b2 358 sv_catpvn(sstr, "\\t", 2);
a8a597b2 359 else if (*s == '\a')
5d7488b2 360 sv_catpvn(sstr, "\\a", 2);
a8a597b2 361 else if (*s == '\b')
5d7488b2 362 sv_catpvn(sstr, "\\b", 2);
a8a597b2 363 else if (*s == '\f')
5d7488b2 364 sv_catpvn(sstr, "\\f", 2);
a8a597b2 365 else if (*s == '\v')
5d7488b2 366 sv_catpvn(sstr, "\\v", 2);
a8a597b2
MB
367 else
368 {
369 /* no trigraph support */
370 char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */
371 /* Don't want promotion of a signed -1 char in sprintf args */
372 unsigned char c = (unsigned char) *s;
373 sprintf(escbuff, "\\%03o", c);
374 sv_catpv(sstr, escbuff);
375 }
5d7488b2 376 sv_catpvn(sstr, "'", 1);
a8a597b2
MB
377 return sstr;
378}
379
5d7488b2
AL
380static void
381walkoptree(pTHX_ SV *opsv, const char *method)
a8a597b2
MB
382{
383 dSP;
f3be9b72 384 OP *o, *kid;
89ca4ac7
JH
385 dMY_CXT;
386
a8a597b2
MB
387 if (!SvROK(opsv))
388 croak("opsv is not a reference");
389 opsv = sv_mortalcopy(opsv);
56431972 390 o = INT2PTR(OP*,SvIV((SV*)SvRV(opsv)));
a8a597b2
MB
391 if (walkoptree_debug) {
392 PUSHMARK(sp);
393 XPUSHs(opsv);
394 PUTBACK;
395 perl_call_method("walkoptree_debug", G_DISCARD);
396 }
397 PUSHMARK(sp);
398 XPUSHs(opsv);
399 PUTBACK;
400 perl_call_method(method, G_DISCARD);
401 if (o && (o->op_flags & OPf_KIDS)) {
a8a597b2
MB
402 for (kid = ((UNOP*)o)->op_first; kid; kid = kid->op_sibling) {
403 /* Use the same opsv. Rely on methods not to mess it up. */
56431972 404 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
cea2e8a9 405 walkoptree(aTHX_ opsv, method);
a8a597b2
MB
406 }
407 }
5464c149 408 if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
f3be9b72
RGS
409 && (kid = cPMOPo->op_pmreplroot))
410 {
5464c149 411 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
f3be9b72
RGS
412 walkoptree(aTHX_ opsv, method);
413 }
a8a597b2
MB
414}
415
5d7488b2 416static SV **
1df34986
AE
417oplist(pTHX_ OP *o, SV **SP)
418{
419 for(; o; o = o->op_next) {
420 SV *opsv;
7252851f
NC
421#if PERL_VERSION >= 9
422 if (o->op_opt == 0)
1df34986 423 break;
2814eb74 424 o->op_opt = 0;
7252851f
NC
425#else
426 if (o->op_seq == 0)
427 break;
428 o->op_seq = 0;
429#endif
1df34986
AE
430 opsv = sv_newmortal();
431 sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ (OP*)o)), PTR2IV(o));
432 XPUSHs(opsv);
433 switch (o->op_type) {
434 case OP_SUBST:
435 SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP);
436 continue;
437 case OP_SORT:
f66c782a 438 if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
1df34986
AE
439 OP *kid = cLISTOPo->op_first->op_sibling; /* pass pushmark */
440 kid = kUNOP->op_first; /* pass rv2gv */
441 kid = kUNOP->op_first; /* pass leave */
f66c782a 442 SP = oplist(aTHX_ kid->op_next, SP);
1df34986
AE
443 }
444 continue;
445 }
446 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
447 case OA_LOGOP:
448 SP = oplist(aTHX_ cLOGOPo->op_other, SP);
449 break;
450 case OA_LOOP:
451 SP = oplist(aTHX_ cLOOPo->op_lastop, SP);
452 SP = oplist(aTHX_ cLOOPo->op_nextop, SP);
453 SP = oplist(aTHX_ cLOOPo->op_redoop, SP);
454 break;
455 }
456 }
457 return SP;
458}
459
a8a597b2
MB
460typedef OP *B__OP;
461typedef UNOP *B__UNOP;
462typedef BINOP *B__BINOP;
463typedef LOGOP *B__LOGOP;
a8a597b2
MB
464typedef LISTOP *B__LISTOP;
465typedef PMOP *B__PMOP;
466typedef SVOP *B__SVOP;
7934575e 467typedef PADOP *B__PADOP;
a8a597b2
MB
468typedef PVOP *B__PVOP;
469typedef LOOP *B__LOOP;
470typedef COP *B__COP;
471
472typedef SV *B__SV;
473typedef SV *B__IV;
474typedef SV *B__PV;
475typedef SV *B__NV;
476typedef SV *B__PVMG;
477typedef SV *B__PVLV;
478typedef SV *B__BM;
479typedef SV *B__RV;
1df34986 480typedef SV *B__FM;
a8a597b2
MB
481typedef AV *B__AV;
482typedef HV *B__HV;
483typedef CV *B__CV;
484typedef GV *B__GV;
485typedef IO *B__IO;
486
487typedef MAGIC *B__MAGIC;
488
489MODULE = B PACKAGE = B PREFIX = B_
490
491PROTOTYPES: DISABLE
492
493BOOT:
4c1f658f
NIS
494{
495 HV *stash = gv_stashpvn("B", 1, TRUE);
496 AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE);
89ca4ac7 497 MY_CXT_INIT;
e8edd1e6
TH
498 specialsv_list[0] = Nullsv;
499 specialsv_list[1] = &PL_sv_undef;
500 specialsv_list[2] = &PL_sv_yes;
501 specialsv_list[3] = &PL_sv_no;
059a8bb7
JH
502 specialsv_list[4] = pWARN_ALL;
503 specialsv_list[5] = pWARN_NONE;
b326da91 504 specialsv_list[6] = pWARN_STD;
f5ba1307 505#if PERL_VERSION <= 8
7252851f
NC
506# define CVf_ASSERTION 0
507#endif
4c1f658f
NIS
508#include "defsubs.h"
509}
a8a597b2 510
3280af22 511#define B_main_cv() PL_main_cv
31d7d75a 512#define B_init_av() PL_initav
651aa52e 513#define B_inc_gv() PL_incgv
ece599bd 514#define B_check_av() PL_checkav_save
059a8bb7
JH
515#define B_begin_av() PL_beginav_save
516#define B_end_av() PL_endav
3280af22
NIS
517#define B_main_root() PL_main_root
518#define B_main_start() PL_main_start
56eca212 519#define B_amagic_generation() PL_amagic_generation
651aa52e
AE
520#define B_defstash() PL_defstash
521#define B_curstash() PL_curstash
522#define B_dowarn() PL_dowarn
3280af22
NIS
523#define B_comppadlist() (PL_main_cv ? CvPADLIST(PL_main_cv) : CvPADLIST(PL_compcv))
524#define B_sv_undef() &PL_sv_undef
525#define B_sv_yes() &PL_sv_yes
526#define B_sv_no() &PL_sv_no
1df34986 527#define B_formfeed() PL_formfeed
9d2bbe64
MB
528#ifdef USE_ITHREADS
529#define B_regex_padav() PL_regex_padav
530#endif
a8a597b2 531
31d7d75a
NIS
532B::AV
533B_init_av()
534
059a8bb7 535B::AV
ece599bd
RGS
536B_check_av()
537
538B::AV
059a8bb7
JH
539B_begin_av()
540
541B::AV
542B_end_av()
543
651aa52e
AE
544B::GV
545B_inc_gv()
546
9d2bbe64
MB
547#ifdef USE_ITHREADS
548
549B::AV
550B_regex_padav()
551
552#endif
553
a8a597b2
MB
554B::CV
555B_main_cv()
556
557B::OP
558B_main_root()
559
560B::OP
561B_main_start()
562
56eca212
GS
563long
564B_amagic_generation()
565
a8a597b2
MB
566B::AV
567B_comppadlist()
568
569B::SV
570B_sv_undef()
571
572B::SV
573B_sv_yes()
574
575B::SV
576B_sv_no()
577
651aa52e
AE
578B::HV
579B_curstash()
580
581B::HV
582B_defstash()
a8a597b2 583
651aa52e
AE
584U8
585B_dowarn()
586
1df34986
AE
587B::SV
588B_formfeed()
589
651aa52e
AE
590void
591B_warnhook()
592 CODE:
593 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_warnhook);
594
595void
596B_diehook()
597 CODE:
598 ST(0) = make_sv_object(aTHX_ sv_newmortal(), PL_diehook);
599
600MODULE = B PACKAGE = B
a8a597b2
MB
601
602void
603walkoptree(opsv, method)
604 SV * opsv
5d7488b2 605 const char * method
cea2e8a9
GS
606 CODE:
607 walkoptree(aTHX_ opsv, method);
a8a597b2
MB
608
609int
610walkoptree_debug(...)
611 CODE:
89ca4ac7 612 dMY_CXT;
a8a597b2
MB
613 RETVAL = walkoptree_debug;
614 if (items > 0 && SvTRUE(ST(1)))
615 walkoptree_debug = 1;
616 OUTPUT:
617 RETVAL
618
56431972 619#define address(sv) PTR2IV(sv)
a8a597b2
MB
620
621IV
622address(sv)
623 SV * sv
624
625B::SV
626svref_2object(sv)
627 SV * sv
628 CODE:
629 if (!SvROK(sv))
630 croak("argument is not a reference");
631 RETVAL = (SV*)SvRV(sv);
632 OUTPUT:
0cc1d052
NIS
633 RETVAL
634
635void
636opnumber(name)
5d7488b2 637const char * name
0cc1d052
NIS
638CODE:
639{
640 int i;
641 IV result = -1;
642 ST(0) = sv_newmortal();
643 if (strncmp(name,"pp_",3) == 0)
644 name += 3;
645 for (i = 0; i < PL_maxo; i++)
646 {
647 if (strcmp(name, PL_op_name[i]) == 0)
648 {
649 result = i;
650 break;
651 }
652 }
653 sv_setiv(ST(0),result);
654}
a8a597b2
MB
655
656void
657ppname(opnum)
658 int opnum
659 CODE:
660 ST(0) = sv_newmortal();
3280af22 661 if (opnum >= 0 && opnum < PL_maxo) {
a8a597b2 662 sv_setpvn(ST(0), "pp_", 3);
22c35a8c 663 sv_catpv(ST(0), PL_op_name[opnum]);
a8a597b2
MB
664 }
665
666void
667hash(sv)
668 SV * sv
669 CODE:
a8a597b2
MB
670 STRLEN len;
671 U32 hash = 0;
faccc32b 672 char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */
5d7488b2 673 const char *s = SvPV(sv, len);
c32d3395 674 PERL_HASH(hash, s, len);
faccc32b 675 sprintf(hexhash, "0x%"UVxf, (UV)hash);
a8a597b2
MB
676 ST(0) = sv_2mortal(newSVpv(hexhash, 0));
677
678#define cast_I32(foo) (I32)foo
679IV
680cast_I32(i)
681 IV i
682
683void
684minus_c()
685 CODE:
3280af22 686 PL_minus_c = TRUE;
a8a597b2 687
059a8bb7
JH
688void
689save_BEGINs()
690 CODE:
aefff11f 691 PL_savebegin = TRUE;
059a8bb7 692
a8a597b2
MB
693SV *
694cstring(sv)
695 SV * sv
cea2e8a9 696 CODE:
52ad86de
JH
697 RETVAL = cstring(aTHX_ sv, 0);
698 OUTPUT:
699 RETVAL
700
701SV *
702perlstring(sv)
703 SV * sv
704 CODE:
705 RETVAL = cstring(aTHX_ sv, 1);
cea2e8a9
GS
706 OUTPUT:
707 RETVAL
a8a597b2
MB
708
709SV *
710cchar(sv)
711 SV * sv
cea2e8a9
GS
712 CODE:
713 RETVAL = cchar(aTHX_ sv);
714 OUTPUT:
715 RETVAL
a8a597b2
MB
716
717void
718threadsv_names()
719 PPCODE:
f5ba1307
NC
720#if PERL_VERSION <= 8
721# ifdef USE_5005THREADS
722 int i;
5d7488b2 723 const STRLEN len = strlen(PL_threadsv_names);
f5ba1307
NC
724
725 EXTEND(sp, len);
726 for (i = 0; i < len; i++)
727 PUSHs(sv_2mortal(newSVpvn(&PL_threadsv_names[i], 1)));
728# endif
729#endif
a8a597b2
MB
730
731#define OP_next(o) o->op_next
732#define OP_sibling(o) o->op_sibling
27da23d5 733#define OP_desc(o) (char *)PL_op_desc[o->op_type]
a8a597b2
MB
734#define OP_targ(o) o->op_targ
735#define OP_type(o) o->op_type
7252851f
NC
736#if PERL_VERSION >= 9
737# define OP_opt(o) o->op_opt
738# define OP_static(o) o->op_static
739#else
740# define OP_seq(o) o->op_seq
741#endif
a8a597b2
MB
742#define OP_flags(o) o->op_flags
743#define OP_private(o) o->op_private
a60ba18b 744#define OP_spare(o) o->op_spare
a8a597b2
MB
745
746MODULE = B PACKAGE = B::OP PREFIX = OP_
747
651aa52e
AE
748size_t
749OP_size(o)
750 B::OP o
751 CODE:
752 RETVAL = opsizes[cc_opclass(aTHX_ o)];
753 OUTPUT:
754 RETVAL
755
a8a597b2
MB
756B::OP
757OP_next(o)
758 B::OP o
759
760B::OP
761OP_sibling(o)
762 B::OP o
763
764char *
3f872cb9
GS
765OP_name(o)
766 B::OP o
767 CODE:
27da23d5 768 RETVAL = (char *)PL_op_name[o->op_type];
8063af02
DM
769 OUTPUT:
770 RETVAL
3f872cb9
GS
771
772
8063af02 773void
a8a597b2
MB
774OP_ppaddr(o)
775 B::OP o
dc333d64
GS
776 PREINIT:
777 int i;
778 SV *sv = sv_newmortal();
a8a597b2 779 CODE:
dc333d64
GS
780 sv_setpvn(sv, "PL_ppaddr[OP_", 13);
781 sv_catpv(sv, PL_op_name[o->op_type]);
7c436af3 782 for (i=13; (STRLEN)i < SvCUR(sv); ++i)
dc333d64
GS
783 SvPVX(sv)[i] = toUPPER(SvPVX(sv)[i]);
784 sv_catpv(sv, "]");
785 ST(0) = sv;
a8a597b2
MB
786
787char *
788OP_desc(o)
789 B::OP o
790
7934575e 791PADOFFSET
a8a597b2
MB
792OP_targ(o)
793 B::OP o
794
795U16
796OP_type(o)
797 B::OP o
798
7252851f
NC
799#if PERL_VERSION >= 9
800
2814eb74
PJ
801U8
802OP_opt(o)
803 B::OP o
804
805U8
806OP_static(o)
a8a597b2
MB
807 B::OP o
808
7252851f
NC
809#else
810
811U16
812OP_seq(o)
813 B::OP o
814
815#endif
816
a8a597b2
MB
817U8
818OP_flags(o)
819 B::OP o
820
821U8
822OP_private(o)
823 B::OP o
824
7252851f
NC
825#if PERL_VERSION >= 9
826
a60ba18b
JC
827U8
828OP_spare(o)
829 B::OP o
830
7252851f
NC
831#endif
832
1df34986
AE
833void
834OP_oplist(o)
835 B::OP o
836 PPCODE:
837 SP = oplist(aTHX_ o, SP);
838
a8a597b2
MB
839#define UNOP_first(o) o->op_first
840
841MODULE = B PACKAGE = B::UNOP PREFIX = UNOP_
842
843B::OP
844UNOP_first(o)
845 B::UNOP o
846
847#define BINOP_last(o) o->op_last
848
849MODULE = B PACKAGE = B::BINOP PREFIX = BINOP_
850
851B::OP
852BINOP_last(o)
853 B::BINOP o
854
855#define LOGOP_other(o) o->op_other
856
857MODULE = B PACKAGE = B::LOGOP PREFIX = LOGOP_
858
859B::OP
860LOGOP_other(o)
861 B::LOGOP o
862
a8a597b2
MB
863MODULE = B PACKAGE = B::LISTOP PREFIX = LISTOP_
864
c03c2844
SM
865U32
866LISTOP_children(o)
867 B::LISTOP o
868 OP * kid = NO_INIT
869 int i = NO_INIT
870 CODE:
c03c2844
SM
871 i = 0;
872 for (kid = o->op_first; kid; kid = kid->op_sibling)
873 i++;
8063af02
DM
874 RETVAL = i;
875 OUTPUT:
876 RETVAL
c03c2844 877
a8a597b2
MB
878#define PMOP_pmreplroot(o) o->op_pmreplroot
879#define PMOP_pmreplstart(o) o->op_pmreplstart
880#define PMOP_pmnext(o) o->op_pmnext
aaa362c4 881#define PMOP_pmregexp(o) PM_GETRE(o)
9d2bbe64
MB
882#ifdef USE_ITHREADS
883#define PMOP_pmoffset(o) o->op_pmoffset
651aa52e
AE
884#define PMOP_pmstashpv(o) o->op_pmstashpv
885#else
886#define PMOP_pmstash(o) o->op_pmstash
9d2bbe64 887#endif
a8a597b2
MB
888#define PMOP_pmflags(o) o->op_pmflags
889#define PMOP_pmpermflags(o) o->op_pmpermflags
9d2bbe64 890#define PMOP_pmdynflags(o) o->op_pmdynflags
a8a597b2
MB
891
892MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_
893
894void
895PMOP_pmreplroot(o)
896 B::PMOP o
897 OP * root = NO_INIT
898 CODE:
899 ST(0) = sv_newmortal();
900 root = o->op_pmreplroot;
901 /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */
902 if (o->op_type == OP_PUSHRE) {
9d2bbe64
MB
903#ifdef USE_ITHREADS
904 sv_setiv(ST(0), INT2PTR(PADOFFSET,root) );
905#else
a8a597b2
MB
906 sv_setiv(newSVrv(ST(0), root ?
907 svclassnames[SvTYPE((SV*)root)] : "B::SV"),
56431972 908 PTR2IV(root));
9d2bbe64 909#endif
a8a597b2
MB
910 }
911 else {
56431972 912 sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root));
a8a597b2
MB
913 }
914
915B::OP
916PMOP_pmreplstart(o)
917 B::PMOP o
918
919B::PMOP
920PMOP_pmnext(o)
921 B::PMOP o
922
9d2bbe64
MB
923#ifdef USE_ITHREADS
924
925IV
926PMOP_pmoffset(o)
927 B::PMOP o
928
651aa52e
AE
929char*
930PMOP_pmstashpv(o)
931 B::PMOP o
932
933#else
934
935B::HV
936PMOP_pmstash(o)
937 B::PMOP o
938
9d2bbe64
MB
939#endif
940
6e21dc91 941U32
a8a597b2
MB
942PMOP_pmflags(o)
943 B::PMOP o
944
6e21dc91 945U32
a8a597b2
MB
946PMOP_pmpermflags(o)
947 B::PMOP o
948
9d2bbe64
MB
949U8
950PMOP_pmdynflags(o)
951 B::PMOP o
952
a8a597b2
MB
953void
954PMOP_precomp(o)
955 B::PMOP o
956 REGEXP * rx = NO_INIT
957 CODE:
958 ST(0) = sv_newmortal();
aaa362c4 959 rx = PM_GETRE(o);
a8a597b2
MB
960 if (rx)
961 sv_setpvn(ST(0), rx->precomp, rx->prelen);
962
ac33dcd1
JH
963#define SVOP_sv(o) cSVOPo->op_sv
964#define SVOP_gv(o) ((GV*)cSVOPo->op_sv)
a8a597b2
MB
965
966MODULE = B PACKAGE = B::SVOP PREFIX = SVOP_
967
a8a597b2
MB
968B::SV
969SVOP_sv(o)
970 B::SVOP o
971
f22444f5 972B::GV
065a1863
GS
973SVOP_gv(o)
974 B::SVOP o
975
7934575e 976#define PADOP_padix(o) o->op_padix
dd2155a4 977#define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv)
7934575e 978#define PADOP_gv(o) ((o->op_padix \
dd2155a4
DM
979 && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \
980 ? (GV*)PAD_SVl(o->op_padix) : Nullgv)
a8a597b2 981
7934575e
GS
982MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_
983
984PADOFFSET
985PADOP_padix(o)
986 B::PADOP o
987
988B::SV
989PADOP_sv(o)
990 B::PADOP o
a8a597b2
MB
991
992B::GV
7934575e
GS
993PADOP_gv(o)
994 B::PADOP o
a8a597b2
MB
995
996MODULE = B PACKAGE = B::PVOP PREFIX = PVOP_
997
998void
999PVOP_pv(o)
1000 B::PVOP o
1001 CODE:
1002 /*
bec89253 1003 * OP_TRANS uses op_pv to point to a table of 256 or >=258 shorts
a8a597b2
MB
1004 * whereas other PVOPs point to a null terminated string.
1005 */
bec89253
RH
1006 if (o->op_type == OP_TRANS &&
1007 (o->op_private & OPpTRANS_COMPLEMENT) &&
1008 !(o->op_private & OPpTRANS_DELETE))
1009 {
5d7488b2
AL
1010 const short* const tbl = (short*)o->op_pv;
1011 const short entries = 257 + tbl[256];
bec89253
RH
1012 ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short)));
1013 }
1014 else if (o->op_type == OP_TRANS) {
1015 ST(0) = sv_2mortal(newSVpv(o->op_pv, 256 * sizeof(short)));
1016 }
1017 else
1018 ST(0) = sv_2mortal(newSVpv(o->op_pv, 0));
a8a597b2
MB
1019
1020#define LOOP_redoop(o) o->op_redoop
1021#define LOOP_nextop(o) o->op_nextop
1022#define LOOP_lastop(o) o->op_lastop
1023
1024MODULE = B PACKAGE = B::LOOP PREFIX = LOOP_
1025
1026
1027B::OP
1028LOOP_redoop(o)
1029 B::LOOP o
1030
1031B::OP
1032LOOP_nextop(o)
1033 B::LOOP o
1034
1035B::OP
1036LOOP_lastop(o)
1037 B::LOOP o
1038
1039#define COP_label(o) o->cop_label
11faa288
GS
1040#define COP_stashpv(o) CopSTASHPV(o)
1041#define COP_stash(o) CopSTASH(o)
57843af0 1042#define COP_file(o) CopFILE(o)
1df34986 1043#define COP_filegv(o) CopFILEGV(o)
a8a597b2
MB
1044#define COP_cop_seq(o) o->cop_seq
1045#define COP_arybase(o) o->cop_arybase
57843af0 1046#define COP_line(o) CopLINE(o)
b295d113 1047#define COP_warnings(o) o->cop_warnings
6e6a1aef 1048#define COP_io(o) o->cop_io
a8a597b2
MB
1049
1050MODULE = B PACKAGE = B::COP PREFIX = COP_
1051
1052char *
1053COP_label(o)
1054 B::COP o
1055
11faa288
GS
1056char *
1057COP_stashpv(o)
1058 B::COP o
1059
a8a597b2
MB
1060B::HV
1061COP_stash(o)
1062 B::COP o
1063
57843af0
GS
1064char *
1065COP_file(o)
a8a597b2
MB
1066 B::COP o
1067
1df34986
AE
1068B::GV
1069COP_filegv(o)
1070 B::COP o
1071
1072
a8a597b2
MB
1073U32
1074COP_cop_seq(o)
1075 B::COP o
1076
1077I32
1078COP_arybase(o)
1079 B::COP o
1080
8bafa735 1081U32
a8a597b2
MB
1082COP_line(o)
1083 B::COP o
1084
b295d113
TH
1085B::SV
1086COP_warnings(o)
1087 B::COP o
1088
6e6a1aef
RGS
1089B::SV
1090COP_io(o)
1091 B::COP o
1092
651aa52e
AE
1093MODULE = B PACKAGE = B::SV
1094
1095U32
1096SvTYPE(sv)
1097 B::SV sv
1098
429a5ce7
SM
1099#define object_2svref(sv) sv
1100#define SVREF SV *
1101
1102SVREF
1103object_2svref(sv)
1104 B::SV sv
1105
a8a597b2
MB
1106MODULE = B PACKAGE = B::SV PREFIX = Sv
1107
1108U32
1109SvREFCNT(sv)
1110 B::SV sv
1111
1112U32
1113SvFLAGS(sv)
1114 B::SV sv
1115
651aa52e
AE
1116U32
1117SvPOK(sv)
1118 B::SV sv
1119
1120U32
1121SvROK(sv)
1122 B::SV sv
1123
1124U32
1125SvMAGICAL(sv)
1126 B::SV sv
1127
a8a597b2
MB
1128MODULE = B PACKAGE = B::IV PREFIX = Sv
1129
1130IV
1131SvIV(sv)
1132 B::IV sv
1133
1134IV
1135SvIVX(sv)
1136 B::IV sv
1137
0ca04487
VB
1138UV
1139SvUVX(sv)
1140 B::IV sv
1141
1142
a8a597b2
MB
1143MODULE = B PACKAGE = B::IV
1144
1145#define needs64bits(sv) ((I32)SvIVX(sv) != SvIVX(sv))
1146
1147int
1148needs64bits(sv)
1149 B::IV sv
1150
1151void
1152packiv(sv)
1153 B::IV sv
1154 CODE:
1155 if (sizeof(IV) == 8) {
1156 U32 wp[2];
5d7488b2 1157 const IV iv = SvIVX(sv);
a8a597b2
MB
1158 /*
1159 * The following way of spelling 32 is to stop compilers on
1160 * 32-bit architectures from moaning about the shift count
1161 * being >= the width of the type. Such architectures don't
1162 * reach this code anyway (unless sizeof(IV) > 8 but then
1163 * everything else breaks too so I'm not fussed at the moment).
1164 */
42718184
RB
1165#ifdef UV_IS_QUAD
1166 wp[0] = htonl(((UV)iv) >> (sizeof(UV)*4));
1167#else
1168 wp[0] = htonl(((U32)iv) >> (sizeof(UV)*4));
1169#endif
a8a597b2 1170 wp[1] = htonl(iv & 0xffffffff);
79cb57f6 1171 ST(0) = sv_2mortal(newSVpvn((char *)wp, 8));
a8a597b2
MB
1172 } else {
1173 U32 w = htonl((U32)SvIVX(sv));
79cb57f6 1174 ST(0) = sv_2mortal(newSVpvn((char *)&w, 4));
a8a597b2
MB
1175 }
1176
1177MODULE = B PACKAGE = B::NV PREFIX = Sv
1178
76ef7183 1179NV
a8a597b2
MB
1180SvNV(sv)
1181 B::NV sv
1182
76ef7183 1183NV
a8a597b2
MB
1184SvNVX(sv)
1185 B::NV sv
1186
1187MODULE = B PACKAGE = B::RV PREFIX = Sv
1188
1189B::SV
1190SvRV(sv)
1191 B::RV sv
1192
1193MODULE = B PACKAGE = B::PV PREFIX = Sv
1194
0b40bd6d
RH
1195char*
1196SvPVX(sv)
1197 B::PV sv
1198
b326da91
MB
1199B::SV
1200SvRV(sv)
1201 B::PV sv
1202 CODE:
1203 if( SvROK(sv) ) {
1204 RETVAL = SvRV(sv);
1205 }
1206 else {
1207 croak( "argument is not SvROK" );
1208 }
1209 OUTPUT:
1210 RETVAL
1211
a8a597b2
MB
1212void
1213SvPV(sv)
1214 B::PV sv
1215 CODE:
b326da91 1216 ST(0) = sv_newmortal();
c0b20461 1217 if( SvPOK(sv) ) {
b55685ae
NC
1218 /* FIXME - we need a better way for B to identify PVs that are
1219 in the pads as variable names. */
1220 if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) {
1221 /* It claims to be longer than the space allocated for it -
1222 presuambly it's a variable name in the pad */
1223 sv_setpv(ST(0), SvPV_nolen_const(sv));
1224 } else {
1225 sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv));
1226 }
b326da91
MB
1227 SvFLAGS(ST(0)) |= SvUTF8(sv);
1228 }
1229 else {
1230 /* XXX for backward compatibility, but should fail */
1231 /* croak( "argument is not SvPOK" ); */
1232 sv_setpvn(ST(0), NULL, 0);
1233 }
a8a597b2 1234
651aa52e
AE
1235void
1236SvPVBM(sv)
1237 B::PV sv
1238 CODE:
1239 ST(0) = sv_newmortal();
aa07b2f6 1240 sv_setpvn(ST(0), SvPVX_const(sv),
651aa52e
AE
1241 SvCUR(sv) + (SvTYPE(sv) == SVt_PVBM ? 257 : 0));
1242
1243
445a12f6
DM
1244STRLEN
1245SvLEN(sv)
1246 B::PV sv
1247
1248STRLEN
1249SvCUR(sv)
1250 B::PV sv
1251
a8a597b2
MB
1252MODULE = B PACKAGE = B::PVMG PREFIX = Sv
1253
1254void
1255SvMAGIC(sv)
1256 B::PVMG sv
1257 MAGIC * mg = NO_INIT
1258 PPCODE:
1259 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
cea2e8a9 1260 XPUSHs(make_mg_object(aTHX_ sv_newmortal(), mg));
a8a597b2
MB
1261
1262MODULE = B PACKAGE = B::PVMG
1263
1264B::HV
1265SvSTASH(sv)
1266 B::PVMG sv
1267
1268#define MgMOREMAGIC(mg) mg->mg_moremagic
1269#define MgPRIVATE(mg) mg->mg_private
1270#define MgTYPE(mg) mg->mg_type
1271#define MgFLAGS(mg) mg->mg_flags
1272#define MgOBJ(mg) mg->mg_obj
88b39979 1273#define MgLENGTH(mg) mg->mg_len
bde7177d 1274#define MgREGEX(mg) PTR2IV(mg->mg_obj)
a8a597b2
MB
1275
1276MODULE = B PACKAGE = B::MAGIC PREFIX = Mg
1277
1278B::MAGIC
1279MgMOREMAGIC(mg)
1280 B::MAGIC mg
c5f0f3aa
RGS
1281 CODE:
1282 if( MgMOREMAGIC(mg) ) {
1283 RETVAL = MgMOREMAGIC(mg);
1284 }
1285 else {
1286 XSRETURN_UNDEF;
1287 }
1288 OUTPUT:
1289 RETVAL
a8a597b2
MB
1290
1291U16
1292MgPRIVATE(mg)
1293 B::MAGIC mg
1294
1295char
1296MgTYPE(mg)
1297 B::MAGIC mg
1298
1299U8
1300MgFLAGS(mg)
1301 B::MAGIC mg
1302
1303B::SV
1304MgOBJ(mg)
1305 B::MAGIC mg
b326da91 1306
9d2bbe64
MB
1307IV
1308MgREGEX(mg)
1309 B::MAGIC mg
1310 CODE:
1311 if( mg->mg_type == 'r' ) {
1312 RETVAL = MgREGEX(mg);
1313 }
1314 else {
1315 croak( "REGEX is only meaningful on r-magic" );
1316 }
1317 OUTPUT:
1318 RETVAL
1319
b326da91
MB
1320SV*
1321precomp(mg)
1322 B::MAGIC mg
1323 CODE:
1324 if (mg->mg_type == 'r') {
1325 REGEXP* rx = (REGEXP*)mg->mg_obj;
1326 if( rx )
1327 RETVAL = newSVpvn( rx->precomp, rx->prelen );
1328 }
1329 else {
1330 croak( "precomp is only meaningful on r-magic" );
1331 }
1332 OUTPUT:
1333 RETVAL
a8a597b2 1334
88b39979
VB
1335I32
1336MgLENGTH(mg)
1337 B::MAGIC mg
1338
a8a597b2
MB
1339void
1340MgPTR(mg)
1341 B::MAGIC mg
1342 CODE:
1343 ST(0) = sv_newmortal();
88b39979
VB
1344 if (mg->mg_ptr){
1345 if (mg->mg_len >= 0){
1346 sv_setpvn(ST(0), mg->mg_ptr, mg->mg_len);
651aa52e
AE
1347 } else if (mg->mg_len == HEf_SVKEY) {
1348 ST(0) = make_sv_object(aTHX_
1349 sv_newmortal(), (SV*)mg->mg_ptr);
88b39979
VB
1350 }
1351 }
a8a597b2
MB
1352
1353MODULE = B PACKAGE = B::PVLV PREFIX = Lv
1354
1355U32
1356LvTARGOFF(sv)
1357 B::PVLV sv
1358
1359U32
1360LvTARGLEN(sv)
1361 B::PVLV sv
1362
1363char
1364LvTYPE(sv)
1365 B::PVLV sv
1366
1367B::SV
1368LvTARG(sv)
1369 B::PVLV sv
1370
1371MODULE = B PACKAGE = B::BM PREFIX = Bm
1372
1373I32
1374BmUSEFUL(sv)
1375 B::BM sv
1376
1377U16
1378BmPREVIOUS(sv)
1379 B::BM sv
1380
1381U8
1382BmRARE(sv)
1383 B::BM sv
1384
1385void
1386BmTABLE(sv)
1387 B::BM sv
1388 STRLEN len = NO_INIT
1389 char * str = NO_INIT
1390 CODE:
1391 str = SvPV(sv, len);
1392 /* Boyer-Moore table is just after string and its safety-margin \0 */
79cb57f6 1393 ST(0) = sv_2mortal(newSVpvn(str + len + 1, 256));
a8a597b2
MB
1394
1395MODULE = B PACKAGE = B::GV PREFIX = Gv
1396
1397void
1398GvNAME(gv)
1399 B::GV gv
1400 CODE:
79cb57f6 1401 ST(0) = sv_2mortal(newSVpvn(GvNAME(gv), GvNAMELEN(gv)));
a8a597b2 1402
87d7fd28
GS
1403bool
1404is_empty(gv)
1405 B::GV gv
1406 CODE:
1407 RETVAL = GvGP(gv) == Null(GP*);
1408 OUTPUT:
1409 RETVAL
1410
651aa52e
AE
1411void*
1412GvGP(gv)
1413 B::GV gv
1414
a8a597b2
MB
1415B::HV
1416GvSTASH(gv)
1417 B::GV gv
1418
1419B::SV
1420GvSV(gv)
1421 B::GV gv
1422
1423B::IO
1424GvIO(gv)
1425 B::GV gv
1426
1df34986 1427B::FM
a8a597b2
MB
1428GvFORM(gv)
1429 B::GV gv
1df34986
AE
1430 CODE:
1431 RETVAL = (SV*)GvFORM(gv);
1432 OUTPUT:
1433 RETVAL
a8a597b2
MB
1434
1435B::AV
1436GvAV(gv)
1437 B::GV gv
1438
1439B::HV
1440GvHV(gv)
1441 B::GV gv
1442
1443B::GV
1444GvEGV(gv)
1445 B::GV gv
1446
1447B::CV
1448GvCV(gv)
1449 B::GV gv
1450
1451U32
1452GvCVGEN(gv)
1453 B::GV gv
1454
8bafa735 1455U32
a8a597b2
MB
1456GvLINE(gv)
1457 B::GV gv
1458
b195d487
GS
1459char *
1460GvFILE(gv)
1461 B::GV gv
1462
a8a597b2
MB
1463B::GV
1464GvFILEGV(gv)
1465 B::GV gv
1466
1467MODULE = B PACKAGE = B::GV
1468
1469U32
1470GvREFCNT(gv)
1471 B::GV gv
1472
1473U8
1474GvFLAGS(gv)
1475 B::GV gv
1476
1477MODULE = B PACKAGE = B::IO PREFIX = Io
1478
1479long
1480IoLINES(io)
1481 B::IO io
1482
1483long
1484IoPAGE(io)
1485 B::IO io
1486
1487long
1488IoPAGE_LEN(io)
1489 B::IO io
1490
1491long
1492IoLINES_LEFT(io)
1493 B::IO io
1494
1495char *
1496IoTOP_NAME(io)
1497 B::IO io
1498
1499B::GV
1500IoTOP_GV(io)
1501 B::IO io
1502
1503char *
1504IoFMT_NAME(io)
1505 B::IO io
1506
1507B::GV
1508IoFMT_GV(io)
1509 B::IO io
1510
1511char *
1512IoBOTTOM_NAME(io)
1513 B::IO io
1514
1515B::GV
1516IoBOTTOM_GV(io)
1517 B::IO io
1518
1519short
1520IoSUBPROCESS(io)
1521 B::IO io
1522
b326da91
MB
1523bool
1524IsSTD(io,name)
1525 B::IO io
5d7488b2 1526 const char* name
b326da91
MB
1527 PREINIT:
1528 PerlIO* handle = 0;
1529 CODE:
1530 if( strEQ( name, "stdin" ) ) {
1531 handle = PerlIO_stdin();
1532 }
1533 else if( strEQ( name, "stdout" ) ) {
1534 handle = PerlIO_stdout();
1535 }
1536 else if( strEQ( name, "stderr" ) ) {
1537 handle = PerlIO_stderr();
1538 }
1539 else {
1540 croak( "Invalid value '%s'", name );
1541 }
1542 RETVAL = handle == IoIFP(io);
1543 OUTPUT:
1544 RETVAL
1545
a8a597b2
MB
1546MODULE = B PACKAGE = B::IO
1547
1548char
1549IoTYPE(io)
1550 B::IO io
1551
1552U8
1553IoFLAGS(io)
1554 B::IO io
1555
1556MODULE = B PACKAGE = B::AV PREFIX = Av
1557
1558SSize_t
1559AvFILL(av)
1560 B::AV av
1561
1562SSize_t
1563AvMAX(av)
1564 B::AV av
1565
a8a597b2
MB
1566void
1567AvARRAY(av)
1568 B::AV av
1569 PPCODE:
1570 if (AvFILL(av) >= 0) {
1571 SV **svp = AvARRAY(av);
1572 I32 i;
1573 for (i = 0; i <= AvFILL(av); i++)
cea2e8a9 1574 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), svp[i]));
a8a597b2
MB
1575 }
1576
429a5ce7
SM
1577void
1578AvARRAYelt(av, idx)
1579 B::AV av
1580 int idx
1581 PPCODE:
1582 if (idx >= 0 && AvFILL(av) >= 0 && idx <= AvFILL(av))
1583 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), (AvARRAY(av)[idx])));
1584 else
1585 XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL));
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) ?
07409e01 1647 make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) :
651aa52e 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
a8a597b2
MB
1685void
1686HvARRAY(hv)
1687 B::HV hv
1688 PPCODE:
1689 if (HvKEYS(hv) > 0) {
1690 SV *sv;
1691 char *key;
1692 I32 len;
1693 (void)hv_iterinit(hv);
1694 EXTEND(sp, HvKEYS(hv) * 2);
8063af02 1695 while ((sv = hv_iternextsv(hv, &key, &len))) {
79cb57f6 1696 PUSHs(newSVpvn(key, len));
cea2e8a9 1697 PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
a8a597b2
MB
1698 }
1699 }