Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (revision 78265) +++ Modules/posixmodule.c (working copy) @@ -1306,8 +1306,8 @@ PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st->st_dev)); #endif PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st->st_nlink)); - PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st->st_uid)); - PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st->st_gid)); + PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)(int)st->st_uid)); + PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)(int)st->st_gid)); #ifdef HAVE_LARGEFILE_SUPPORT PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong((PY_LONG_LONG)st->st_size)); @@ -1884,9 +1884,9 @@ posix_chown(PyObject *self, PyObject *args) { char *path = NULL; - long uid, gid; + int uid, gid; int res; - if (!PyArg_ParseTuple(args, "etll:chown", + if (!PyArg_ParseTuple(args, "etii:chown", Py_FileSystemDefaultEncoding, &path, &uid, &gid)) return NULL; @@ -3782,7 +3782,7 @@ static PyObject * posix_getegid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)getegid()); + return PyInt_FromLong((long)(int)getegid()); } #endif @@ -3795,7 +3795,7 @@ static PyObject * posix_geteuid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)geteuid()); + return PyInt_FromLong((long)(int)geteuid()); } #endif @@ -3808,7 +3808,7 @@ static PyObject * posix_getgid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)getgid()); + return PyInt_FromLong((long)(int)getgid()); } #endif @@ -3829,6 +3829,9 @@ "getgroups() -> list of group IDs\n\n\ Return list of supplemental group IDs for the process."); +#include +int getgrouplist_2(const char *name, gid_t basegid, gid_t **groups); + static PyObject * posix_getgroups(PyObject *self, PyObject *noargs) { @@ -3840,18 +3843,25 @@ /* defined to be 16 on Solaris7, so this should be a small number */ #define MAX_GROUPS 64 #endif - gid_t grouplist[MAX_GROUPS]; + gid_t *grouplist = NULL; + struct passwd *pw; int n; - n = getgroups(MAX_GROUPS, grouplist); - if (n < 0) + if ((pw = getpwuid(getuid())) == NULL) { + errno = EINVAL; posix_error(); - else { + return NULL; + } + n = getgrouplist_2(pw->pw_name, pw->pw_gid, &grouplist); + if (n < 0) { + errno = EINVAL; + posix_error(); + } else { result = PyList_New(n); if (result != NULL) { int i; for (i = 0; i < n; ++i) { - PyObject *o = PyInt_FromLong((long)grouplist[i]); + PyObject *o = PyInt_FromLong((long)(int)grouplist[i]); if (o == NULL) { Py_DECREF(result); result = NULL; @@ -3862,6 +3872,7 @@ } } + if (grouplist) free(grouplist); return result; } #endif @@ -3996,7 +4007,7 @@ static PyObject * posix_getuid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)getuid()); + return PyInt_FromLong((long)(int)getuid()); } #endif @@ -5713,15 +5724,15 @@ posix_setgroups(PyObject *self, PyObject *groups) { int i, len; - gid_t grouplist[MAX_GROUPS]; + gid_t *grouplist; if (!PySequence_Check(groups)) { PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence"); return NULL; } len = PySequence_Size(groups); - if (len > MAX_GROUPS) { - PyErr_SetString(PyExc_ValueError, "too many groups"); + if ((grouplist = (gid_t *)malloc(len * sizeof(gid_t))) == NULL) { + PyErr_NoMemory(); return NULL; } for(i = 0; i < len; i++) { @@ -5745,7 +5756,7 @@ } grouplist[i] = x; /* read back to see if it fits in gid_t */ - if (grouplist[i] != x) { + if ((int)grouplist[i] != x) { PyErr_SetString(PyExc_TypeError, "group id too big"); Py_DECREF(elem); @@ -5755,7 +5766,7 @@ } else { long x = PyInt_AsLong(elem); grouplist[i] = x; - if (grouplist[i] != x) { + if ((int)grouplist[i] != x) { PyErr_SetString(PyExc_TypeError, "group id too big"); Py_DECREF(elem); @@ -5767,6 +5778,7 @@ if (setgroups(len, grouplist) < 0) return posix_error(); + free(grouplist); Py_INCREF(Py_None); return Py_None; } @@ -7538,6 +7550,15 @@ #ifdef _MIPS_CS_VENDOR {"MIPS_CS_VENDOR", _MIPS_CS_VENDOR}, #endif +#ifdef _CS_DARWIN_USER_DIR + {"CS_DARWIN_USER_DIR", _CS_DARWIN_USER_DIR}, +#endif +#ifdef _CS_DARWIN_USER_TEMP_DIR + {"CS_DARWIN_USER_TEMP_DIR", _CS_DARWIN_USER_TEMP_DIR}, +#endif +#ifdef _CS_DARWIN_USER_CACHE_DIR + {"CS_DARWIN_USER_CACHE_DIR", _CS_DARWIN_USER_CACHE_DIR}, +#endif }; static int