diff options
author | Markus Armbruster <armbru@redhat.com> | 2016-07-01 13:47:47 +0200 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2016-07-04 16:49:33 +0300 |
commit | a0efbf16604770b9d805bcf210ec29942321134f (patch) | |
tree | 46e9cde32a5f519dab0d28f96a87ae74d4e72b4d /qapi/string-output-visitor.c | |
parent | 58e19e6e7914354242a67442d0006f9e31684d1a (diff) | |
download | qemu-a0efbf16604770b9d805bcf210ec29942321134f.zip qemu-a0efbf16604770b9d805bcf210ec29942321134f.tar.gz qemu-a0efbf16604770b9d805bcf210ec29942321134f.tar.bz2 |
range: Eliminate direct Range member access
Users of struct Range mess liberally with its members, which makes
refactoring hard. Create a set of methods, and convert all users to
call them instead of accessing members. The methods have carefully
worded contracts, and use assertions to check them.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'qapi/string-output-visitor.c')
-rw-r--r-- | qapi/string-output-visitor.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 5ea395a..c6f01f9 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -83,8 +83,8 @@ static void string_output_set(StringOutputVisitor *sov, char *string) static void string_output_append(StringOutputVisitor *sov, int64_t a) { Range *r = g_malloc0(sizeof(*r)); - r->begin = a; - r->end = a + 1; + + range_set_bounds(r, a, a); sov->ranges = range_list_insert(sov->ranges, r); } @@ -92,28 +92,28 @@ static void string_output_append_range(StringOutputVisitor *sov, int64_t s, int64_t e) { Range *r = g_malloc0(sizeof(*r)); - r->begin = s; - r->end = e + 1; + + range_set_bounds(r, s, e); sov->ranges = range_list_insert(sov->ranges, r); } static void format_string(StringOutputVisitor *sov, Range *r, bool next, bool human) { - if (r->end - r->begin > 1) { + if (range_lob(r) != range_upb(r)) { if (human) { g_string_append_printf(sov->string, "0x%" PRIx64 "-0x%" PRIx64, - r->begin, r->end - 1); + range_lob(r), range_upb(r)); } else { g_string_append_printf(sov->string, "%" PRId64 "-%" PRId64, - r->begin, r->end - 1); + range_lob(r), range_upb(r)); } } else { if (human) { - g_string_append_printf(sov->string, "0x%" PRIx64, r->begin); + g_string_append_printf(sov->string, "0x%" PRIx64, range_lob(r)); } else { - g_string_append_printf(sov->string, "%" PRId64, r->begin); + g_string_append_printf(sov->string, "%" PRId64, range_lob(r)); } } if (next) { |