Update dependencies and remove obsolete VAXC support
[p5sagit/p5-mst-13.2.git] / mg.c
diff --git a/mg.c b/mg.c
index fdaf3bb..a3607eb 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1,6 +1,6 @@
 /*    mg.c
  *
- *    Copyright (c) 1991-1999, Larry Wall
+ *    Copyright (c) 1991-2000, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -60,6 +60,14 @@ S_save_magic(pTHX_ I32 mgs_ix, SV *sv)
     SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
 }
 
+/*
+=for apidoc mg_magical
+
+Turns on the magical status of an SV.  See C<sv_magic>.
+
+=cut
+*/
+
 void
 Perl_mg_magical(pTHX_ SV *sv)
 {
@@ -77,6 +85,14 @@ Perl_mg_magical(pTHX_ SV *sv)
     }
 }
 
+/*
+=for apidoc mg_get
+
+Do magic after a value is retrieved from the SV.  See C<sv_magic>.
+
+=cut
+*/
+
 int
 Perl_mg_get(pTHX_ SV *sv)
 {
@@ -112,6 +128,14 @@ Perl_mg_get(pTHX_ SV *sv)
     return 0;
 }
 
+/*
+=for apidoc mg_set
+
+Do magic after a value is assigned to the SV.  See C<sv_magic>.
+
+=cut
+*/
+
 int
 Perl_mg_set(pTHX_ SV *sv)
 {
@@ -138,6 +162,14 @@ Perl_mg_set(pTHX_ SV *sv)
     return 0;
 }
 
+/*
+=for apidoc mg_length
+
+Report on the SV's length.  See C<sv_magic>.
+
+=cut
+*/
+
 U32
 Perl_mg_length(pTHX_ SV *sv)
 {
@@ -196,6 +228,14 @@ Perl_mg_size(pTHX_ SV *sv)
     return 0;
 }
 
+/*
+=for apidoc mg_clear
+
+Clear something magical that the SV represents.  See C<sv_magic>.
+
+=cut
+*/
+
 int
 Perl_mg_clear(pTHX_ SV *sv)
 {
@@ -217,6 +257,14 @@ Perl_mg_clear(pTHX_ SV *sv)
     return 0;
 }
 
+/*
+=for apidoc mg_find
+
+Finds the magic pointer for type matching the SV.  See C<sv_magic>.
+
+=cut
+*/
+
 MAGIC*
 Perl_mg_find(pTHX_ SV *sv, int type)
 {
@@ -228,6 +276,14 @@ Perl_mg_find(pTHX_ SV *sv, int type)
     return 0;
 }
 
+/*
+=for apidoc mg_copy
+
+Copies the magic from one SV to another.  See C<sv_magic>.
+
+=cut
+*/
+
 int
 Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen)
 {
@@ -244,6 +300,14 @@ Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen)
     return count;
 }
 
+/*
+=for apidoc mg_free
+
+Free any magic storage used by the SV.  See C<sv_magic>.
+
+=cut
+*/
+
 int
 Perl_mg_free(pTHX_ SV *sv)
 {
@@ -406,6 +470,9 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
 
     case '\004':               /* ^D */
        sv_setiv(sv, (IV)(PL_debug & 32767));
+#if defined(YYDEBUG) && defined(DEBUGGING)
+       PL_yydebug = (PL_debug & 1);
+#endif
        break;
     case '\005':  /* ^E */
 #ifdef MACOS_TRADITIONAL
@@ -500,10 +567,10 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        sv_setiv(sv, (IV)PL_basetime);
 #endif
        break;
-    case '\027':               /* ^W  & $^Warnings*/
+    case '\027':               /* ^W  & $^WARNING_BITS & ^WIDE_SYSTEM_CALLS */
        if (*(mg->mg_ptr+1) == '\0')
            sv_setiv(sv, (IV)((PL_dowarn & G_WARN_ON) ? TRUE : FALSE));
-       else if (strEQ(mg->mg_ptr, "\027arnings")) {
+       else if (strEQ(mg->mg_ptr, "\027ARNING_BITS")) {
            if (PL_compiling.cop_warnings == WARN_NONE ||
                PL_compiling.cop_warnings == WARN_STD)
            {
@@ -516,6 +583,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
                sv_setsv(sv, PL_compiling.cop_warnings);
            }    
        }
+       else if (strEQ(mg->mg_ptr, "\027IDE_SYSTEM_CALLS"))
+           sv_setiv(sv, (IV)PL_widesyscalls);
        break;
     case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9': case '&':
@@ -542,6 +611,10 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
                        PL_tainted = FALSE;
                    }
                    sv_setpvn(sv, s, i);
+                   if ((PL_curpm->op_pmdynflags & PMdf_UTF8) && !IN_BYTE)
+                       SvUTF8_on(sv);
+                   else
+                       SvUTF8_off(sv);
                    if (PL_tainting)
                        PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
                    break;
@@ -665,11 +738,15 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
        break;
     case '(':
        sv_setiv(sv, (IV)PL_gid);
+#ifdef HAS_GETGROUPS
        Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_gid);
+#endif
        goto add_groups;
     case ')':
        sv_setiv(sv, (IV)PL_egid);
