Change 26788 by [EMAIL PROTECTED] on 2006/01/11 17:19:22

        Integrate:
        [ 26480]
        Subject: Re: [perl #37907] Perl_magic_get reqires ridiculous amounts of 
stackmemory
        From: Jim Cromie <[EMAIL PROTECTED]>
        Date: Fri, 23 Dec 2005 13:24:29 -0700
        Message-ID: <[EMAIL PROTECTED]>
        
        Includes a change in variable names from "j" to "num_groups".
        
        [ 26486]
        Obviously, Perl_ingroup() is also using 256k of stack memory on Linux.
        Adapt change #26480 to reduce memory usage here as well.
        
        [ 26489]
        Subject: chg 26486 removes last use of NGROUPS, so remove the macro-def
        From: Jim Cromie <[EMAIL PROTECTED]>
        Date: Mon, 26 Dec 2005 07:57:51 -0700
        Message-ID: <[EMAIL PROTECTED]>
        
        [ 26492]
        In this, the last tale of the NGROUPS saga, a former pumpking prods
        a mere committer to remove the last of the NGROUPS-sized arrays...
        
        Perl_magic_set() was using the last of these arrays to do the 
        lvalue work on $).  Instead of an array, a pointer is used and 
        re-sized as needed.  

Affected files ...

... //depot/maint-5.8/perl/doio.c#62 integrate
... //depot/maint-5.8/perl/mg.c#95 integrate

Differences ...

==== //depot/maint-5.8/perl/doio.c#62 (text) ====
Index: perl/doio.c
--- perl/doio.c#61~26610~       2006-01-03 08:56:22.000000000 -0800
+++ perl/doio.c 2006-01-11 09:19:22.000000000 -0800
@@ -1972,17 +1972,22 @@
     if (testgid == (effective ? PL_egid : PL_gid))
        return TRUE;
 #ifdef HAS_GETGROUPS
-#ifndef NGROUPS
-#define NGROUPS 32
-#endif
     {
-       Groups_t gary[NGROUPS];
+       Groups_t *gary = NULL;
        I32 anum;
+        bool rc = FALSE;
 
-       anum = getgroups(NGROUPS,gary);
+       anum = getgroups(0, gary);
+        Newx(gary, anum, Groups_t);
+        anum = getgroups(anum, gary);
        while (--anum >= 0)
-           if (gary[anum] == testgid)
-               return TRUE;
+           if (gary[anum] == testgid) {
+                rc = TRUE;
+                break;
+            }
+
+        Safefree(gary);
+        return rc;
     }
 #endif
     return FALSE;

==== //depot/maint-5.8/perl/mg.c#95 (text) ====
Index: perl/mg.c
--- perl/mg.c#94~26763~ 2006-01-10 02:44:50.000000000 -0800
+++ perl/mg.c   2006-01-11 09:19:22.000000000 -0800
@@ -40,14 +40,17 @@
 #include "perl.h"
 
 #if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS)
-#  ifndef NGROUPS
-#    define NGROUPS 32
-#  endif
 #  ifdef I_GRP
 #    include <grp.h>
 #  endif
 #endif
 
+#if defined(HAS_SETGROUPS)
+#  ifndef NGROUPS
+#    define NGROUPS 32
+#  endif
+#endif
+
 #ifdef __hpux
 #  include <sys/pstat.h>
 #endif
@@ -942,10 +945,14 @@
       add_groups:
 #ifdef HAS_GETGROUPS
        {
-           Groups_t gary[NGROUPS];
-           I32 j = getgroups(NGROUPS,gary);
-           while (--j >= 0)
-               Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f, (long unsigned 
int)gary[j]);
+           Groups_t *gary = NULL;
+           I32 num_groups = getgroups(0, gary);
+            Newx(gary, num_groups, Groups_t);
+            num_groups = getgroups(num_groups, gary);
+           while (--num_groups >= 0)
+               Perl_sv_catpvf(aTHX_ sv, " %"Gid_t_f,
+                    (long unsigned int)gary[num_groups]);
+            Safefree(gary);
        }
 #endif
        (void)SvIOK_on(sv);     /* what a wonderful hack! */
@@ -2418,22 +2425,28 @@
 #ifdef HAS_SETGROUPS
        {
            const char *p = SvPV_const(sv, len);
-           Groups_t gary[NGROUPS];
+            Groups_t *gary = NULL;
 
-           while (isSPACE(*p))
-               ++p;
-           PL_egid = Atol(p);
-           for (i = 0; i < NGROUPS; ++i) {
-               while (*p && !isSPACE(*p))
-                   ++p;
-               while (isSPACE(*p))
-                   ++p;
-               if (!*p)
-                   break;
-               gary[i] = Atol(p);
-           }
-           if (i)
-               (void)setgroups(i, gary);
+            while (isSPACE(*p))
+                ++p;
+            PL_egid = Atol(p);
+            for (i = 0; i < NGROUPS; ++i) {
+                while (*p && !isSPACE(*p))
+                    ++p;
+                while (isSPACE(*p))
+                    ++p;
+                if (!*p)
+                    break;
+                if(!gary)
+                    Newx(gary, i + 1, Groups_t);
+                else
+                    Renew(gary, i + 1, Groups_t);
+                gary[i] = Atol(p);
+            }
+            if (i)
+                (void)setgroups(i, gary);
+            if (gary)
+                Safefree(gary);
        }
 #else  /* HAS_SETGROUPS */
        PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
End of Patch.

Reply via email to