[SATYR PATCH] python: treat UINT64_MAX as None
Jiri Moskovcak
jmoskovc at redhat.com
Mon Aug 19 07:09:40 UTC 2013
- please add a comment about the conversion also in the code, so it's
clear on the first sight
thx,
Jirka
On 08/16/2013 05:56 PM, Martin Milata wrote:
> Note: this patch depends on "[SATYR PATCH 7/7] tests for json
> deserialization of stacktraces" as it modifies one of the tests.
>
> -->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8--
> Some structures (namely struct sr_core_frame) use (uint64_t)-1 to denote
> unknown value. This is difficult to compare with in python, so this
> patch introduces translation to None in uint64 accessor function.
>
> Signed-off-by: Martin Milata <mmilata at redhat.com>
> ---
> python/py_common.c | 20 ++++++++++++++++----
> tests/python/core.py | 6 +++---
> 2 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/python/py_common.c b/python/py_common.c
> index 90a0ccb..c1366dd 100644
> --- a/python/py_common.c
> +++ b/python/py_common.c
> @@ -162,6 +162,10 @@ sr_py_getter_uint64(PyObject *self, void *data)
>
> uint64_t num
> = MEMB_T(uint64_t, MEMB(self, gsoff->c_struct_offset), gsoff->member_offset);
> +
> + if (num == -1)
> + Py_RETURN_NONE;
> +
> return PyLong_FromUnsignedLongLong(num);
> }
>
> @@ -174,12 +178,20 @@ sr_py_setter_uint64(PyObject *self, PyObject *rhs, void *data)
> return -1;
> }
>
> - struct getset_offsets *gsoff = data;
> + uint64_t newvalue;
>
> - unsigned long long newvalue = PyInt_AsUnsignedLongLongMask(rhs);
> - if (PyErr_Occurred())
> - return -1;
> + if (rhs == Py_None)
> + {
> + newvalue = -1;
> + }
> + else
> + {
> + newvalue = (uint64_t)PyInt_AsUnsignedLongLongMask(rhs);
> + if (PyErr_Occurred())
> + return -1;
> + }
>
> + struct getset_offsets *gsoff = data;
> MEMB_T(uint64_t, MEMB(self, gsoff->c_struct_offset), gsoff->member_offset) = newvalue;
> return 0;
> }
> diff --git a/tests/python/core.py b/tests/python/core.py
> index e4593b4..cb880ae 100755
> --- a/tests/python/core.py
> +++ b/tests/python/core.py
> @@ -113,9 +113,9 @@ class TestCoreStacktrace(BindingsTestCase):
> self.assertEqual(trace.threads[0].frames[0].fingerprint, '1234123412341234123412341234')
> self.assertTrue(trace.threads[0].frames[0].fingerprint_hashed)
>
> - self.assertEqual(trace.threads[0].frames[1].address, 18446744073709551615L) # !!! FIXME
> + self.assertEqual(trace.threads[0].frames[1].address, None)
> self.assertEqual(trace.threads[0].frames[1].build_id, None)
> - self.assertEqual(trace.threads[0].frames[1].build_id_offset, 18446744073709551615L) # !!!
> + self.assertEqual(trace.threads[0].frames[1].build_id_offset, None)
> self.assertEqual(trace.threads[0].frames[1].function_name, None)
> self.assertEqual(trace.threads[0].frames[1].file_name, None)
> self.assertEqual(trace.threads[0].frames[1].fingerprint, None)
> @@ -123,7 +123,7 @@ class TestCoreStacktrace(BindingsTestCase):
>
> self.assertEqual(trace.threads[0].frames[2].address, 2)
> self.assertEqual(trace.threads[0].frames[2].build_id, None)
> - self.assertEqual(trace.threads[0].frames[2].build_id_offset, 18446744073709551615L) # !!!
> + self.assertEqual(trace.threads[0].frames[2].build_id_offset, None)
> self.assertEqual(trace.threads[0].frames[2].function_name, None)
> self.assertEqual(trace.threads[0].frames[2].file_name, None)
> self.assertEqual(trace.threads[0].frames[2].fingerprint, 'a b c d')
>
More information about the Crash-catcher
mailing list