Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3569,6 +3569,7 @@ def test_cli_converters(self):
"DWORD",
"fildes",
"float",
"gid_t",
"HANDLE",
"int",
"long",
Expand All @@ -3587,6 +3588,7 @@ def test_cli_converters(self):
"size_t",
"slice_index",
"str",
"uid_t",
"uint16",
"uint32",
"uint64",
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_pwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def test_errors(self):
self.assertRaises(TypeError, pwd.getpwuid, 0.0)
self.assertRaises(TypeError, pwd.getpwuid, 0, 0)
# should be out of uid_t range
self.assertRaises(KeyError, pwd.getpwuid, 2**128)
self.assertRaises(KeyError, pwd.getpwuid, -2**128)
self.assertRaises(OverflowError, pwd.getpwuid, 2**128)
self.assertRaises(OverflowError, pwd.getpwuid, -2**128)
self.assertRaises(TypeError, pwd.getpwnam)
self.assertRaises(TypeError, pwd.getpwnam, 42)
self.assertRaises(TypeError, pwd.getpwnam, b'root')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`pwd.getpwuid` now raises :exc:`OverflowError` instead of
:exc:`KeyError` if the user id is out of the range of the C ``uid_t`` type,
as :func:`grp.getgrgid` does for the group id.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Argument Clinic: the ``pid_t``, ``Py_off_t``, ``HANDLE``, ``DWORD`` and
``BOOL`` converters, previously defined in 9 different files, are now
provided by Argument Clinic itself.
Argument Clinic: the ``pid_t``, ``uid_t``, ``gid_t``, ``Py_off_t``,
``HANDLE``, ``DWORD`` and ``BOOL`` converters, previously defined in
individual files, are now provided by Argument Clinic itself.
12 changes: 7 additions & 5 deletions Modules/clinic/grpmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion Modules/clinic/pwdmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions Modules/grpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,22 @@ mkgrent(PyObject *module, struct group *p)
/*[clinic input]
grp.getgrgid

id: object
id as gid: gid_t

Return the group database entry for the given numeric group ID.

If id is not valid, raise KeyError.
[clinic start generated code]*/

static PyObject *
grp_getgrgid_impl(PyObject *module, PyObject *id)
/*[clinic end generated code: output=30797c289504a1ba input=15fa0e2ccf5cda25]*/
grp_getgrgid_impl(PyObject *module, gid_t gid)
/*[clinic end generated code: output=a9e7385cd6df08da input=fca15128dd772588]*/
{
PyObject *retval = NULL;
int nomem = 0;
char *buf = NULL, *buf2 = NULL;
gid_t gid;
struct group *p;

if (!_Py_Gid_Converter(id, &gid)) {
return NULL;
}
#ifdef HAVE_GETGRGID_R
int status;
Py_ssize_t bufsize;
Expand Down
10 changes: 1 addition & 9 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3185,14 +3185,6 @@ class dir_fd_converter(CConverter):
def c_default_init(self):
self.c_default = 'DEFAULT_DIR_FD'

class uid_t_converter(CConverter):
type = "uid_t"
converter = '_Py_Uid_Converter'

class gid_t_converter(CConverter):
type = "gid_t"
converter = '_Py_Gid_Converter'

class dev_t_converter(CConverter):
type = 'dev_t'
converter = '_Py_Dev_Converter'
Expand Down Expand Up @@ -3249,7 +3241,7 @@ class confname_converter(CConverter):
""", argname=argname, converter=self.converter, table=self.table)

[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=e459765bdf453ebf]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=7ceccf55bb600f61]*/

/*[clinic input]

Expand Down
13 changes: 3 additions & 10 deletions Modules/pwdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mkpwent(PyObject *module, struct passwd *p)
/*[clinic input]
pwd.getpwuid

uidobj: object
uidobj as uid: uid_t
/

Return the password database entry for the given numeric user ID.
Expand All @@ -130,21 +130,14 @@ See `help(pwd)` for more on password database entries.
[clinic start generated code]*/

static PyObject *
pwd_getpwuid(PyObject *module, PyObject *uidobj)
/*[clinic end generated code: output=c4ee1d4d429b86c4 input=ae64d507a1c6d3e8]*/
pwd_getpwuid_impl(PyObject *module, uid_t uid)
/*[clinic end generated code: output=631bad376fa670c3 input=506d3a592ef19799]*/
{
PyObject *retval = NULL;
uid_t uid;
int nomem = 0;
struct passwd *p;
char *buf = NULL, *buf2 = NULL;

if (!_Py_Uid_Converter(uidobj, &uid)) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_Format(PyExc_KeyError,
"getpwuid(): uid not found");
return NULL;
}
#ifdef HAVE_GETPWUID_R
int status;
Py_ssize_t bufsize;
Expand Down
10 changes: 10 additions & 0 deletions Tools/clinic/libclinic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,16 @@ def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> st
argname=argname)


class gid_t_converter(CConverter):
type = 'gid_t'
converter = '_Py_Gid_Converter'


class uid_t_converter(CConverter):
type = 'uid_t'
converter = '_Py_Uid_Converter'


class pid_t_converter(CConverter):
type = 'pid_t'
format_unit = '" _Py_PARSE_PID "'
Expand Down
Loading