diff -r 328781ae35d2 Modules/posixmodule.c --- a/Modules/posixmodule.c Fri Jul 05 01:41:30 2013 +0200 +++ b/Modules/posixmodule.c Sat Jul 06 15:00:06 2013 +0200 @@ -4054,6 +4054,38 @@ gid_t* alt_grouplist = grouplist; int n; + /* On MacOSX starting from 10.8 getgroups(2) doesn't return EINVAL, + * when there are more than MAX_GROUPS groups. Instead it returns + * an array with MAX_GROUPS entries. + * + * To work it around getgroups(2) can be called with 0 as the first + * argument so that it returns the actual number of groups and then + * subsequent call could be done to fetch the group ids. + */ +#ifdef __APPLE__ + n = getgroups(0, NULL); + if (n < 0) { + return posix_error(); + } else if (n <= MAX_GROUPS) { + /* Avoid malloc(0) */ + alt_grouplist = grouplist; + } else { + alt_grouplist = PyMem_Malloc(n * sizeof(gid_t)); + if (alt_grouplist == NULL) { + errno = EINVAL; + return posix_error(); + } + } + + n = getgroups(n, alt_grouplist); + if (n == -1) { + if (alt_grouplist != grouplist) { + PyMem_Free(alt_grouplist); + } + + return posix_error(); + } +#else n = getgroups(MAX_GROUPS, grouplist); if (n < 0) { if (errno == EINVAL) { @@ -4080,6 +4112,8 @@ return posix_error(); } } +#endif + result = PyList_New(n); if (result != NULL) { int i;