From: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: "Toke Høiland-Jørgensen" <toke@toke.dk>,
"cake@lists.bufferbloat.net" <cake@lists.bufferbloat.net>
Subject: Re: [Cake] [PATCH 1/2] cake: print_uint format fixes
Date: Fri, 16 Mar 2018 08:02:28 +0000 [thread overview]
Message-ID: <6DC9DE5E-0ED4-4BBB-9C7C-0F8887856D25@darbyshire-bryant.me.uk> (raw)
In-Reply-To: <20180312081142.0a9da85c@xeon-e3>
[-- Attachment #1.1: Type: text/plain, Size: 1062 bytes --]
> On 12 Mar 2018, at 15:11, Stephen Hemminger <stephen@networkplumber.org> wrote:
>
> On Mon, 12 Mar 2018 10:56:09 +0100
> Toke Høiland-Jørgensen <toke@toke.dk> wrote:
>>
>> Stephen, would you accept patches to fix the API (to add
>> print_{u,}int64() variants and turn print_uint() into native-int size)?
>> Or should we stick with the API currently there and live with the
>> inconsistency? :)
>>
>> -Toke
>
> I agree print_int should take int, print_uint should take unsigned int, and there should
> be print_u64 (and print_u32, print_u8)
Submitted a patch to netdev but almost certainly did it wrong/based on wrong tree etc ‘cos I don’t normally inhabit that space. The quite simple attached patch restores corrrect functioning on my BE MIPS box. Validation that the MANY calls to print_uint are using the correct type is left as an exercise for the reader :-) But at least there’s no longer a hidden promotion from uint to uint_64t going on.
Cheers,
Kevin D-B
012C ACB2 28C6 C53E 9775 9123 B3A2 389B 9DE2 334A
[-- Attachment #1.2: [PATCH] json_print: fix print_uint with helper type extensions.eml --]
[-- Type: message/rfc822, Size: 8546 bytes --]
From: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
To: netdev@vger.kernel.org
Cc: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Subject: [PATCH] json_print: fix print_uint with helper type extensions
Date: Thu, 15 Mar 2018 20:07:20 +0000
Message-ID: <20180315200720.829-1-ldir@darbyshire-bryant.me.uk>
Introduce print helper functions for int, uint, explicit int32, uint32,
int64 & uint64.
print_int used 'int' type internally, whereas print_uint used 'uint64_t'
These helper functions eventually call vfprintf(fp, fmt, args) which is
a variable argument list function and is dependent upon 'fmt' containing
correct information about the length of the passed arguments.
Unfortunately print_int v print_uint offered no clue to the programmer
that internally passed ints to print_uint were being promoted to 64bits,
thus the format passed in 'fmt' string vs the actual passed integer
could be different lengths. This is even more interesting on big endian
architectures where 'vfprintf' would be looking in the middle of an
int64 type and hence produced wildly incorrect values in tc qdisc
output.
print_u/int now stick with native int size. print_u/int32 & print
u/int64 functions offer explicit integer sizes.
To portably use these formats you should use the relevant PRIdN or PRIuN
formats as defined in inttypes.h
e.g.
print_uint64(PRINT_ANY, "refcnt", "refcnt %" PRIu64 " ", t->tcm_info)
Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
---
include/json_print.h | 6 +++++-
lib/json_print.c | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/json_print.h b/include/json_print.h
index 2ca7830a..fb62b142 100644
--- a/include/json_print.h
+++ b/include/json_print.h
@@ -56,10 +56,14 @@ void close_json_array(enum output_type type, const char *delim);
print_color_##type_name(t, COLOR_NONE, key, fmt, value); \
}
_PRINT_FUNC(int, int);
+_PRINT_FUNC(uint, unsigned int);
_PRINT_FUNC(bool, bool);
_PRINT_FUNC(null, const char*);
_PRINT_FUNC(string, const char*);
-_PRINT_FUNC(uint, uint64_t);
+_PRINT_FUNC(int32, int32_t);
+_PRINT_FUNC(uint32, uint32_t);
+_PRINT_FUNC(int64, int64_t);
+_PRINT_FUNC(uint64, uint64_t);
_PRINT_FUNC(hu, unsigned short);
_PRINT_FUNC(hex, unsigned int);
_PRINT_FUNC(0xhex, unsigned int);
diff --git a/lib/json_print.c b/lib/json_print.c
index 6518ba98..12ee26df 100644
--- a/lib/json_print.c
+++ b/lib/json_print.c
@@ -117,8 +117,12 @@ void close_json_array(enum output_type type, const char *str)
} \
}
_PRINT_FUNC(int, int);
+_PRINT_FUNC(uint, unsigned int);
_PRINT_FUNC(hu, unsigned short);
-_PRINT_FUNC(uint, uint64_t);
+_PRINT_FUNC(int32, int32_t);
+_PRINT_FUNC(uint32, uint32_t);
+_PRINT_FUNC(int64, int64_t);
+_PRINT_FUNC(uint64, uint64_t);
_PRINT_FUNC(lluint, unsigned long long int);
_PRINT_FUNC(float, double);
#undef _PRINT_FUNC
--
2.14.3 (Apple Git-98)
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-03-16 8:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-11 9:19 [Cake] fixing tc cake output since json-ification Kevin Darbyshire-Bryant
2018-03-11 9:19 ` [Cake] [PATCH 1/2] cake: print_uint format fixes Kevin Darbyshire-Bryant
2018-03-11 20:49 ` Toke Høiland-Jørgensen
2018-03-11 22:10 ` Kevin Darbyshire-Bryant
2018-03-11 23:34 ` Stephen Hemminger
2018-03-12 9:28 ` Kevin Darbyshire-Bryant
2018-03-12 9:56 ` Toke Høiland-Jørgensen
2018-03-12 15:11 ` Stephen Hemminger
2018-03-12 15:38 ` Toke Høiland-Jørgensen
2018-03-12 21:44 ` Kevin Darbyshire-Bryant
2018-03-16 8:02 ` Kevin Darbyshire-Bryant [this message]
2018-03-17 14:33 ` Toke Høiland-Jørgensen
2018-03-11 9:19 ` [Cake] [PATCH 2/2] tc " Kevin Darbyshire-Bryant
2018-03-11 20:50 ` Toke Høiland-Jørgensen
2018-03-11 20:57 ` Kevin Darbyshire-Bryant
2018-03-11 21:22 ` Toke Høiland-Jørgensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.bufferbloat.net/postorius/lists/cake.lists.bufferbloat.net/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6DC9DE5E-0ED4-4BBB-9C7C-0F8887856D25@darbyshire-bryant.me.uk \
--to=kevin@darbyshire-bryant.me.uk \
--cc=cake@lists.bufferbloat.net \
--cc=stephen@networkplumber.org \
--cc=toke@toke.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox