Re: [PATCH v3] routines to generate JSON data
On 3/23/2018 2:14 PM, Ramsay Jones wrote: On 23/03/18 16:29, g...@jeffhostetler.com wrote: From: Jeff Hostetler This is version 3 of my JSON data format routines. I have not looked at v3 yet - the patch below is against the version in 'pu' @3284f940c (presumably that would be v2). I built my v3 on Linux and didn't see any warnings. I'll add your extra CFLAGS and fix anything that I find and send up a v4 shortly. Thanks. Jeff The version in 'pu' broke my build on Linux, but not on cygwin - which was a bit of a surprise. That is, until I saw the warnings and remembered that I have this in my config.mak on Linux, but not on cygwin: ifneq ($(CC),clang) CFLAGS += -Wold-style-declaration CFLAGS += -Wno-pointer-to-int-cast CFLAGS += -Wsystem-headers endif ... and the warnings were: $ diff nout pout 1c1 < GIT_VERSION = 2.17.0.rc1.317.g4a561d2cc --- > GIT_VERSION = 2.17.0.rc1.445.g3284f940c 29a30 > CC commit-graph.o 73a75,87 > CC json-writer.o > json-writer.c:53:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline assert_in_object(const struct json_writer *jw, const char *key) > ^ > json-writer.c:64:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline assert_in_array(const struct json_writer *jw) > ^ > json-writer.c:75:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline maybe_add_comma(struct json_writer *jw) > ^ > json-writer.c:87:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline assert_is_terminated(const struct json_writer *jw) > ^ 83a98 > CC ls-refs.o ... $ The '-Wold-style-declaration' gcc warning flag is not a standard project flag, and I can't quite remember why I have it set, so I guess you could just ignore it. However, all other 'static inline' functions in the project have the inline keyword before the return type, so ... ;-) Also, sparse spewed 40 warnings for t/helper/test-json-writer.c, which were mainly about file-local symbols, but had a couple of 'constant is so large ...', like so: $ grep warning psp-out | head -8 t/helper/test-json-writer.c:45:46: warning: constant 0x is so big it is unsigned long t/helper/test-json-writer.c:108:40: warning: constant 0x is so big it is unsigned long t/helper/test-json-writer.c:4:12: warning: symbol 'expect_obj1' was not declared. Should it be static? t/helper/test-json-writer.c:5:12: warning: symbol 'expect_obj2' was not declared. Should it be static? t/helper/test-json-writer.c:6:12: warning: symbol 'expect_obj3' was not declared. Should it be static? t/helper/test-json-writer.c:7:12: warning: symbol 'expect_obj4' was not declared. Should it be static? t/helper/test-json-writer.c:8:12: warning: symbol 'expect_obj5' was not declared. Should it be static? t/helper/test-json-writer.c:10:20: warning: symbol 'obj1' was not declared. Should it be static? $ I decided to use the UINT64_C(v) macro from , which is a C99 feature, and will (hopefully) not be a problem. ATB, Ramsay Jones -- >8 -- Subject: [PATCH] json-writer: fix up gcc and sparse warnings Signed-off-by: Ramsay Jones --- json-writer.c | 8 ++--- t/helper/test-json-writer.c | 80 ++--- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/json-writer.c b/json-writer.c index 89a6abb57..ba0365d20 100644 --- a/json-writer.c +++ b/json-writer.c @@ -50,7 +50,7 @@ static inline void begin(struct json_writer *jw, int is_array) /* * Assert that we have an open object at this level. */ -static void inline assert_in_object(const struct json_writer *jw, const char *key) +static inline void assert_in_object(const struct json_writer *jw, const char *key) { if (!jw->nr) BUG("object: missing jw_object_begin(): '%s'", key); @@ -61,7 +61,7 @@ static void inline assert_in_object(const struct json_writer *jw, const char *ke /* * Assert that we have an open array at this level. */ -static void inline assert_in_array(const struct json_writer *jw) +static inline void assert_in_array(const struct json_writer *jw) { if (!jw->nr) BUG("array: missing jw_begin()"); @@ -72,7 +72,7 @@ static void inline assert_in_array(const struct json_writer *jw) /* * Add comma if we have already seen a member at this level. */ -static void inline maybe_add_comma(struct json_writer *jw) +static inline void maybe_add_comma(struct json_writer *jw) { if (jw->levels[jw->nr - 1].level_is_empty) jw->levels[jw->nr - 1].level_is_empty = 0; @@ -84,7 +84,7 @@ static void inline maybe_add_comma(struct json_writer *jw) * Assert that the given JSON object or JSON array has been
Re: [PATCH v3] routines to generate JSON data
On 23/03/18 16:29, g...@jeffhostetler.com wrote: > From: Jeff Hostetler > > This is version 3 of my JSON data format routines. I have not looked at v3 yet - the patch below is against the version in 'pu' @3284f940c (presumably that would be v2). The version in 'pu' broke my build on Linux, but not on cygwin - which was a bit of a surprise. That is, until I saw the warnings and remembered that I have this in my config.mak on Linux, but not on cygwin: ifneq ($(CC),clang) CFLAGS += -Wold-style-declaration CFLAGS += -Wno-pointer-to-int-cast CFLAGS += -Wsystem-headers endif ... and the warnings were: $ diff nout pout 1c1 < GIT_VERSION = 2.17.0.rc1.317.g4a561d2cc --- > GIT_VERSION = 2.17.0.rc1.445.g3284f940c 29a30 > CC commit-graph.o 73a75,87 > CC json-writer.o > json-writer.c:53:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline assert_in_object(const struct json_writer *jw, const char *key) > ^ > json-writer.c:64:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline assert_in_array(const struct json_writer *jw) > ^ > json-writer.c:75:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline maybe_add_comma(struct json_writer *jw) > ^ > json-writer.c:87:1: warning: ‘inline’ is not at beginning of declaration [-Wold-style-declaration] > static void inline assert_is_terminated(const struct json_writer *jw) > ^ 83a98 > CC ls-refs.o ... $ The '-Wold-style-declaration' gcc warning flag is not a standard project flag, and I can't quite remember why I have it set, so I guess you could just ignore it. However, all other 'static inline' functions in the project have the inline keyword before the return type, so ... ;-) Also, sparse spewed 40 warnings for t/helper/test-json-writer.c, which were mainly about file-local symbols, but had a couple of 'constant is so large ...', like so: $ grep warning psp-out | head -8 t/helper/test-json-writer.c:45:46: warning: constant 0x is so big it is unsigned long t/helper/test-json-writer.c:108:40: warning: constant 0x is so big it is unsigned long t/helper/test-json-writer.c:4:12: warning: symbol 'expect_obj1' was not declared. Should it be static? t/helper/test-json-writer.c:5:12: warning: symbol 'expect_obj2' was not declared. Should it be static? t/helper/test-json-writer.c:6:12: warning: symbol 'expect_obj3' was not declared. Should it be static? t/helper/test-json-writer.c:7:12: warning: symbol 'expect_obj4' was not declared. Should it be static? t/helper/test-json-writer.c:8:12: warning: symbol 'expect_obj5' was not declared. Should it be static? t/helper/test-json-writer.c:10:20: warning: symbol 'obj1' was not declared. Should it be static? $ I decided to use the UINT64_C(v) macro from , which is a C99 feature, and will (hopefully) not be a problem. ATB, Ramsay Jones -- >8 -- Subject: [PATCH] json-writer: fix up gcc and sparse warnings Signed-off-by: Ramsay Jones --- json-writer.c | 8 ++--- t/helper/test-json-writer.c | 80 ++--- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/json-writer.c b/json-writer.c index 89a6abb57..ba0365d20 100644 --- a/json-writer.c +++ b/json-writer.c @@ -50,7 +50,7 @@ static inline void begin(struct json_writer *jw, int is_array) /* * Assert that we have an open object at this level. */ -static void inline assert_in_object(const struct json_writer *jw, const char *key) +static inline void assert_in_object(const struct json_writer *jw, const char *key) { if (!jw->nr) BUG("object: missing jw_object_begin(): '%s'", key); @@ -61,7 +61,7 @@ static void inline assert_in_object(const struct json_writer *jw, const char *ke /* * Assert that we have an open array at this level. */ -static void inline assert_in_array(const struct json_writer *jw) +static inline void assert_in_array(const struct json_writer *jw) { if (!jw->nr) BUG("array: missing jw_begin()"); @@ -72,7 +72,7 @@ static void inline assert_in_array(const struct json_writer *jw) /* * Add comma if we have already seen a member at this level. */ -static void inline maybe_add_comma(struct json_writer *jw) +static inline void maybe_add_comma(struct json_writer *jw) { if (jw->levels[jw->nr - 1].level_is_empty) jw->levels[jw->nr - 1].level_is_empty = 0; @@ -84,7 +84,7 @@ static void inline maybe_add_comma(struct json_writer *jw) * Assert that the given JSON object or JSON array has been properly * terminated. (Has closing bracket.) */ -static void inline assert_is_terminated(const struct json_writer *jw) +static inline void assert_is_terminated(const struct json_writer *jw) { if (jw->nr) BUG("object: m
Re: [PATCH v3] routines to generate JSON data
Hi, g...@jeffhostetler.com wrote: > From: Jeff Hostetler > > This is version 3 of my JSON data format routines. > > This version addresses the variable name changes in [v2] and adds additional > test cases. I also changed the BUG() calls to die() to help with testing. Can the information below go in the commit message? Usually to avoid that kind of problem, I don't send a cover letter in one-patch series. Information that I don't want to make part of permanent history (like the above) can go after the three-dash line to ensure it doesn't go in the commit message. Thanks, Jonathan > The json-writer routines can be used generate structured data in a JSON-like > format. I say "JSON-like" because we don't enforce the Unicode/UTF-8 > requirement [3,4] on string values. This was discussed on the mailing list > in the [v1] and [v2] threads, but to summarize here: Git doesn't know if > various fields, such as Unix pathnames and author names, are Unicode or just > 8-bit character data, so Git would not know how to properly encode such > fields and the consumer of such output would not know these strings were > encoded (once or twice). So, until we have a pressing need to generate > proper Unicode data, we avoid it for now. > > The initial use for the json-writer routines is for generating telemetry data > for executed Git commands. Later, we might want to use them in other commands > such as status. > > [v1] > https://public-inbox.org/git/20180316194057.77513-1-...@jeffhostetler.com/ > [v2] > https://public-inbox.org/git/20180321192827.44330-1-...@jeffhostetler.com/ > [3] http://www.ietf.org/rfc/rfc7159.txt > [4] http://json.org/