This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add lib/overload/numbers.pm to (unused) output file list in regen.pl
[perl5.git] / mg.c
diff --git a/mg.c b/mg.c
index 28eb9d2..276e13d 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -463,15 +463,19 @@ Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen)
 /*
 =for apidoc mg_localize
 
-Copy some of the magic from an existing SV to new localized version of
-that SV. Container magic (eg %ENV, $1, tie) gets copied, value magic
-doesn't (eg taint, pos).
+Copy some of the magic from an existing SV to new localized version of that
+SV. Container magic (eg %ENV, $1, tie) gets copied, value magic doesn't (eg
+taint, pos).
+
+If setmagic is false then no set magic will be called on the new (empty) SV.
+This typically means that assignment will soon follow (e.g. 'local $x = $y'),
+and that will handle the magic.
 
 =cut
 */
 
 void
-Perl_mg_localize(pTHX_ SV *sv, SV *nsv)
+Perl_mg_localize(pTHX_ SV *sv, SV *nsv, bool setmagic)
 {
     dVAR;
     MAGIC *mg;
@@ -495,9 +499,11 @@ Perl_mg_localize(pTHX_ SV *sv, SV *nsv)
 
     if (SvTYPE(nsv) >= SVt_PVMG && SvMAGIC(nsv)) {
        SvFLAGS(nsv) |= SvMAGICAL(sv);
-       PL_localizing = 1;
-       SvSETMAGIC(nsv);
-       PL_localizing = 0;
+       if (setmagic) {
+           PL_localizing = 1;
+           SvSETMAGIC(nsv);
+           PL_localizing = 0;
+       }
     }      
 }
 
@@ -766,14 +772,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        break;
     case '\005':  /* ^E */
         if (nextchar == '\0') {
-#if defined(MACOS_TRADITIONAL)
-            {
-                 char msg[256];
-
-                 sv_setnv(sv,(double)gMacPerl_OSErr);
-                 sv_setpv(sv, gMacPerl_OSErr ? GetSysErrText(gMacPerl_OSErr, msg) : "");
-            }
-#elif defined(VMS)
+#if defined(VMS)
             {
 #                include <descrip.h>
 #                include <starlet.h>
@@ -811,10 +810,10 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
             }
 #else
             {
-                const int saveerrno = errno;
+                dSAVE_ERRNO;
                 sv_setnv(sv, (NV)errno);
                 sv_setpv(sv, errno ? Strerror(errno) : "");
-                errno = saveerrno;
+                RESTORE_ERRNO;
             }
 #endif
             SvRTRIM(sv);
@@ -898,7 +897,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
             else if (PL_compiling.cop_warnings == pWARN_ALL) {
                /* Get the bit mask for $warnings::Bits{all}, because
                 * it could have been extended by warnings::register */
-               HV * const bits=get_hv("warnings::Bits", FALSE);
+               HV * const bits=get_hv("warnings::Bits", 0);
                if (bits) {
                    SV ** const bits_all = hv_fetchs(bits, "all", FALSE);
                    if (bits_all)
@@ -1020,8 +1019,6 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        if (GvIOp(PL_defoutgv))
            sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
        break;
-    case ',':
-       break;
     case '\\':
        if (PL_ors_sv)
            sv_copypv(sv, PL_ors_sv);
@@ -1032,7 +1029,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        sv_setpv(sv, errno ? Strerror(errno) : "");
 #else
        {
-       const int saveerrno = errno;
+       dSAVE_ERRNO;
        sv_setnv(sv, (NV)errno);
 #ifdef OS2
        if (errno == errno_isOS2 || errno == errno_isOS2_set)
@@ -1040,7 +1037,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        else
 #endif
        sv_setpv(sv, errno ? Strerror(errno) : "");
-       errno = saveerrno;
+       RESTORE_ERRNO;
        }
 #endif
        SvRTRIM(sv);
@@ -1071,10 +1068,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        (void)SvIOK_on(sv);     /* what a wonderful hack! */
 #endif
        break;
-#ifndef MACOS_TRADITIONAL
     case '0':
        break;
-#endif
     }
     return 0;
 }
@@ -2381,21 +2376,17 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
        break;
     case '\005':  /* ^E */
        if (*(mg->mg_ptr+1) == '\0') {
-#ifdef MACOS_TRADITIONAL
-           gMacPerl_OSErr = SvIV(sv);
-#else
-#  ifdef VMS
+#ifdef VMS
            set_vaxc_errno(SvIV(sv));
-#  else
-#    ifdef WIN32
+#else
+#  ifdef WIN32
            SetLastError( SvIV(sv) );
-#    else
-#      ifdef OS2
+#  else
+#    ifdef OS2
            os2_setsyserrno(SvIV(sv));
-#      else
+#    else
            /* will anyone ever use this? */
            SETERRNO(SvIV(sv), 4);
-#      endif
 #    endif
 #  endif
 #endif
@@ -2598,16 +2589,6 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
            PL_ors_sv = NULL;
        }
        break;
-    case ',':
-       if (PL_ofs_sv)
-           SvREFCNT_dec(PL_ofs_sv);
-       if (SvOK(sv) || SvGMAGICAL(sv)) {
-           PL_ofs_sv = newSVsv(sv);
-       }
-       else {
-           PL_ofs_sv = NULL;
-       }
-       break;
     case '[':
        CopARYBASE_set(&PL_compiling, SvIV(sv));
        break;
@@ -2780,7 +2761,6 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
     case ':':
        PL_chopset = SvPV_force(sv,len);
        break;
-#ifndef MACOS_TRADITIONAL
     case '0':
        LOCK_DOLLARZERO_MUTEX;
 #ifdef HAS_SETPROCTITLE
@@ -2846,7 +2826,6 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
 #endif
        UNLOCK_DOLLARZERO_MUTEX;
        break;
-#endif
     }
     return 0;
 }