diff -r ce3b22951c7e Include/longobject.h --- a/Include/longobject.h Fri Nov 23 22:17:02 2012 +0200 +++ b/Include/longobject.h Sat Nov 24 20:28:10 2012 +0200 @@ -49,6 +49,15 @@ #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)" #endif /* SIZEOF_PID_T */ +#ifndef Py_LIMITED_API +#ifndef MS_WINDOWS +PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t); +PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t); +PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, void *); +PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *); +#endif /* MS_WINDOWS */ +#endif + /* Used by Python/mystrtoul.c. */ #ifndef Py_LIMITED_API PyAPI_DATA(unsigned char) _PyLong_DigitValue[256]; diff -r ce3b22951c7e Lib/test/test_posix.py --- a/Lib/test/test_posix.py Fri Nov 23 22:17:02 2012 +0200 +++ b/Lib/test/test_posix.py Sat Nov 24 20:28:10 2012 +0200 @@ -387,10 +387,20 @@ else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) - def _test_all_chown_common(self, chown_func, first_param): + def _test_all_chown_common(self, chown_func, first_param, stat_func): """Common code for chown, fchown and lchown tests.""" + def check_stat(): + if stat_func is not None: + stat = stat_func(first_param) + self.assertEqual(stat.st_uid, os.getuid()) + self.assertEqual(stat.st_gid, os.getgid()) # test a successful chown call chown_func(first_param, os.getuid(), os.getgid()) + check_stat() + chown_func(first_param, -1, os.getgid()) + check_stat() + chown_func(first_param, os.getuid(), -1) + check_stat() if os.getuid() == 0: try: @@ -410,8 +420,12 @@ "behavior") else: # non-root cannot chown to root, raises OSError - self.assertRaises(OSError, chown_func, - first_param, 0, 0) + self.assertRaises(OSError, chown_func, first_param, 0, 0) + check_stat() + self.assertRaises(OSError, chown_func, first_param, -1, 0) + check_stat() + self.assertRaises(OSError, chown_func, first_param, 0, -1) + check_stat() @unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()") def test_chown(self): @@ -421,7 +435,8 @@ # re-create the file support.create_empty_file(support.TESTFN) - self._test_all_chown_common(posix.chown, support.TESTFN) + self._test_all_chown_common(posix.chown, support.TESTFN, + getattr(posix, 'stat', None)) @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()") def test_fchown(self): @@ -431,7 +446,8 @@ test_file = open(support.TESTFN, 'w') try: fd = test_file.fileno() - self._test_all_chown_common(posix.fchown, fd) + self._test_all_chown_common(posix.fchown, fd, + getattr(posix, 'fstat', None)) finally: test_file.close() @@ -440,7 +456,8 @@ os.unlink(support.TESTFN) # create a symlink os.symlink(_DUMMY_SYMLINK, support.TESTFN) - self._test_all_chown_common(posix.lchown, support.TESTFN) + self._test_all_chown_common(posix.lchown, support.TESTFN, + getattr(posix, 'lstat', None)) def test_chdir(self): if hasattr(posix, 'chdir'): diff -r ce3b22951c7e Modules/grpmodule.c --- a/Modules/grpmodule.c Fri Nov 23 22:17:02 2012 +0200 +++ b/Modules/grpmodule.c Sat Nov 24 20:28:10 2012 +0200 @@ -69,7 +69,7 @@ Py_INCREF(Py_None); } #endif - SET(setIndex++, PyLong_FromLong((long) p->gr_gid)); + SET(setIndex++, _PyLong_FromGid(p->gr_gid)); SET(setIndex++, w); #undef SET @@ -85,17 +85,24 @@ grp_getgrgid(PyObject *self, PyObject *pyo_id) { PyObject *py_int_id; - unsigned int gid; + gid_t gid; struct group *p; py_int_id = PyNumber_Long(pyo_id); if (!py_int_id) return NULL; - gid = PyLong_AS_LONG(py_int_id); + if (!_Py_Gid_Converter(py_int_id, &gid)) { + Py_DECREF(py_int_id); + return NULL; + } Py_DECREF(py_int_id); if ((p = getgrgid(gid)) == NULL) { - PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid); + PyObject *gid_obj = _PyLong_FromGid(gid); + if (gid_obj == NULL) + return NULL; + PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %S", gid_obj); + Py_DECREF(gid_obj); return NULL; } return mkgrent(p); diff -r ce3b22951c7e Modules/posixmodule.c --- a/Modules/posixmodule.c Fri Nov 23 22:17:02 2012 +0200 +++ b/Modules/posixmodule.c Sat Nov 24 20:28:10 2012 +0200 @@ -1956,8 +1956,13 @@ PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev)); #endif PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink)); - PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long)st->st_uid)); - PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long)st->st_gid)); +#if defined(MS_WINDOWS) + PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong(0)); + PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong(0)); +#else + PyStructSequence_SET_ITEM(v, 4, _PyLong_FromUid(st->st_uid)); + PyStructSequence_SET_ITEM(v, 5, _PyLong_FromGid(st->st_gid)); +#endif #ifdef HAVE_LARGEFILE_SUPPORT PyStructSequence_SET_ITEM(v, 6, PyLong_FromLongLong((PY_LONG_LONG)st->st_size)); @@ -2771,7 +2776,6 @@ posix_chown(PyObject *self, PyObject *args, PyObject *kwargs) { path_t path; - long uid_l, gid_l; uid_t uid; gid_t gid; int dir_fd = DEFAULT_DIR_FD; @@ -2786,9 +2790,10 @@ #ifdef HAVE_FCHOWN path.allow_fd = 1; #endif - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&ll|$O&p:chown", keywords, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&|$O&p:chown", keywords, path_converter, &path, - &uid_l, &gid_l, + _Py_Uid_Converter, &uid, + _Py_Gid_Converter, &gid, #ifdef HAVE_FCHOWNAT dir_fd_converter, &dir_fd, #else @@ -2819,8 +2824,6 @@ #endif Py_BEGIN_ALLOW_THREADS - uid = (uid_t)uid_l; - gid = (uid_t)gid_l; #ifdef HAVE_FCHOWN if (path.fd != -1) result = fchown(path.fd, uid, gid); @@ -2864,12 +2867,15 @@ posix_fchown(PyObject *self, PyObject *args) { int fd; - long uid, gid; + uid_t uid; + gid_t gid; int res; - if (!PyArg_ParseTuple(args, "ill:fchown", &fd, &uid, &gid)) + if (!PyArg_ParseTuple(args, "iO&O&:fchown", &fd, + _Py_Uid_Converter, &uid, + _Py_Gid_Converter, &gid)) return NULL; Py_BEGIN_ALLOW_THREADS - res = fchown(fd, (uid_t) uid, (gid_t) gid); + res = fchown(fd, uid, gid); Py_END_ALLOW_THREADS if (res < 0) return posix_error(); @@ -2888,16 +2894,18 @@ posix_lchown(PyObject *self, PyObject *args) { path_t path; - long uid, gid; + uid_t uid; + gid_t gid; int res; memset(&path, 0, sizeof(path)); path.function_name = "lchown"; - if (!PyArg_ParseTuple(args, "O&ll:lchown", + if (!PyArg_ParseTuple(args, "O&O&O&:lchown", path_converter, &path, - &uid, &gid)) + _Py_Uid_Converter, &uid, + _Py_Gid_Converter, &gid)) return NULL; Py_BEGIN_ALLOW_THREADS - res = lchown(path.narrow, (uid_t) uid, (gid_t) gid); + res = lchown(path.narrow, uid, gid); Py_END_ALLOW_THREADS if (res < 0) { path_error(&path); @@ -5571,7 +5579,7 @@ static PyObject * posix_getegid(PyObject *self, PyObject *noargs) { - return PyLong_FromLong((long)getegid()); + return _PyLong_FromGid(getegid()); } #endif @@ -5584,7 +5592,7 @@ static PyObject * posix_geteuid(PyObject *self, PyObject *noargs) { - return PyLong_FromLong((long)geteuid()); + return _PyLong_FromUid(geteuid()); } #endif @@ -5597,7 +5605,7 @@ static PyObject * posix_getgid(PyObject *self, PyObject *noargs) { - return PyLong_FromLong((long)getgid()); + return _PyLong_FromGid(getgid()); } #endif @@ -5639,8 +5647,14 @@ #endif ngroups = MAX_GROUPS; - if (!PyArg_ParseTuple(args, "si", &user, &basegid)) - return NULL; +#ifdef __APPLE__ + if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid)) + return NULL; +#else + if (!PyArg_ParseTuple(args, "sO&:getgrouplist", &user, + _Py_Gid_Converter, &basegid)) + return NULL; +#endif #ifdef __APPLE__ groups = PyMem_Malloc(ngroups * sizeof(int)); @@ -5662,7 +5676,11 @@ } for (i = 0; i < ngroups; i++) { +#ifdef __APPLE__ PyObject *o = PyLong_FromUnsignedLong((unsigned long)groups[i]); +#else + PyObject *o = _PyLong_FromGid(groups[i]); +#endif if (o == NULL) { Py_DECREF(list); PyMem_Del(groups); @@ -5736,7 +5754,7 @@ if (result != NULL) { int i; for (i = 0; i < n; ++i) { - PyObject *o = PyLong_FromLong((long)alt_grouplist[i]); + PyObject *o = _PyLong_FromGid(alt_grouplist[i]); if (o == NULL) { Py_DECREF(result); result = NULL; @@ -5767,14 +5785,25 @@ PyObject *oname; char *username; int res; - long gid; - - if (!PyArg_ParseTuple(args, "O&l:initgroups", - PyUnicode_FSConverter, &oname, &gid)) +#ifdef __APPLE__ + int gid; +#else + gid_t gid; +#endif + +#ifdef __APPLE__ + if (!PyArg_ParseTuple(args, "O&i:initgroups", + PyUnicode_FSConverter, &oname, + &gid)) +#else + if (!PyArg_ParseTuple(args, "O&O&:initgroups", + PyUnicode_FSConverter, &oname, + _Py_Gid_Converter, &gid)) +#endif return NULL; username = PyBytes_AS_STRING(oname); - res = initgroups(username, (gid_t) gid); + res = initgroups(username, gid); Py_DECREF(oname); if (res == -1) return PyErr_SetFromErrno(PyExc_OSError); @@ -5949,7 +5978,7 @@ static PyObject * posix_getuid(PyObject *self, PyObject *noargs) { - return PyLong_FromLong((long)getuid()); + return _PyLong_FromUid(getuid()); } #endif @@ -6074,15 +6103,9 @@ static PyObject * posix_setuid(PyObject *self, PyObject *args) { - long uid_arg; uid_t uid; - if (!PyArg_ParseTuple(args, "l:setuid", &uid_arg)) - return NULL; - uid = uid_arg; - if (uid != uid_arg) { - PyErr_SetString(PyExc_OverflowError, "user id too big"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O&:setuid", _Py_Uid_Converter, &uid)) + return NULL; if (setuid(uid) < 0) return posix_error(); Py_INCREF(Py_None); @@ -6099,15 +6122,9 @@ static PyObject * posix_seteuid (PyObject *self, PyObject *args) { - long euid_arg; uid_t euid; - if (!PyArg_ParseTuple(args, "l", &euid_arg)) - return NULL; - euid = euid_arg; - if (euid != euid_arg) { - PyErr_SetString(PyExc_OverflowError, "user id too big"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O&:seteuid", _Py_Uid_Converter, &euid)) + return NULL; if (seteuid(euid) < 0) { return posix_error(); } else { @@ -6125,15 +6142,9 @@ static PyObject * posix_setegid (PyObject *self, PyObject *args) { - long egid_arg; gid_t egid; - if (!PyArg_ParseTuple(args, "l", &egid_arg)) - return NULL; - egid = egid_arg; - if (egid != egid_arg) { - PyErr_SetString(PyExc_OverflowError, "group id too big"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O&:setegid", _Py_Gid_Converter, &egid)) + return NULL; if (setegid(egid) < 0) { return posix_error(); } else { @@ -6151,23 +6162,11 @@ static PyObject * posix_setreuid (PyObject *self, PyObject *args) { - long ruid_arg, euid_arg; uid_t ruid, euid; - if (!PyArg_ParseTuple(args, "ll", &ruid_arg, &euid_arg)) - return NULL; - if (ruid_arg == -1) - ruid = (uid_t)-1; /* let the compiler choose how -1 fits */ - else - ruid = ruid_arg; /* otherwise, assign from our long */ - if (euid_arg == -1) - euid = (uid_t)-1; - else - euid = euid_arg; - if ((euid_arg != -1 && euid != euid_arg) || - (ruid_arg != -1 && ruid != ruid_arg)) { - PyErr_SetString(PyExc_OverflowError, "user id too big"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O&O&:setreuid", + _Py_Uid_Converter, &ruid, + _Py_Uid_Converter, &euid)) + return NULL; if (setreuid(ruid, euid) < 0) { return posix_error(); } else { @@ -6185,23 +6184,11 @@ static PyObject * posix_setregid (PyObject *self, PyObject *args) { - long rgid_arg, egid_arg; gid_t rgid, egid; - if (!PyArg_ParseTuple(args, "ll", &rgid_arg, &egid_arg)) - return NULL; - if (rgid_arg == -1) - rgid = (gid_t)-1; /* let the compiler choose how -1 fits */ - else - rgid = rgid_arg; /* otherwise, assign from our long */ - if (egid_arg == -1) - egid = (gid_t)-1; - else - egid = egid_arg; - if ((egid_arg != -1 && egid != egid_arg) || - (rgid_arg != -1 && rgid != rgid_arg)) { - PyErr_SetString(PyExc_OverflowError, "group id too big"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O&O&:setregid", + _Py_Gid_Converter, &rgid, + _Py_Gid_Converter, &egid)) + return NULL; if (setregid(rgid, egid) < 0) { return posix_error(); } else { @@ -6219,15 +6206,9 @@ static PyObject * posix_setgid(PyObject *self, PyObject *args) { - long gid_arg; gid_t gid; - if (!PyArg_ParseTuple(args, "l:setgid", &gid_arg)) - return NULL; - gid = gid_arg; - if (gid != gid_arg) { - PyErr_SetString(PyExc_OverflowError, "group id too big"); - return NULL; - } + if (!PyArg_ParseTuple(args, "O&:setgid", _Py_Gid_Converter, &gid)) + return NULL; if (setgid(gid) < 0) return posix_error(); Py_INCREF(Py_None); @@ -6266,18 +6247,7 @@ Py_DECREF(elem); return NULL; } else { - unsigned long x = PyLong_AsUnsignedLong(elem); - if (PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "group id too big"); - Py_DECREF(elem); - return NULL; - } - grouplist[i] = x; - /* read back the value to see if it fitted in gid_t */ - if (grouplist[i] != x) { - PyErr_SetString(PyExc_TypeError, - "group id too big"); + if (!_Py_Gid_Converter(elem, &grouplist[i])) { Py_DECREF(elem); return NULL; } @@ -6439,7 +6409,7 @@ return NULL; PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid)); - PyStructSequence_SET_ITEM(result, 1, PyLong_FromPid(si.si_uid)); + PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid)); PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo))); PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status))); PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code))); @@ -9689,8 +9659,11 @@ posix_setresuid (PyObject *self, PyObject *args) { /* We assume uid_t is no larger than a long. */ - long ruid, euid, suid; - if (!PyArg_ParseTuple(args, "lll", &ruid, &euid, &suid)) + uid_t ruid, euid, suid; + if (!PyArg_ParseTuple(args, "O&O&O&:setresuid", + _Py_Uid_Converter, &ruid, + _Py_Uid_Converter, &euid, + _Py_Uid_Converter, &suid)) return NULL; if (setresuid(ruid, euid, suid) < 0) return posix_error(); @@ -9706,9 +9679,11 @@ static PyObject* posix_setresgid (PyObject *self, PyObject *args) { - /* We assume uid_t is no larger than a long. */ - long rgid, egid, sgid; - if (!PyArg_ParseTuple(args, "lll", &rgid, &egid, &sgid)) + gid_t rgid, egid, sgid; + if (!PyArg_ParseTuple(args, "O&O&O&:setresgid", + _Py_Gid_Converter, &rgid, + _Py_Gid_Converter, &egid, + _Py_Gid_Converter, &sgid)) return NULL; if (setresgid(rgid, egid, sgid) < 0) return posix_error(); @@ -9725,14 +9700,11 @@ posix_getresuid (PyObject *self, PyObject *noargs) { uid_t ruid, euid, suid; - long l_ruid, l_euid, l_suid; if (getresuid(&ruid, &euid, &suid) < 0) return posix_error(); - /* Force the values into long's as we don't know the size of uid_t. */ - l_ruid = ruid; - l_euid = euid; - l_suid = suid; - return Py_BuildValue("(lll)", l_ruid, l_euid, l_suid); + return Py_BuildValue("(NNN)", _PyLong_FromUid(ruid), + _PyLong_FromUid(euid), + _PyLong_FromUid(suid)); } #endif @@ -9745,14 +9717,11 @@ posix_getresgid (PyObject *self, PyObject *noargs) { uid_t rgid, egid, sgid; - long l_rgid, l_egid, l_sgid; if (getresgid(&rgid, &egid, &sgid) < 0) return posix_error(); - /* Force the values into long's as we don't know the size of uid_t. */ - l_rgid = rgid; - l_egid = egid; - l_sgid = sgid; - return Py_BuildValue("(lll)", l_rgid, l_egid, l_sgid); + return Py_BuildValue("(NNN)", _PyLong_FromGid(rgid), + _PyLong_FromGid(egid), + _PyLong_FromGid(sgid)); } #endif diff -r ce3b22951c7e Modules/pwdmodule.c --- a/Modules/pwdmodule.c Fri Nov 23 22:17:02 2012 +0200 +++ b/Modules/pwdmodule.c Sat Nov 24 20:28:10 2012 +0200 @@ -74,8 +74,8 @@ #else SETS(setIndex++, p->pw_passwd); #endif - SETI(setIndex++, p->pw_uid); - SETI(setIndex++, p->pw_gid); + PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid)); + PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid)); #ifdef __VMS SETS(setIndex++, ""); #else @@ -104,13 +104,17 @@ static PyObject * pwd_getpwuid(PyObject *self, PyObject *args) { - unsigned int uid; + uid_t uid; struct passwd *p; - if (!PyArg_ParseTuple(args, "I:getpwuid", &uid)) + if (!PyArg_ParseTuple(args, "O&:getpwuid", _Py_Uid_Converter, &uid)) return NULL; if ((p = getpwuid(uid)) == NULL) { + PyObject *uid_obj = _PyLong_FromUid(uid); + if (uid_obj == NULL) + return NULL; PyErr_Format(PyExc_KeyError, - "getpwuid(): uid not found: %d", uid); + "getpwuid(): uid not found: %S", uid_obj); + Py_DECREF(uid_obj); return NULL; } return mkpwent(p); diff -r ce3b22951c7e Modules/signalmodule.c --- a/Modules/signalmodule.c Fri Nov 23 22:17:02 2012 +0200 +++ b/Modules/signalmodule.c Sat Nov 24 20:28:10 2012 +0200 @@ -723,7 +723,7 @@ PyStructSequence_SET_ITEM(result, 1, PyLong_FromLong((long)(si->si_code))); PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si->si_errno))); PyStructSequence_SET_ITEM(result, 3, PyLong_FromPid(si->si_pid)); - PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si->si_uid))); + PyStructSequence_SET_ITEM(result, 4, _PyLong_FromUid(si->si_uid)); PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong((long)(si->si_status))); PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(si->si_band)); diff -r ce3b22951c7e Objects/longobject.c --- a/Objects/longobject.c Fri Nov 23 22:17:02 2012 +0200 +++ b/Objects/longobject.c Sat Nov 24 20:28:10 2012 +0200 @@ -1387,6 +1387,122 @@ #endif /* HAVE_LONG_LONG */ + +#ifndef MS_WINDOWS +PyObject * +_PyLong_FromUid(uid_t uid) +{ + if (uid == (uid_t)-1) + return PyLong_FromLong(-1); + return PyLong_FromUnsignedLong(uid); +} + +PyObject * +_PyLong_FromGid(gid_t gid) +{ + if (gid == (gid_t)-1) + return PyLong_FromLong(-1); + return PyLong_FromUnsignedLong(gid); +} + +int +_Py_Uid_Converter(PyObject *obj, void *p) +{ + int overflow; + long result = PyLong_AsLongAndOverflow(obj, &overflow); + if (overflow < 0) + goto OverflowDown; + if (!overflow && result == -1) { + /* error or -1 */ + if (PyErr_Occurred()) + return 0; + *(uid_t *)p = (uid_t)-1; + } + else { + /* unsigned uid_t */ + unsigned long uresult; + if (overflow > 0) { + uresult = PyLong_AsUnsignedLong(obj); + if (PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + goto OverflowUp; + return 0; + } + if ((uid_t)uresult == (uid_t)-1) + goto OverflowUp; + } else { + if (result < 0) + goto OverflowDown; + uresult = result; + } + if (sizeof(uid_t) < sizeof(long) && + (unsigned long)(uid_t)uresult != uresult) + goto OverflowUp; + *(uid_t *)p = (uid_t)uresult; + } + return 1; + +OverflowDown: + PyErr_SetString(PyExc_OverflowError, + "user id is less than minimum"); + return 0; + +OverflowUp: + PyErr_SetString(PyExc_OverflowError, + "user id is greater than maximum"); + return 0; +} + +int +_Py_Gid_Converter(PyObject *obj, void *p) +{ + int overflow; + long result = PyLong_AsLongAndOverflow(obj, &overflow); + if (overflow < 0) + goto OverflowDown; + if (!overflow && result == -1) { + /* error or -1 */ + if (PyErr_Occurred()) + return 0; + *(gid_t *)p = (gid_t)-1; + } + else { + /* unsigned gid_t */ + unsigned long uresult; + if (overflow > 0) { + uresult = PyLong_AsUnsignedLong(obj); + if (PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + goto OverflowUp; + return 0; + } + if ((gid_t)uresult == (gid_t)-1) + goto OverflowUp; + } else { + if (result < 0) + goto OverflowDown; + uresult = result; + } + if (sizeof(gid_t) < sizeof(long) && + (unsigned long)(gid_t)uresult != uresult) + goto OverflowUp; + *(gid_t *)p = (gid_t)uresult; + } + return 1; + +OverflowDown: + PyErr_SetString(PyExc_OverflowError, + "group id is less than minimum"); + return 0; + +OverflowUp: + PyErr_SetString(PyExc_OverflowError, + "group id is greater than maximum"); + return 0; +} +#endif /* MS_WINDOWS */ + + #define CHECK_BINOP(v,w) \ do { \ if (!PyLong_Check(v) || !PyLong_Check(w)) \