`id -Gn` might be available where `groups` is not.
[p5sagit/p5-mst-13.2.git] / mg.c
diff --git a/mg.c b/mg.c
index e4ddcd6..2906a4c 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -31,6 +31,7 @@
 #else
 #  define VTBL                 *vtbl
 static void restore_magic _((void *p));
+static int magic_methcall(SV *sv, MAGIC *mg, char *meth, I32 f, int n, SV *val);
 #endif
 
 /*
@@ -94,10 +95,13 @@ restore_magic(void *p)
      */
     if (PL_savestack_ix == mgs->mgs_ss_ix)
     {
-        assert(SSPOPINT == SAVEt_DESTRUCTOR);
+       I32 popval = SSPOPINT;
+        assert(popval == SAVEt_DESTRUCTOR);
         PL_savestack_ix -= 2;
-        assert(SSPOPINT == SAVEt_ALLOC);
-        PL_savestack_ix -= SSPOPINT;
+       popval = SSPOPINT;
+        assert(popval == SAVEt_ALLOC);
+       popval = SSPOPINT;
+        PL_savestack_ix -= popval;
     }
 
 }
@@ -277,7 +281,9 @@ mg_copy(SV *sv, SV *nsv, char *key, I32 klen)
     MAGIC* mg;
     for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
        if (isUPPER(mg->mg_type)) {
-           sv_magic(nsv, mg->mg_obj, toLOWER(mg->mg_type), key, klen);
+           sv_magic(nsv,
+                    mg->mg_type == 'P' ? SvTIED_obj(sv, mg) : mg->mg_obj,
+                    toLOWER(mg->mg_type), key, klen);
            count++;
        }
     }
@@ -461,15 +467,15 @@ magic_get(SV *sv, MAGIC *mg)
        break;
     case '\002':               /* ^B */
        /* printf("magic_get $^B: ") ; */
-       if (curcop->cop_warnings == WARN_NONE)
+       if (PL_curcop->cop_warnings == WARN_NONE)
            /* printf("WARN_NONE\n"), */
            sv_setpvn(sv, WARN_NONEstring, WARNsize) ;
-        else if (curcop->cop_warnings == WARN_ALL)
+        else if (PL_curcop->cop_warnings == WARN_ALL)
            /* printf("WARN_ALL\n"), */
            sv_setpvn(sv, WARN_ALLstring, WARNsize) ;
         else 
-           /* printf("some %s\n", printW(curcop->cop_warnings)), */
-           sv_setsv(sv, curcop->cop_warnings);
+           /* printf("some %s\n", printW(PL_curcop->cop_warnings)), */
+           sv_setsv(sv, PL_curcop->cop_warnings);
        break;
     case '\004':               /* ^D */
        sv_setiv(sv, (IV)(PL_debug & 32767));
@@ -493,8 +499,11 @@ magic_get(SV *sv, MAGIC *mg)
            sv_setnv(sv, (double)errno);
            sv_setpv(sv, errno ? Strerror(errno) : "");
        } else {
-           if (errno != errno_isOS2)
-               Perl_rc = _syserrno();
+           if (errno != errno_isOS2) {
+               int tmp = _syserrno();
+               if (tmp)        /* 2nd call to _syserrno() makes it 0 */
+                   Perl_rc = tmp;
+           }
            sv_setnv(sv, (double)Perl_rc);
            sv_setpv(sv, os2error(Perl_rc));
        }
