[SATYR PATCHv3] python: treat UINT64_MAX as None
Richard Marko
rmarko at redhat.com
Wed Aug 28 09:45:28 UTC 2013
Pushed.
On 08/19/2013 12:26 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 of this value to None in uint64 accessor
> functions.
>
> Signed-off-by: Martin Milata <mmilata at redhat.com>
> ---
> python/py_common.c | 22 ++++++++++++++++++----
> python/py_common.h | 2 ++
> tests/python/core.py | 6 +++---
> 3 files changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/python/py_common.c b/python/py_common.c
> index 90a0ccb..80b76f1 100644
> --- a/python/py_common.c
> +++ b/python/py_common.c
> @@ -162,6 +162,11 @@ 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 the attribute is UINT64_MAX, return None. */
> + if (num == -1)
> + Py_RETURN_NONE;
> +
> return PyLong_FromUnsignedLongLong(num);
> }
>
> @@ -174,12 +179,21 @@ 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 is None, set the attribute to UINT64_MAX. */
> + 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/python/py_common.h b/python/py_common.h
> index f64a43a..757df21 100644
> --- a/python/py_common.h
> +++ b/python/py_common.h
> @@ -123,7 +123,9 @@ int sr_py_setter_uint32(PyObject *self, PyObject *rhs, void *data);
> PyObject *sr_py_getter_bool(PyObject *self, void *data);
> int sr_py_setter_bool(PyObject *self, PyObject *rhs, void *data);
>
> +/* NOTE: if the attribute is UINT64_MAX, None object is returned */
> PyObject *sr_py_getter_uint64(PyObject *self, void *data);
> +/* NOTE: when rhs is None, the attribute is set to UINT64_MAX */
> int sr_py_setter_uint64(PyObject *self, PyObject *rhs, void *data);
>
> /*
> 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')
--
Richard Marko
More information about the Crash-catcher
mailing list