Remove support for assertions and -A
[p5sagit/p5-mst-13.2.git] / ext / B / B.xs
index b2627aa..99c1409 100644 (file)
@@ -21,6 +21,9 @@ typedef FILE * InputStream;
 
 static const char* const svclassnames[] = {
     "B::NULL",
+#if PERL_VERSION >= 9
+    "B::BIND",
+#endif
     "B::IV",
     "B::NV",
     "B::RV",
@@ -28,7 +31,9 @@ static const char* const svclassnames[] = {
     "B::PVIV",
     "B::PVNV",
     "B::PVMG",
+#if PERL_VERSION <= 8
     "B::BM",
+#endif
 #if PERL_VERSION >= 9
     "B::GV",
 #endif
@@ -246,6 +251,7 @@ make_sv_object(pTHX_ SV *arg, SV *sv)
     return arg;
 }
 
+#if PERL_VERSION >= 9
 static SV *
 make_temp_object(pTHX_ SV *arg, SV *temp)
 {
@@ -297,21 +303,18 @@ make_warnings_object(pTHX_ SV *arg, STRLEN *warnings)
 static SV *
 make_cop_io_object(pTHX_ SV *arg, COP *cop)
 {
-    if (CopHINTS_get(cop) & HINT_LEXICAL_IO) {
-       /* I feel you should be able to simply SvREFCNT_inc the return value
-          from this, but if you do (and restore the line
-          my $ioix = $cop->io->ix;
-          in B::COP::bsave in Bytecode.pm, then you get errors about
-          "attempt to free temp prematurely ... during global destruction.
-          The SV's flags are consistent with the error, but quite how the
-          temp escaped from the save stack is not clear.  */
-       SV *value = Perl_refcounted_he_fetch(aTHX_ cop->cop_hints_hash,
-                                            0, "open", 4, 0, 0);
+    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)
@@ -484,7 +487,12 @@ walkoptree(pTHX_ SV *opsv, const char *method)
        }
     }
     if (o && (cc_opclass(aTHX_ o) == OPc_PMOP) && o->op_type != OP_PUSHRE
-           && (kid = cPMOPo->op_pmreplroot))
+#if PERL_VERSION >= 9
+           && (kid = cPMOPo->op_pmreplrootu.op_pmreplroot)
+#else
+           && (kid = cPMOPo->op_pmreplroot)
+#endif
+       )
     {
        sv_setiv(newSVrv(opsv, cc_opclassname(aTHX_ kid)), PTR2IV(kid));
        walkoptree(aTHX_ opsv, method);
@@ -510,7 +518,11 @@ oplist(pTHX_ OP *o, SV **SP)
        XPUSHs(opsv);
         switch (o->op_type) {
        case OP_SUBST:
+#if PERL_VERSION >= 9
+            SP = oplist(aTHX_ cPMOPo->op_pmstashstartu.op_pmreplstart, SP);
+#else
             SP = oplist(aTHX_ cPMOPo->op_pmreplstart, SP);
+#endif
             continue;
        case OP_SORT:
            if (o->op_flags & OPf_STACKED && o->op_flags & OPf_SPECIAL) {
@@ -564,7 +576,9 @@ 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_
 
@@ -572,7 +586,7 @@ 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;
@@ -583,7 +597,7 @@ BOOT:
     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"
 }
@@ -592,7 +606,11 @@ BOOT:
 #define B_init_av()    PL_initav
 #define B_inc_gv()     PL_incgv
 #define B_check_av()   PL_checkav_save
-#define B_unitcheck_av()       PL_unitcheckav_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
@@ -617,9 +635,13 @@ B_init_av()
 B::AV
 B_check_av()
 
+#if PERL_VERSION >= 9
+
 B::AV
 B_unitcheck_av()
 
+#endif
+
 B::AV
 B_begin_av()
 
@@ -963,22 +985,27 @@ LISTOP_children(o)
     OUTPUT:
         RETVAL
 
-#define PMOP_pmreplroot(o)     o->op_pmreplroot
-#define PMOP_pmreplstart(o)    o->op_pmreplstart
+#if PERL_VERSION >= 9
+#  define PMOP_pmreplstart(o)  o->op_pmstashstartu.op_pmreplstart
+#else
+#  define PMOP_pmreplstart(o)  o->op_pmreplstart
+#  define PMOP_pmpermflags(o)  o->op_pmpermflags
+#  define PMOP_pmdynflags(o)      o->op_pmdynflags
+#endif
 #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
@@ -988,26 +1015,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
@@ -1030,6 +1086,8 @@ U32
 PMOP_pmflags(o)
        B::PMOP         o
 
+#if PERL_VERSION < 9
+
 U32
 PMOP_pmpermflags(o)
        B::PMOP         o
@@ -1038,6 +1096,8 @@ U8
 PMOP_pmdynflags(o)
         B::PMOP         o
 
+#endif
+
 void
 PMOP_precomp(o)
        B::PMOP         o
@@ -1048,6 +1108,20 @@ PMOP_precomp(o)
        if (rx)
            sv_setpvn(ST(0), rx->precomp, rx->prelen);
 
+#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);
+
+#endif
+
 #define SVOP_sv(o)     cSVOPo->op_sv
 #define SVOP_gv(o)     ((GV*)cSVOPo->op_sv)
 
@@ -1133,6 +1207,10 @@ LOOP_lastop(o)
 #define COP_arybase(o) CopARYBASE_get(o)
 #define COP_line(o)    CopLINE(o)
 #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_
 
@@ -1169,6 +1247,8 @@ U32
 COP_line(o)
        B::COP  o
 
+#if PERL_VERSION >= 9
+
 void
 COP_warnings(o)
        B::COP  o
@@ -1183,10 +1263,6 @@ COP_io(o)
        ST(0) = make_cop_io_object(aTHX_ sv_newmortal(), o);
        XSRETURN(1);
 
-U32
-COP_hints(o)
-       B::COP  o
-
 B::RHE
 COP_hints_hash(o)
        B::COP o
@@ -1195,6 +1271,22 @@ COP_hints_hash(o)
     OUTPUT:
        RETVAL
 
+#else
+
+B::SV
+COP_warnings(o)
+       B::COP  o
+
+B::SV
+COP_io(o)
+       B::COP  o
+
+#endif
+
+U32
+COP_hints(o)
+       B::COP  o
+
 MODULE = B     PACKAGE = B::SV
 
 U32
@@ -1289,6 +1381,22 @@ 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
+
 MODULE = B     PACKAGE = B::RV         PREFIX = Sv
 
 B::SV
@@ -1337,13 +1445,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_const(sv),
-           SvCUR(sv) + (SvTYPE(sv) == SVt_PVBM ? 257 : 0));
+           SvCUR(sv) + (SvVALID(sv) ? 256 + PERL_FBM_TABLE_OFFSET : 0));
 
 
 STRLEN
@@ -1480,7 +1591,7 @@ I32
 BmUSEFUL(sv)
        B::BM   sv
 
-U16
+U32
 BmPREVIOUS(sv)
        B::BM   sv
 
@@ -1496,7 +1607,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
 
@@ -1857,6 +1968,8 @@ HeSVKEY_force(he)
 
 MODULE = B     PACKAGE = B::RHE        PREFIX = RHE_
 
+#if PERL_VERSION >= 9
+
 SV*
 RHE_HASH(h)
        B::RHE h
@@ -1864,3 +1977,5 @@ RHE_HASH(h)
        RETVAL = newRV( (SV*)Perl_refcounted_he_chain_2hv(aTHX_ h) );
     OUTPUT:
        RETVAL
+
+#endif