Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 78265) +++ Modules/posixmodule.c (working copy) @@ -3823,6 +3823,12 @@ return PyLong_FromPid(getpid()); } +#ifdef NGROUPS_MAX +#define MAX_GROUPS NGROUPS_MAX +#else + /* defined to be 16 on Solaris7, so this should be a small number */ +#define MAX_GROUPS 64 +#endif #ifdef HAVE_GETGROUPS PyDoc_STRVAR(posix_getgroups__doc__, @@ -3832,18 +3838,23 @@ static PyObject * posix_getgroups(PyObject *self, PyObject *noargs) { - PyObject *result = NULL; + PyObject *result = NULL; + int n; -#ifdef NGROUPS_MAX -#define MAX_GROUPS NGROUPS_MAX +#ifdef _DARWIN_C_SOURCE + gid_t *grouplist = NULL; + n = getgroups(0, grouplist); + if (n > 0) { + grouplist = PyMem_MALLOC(n * sizeof(gid_t)); + if (grouplist == NULL) + return PyErr_NoMemory(); + } + n = getgroups(n, grouplist); #else - /* defined to be 16 on Solaris7, so this should be a small number */ -#define MAX_GROUPS 64 + gid_t grouplist[MAX_GROUPS]; + n = getgroups(MAX_GROUPS, grouplist); #endif - gid_t grouplist[MAX_GROUPS]; - int n; - n = getgroups(MAX_GROUPS, grouplist); if (n < 0) posix_error(); else { @@ -3861,7 +3872,10 @@ } } } - +#ifdef _DARWIN_C_SOURCE + if (grouplist) + PyMem_FREE(grouplist); +#endif return result; } #endif