summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2023-02-13 14:17:56 +0100
committerMichal Privoznik <mprivozn@redhat.com>2023-02-13 14:24:32 +0100
commitf8fefdf45c6ba1235f0c9ca454e5ea8f27a83607 (patch)
tree318f6d4ab5c560b569292ee79dbb3a28b23db9b0
parent8ef7420806d7d2bf6368b637c5acced227f6d5e5 (diff)
downloadlibvirt-python-f8fefdf45c6ba1235f0c9ca454e5ea8f27a83607.tar.gz
typewrappers: Rework libvirt_uintUnwrap()
Python C API offers PyLong_AsUnsignedLong() which already raises an exception on negative values. Rewrite our libvirt_uintUnwrap() to use that and drop check for negative values. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
-rw-r--r--typewrappers.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/typewrappers.c b/typewrappers.c
index 6d53247..1395728 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -132,18 +132,18 @@ int
libvirt_uintUnwrap(PyObject *obj,
unsigned int *val)
{
- long long_val;
+ unsigned long long_val;
if (!obj) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
return -1;
}
- long_val = PyLong_AsLong(obj);
- if ((long_val == -1) && PyErr_Occurred())
+ long_val = PyLong_AsUnsignedLong(obj);
+ if ((long_val == (unsigned long)-1) && PyErr_Occurred())
return -1;
- if (long_val >= 0 && long_val <= UINT_MAX) {
+ if (long_val <= UINT_MAX) {
*val = long_val;
} else {
PyErr_SetString(PyExc_OverflowError,