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