diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-11-10 14:33:23 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-11-14 19:34:43 +0000 |
commit | 5209b83f530fad1598db3eeb406762bf3fa3d5d2 (patch) | |
tree | 9e7abb432349acaa23f93a24c1477eb676423734 /gdb/python | |
parent | d8a2c719dace17e329d329dc2e38fbddb95fef11 (diff) | |
download | gdb-5209b83f530fad1598db3eeb406762bf3fa3d5d2.zip gdb-5209b83f530fad1598db3eeb406762bf3fa3d5d2.tar.gz gdb-5209b83f530fad1598db3eeb406762bf3fa3d5d2.tar.bz2 |
gdb/python: missing PyObject_IsTrue error check in py-arch.c
Building on the previous two commits, I was auditing our uses of
PyObject_IsTrue looking for places where we were missing an error
check.
The gdb.Architecture.integer_type() function takes a 'signed' argument
which should be a 'bool', and the docs do say:
If SIGNED is not specified, it defaults to 'True'. If SIGNED is
'False', the returned type will be unsigned.
Currently we use PyObject_IsTrue, but we are missing an error check.
To fix this I've tightened the code to enforce the bool requirement at
the point that the arguments are parsed. With that done I can remove
the call to PyObject_IsTrue and instead compare to Py_True directly,
the object in question will always be a PyBool_Type.
However, we were testing that passing a non-bool argument for 'signed'
is treated as Py_False, this was added with this commit:
commit 90fe61ced1c9aa4afb263326e336330d15603fbf
Date: Mon Nov 29 13:53:06 2021 +0000
gdb/python: don't use the 'p' format for parsing args
which is when the PyObject_IsTrue call was added. Given that the docs
do seem pretty clear that only True or False are suitable argument
values, my proposal is that we just remove these tests and instead
test that any non-bool argument value for 'signed' gives a TypeError.
This is a breaking change to the Python API, however, my hope is that
this is such a edge case that it will not cause too many problem.
I've added a NEWS entry to highlight this change though.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-arch.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index d73d7fc..f7e35a4 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -269,15 +269,16 @@ archpy_integer_type (PyObject *self, PyObject *args, PyObject *kw) { static const char *keywords[] = { "size", "signed", NULL }; int size; - PyObject *is_signed_obj = nullptr; + PyObject *is_signed_obj = Py_True; - if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "i|O", keywords, - &size, &is_signed_obj)) + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "i|O!", keywords, + &size, + &PyBool_Type, &is_signed_obj)) return nullptr; /* Assume signed by default. */ - bool is_signed = (is_signed_obj == nullptr - || PyObject_IsTrue (is_signed_obj)); + gdb_assert (PyBool_Check (is_signed_obj)); + bool is_signed = is_signed_obj == Py_True; struct gdbarch *gdbarch; ARCHPY_REQUIRE_VALID (self, gdbarch); |