@@ -1033,7 +1042,7 @@ magic_getnkeys(SV *sv, MAGIC *mg)
 
     if (hv) {
        (void) hv_iterinit(hv);
-       if (!SvRMAGICAL(hv) || !mg_find((SV*)hv,'P'))
+       if (! SvTIED_mg((SV*)hv, 'P'))
            i = HvKEYS(hv);
        else {
            /*SUPPRESS 560*/
@@ -1058,13 +1067,13 @@ magic_setnkeys(SV *sv, MAGIC *mg)
 
 /* caller is responsible for stack switching/cleanup */
 STATIC int
-magic_methcall(MAGIC *mg, char *meth, I32 flags, int n, SV *val)
+magic_methcall(SV *sv, MAGIC *mg, char *meth, I32 flags, int n, SV *val)
 {
     dSP;
 
     PUSHMARK(SP);
     EXTEND(SP, n);
-    PUSHs(mg->mg_obj);
+    PUSHs(SvTIED_obj(sv, mg));
     if (n > 1) { 
        if (mg->mg_ptr) {
            if (mg->mg_len >= 0)
@@ -1093,7 +1102,7 @@ magic_methpack(SV *sv, MAGIC *mg, char *meth)
     SAVETMPS;
     PUSHSTACKi(PERLSI_MAGIC);
 
-    if (magic_methcall(mg, meth, G_SCALAR, 2, NULL)) {
+    if (magic_methcall(sv, mg, meth, G_SCALAR, 2, NULL)) {
        sv_setsv(sv, *PL_stack_sp--);
     }
 
@@ -1118,7 +1127,7 @@ magic_setpack(SV *sv, MAGIC *mg)
     dSP;
     ENTER;
     PUSHSTACKi(PERLSI_MAGIC);
-    magic_methcall(mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
+    magic_methcall(sv, mg, "STORE", G_SCALAR|G_DISCARD, 3, sv);
     POPSTACK;
     LEAVE;
     return 0;
@@ -1140,7 +1149,7 @@ magic_sizepack(SV *sv, MAGIC *mg)
     ENTER;
     SAVETMPS;
     PUSHSTACKi(PERLSI_MAGIC);
-    if (magic_methcall(mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
+    if (magic_methcall(sv, mg, "FETCHSIZE", G_SCALAR, 2, NULL)) {
        sv = *PL_stack_sp--;
        retval = (U32) SvIV(sv)-1;
     }
@@ -1157,7 +1166,7 @@ int magic_wipepack(SV *sv, MAGIC *mg)
     ENTER;
     PUSHSTACKi(PERLSI_MAGIC);
     PUSHMARK(SP);
-    XPUSHs(mg->mg_obj);
+    XPUSHs(SvTIED_obj(sv, mg));
     PUTBACK;
     perl_call_method("CLEAR", G_SCALAR|G_DISCARD);
     POPSTACK;
@@ -1176,7 +1185,7 @@ magic_nextpack(SV *sv, MAGIC *mg, SV *key)
     PUSHSTACKi(PERLSI_MAGIC);
     PUSHMARK(SP);
     EXTEND(SP, 2);
-    PUSHs(mg->mg_obj);
+    PUSHs(SvTIED_obj(sv, mg));
     if (SvOK(key))
        PUSHs(key);
     PUTBACK;
@@ -1607,7 +1616,7 @@ int
 magic_setcollxfrm(SV *sv, MAGIC *mg)
 {
     /*
-     * RenĂ© Descartes said "I think not."
+     * RenE<eacute> Descartes said "I think not."
      * and vanished with a faint plop.
      */
     if (mg->mg_ptr) {
@@ -1633,15 +1642,15 @@ magic_set(SV *sv, MAGIC *mg)
     case '\002':       /* ^B */
        if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
             if (memEQ(SvPVX(sv), WARN_ALLstring, WARNsize))
-               compiling.cop_warnings = WARN_ALL;
+               PL_compiling.cop_warnings = WARN_ALL;
            else if (memEQ(SvPVX(sv), WARN_NONEstring, WARNsize))
-               compiling.cop_warnings = WARN_NONE;
+               PL_compiling.cop_warnings = WARN_NONE;
             else {
-               if (compiling.cop_warnings != WARN_NONE && 
-                   compiling.cop_warnings != WARN_ALL)
-                   sv_setsv(compiling.cop_warnings, sv);
+               if (PL_compiling.cop_warnings != WARN_NONE && 
+                   PL_compiling.cop_warnings != WARN_ALL)
+                   sv_setsv(PL_compiling.cop_warnings, sv);
                else
-                   compiling.cop_warnings = newSVsv(sv) ;
+                   PL_compiling.cop_warnings = newSVsv(sv) ;
            }
        }
        break;
@@ -2001,7 +2010,6 @@ magic_mutexfree(SV *sv, MAGIC *mg)
        croak("panic: magic_mutexfree");
     MUTEX_DESTROY(MgMUTEXP(mg));
     COND_DESTROY(MgCONDP(mg));
-    SvREFCNT_dec(sv);
     return 0;
 }
 #endif /* USE_THREADS */