--- Modules/posixmodule.c.orig 2010-02-14 16:18:38 +0100 +++ Modules/posixmodule.c 2010-02-14 16:19:13 +0100 @@ -1310,8 +1310,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)); @@ -1897,9 +1897,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; @@ -3804,7 +3804,7 @@ static PyObject * posix_getegid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)getegid()); + return PyInt_FromLong((long)(int)getegid()); } #endif @@ -3817,7 +3817,7 @@ static PyObject * posix_geteuid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)geteuid()); + return PyInt_FromLong((long)(int)geteuid()); } #endif @@ -3830,7 +3830,7 @@ static PyObject * posix_getgid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)getgid()); + return PyInt_FromLong((long)(int)getgid()); } #endif @@ -3851,6 +3851,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) { @@ -3862,18 +3865,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; @@ -3884,6 +3894,7 @@ } } + if (grouplist) free(grouplist); return result; } #endif @@ -3994,7 +4005,7 @@ static PyObject * posix_getuid(PyObject *self, PyObject *noargs) { - return PyInt_FromLong((long)getuid()); + return PyInt_FromLong((long)(int)getuid()); } #endif @@ -5711,15 +5722,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++) { @@ -5743,7 +5754,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); @@ -5753,7 +5764,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); @@ -5765,6 +5776,7 @@ if (setgroups(len, grouplist) < 0) return posix_error(); + free(grouplist); Py_INCREF(Py_None); return Py_None; } @@ -7521,6 +7533,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