X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FB%2FB.xs;h=eca6f08870c718c0e8607c09125f275b76122f9b;hb=597c4554ca87aa4325a00c70a0fbb22acbfcfa07;hp=107d3a6ccecadc48d4c39f10e13e5f8803bd0c79;hpb=5464c1495ed0e2dec7738478e7bb89ce97a68c52;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/B/B.xs b/ext/B/B.xs index 107d3a6..eca6f08 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -19,16 +19,26 @@ typedef FILE * InputStream; #endif -static char *svclassnames[] = { +static const char* const svclassnames[] = { "B::NULL", +#if PERL_VERSION >= 9 + "B::BIND", +#endif "B::IV", "B::NV", +#if PERL_VERSION <= 10 "B::RV", +#endif "B::PV", "B::PVIV", "B::PVNV", "B::PVMG", +#if PERL_VERSION <= 8 "B::BM", +#endif +#if PERL_VERSION >= 11 + "B::REGEXP", +#endif #if PERL_VERSION >= 9 "B::GV", #endif @@ -58,7 +68,7 @@ typedef enum { OPc_COP /* 11 */ } opclass; -static char *opclassnames[] = { +static const char* const opclassnames[] = { "B::NULL", "B::OP", "B::UNOP", @@ -73,7 +83,7 @@ static char *opclassnames[] = { "B::COP" }; -static size_t opsizes[] = { +static const size_t opsizes[] = { 0, sizeof(OP), sizeof(UNOP), @@ -101,7 +111,7 @@ START_MY_CXT #define specialsv_list (MY_CXT.x_specialsv_list) static opclass -cc_opclass(pTHX_ OP *o) +cc_opclass(pTHX_ const OP *o) { if (!o) return OPc_NULL; @@ -112,9 +122,20 @@ cc_opclass(pTHX_ OP *o) if (o->op_type == OP_SASSIGN) return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP); + if (o->op_type == OP_AELEMFAST) { + if (o->op_flags & OPf_SPECIAL) + return OPc_BASEOP; + else +#ifdef USE_ITHREADS + return OPc_PADOP; +#else + return OPc_SVOP; +#endif + } + #ifdef USE_ITHREADS if (o->op_type == OP_GV || o->op_type == OP_GVSV || - o->op_type == OP_AELEMFAST || o->op_type == OP_RCATLINE) + o->op_type == OP_RCATLINE) return OPc_PADOP; #endif @@ -209,15 +230,15 @@ cc_opclass(pTHX_ OP *o) } static char * -cc_opclassname(pTHX_ OP *o) +cc_opclassname(pTHX_ const OP *o) { - return opclassnames[cc_opclass(aTHX_ o)]; + return (char *)opclassnames[cc_opclass(aTHX_ o)]; } static SV * make_sv_object(pTHX_ SV *arg, SV *sv) { - char *type = 0; + const char *type = 0; IV iv; dMY_CXT; @@ -235,6 +256,71 @@ make_sv_object(pTHX_ SV *arg, SV *sv) return arg; } +#if PERL_VERSION >= 9 +static SV * +make_temp_object(pTHX_ SV *arg, SV *temp) +{ + SV *target; + const char *const type = svclassnames[SvTYPE(temp)]; + const IV iv = PTR2IV(temp); + + target = newSVrv(arg, type); + sv_setiv(target, iv); + + /* Need to keep our "temp" around as long as the target exists. + Simplest way seems to be to hang it from magic, and let that clear + it up. No vtable, so won't actually get in the way of anything. */ + sv_magicext(target, temp, PERL_MAGIC_sv, NULL, NULL, 0); + /* magic object has had its reference count increased, so we must drop + our reference. */ + SvREFCNT_dec(temp); + return arg; +} + +static SV * +make_warnings_object(pTHX_ SV *arg, STRLEN *warnings) +{ + const char *type = 0; + dMY_CXT; + IV iv = sizeof(specialsv_list)/sizeof(SV*); + + /* Counting down is deliberate. Before the split between make_sv_object + and make_warnings_obj there appeared to be a bug - Nullsv and pWARN_STD + were both 0, so you could never get a B::SPECIAL for pWARN_STD */ + + while (iv--) { + if ((SV*)warnings == specialsv_list[iv]) { + type = "B::SPECIAL"; + break; + } + } + if (type) { + sv_setiv(newSVrv(arg, type), iv); + return arg; + } else { + /* B assumes that warnings are a regular SV. Seems easier to keep it + happy by making them into a regular SV. */ + return make_temp_object(aTHX_ arg, + newSVpvn((char *)(warnings + 1), *warnings)); + } +} + +static SV * +make_cop_io_object(pTHX_ SV *arg, COP *cop) +{ + SV *const value = newSV(0); + + Perl_emulate_cop_io(aTHX_ cop, value); + + if(SvOK(value)) { + return make_temp_object(aTHX_ arg, newSVsv(value)); + } else { + SvREFCNT_dec(value); + return make_sv_object(aTHX_ arg, NULL); + } +} +#endif + static SV * make_mg_object(pTHX_ SV *arg, MAGIC *mg) { @@ -246,32 +332,28 @@ static SV * cstring(pTHX_ SV *sv, bool perlstyle) { SV *sstr = newSVpvn("", 0); - STRLEN len; - char *s; - char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */ if (!SvOK(sv)) sv_setpvn(sstr, "0", 1); - else if (perlstyle && SvUTF8(sv)) - { + else if (perlstyle && SvUTF8(sv)) { SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */ - len = SvCUR(sv); - s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ); - sv_setpv(sstr,"\""); + const STRLEN len = SvCUR(sv); + const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ); + sv_setpvn(sstr,"\"",1); while (*s) { if (*s == '"') - sv_catpv(sstr, "\\\""); + sv_catpvn(sstr, "\\\"", 2); else if (*s == '$') - sv_catpv(sstr, "\\$"); + sv_catpvn(sstr, "\\$", 2); else if (*s == '@') - sv_catpv(sstr, "\\@"); + sv_catpvn(sstr, "\\@", 2); else if (*s == '\\') { if (strchr("nrftax\\",*(s+1))) sv_catpvn(sstr, s++, 2); else - sv_catpv(sstr, "\\\\"); + sv_catpvn(sstr, "\\\\", 2); } else /* should always be printable */ sv_catpvn(sstr, s, 1); @@ -283,7 +365,8 @@ cstring(pTHX_ SV *sv, bool perlstyle) else { /* XXX Optimise? */ - s = SvPV(sv, len); + STRLEN len; + const char *s = SvPV(sv, len); sv_catpv(sstr, "\""); for (; len; len--, s++) { @@ -293,8 +376,8 @@ cstring(pTHX_ SV *sv, bool perlstyle) else if (*s == '\\') sv_catpv(sstr, "\\\\"); /* trigraphs - bleagh */ - else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') - { + else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') { + char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */ sprintf(escbuff, "\\%03o", '?'); sv_catpv(sstr, escbuff); } @@ -325,7 +408,8 @@ cstring(pTHX_ SV *sv, bool perlstyle) else { /* Don't want promotion of a signed -1 char in sprintf args */ - unsigned char c = (unsigned char) *s; + char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */ + const unsigned char c = (unsigned char) *s; sprintf(escbuff, "\\%03o", c); sv_catpv(sstr, escbuff); } @@ -340,13 +424,12 @@ static SV * cchar(pTHX_ SV *sv) { SV *sstr = newSVpvn("'", 1); - STRLEN n_a; - char *s = SvPV(sv, n_a); + const char *s = SvPV_nolen(sv); if (*s == '\'') - sv_catpv(sstr, "\\'"); + sv_catpvn(sstr, "\\'", 2); else if (*s == '\\') - sv_catpv(sstr, "\\\\"); + sv_catpvn(sstr, "\\\\", 2); #ifdef EBCDIC else if (isPRINT(*s)) #else @@ -354,19 +437,19 @@ cchar(pTHX_ SV *sv) #endif /* EBCDIC */ sv_catpvn(sstr, s, 1); else if (*s == '\n') - sv_catpv(sstr, "\\n"); + sv_catpvn(sstr, "\\n", 2); else if (*s == '\r') - sv_catpv(sstr, "\\r"); + sv_catpvn(sstr, "\\r", 2); else if (*s == '\t') - sv_catpv(sstr, "\\t"); + sv_catpvn(sstr, "\\t", 2); else if (*s == '\a') - sv_catpv(sstr, "\\a"); + sv_catpvn(sstr, "\\a", 2); else if (*s == '\b') - sv_catpv(sstr, "\\b"); + sv_catpvn(sstr, "\\b", 2); else if (*s == '\f') - sv_catpv(sstr, "\\f"); + sv_catpvn(sstr, "\\f", 2); else if (*s == '\v') - sv_catpv(sstr, "\\v"); + sv_catpvn(sstr, "\\v", 2); else { /* no trigraph support */ @@ -376,12 +459,22 @@ cchar(pTHX_ SV *sv) sprintf(escbuff, "\\%03o", c); sv_catpv(sstr, escbuff); } - sv_catpv(sstr, "'"); + sv_catpvn(sstr, "'", 1); return sstr; } -void -walkoptree(pTHX_ SV *opsv, char *method) +#if PERL_VERSION >= 9 +# define PMOP_pmreplstart(o) o->op_pmstashstartu.op_pmreplstart +# define PMOP_pmreplroot(o) o->op_pmreplrootu.op_pmreplroot +#else +# define PMOP_pmreplstart(o) o->op_pmreplstart +# define PMOP_pmreplroot(o) o->op_pmreplroot +# define PMOP_pmpermflags(o) o->op_pmpermflags +# define PMOP_pmdynflags(o) o->op_pmdynflags +#endif + +static void +walkoptree(pTHX_ SV *opsv, const char *method) { dSP; OP *o, *kid; @@ -409,14 +502,14 @@ walkoptree(pTHX_ SV *opsv, char *method) } } if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE - && (kid = cPMOPo->op_pmreplroot)) + && (kid = PMOP_pmreplroot(cPMOPo))) { sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid)); walkoptree(aTHX_ opsv, method); } } -SV ** +static SV ** oplist(pTHX_ OP *o, SV **SP) { for(; o; o = o->op_next) { @@ -435,7 +528,7 @@ oplist(pTHX_ OP *o, SV **SP) XPUSHs(opsv); switch (o->op_type) { case OP_SUBST: - SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP); + SP = oplist(aTHX_ PMOP_pmreplstart(cPMOPo), SP); continue; case OP_SORT: if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) { @@ -477,6 +570,9 @@ typedef SV *B__IV; typedef SV *B__PV; typedef SV *B__NV; typedef SV *B__PVMG; +#if PERL_VERSION >= 11 +typedef SV *B__REGEXP; +#endif typedef SV *B__PVLV; typedef SV *B__BM; typedef SV *B__RV; @@ -488,6 +584,10 @@ typedef GV *B__GV; typedef IO *B__IO; typedef MAGIC *B__MAGIC; +typedef HE *B__HE; +#if PERL_VERSION >= 9 +typedef struct refcounted_he *B__RHE; +#endif MODULE = B PACKAGE = B PREFIX = B_ @@ -495,18 +595,18 @@ PROTOTYPES: DISABLE BOOT: { - HV *stash = gv_stashpvn("B", 1, TRUE); + HV *stash = gv_stashpvn("B", 1, GV_ADD); AV *export_ok = perl_get_av("B::EXPORT_OK",TRUE); MY_CXT_INIT; specialsv_list[0] = Nullsv; specialsv_list[1] = &PL_sv_undef; specialsv_list[2] = &PL_sv_yes; specialsv_list[3] = &PL_sv_no; - specialsv_list[4] = pWARN_ALL; - specialsv_list[5] = pWARN_NONE; - specialsv_list[6] = pWARN_STD; + specialsv_list[4] = (SV *) pWARN_ALL; + specialsv_list[5] = (SV *) pWARN_NONE; + specialsv_list[6] = (SV *) pWARN_STD; #if PERL_VERSION <= 8 -# define CVf_ASSERTION 0 +# define OPpPAD_STATE 0 #endif #include "defsubs.h" } @@ -515,11 +615,17 @@ BOOT: #define B_init_av() PL_initav #define B_inc_gv() PL_incgv #define B_check_av() PL_checkav_save +#if PERL_VERSION > 8 +# define B_unitcheck_av() PL_unitcheckav_save +#else +# define B_unitcheck_av() NULL +#endif #define B_begin_av() PL_beginav_save #define B_end_av() PL_endav #define B_main_root() PL_main_root #define B_main_start() PL_main_start #define B_amagic_generation() PL_amagic_generation +#define B_sub_generation() PL_sub_generation #define B_defstash() PL_defstash #define B_curstash() PL_curstash #define B_dowarn() PL_dowarn @@ -538,6 +644,13 @@ B_init_av() B::AV B_check_av() +#if PERL_VERSION >= 9 + +B::AV +B_unitcheck_av() + +#endif + B::AV B_begin_av() @@ -566,6 +679,9 @@ B_main_start() long B_amagic_generation() +long +B_sub_generation() + B::AV B_comppadlist() @@ -605,7 +721,7 @@ MODULE = B PACKAGE = B void walkoptree(opsv, method) SV * opsv - char * method + const char * method CODE: walkoptree(aTHX_ opsv, method); @@ -637,7 +753,7 @@ svref_2object(sv) void opnumber(name) -char * name +const char * name CODE: { int i; @@ -670,11 +786,10 @@ void hash(sv) SV * sv CODE: - char *s; STRLEN len; U32 hash = 0; char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */ - s = SvPV(sv, len); + const char *s = SvPV(sv, len); PERL_HASH(hash, s, len); sprintf(hexhash, "0x%"UVxf, (UV)hash); ST(0) = sv_2mortal(newSVpv(hexhash, 0)); @@ -724,7 +839,7 @@ threadsv_names() #if PERL_VERSION <= 8 # ifdef USE_5005THREADS int i; - STRLEN len = strlen(PL_threadsv_names); + const STRLEN len = strlen(PL_threadsv_names); EXTEND(sp, len); for (i = 0; i < len; i++) @@ -734,12 +849,11 @@ threadsv_names() #define OP_next(o) o->op_next #define OP_sibling(o) o->op_sibling -#define OP_desc(o) PL_op_desc[o->op_type] +#define OP_desc(o) (char *)PL_op_desc[o->op_type] #define OP_targ(o) o->op_targ #define OP_type(o) o->op_type #if PERL_VERSION >= 9 # define OP_opt(o) o->op_opt -# define OP_static(o) o->op_static #else # define OP_seq(o) o->op_seq #endif @@ -769,7 +883,7 @@ char * OP_name(o) B::OP o CODE: - RETVAL = PL_op_name[o->op_type]; + RETVAL = (char *)PL_op_name[o->op_type]; OUTPUT: RETVAL @@ -802,14 +916,10 @@ OP_type(o) #if PERL_VERSION >= 9 -U8 +U16 OP_opt(o) B::OP o -U8 -OP_static(o) - B::OP o - #else U16 @@ -828,7 +938,7 @@ OP_private(o) #if PERL_VERSION >= 9 -U8 +U16 OP_spare(o) B::OP o @@ -879,22 +989,20 @@ LISTOP_children(o) OUTPUT: RETVAL -#define PMOP_pmreplroot(o) o->op_pmreplroot -#define PMOP_pmreplstart(o) o->op_pmreplstart #define PMOP_pmnext(o) o->op_pmnext #define PMOP_pmregexp(o) PM_GETRE(o) #ifdef USE_ITHREADS #define PMOP_pmoffset(o) o->op_pmoffset -#define PMOP_pmstashpv(o) o->op_pmstashpv +#define PMOP_pmstashpv(o) PmopSTASHPV(o); #else -#define PMOP_pmstash(o) o->op_pmstash +#define PMOP_pmstash(o) PmopSTASH(o); #endif #define PMOP_pmflags(o) o->op_pmflags -#define PMOP_pmpermflags(o) o->op_pmpermflags -#define PMOP_pmdynflags(o) o->op_pmdynflags MODULE = B PACKAGE = B::PMOP PREFIX = PMOP_ +#if PERL_VERSION <= 8 + void PMOP_pmreplroot(o) B::PMOP o @@ -904,26 +1012,55 @@ PMOP_pmreplroot(o) root = o->op_pmreplroot; /* OP_PUSHRE stores an SV* instead of an OP* in op_pmreplroot */ if (o->op_type == OP_PUSHRE) { -#ifdef USE_ITHREADS +# ifdef USE_ITHREADS sv_setiv(ST(0), INT2PTR(PADOFFSET,root) ); -#else +# else sv_setiv(newSVrv(ST(0), root ? svclassnames[SvTYPE((SV*)root)] : "B::SV"), PTR2IV(root)); -#endif +# endif } else { sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), PTR2IV(root)); } +#else + +void +PMOP_pmreplroot(o) + B::PMOP o + CODE: + ST(0) = sv_newmortal(); + if (o->op_type == OP_PUSHRE) { +# ifdef USE_ITHREADS + sv_setiv(ST(0), o->op_pmreplrootu.op_pmtargetoff); +# else + GV *const target = o->op_pmreplrootu.op_pmtargetgv; + sv_setiv(newSVrv(ST(0), target ? + svclassnames[SvTYPE((SV*)target)] : "B::SV"), + PTR2IV(target)); +# endif + } + else { + OP *const root = o->op_pmreplrootu.op_pmreplroot; + sv_setiv(newSVrv(ST(0), cc_opclassname(aTHX_ root)), + PTR2IV(root)); + } + +#endif + B::OP PMOP_pmreplstart(o) B::PMOP o +#if PERL_VERSION < 9 + B::PMOP PMOP_pmnext(o) B::PMOP o +#endif + #ifdef USE_ITHREADS IV @@ -946,6 +1083,8 @@ U32 PMOP_pmflags(o) B::PMOP o +#if PERL_VERSION < 9 + U32 PMOP_pmpermflags(o) B::PMOP o @@ -954,6 +1093,8 @@ U8 PMOP_pmdynflags(o) B::PMOP o +#endif + void PMOP_precomp(o) B::PMOP o @@ -962,7 +1103,21 @@ PMOP_precomp(o) ST(0) = sv_newmortal(); rx = PM_GETRE(o); if (rx) - sv_setpvn(ST(0), rx->precomp, rx->prelen); + sv_setpvn(ST(0), RX_PRECOMP(rx), RX_PRELEN(rx)); + +#if PERL_VERSION >= 9 + +void +PMOP_reflags(o) + B::PMOP o + REGEXP * rx = NO_INIT + CODE: + ST(0) = sv_newmortal(); + rx = PM_GETRE(o); + if (rx) + sv_setuv(ST(0), RX_EXTFLAGS(rx)); + +#endif #define SVOP_sv(o) cSVOPo->op_sv #define SVOP_gv(o) ((GV*)cSVOPo->op_sv) @@ -981,7 +1136,7 @@ SVOP_gv(o) #define PADOP_sv(o) (o->op_padix ? PAD_SVl(o->op_padix) : Nullsv) #define PADOP_gv(o) ((o->op_padix \ && SvTYPE(PAD_SVl(o->op_padix)) == SVt_PVGV) \ - ? (GV*)PAD_SVl(o->op_padix) : Nullgv) + ? (GV*)PAD_SVl(o->op_padix) : (GV *)NULL) MODULE = B PACKAGE = B::PADOP PREFIX = PADOP_ @@ -1011,8 +1166,8 @@ PVOP_pv(o) (o->op_private & OPpTRANS_COMPLEMENT) && !(o->op_private & OPpTRANS_DELETE)) { - short* tbl = (short*)o->op_pv; - short entries = 257 + tbl[256]; + const short* const tbl = (short*)o->op_pv; + const short entries = 257 + tbl[256]; ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short))); } else if (o->op_type == OP_TRANS) { @@ -1040,23 +1195,36 @@ B::OP LOOP_lastop(o) B::LOOP o -#define COP_label(o) o->cop_label +#define COP_label(o) CopLABEL(o) #define COP_stashpv(o) CopSTASHPV(o) #define COP_stash(o) CopSTASH(o) #define COP_file(o) CopFILE(o) #define COP_filegv(o) CopFILEGV(o) #define COP_cop_seq(o) o->cop_seq -#define COP_arybase(o) o->cop_arybase +#define COP_arybase(o) CopARYBASE_get(o) #define COP_line(o) CopLINE(o) -#define COP_warnings(o) o->cop_warnings -#define COP_io(o) o->cop_io +#define COP_hints(o) CopHINTS_get(o) +#if PERL_VERSION < 9 +# define COP_warnings(o) o->cop_warnings +# define COP_io(o) o->cop_io +#endif MODULE = B PACKAGE = B::COP PREFIX = COP_ +#if PERL_VERSION >= 11 + +const char * +COP_label(o) + B::COP o + +#else + char * COP_label(o) B::COP o +#endif + char * COP_stashpv(o) B::COP o @@ -1086,6 +1254,32 @@ U32 COP_line(o) B::COP o +#if PERL_VERSION >= 9 + +void +COP_warnings(o) + B::COP o + PPCODE: + ST(0) = make_warnings_object(aTHX_ sv_newmortal(), o->cop_warnings); + XSRETURN(1); + +void +COP_io(o) + B::COP o + PPCODE: + ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o); + XSRETURN(1); + +B::RHE +COP_hints_hash(o) + B::COP o + CODE: + RETVAL = o->cop_hints_hash; + OUTPUT: + RETVAL + +#else + B::SV COP_warnings(o) B::COP o @@ -1094,6 +1288,12 @@ B::SV COP_io(o) B::COP o +#endif + +U32 +COP_hints(o) + B::COP o + MODULE = B PACKAGE = B::SV U32 @@ -1158,7 +1358,7 @@ packiv(sv) CODE: if (sizeof(IV) == 8) { U32 wp[2]; - IV iv = SvIVX(sv); + const IV iv = SvIVX(sv); /* * The following way of spelling 32 is to stop compilers on * 32-bit architectures from moaning about the shift count @@ -1178,6 +1378,24 @@ packiv(sv) ST(0) = sv_2mortal(newSVpvn((char *)&w, 4)); } + +#if PERL_VERSION >= 11 + +B::SV +RV(sv) + B::IV sv + CODE: + if( SvROK(sv) ) { + RETVAL = SvRV(sv); + } + else { + croak( "argument is not SvROK" ); + } + OUTPUT: + RETVAL + +#endif + MODULE = B PACKAGE = B::NV PREFIX = Sv NV @@ -1188,12 +1406,32 @@ NV SvNVX(sv) B::NV sv +U32 +COP_SEQ_RANGE_LOW(sv) + B::NV sv + +U32 +COP_SEQ_RANGE_HIGH(sv) + B::NV sv + +U32 +PARENT_PAD_INDEX(sv) + B::NV sv + +U32 +PARENT_FAKELEX_FLAGS(sv) + B::NV sv + +#if PERL_VERSION < 11 + MODULE = B PACKAGE = B::RV PREFIX = Sv B::SV SvRV(sv) B::RV sv +#endif + MODULE = B PACKAGE = B::PV PREFIX = Sv char* @@ -1218,8 +1456,16 @@ SvPV(sv) B::PV sv CODE: ST(0) = sv_newmortal(); - if( SvPOK(sv) ) { - sv_setpvn(ST(0), SvPVX(sv), SvCUR(sv)); + if( SvPOK(sv) ) { + /* FIXME - we need a better way for B to identify PVs that are + in the pads as variable names. */ + if((SvLEN(sv) && SvCUR(sv) >= SvLEN(sv))) { + /* It claims to be longer than the space allocated for it - + presuambly it's a variable name in the pad */ + sv_setpv(ST(0), SvPV_nolen_const(sv)); + } else { + sv_setpvn(ST(0), SvPVX_const(sv), SvCUR(sv)); + } SvFLAGS(ST(0)) |= SvUTF8(sv); } else { @@ -1228,13 +1474,16 @@ SvPV(sv) sv_setpvn(ST(0), NULL, 0); } +# This used to read 257. I think that that was buggy - should have been 258. +# (The "\0", the flags byte, and 256 for the table. Not that anything +# anywhere calls this method. NWC. void SvPVBM(sv) B::PV sv CODE: ST(0) = sv_newmortal(); - sv_setpvn(ST(0), SvPVX(sv), - SvCUR(sv) + (SvTYPE(sv) == SVt_PVBM ? 257 : 0)); + sv_setpvn(ST(0), SvPVX_const(sv), + SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0)); STRLEN @@ -1261,6 +1510,29 @@ B::HV SvSTASH(sv) B::PVMG sv +MODULE = B PACKAGE = B::REGEXP + +#if PERL_VERSION >= 11 + +IV +REGEX(sv) + B::REGEXP sv + CODE: + /* FIXME - can we code this method more efficiently? */ + RETVAL = PTR2IV(sv); + OUTPUT: + RETVAL + +SV* +precomp(sv) + B::REGEXP sv + CODE: + RETVAL = newSVpvn( RX_PRECOMP(sv), RX_PRELEN(sv) ); + OUTPUT: + RETVAL + +#endif + #define MgMOREMAGIC(mg) mg->mg_moremagic #define MgPRIVATE(mg) mg->mg_private #define MgTYPE(mg) mg->mg_type @@ -1304,7 +1576,7 @@ IV MgREGEX(mg) B::MAGIC mg CODE: - if( mg->mg_type == 'r' ) { + if(mg->mg_type == PERL_MAGIC_qr) { RETVAL = MgREGEX(mg); } else { @@ -1317,10 +1589,11 @@ SV* precomp(mg) B::MAGIC mg CODE: - if (mg->mg_type == 'r') { + if (mg->mg_type == PERL_MAGIC_qr) { REGEXP* rx = (REGEXP*)mg->mg_obj; + RETVAL = Nullsv; if( rx ) - RETVAL = newSVpvn( rx->precomp, rx->prelen ); + RETVAL = newSVpvn( RX_PRECOMP(rx), RX_PRELEN(rx) ); } else { croak( "precomp is only meaningful on r-magic" ); @@ -1370,7 +1643,7 @@ I32 BmUSEFUL(sv) B::BM sv -U16 +U32 BmPREVIOUS(sv) B::BM sv @@ -1386,7 +1659,7 @@ BmTABLE(sv) CODE: str = SvPV(sv, len); /* Boyer-Moore table is just after string and its safety-margin \0 */ - ST(0) = sv_2mortal(newSVpvn(str + len + 1, 256)); + ST(0) = sv_2mortal(newSVpvn(str + len + PERL_FBM_TABLE_OFFSET, 256)); MODULE = B PACKAGE = B::GV PREFIX = Gv @@ -1404,6 +1677,18 @@ is_empty(gv) OUTPUT: RETVAL +bool +isGV_with_GP(gv) + B::GV gv + CODE: +#if PERL_VERSION >= 9 + RETVAL = isGV_with_GP(gv) ? TRUE : FALSE; +#else + RETVAL = TRUE; /* In 5.8 and earlier they all are. */ +#endif + OUTPUT: + RETVAL + void* GvGP(gv) B::GV gv @@ -1512,14 +1797,18 @@ B::GV IoBOTTOM_GV(io) B::IO io +#if PERL_VERSION <= 8 + short IoSUBPROCESS(io) B::IO io +#endif + bool IsSTD(io,name) B::IO io - char* name + const char* name PREINIT: PerlIO* handle = 0; CODE: @@ -1559,12 +1848,17 @@ SSize_t AvMAX(av) B::AV av +#if PERL_VERSION < 9 + + #define AvOFF(av) ((XPVAV*)SvANY(av))->xof_off IV AvOFF(av) B::AV av +#endif + void AvARRAY(av) B::AV av @@ -1586,6 +1880,7 @@ AvARRAYelt(av, idx) else XPUSHs(make_sv_object(aTHX_ sv_newmortal(), NULL)); +#if PERL_VERSION < 9 MODULE = B PACKAGE = B::AV @@ -1593,6 +1888,8 @@ U8 AvFLAGS(av) B::AV av +#endif + MODULE = B PACKAGE = B::FM PREFIX = Fm IV @@ -1612,10 +1909,18 @@ CvSTASH(cv) B::OP CvSTART(cv) B::CV cv + CODE: + RETVAL = CvISXSUB(cv) ? NULL : CvSTART(cv); + OUTPUT: + RETVAL B::OP CvROOT(cv) B::CV cv + CODE: + RETVAL = CvISXSUB(cv) ? NULL : CvROOT(cv); + OUTPUT: + RETVAL B::GV CvGV(cv) @@ -1645,7 +1950,7 @@ void CvXSUB(cv) B::CV cv CODE: - ST(0) = sv_2mortal(newSViv(PTR2IV(CvXSUB(cv)))); + ST(0) = sv_2mortal(newSViv(CvISXSUB(cv) ? PTR2IV(CvXSUB(cv)) : 0)); void @@ -1653,8 +1958,8 @@ CvXSUBANY(cv) B::CV cv CODE: ST(0) = CvCONST(cv) ? - make_sv_object(aTHX_ sv_newmortal(),CvXSUBANY(cv).any_ptr) : - sv_2mortal(newSViv(CvXSUBANY(cv).any_iv)); + make_sv_object(aTHX_ sv_newmortal(),(SV *)CvXSUBANY(cv).any_ptr) : + sv_2mortal(newSViv(CvISXSUB(cv) ? CvXSUBANY(cv).any_iv : 0)); MODULE = B PACKAGE = B::CV @@ -1691,10 +1996,14 @@ char * HvNAME(hv) B::HV hv +#if PERL_VERSION < 9 + B::PMOP HvPMROOT(hv) B::HV hv +#endif + void HvARRAY(hv) B::HV hv @@ -1706,7 +2015,35 @@ HvARRAY(hv) (void)hv_iterinit(hv); EXTEND(sp, HvKEYS(hv) * 2); while ((sv = hv_iternextsv(hv, &key, &len))) { - PUSHs(newSVpvn(key, len)); + mPUSHp(key, len); PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv)); } } + +MODULE = B PACKAGE = B::HE PREFIX = He + +B::SV +HeVAL(he) + B::HE he + +U32 +HeHASH(he) + B::HE he + +B::SV +HeSVKEY_force(he) + B::HE he + +MODULE = B PACKAGE = B::RHE PREFIX = RHE_ + +#if PERL_VERSION >= 9 + +SV* +RHE_HASH(h) + B::RHE h + CODE: + RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) ); + OUTPUT: + RETVAL + +#endif