[Python-checkins] cpython (merge 3.3 -> default): Issue #17557: merge from 3.3
ned.deily
python-checkins at python.org
Fri Aug 2 06:38:12 CEST 2013
http://hg.python.org/cpython/rev/634a8e8816d4
changeset: 84970:634a8e8816d4
parent: 84966:e51cbc45f4ca
parent: 84969:0a4afa8833b5
user: Ned Deily <nad at acm.org>
date: Thu Aug 01 21:37:17 2013 -0700
summary:
Issue #17557: merge from 3.3
files:
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
Modules/posixmodule.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -737,6 +737,7 @@
Luke Kenneth Casson Leighton
Tshepang Lekhonkhobe
Marc-André Lemburg
+Mateusz Lenik
John Lenton
Kostyantyn Leschenko
Benno Leslie
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -184,6 +184,9 @@
Library
-------
+- Issue #17557: Fix os.getgroups() to work with the modified behavior of
+ getgroups(2) on OS X 10.8. Original patch by Mateusz Lenik.
+
- Issue #18608: Avoid keeping a strong reference to the locale module
inside the _io module.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5911,6 +5911,34 @@
gid_t* alt_grouplist = grouplist;
int n;
+#ifdef __APPLE__
+ /* Issue #17557: As of OS X 10.8, getgroups(2) no longer raises EINVAL if
+ * there are more groups than can fit in grouplist. Therefore, on OS X
+ * always first call getgroups with length 0 to get the actual number
+ * of groups.
+ */
+ n = getgroups(0, NULL);
+ if (n < 0) {
+ return posix_error();
+ } else if (n <= MAX_GROUPS) {
+ /* groups will fit in existing array */
+ 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) {
@@ -5937,6 +5965,8 @@
return posix_error();
}
}
+#endif
+
result = PyList_New(n);
if (result != NULL) {
int i;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list