This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Consolidate adjacent padrange ops
[perl5.git] / universal.c
index cb49e0b..055d8ab 100644 (file)
@@ -808,6 +808,7 @@ XS(XS_utf8_encode)
     if (items != 1)
        croak_xs_usage(cv, "sv");
     sv_utf8_encode(ST(0));
+    SvSETMAGIC(ST(0));
     XSRETURN_EMPTY;
 }
 
@@ -822,6 +823,7 @@ XS(XS_utf8_decode)
        bool RETVAL;
        SvPV_force_nolen(sv);
        RETVAL = sv_utf8_decode(sv);
+       SvSETMAGIC(sv);
        ST(0) = boolSV(RETVAL);
     }
     XSRETURN(1);
@@ -1033,40 +1035,41 @@ XS(XS_PerlIO_get_layers)
                  const bool argok = argsvp && *argsvp && SvPOK(*argsvp);
                  const bool flgok = flgsvp && *flgsvp && SvIOK(*flgsvp);
 
+                 EXTEND(SP, 3); /* Three is the max in all branches: better check just once */
                  if (details) {
                      /* Indents of 5? Yuck.  */
                      /* We know that PerlIO_get_layers creates a new SV for
                         the name and flags, so we can just take a reference
                         and "steal" it when we free the AV below.  */
-                      XPUSHs(namok
+                      PUSHs(namok
                              ? sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp))
                              : &PL_sv_undef);
-                      XPUSHs(argok
+                      PUSHs(argok
                              ? newSVpvn_flags(SvPVX_const(*argsvp),
                                               SvCUR(*argsvp),
                                               (SvUTF8(*argsvp) ? SVf_UTF8 : 0)
                                               | SVs_TEMP)
                              : &PL_sv_undef);
-                      XPUSHs(flgok
+                      PUSHs(flgok
                              ? sv_2mortal(SvREFCNT_inc_simple_NN(*flgsvp))
                              : &PL_sv_undef);
                       nitem += 3;
                  }
                  else {
                       if (namok && argok)
-                           XPUSHs(sv_2mortal(Perl_newSVpvf(aTHX_ "%"SVf"(%"SVf")",
+                           PUSHs(sv_2mortal(Perl_newSVpvf(aTHX_ "%"SVf"(%"SVf")",
                                                 SVfARG(*namsvp),
                                                 SVfARG(*argsvp))));
                       else if (namok)
-                          XPUSHs(sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp)));
+                           PUSHs(sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp)));
                       else
-                           XPUSHs(&PL_sv_undef);
+                           PUSHs(&PL_sv_undef);
                       nitem++;
                       if (flgok) {
                            const IV flags = SvIVX(*flgsvp);
 
                            if (flags & PERLIO_F_UTF8) {
-                                XPUSHs(newSVpvs_flags("utf8", SVs_TEMP));
+                                PUSHs(newSVpvs_flags("utf8", SVs_TEMP));
                                 nitem++;
                            }
                       }
@@ -1232,13 +1235,14 @@ XS(XS_re_regnames)
     av = MUTABLE_AV(SvRV(ret));
     length = av_len(av);
 
+    EXTEND(SP, length+1); /* better extend stack just once */
     for (i = 0; i <= length; i++) {
         entry = av_fetch(av, i, FALSE);
         
         if (!entry)
             Perl_croak(aTHX_ "NULL array element in re::regnames()");
 
-        mXPUSHs(SvREFCNT_inc_simple_NN(*entry));
+        mPUSHs(SvREFCNT_inc_simple_NN(*entry));
     }
 
     SvREFCNT_dec(ret);
@@ -1309,8 +1313,9 @@ XS(XS_re_regexp_pattern)
                                     (RX_UTF8(re) ? SVf_UTF8 : 0) | SVs_TEMP);
 
             /* return the pattern and the modifiers */
-            XPUSHs(pattern);
-            XPUSHs(newSVpvn_flags(reflags, left, SVs_TEMP));
+            EXTEND(SP, 2);
+            PUSHs(pattern);
+            PUSHs(newSVpvn_flags(reflags, left, SVs_TEMP));
             XSRETURN(2);
         } else {
             /* Scalar, so use the string that Perl would return */
@@ -1353,7 +1358,7 @@ struct xsub_details {
     const char *proto;
 };
 
-struct xsub_details details[] = {
+const struct xsub_details details[] = {
     {"UNIVERSAL::isa", XS_UNIVERSAL_isa, NULL},
     {"UNIVERSAL::can", XS_UNIVERSAL_can, NULL},
     {"UNIVERSAL::DOES", XS_UNIVERSAL_DOES, NULL},
@@ -1413,7 +1418,7 @@ Perl_boot_core_UNIVERSAL(pTHX)
 {
     dVAR;
     static const char file[] = __FILE__;
-    struct xsub_details *xsub = details;
+    const struct xsub_details *xsub = details;
     const struct xsub_details *end
        = details + sizeof(details) / sizeof(details[0]);