+#ifdef HAS_GETGROUPS
        Perl_sv_setpvf(aTHX_ sv, "%"Gid_t_f, PL_egid);
+#endif
       add_groups:
 #ifdef HAS_GETGROUPS
        {
@@ -818,7 +895,10 @@ Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
 #if defined(VMS)
     Perl_die(aTHX_ "Can't make list assignment to %%ENV on this system");
 #else
-#  ifdef WIN32
+#   ifdef PERL_IMPLICIT_SYS
+    PerlEnv_clearenv();
+#   else
+#      ifdef WIN32
     char *envv = GetEnvironmentStrings();
     char *cur = envv;
     STRLEN len;
@@ -834,13 +914,13 @@ Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
            cur += len+1;
     }
     FreeEnvironmentStrings(envv);
-#  else
-#    ifdef CYGWIN
+#   else
+#      ifdef __CYGWIN__
     I32 i;
     for (i = 0; environ[i]; i++)
-       Safefree(environ[i]);
-#    else
-#      ifndef PERL_USE_SAFE_PUTENV
+       safesysfree(environ[i]);
+#      else
+#          ifndef PERL_USE_SAFE_PUTENV
     I32 i;
 
     if (environ == PL_origenviron)
@@ -848,12 +928,13 @@ Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
     else
        for (i = 0; environ[i]; i++)
            safesysfree(environ[i]);
-#      endif /* PERL_USE_SAFE_PUTENV */
-#    endif /* CYGWIN */
+#          endif /* PERL_USE_SAFE_PUTENV */
+#      endif /* __CYGWIN__ */
 
     environ[0] = Nullch;
 
-#  endif /* WIN32 */
+#      endif /* WIN32 */
+#   endif /* PERL_IMPLICIT_SYS */
 #endif /* VMS */
     return 0;
 }
@@ -928,7 +1009,7 @@ Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
     else {
        i = whichsig(s);        /* ...no, a brick */
        if (!i) {
-           if (ckWARN(WARN_SIGNAL) || strEQ(s,"ALARM"))
+           if (ckWARN(WARN_SIGNAL))
                Perl_warner(aTHX_ WARN_SIGNAL, "No such signal: SIG%s", s);
            return 0;
        }
@@ -1178,7 +1259,7 @@ Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg)
     i = SvTRUE(sv);
     svp = av_fetch(GvAV(gv),
                     atoi(MgPV(mg,n_a)), FALSE);
-    if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
+    if (svp && SvIOKp(*svp) && (o = INT2PTR(OP*,SvIVX(*svp))))
        o->op_private = i;
     else if (ckWARN_d(WARN_INTERNAL))
        Perl_warner(aTHX_ WARN_INTERNAL, "Can't break at that line\n");
@@ -1211,7 +1292,7 @@ Perl_magic_getpos(pTHX_ SV *sv, MAGIC *mg)
        if (mg && mg->mg_len >= 0) {
            dTHR;
            I32 i = mg->mg_len;
-           if (IN_UTF8)
+           if (DO_UTF8(lsv))
                sv_pos_b2u(lsv, &i);
            sv_setiv(sv, i + PL_curcop->cop_arybase);
            return 0;
@@ -1227,7 +1308,7 @@ Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg)
     SV* lsv = LvTARG(sv);
     SSize_t pos;
     STRLEN len;
-    STRLEN ulen;
+    STRLEN ulen = 0;
     dTHR;
 
     mg = 0;
@@ -1248,12 +1329,10 @@ Perl_magic_setpos(pTHX_ SV *sv, MAGIC *mg)
 
     pos = SvIV(sv) - PL_curcop->cop_arybase;
 
-    if (IN_UTF8) {
+    if (DO_UTF8(lsv)) {
        ulen = sv_len_utf8(lsv);
        if (ulen)
            len = ulen;
-       else
-           ulen = 0;
     }
 
     if (pos < 0) {
@@ -1630,7 +1709,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
        PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
 #endif
        break;
-    case '\027':       /* ^W & $^Warnings */
+    case '\027':       /* ^W & $^WARNING_BITS & ^WIDE_SYSTEM_CALLS */
        if (*(mg->mg_ptr+1) == '\0') {
            if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
                i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
@@ -1638,7 +1717,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
                                | (i ? G_WARN_ON : G_WARN_OFF) ;
            }
        }
-       else if (strEQ(mg->mg_ptr, "\027arnings")) {
+       else if (strEQ(mg->mg_ptr, "\027ARNING_BITS")) {
            if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
                 if (memEQ(SvPVX(sv), WARN_ALLstring, WARNsize)) {
                    PL_compiling.cop_warnings = WARN_ALL;
@@ -1656,11 +1735,13 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
                }
            }
        }
+       else if (strEQ(mg->mg_ptr, "\027IDE_SYSTEM_CALLS"))
+           PL_widesyscalls = SvTRUE(sv);
        break;
     case '.':
        if (PL_localizing) {
            if (PL_localizing == 1)
-               save_sptr((SV**)&PL_last_in_gv);
+               SAVESPTR(PL_last_in_gv);
        }
        else if (SvOK(sv) && GvIO(PL_last_in_gv))
            IoLINES(GvIOp(PL_last_in_gv)) = (long)SvIV(sv);