Issue #4591: Uid and gid values larger than 2**31 are supported now.
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 6729c84..c2907f6 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -3,8 +3,8 @@
 
 #include "Python.h"
 #include "structseq.h"
+#include "posixmodule.h"
 
-#include <sys/types.h>
 #include <pwd.h>
 
 static PyStructSequence_Field struct_pwd_type_fields[] = {
@@ -73,8 +73,8 @@
 #else
     SETS(setIndex++, p->pw_passwd);
 #endif
-    SETI(setIndex++, p->pw_uid);
-    SETI(setIndex++, p->pw_gid);
+    PyStructSequence_SET_ITEM(v, setIndex++, _PyInt_FromUid(p->pw_uid));
+    PyStructSequence_SET_ITEM(v, setIndex++, _PyInt_FromGid(p->pw_gid));
 #ifdef __VMS
     SETS(setIndex++, "");
 #else
@@ -103,13 +103,21 @@
 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)) {
+        if (PyErr_ExceptionMatches(PyExc_OverflowError))
+            PyErr_Format(PyExc_KeyError,
+                         "getpwuid(): uid not found");
         return NULL;
+    }
     if ((p = getpwuid(uid)) == NULL) {
-        PyErr_Format(PyExc_KeyError,
-                     "getpwuid(): uid not found: %d", uid);
+        if (uid < 0)
+            PyErr_Format(PyExc_KeyError,
+                         "getpwuid(): uid not found: %ld", (long)uid);
+        else
+            PyErr_Format(PyExc_KeyError,
+                         "getpwuid(): uid not found: %lu", (unsigned long)uid);
         return NULL;
     }
     return mkpwent(p);