Double magic with substr
[p5sagit/p5-mst-13.2.git] / universal.c
index c835286..d03596c 100644 (file)
@@ -45,6 +45,8 @@ S_isa_lookup(pTHX_ HV *stash, const char * const name, const HV* const name_stas
     const char *hvname;
     I32 items;
 
+    PERL_ARGS_ASSERT_ISA_LOOKUP;
+
     /* A stash/class can go by many names (ie. User == main::User), so 
        we compare the stash itself just in case */
     if (name_stash && ((const HV *)stash == name_stash))
@@ -91,11 +93,13 @@ normal Perl method.
 */
 
 bool
-Perl_sv_derived_from(pTHX_ SV *sv, const char *name)
+Perl_sv_derived_from(pTHX_ SV *sv, const char *const name)
 {
     dVAR;
     HV *stash;
 
+    PERL_ARGS_ASSERT_SV_DERIVED_FROM;
+
     SvGETMAGIC(sv);
 
     if (SvROK(sv)) {
@@ -131,13 +135,15 @@ The SV can be a Perl object or the name of a Perl class.
 #include "XSUB.h"
 
 bool
-Perl_sv_does(pTHX_ SV *sv, const char *name)
+Perl_sv_does(pTHX_ SV *sv, const char *const name)
 {
     const char *classname;
     bool does_it;
     SV *methodname;
-
     dSP;
+
+    PERL_ARGS_ASSERT_SV_DOES;
+
     ENTER;
     SAVETMPS;
 
@@ -969,16 +975,22 @@ XS(XS_PerlIO_get_layers)
                  const bool flgok = flgsvp && *flgsvp && SvIOK(*flgsvp);
 
                  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
-                             ? sv_2mortal(newSVpvn(SvPVX_const(*namsvp), SvCUR(*namsvp)))
+                             ? sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp))
                              : &PL_sv_undef);
                       XPUSHs(argok
-                             ? sv_2mortal(newSVpvn(SvPVX_const(*argsvp), SvCUR(*argsvp)))
+                             ? newSVpvn_flags(SvPVX_const(*argsvp),
+                                              SvCUR(*argsvp),
+                                              (SvUTF8(*argsvp) ? SVf_UTF8 : 0)
+                                              | SVs_TEMP)
+                             : &PL_sv_undef);
+                      XPUSHs(namok
+                             ? sv_2mortal(SvREFCNT_inc_simple_NN(*flgsvp))
                              : &PL_sv_undef);
-                      if (flgok)
-                           mXPUSHi(SvIVX(*flgsvp));
-                      else
-                           XPUSHs(&PL_sv_undef);
                       nitem += 3;
                  }
                  else {
@@ -987,8 +999,7 @@ XS(XS_PerlIO_get_layers)
                                                 SVfARG(*namsvp),
                                                 SVfARG(*argsvp))));
                       else if (namok)
-                           XPUSHs(sv_2mortal(Perl_newSVpvf(aTHX_ "%"SVf,
-                                                SVfARG(*namsvp))));
+                          XPUSHs(sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp)));
                       else
                            XPUSHs(&PL_sv_undef);
                       nitem++;
@@ -1238,13 +1249,12 @@ XS(XS_re_regexp_pattern)
                 match_flags >>= 1;
             }
 
-            pattern = sv_2mortal(newSVpvn(RX_PRECOMP(re),RX_PRELEN(re)));
-            if (RX_UTF8(re))
-                SvUTF8_on(pattern);
+            pattern = newSVpvn_flags(RX_PRECOMP(re),RX_PRELEN(re),
+                                    (RX_UTF8(re) ? SVf_UTF8 : 0) | SVs_TEMP);
 
             /* return the pattern and the modifiers */
             XPUSHs(pattern);
-            XPUSHs(sv_2mortal(newSVpvn(reflags,left)));
+            XPUSHs(newSVpvn_flags(reflags, left, SVs_TEMP));
             XSRETURN(2);
         } else {
             /* Scalar, so use the string that Perl would return */
@@ -1252,9 +1262,8 @@ XS(XS_re_regexp_pattern)
 #if PERL_VERSION >= 11
             pattern = sv_2mortal(newSVsv((SV*)re));
 #else
-            pattern = sv_2mortal(newSVpvn(RX_WRAPPED(re),RX_WRAPLEN(re)));
-            if (RX_UTF8(re))
-                SvUTF8_on(pattern);
+            pattern = newSVpvn_flags(RX_WRAPPED(re), RX_WRAPLEN(re),
+                                    (RX_UTF8(re) ? SVf_UTF8 : 0) | SVs_TEMP);
 #endif
             XPUSHs(pattern);
             XSRETURN(1);