From 14be0062e7fe2f79d0428596c15b3e609d8d195a Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Wed, 6 Apr 2016 15:17:26 +0200 Subject: [PATCH 1/7] build: don't force -Werror in released code Running -Werror during development is fine, but not in released code. See [1] for further details. [1] https://blog.flameeyes.eu/2009/02/future-proof-your-code-dont-use-werror --- Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index e81f066..07a8170 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,7 +25,6 @@ libfastjsoninclude_HEADERS = \ libfastjson_la_LDFLAGS = -version-info 3:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ \ -export-symbols-regex '^fjson_.*' -libfastjson_la_CPPFLAGS = -Werror libfastjson_la_SOURCES = \ arraylist.c \ From ef47269cf6b14a3ab05944339296279e09d21318 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Wed, 6 Apr 2016 15:23:20 +0200 Subject: [PATCH 2/7] build: install and distribute atomic.h The atomic.h header file was added in 81a70813855d99d26d7ed60b7bf9f25743333624. Make sure it is distributed in the dist tarball and also installed as public header file, as it is referenced in json_object_private.h. This basically reverts 95c76f181c17e391c3d9e151ffe911f81c0da06b. --- Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 07a8170..7b009b1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ -EXTRA_DIST = README.html \ - atomic.h +EXTRA_DIST = README.html + SUBDIRS = . tests lib_LTLIBRARIES = libfastjson.la @@ -10,6 +10,7 @@ pkgconfig_DATA = libfastjson.pc libfastjsonincludedir = $(includedir)/libfastjson libfastjsoninclude_HEADERS = \ + atomic.h \ arraylist.h \ debug.h \ json.h \ From 1b5d8a07096b67ae4ce923492f394afb6a64dc9a Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Wed, 6 Apr 2016 15:29:19 +0200 Subject: [PATCH 3/7] build: wrap LDFLAGS for better readability This also reduces the visual clutter when updating the version info. --- Makefile.am | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7b009b1..57310fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,8 +24,11 @@ libfastjsoninclude_HEADERS = \ printbuf.h \ random_seed.h -libfastjson_la_LDFLAGS = -version-info 3:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ \ - -export-symbols-regex '^fjson_.*' +libfastjson_la_LDFLAGS = \ + -version-info 3:0:0 \ + -export-symbols-regex '^fjson_.*' \ + -no-undefined \ + @JSON_BSYMBOLIC_LDFLAGS@ libfastjson_la_SOURCES = \ arraylist.c \ From bdb2e2b8bc1511acf7c3f91964d64804d882245a Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Thu, 7 Apr 2016 14:41:19 +0200 Subject: [PATCH 4/7] build: move private symbols into a convenience library Since 99eb6a343ca68148ee8d34c5a08397cc4108c145 we no longer export any private symbols. The tests do require those private symbols though. Instead of compiling the source twice, as done in f415452f64c22fa9acf3b0e9983b31053a8efd86, create a convenience library and link the tests against it. --- Makefile.am | 13 ++++++++----- tests/Makefile.am | 9 ++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile.am b/Makefile.am index 57310fe..b1cbed6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,8 @@ EXTRA_DIST = README.html SUBDIRS = . tests -lib_LTLIBRARIES = libfastjson.la +lib_LTLIBRARIES = libfastjson.la +noinst_LTLIBRARIES = libfastjson-internal.la pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libfastjson.pc @@ -29,20 +30,22 @@ libfastjson_la_LDFLAGS = \ -export-symbols-regex '^fjson_.*' \ -no-undefined \ @JSON_BSYMBOLIC_LDFLAGS@ +libfastjson_la_LIBADD = libfastjson-internal.la libfastjson_la_SOURCES = \ - arraylist.c \ - debug.c \ json_version.c \ json_object.c \ json_object_iterator.c \ json_tokener.c \ - json_util.c \ + json_util.c + +libfastjson_internal_la_SOURCES = \ + arraylist.c \ + debug.c \ linkhash.c \ printbuf.c \ random_seed.c - uninstall-local: rm -rf "$(DESTDIR)@includedir@/libfastjson" diff --git a/tests/Makefile.am b/tests/Makefile.am index be30f89..3dabc03 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,6 @@ -LDADD= $(LIBJSON_LA) - -LIBJSON_LA=$(top_builddir)/libfastjson.la +LDADD = $(top_builddir)/libfastjson.la \ + $(top_builddir)/libfastjson-internal.la TESTS= TESTS+= test1.test @@ -29,8 +28,8 @@ TESTS += chk_version check_PROGRAMS += chk_version chk_version_SOURCES = chk_version.c -test_printbuf_SOURCES = test_printbuf.c ../printbuf.c ../debug.c -test_set_serializer_SOURCES = test_set_serializer.c ../printbuf.c +test_printbuf_SOURCES = test_printbuf.c +test_set_serializer_SOURCES = test_set_serializer.c # Note: handled by test1.test check_PROGRAMS += test1Formatted From 25daae30fdd6c39b94468f67ece9af9403bcd892 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Thu, 7 Apr 2016 15:08:50 +0200 Subject: [PATCH 5/7] build: stop installing private headers Those are no longer public ABI, so they shouldn't be public API either. Fix json.h to no longer reference those files. --- Makefile.am | 12 ++++++------ json.h | 3 --- json_object_iterator.c | 3 +++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index b1cbed6..3d883cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,18 +12,13 @@ pkgconfig_DATA = libfastjson.pc libfastjsonincludedir = $(includedir)/libfastjson libfastjsoninclude_HEADERS = \ atomic.h \ - arraylist.h \ - debug.h \ json.h \ json_inttypes.h \ json_object.h \ json_object_iterator.h \ json_object_private.h \ json_tokener.h \ - json_util.h \ - linkhash.h \ - printbuf.h \ - random_seed.h + json_util.h libfastjson_la_LDFLAGS = \ -version-info 3:0:0 \ @@ -40,10 +35,15 @@ libfastjson_la_SOURCES = \ json_util.c libfastjson_internal_la_SOURCES = \ + arraylist.h \ arraylist.c \ + debug.h \ debug.c \ + linkhash.h \ linkhash.c \ + printbuf.h \ printbuf.c \ + random_seed.h \ random_seed.c uninstall-local: diff --git a/json.h b/json.h index 5d4538f..81e9e07 100644 --- a/json.h +++ b/json.h @@ -17,9 +17,6 @@ extern "C" { #endif -#include "debug.h" -#include "linkhash.h" -#include "arraylist.h" #include "json_util.h" #include "json_object.h" #include "json_tokener.h" diff --git a/json_object_iterator.c b/json_object_iterator.c index 5e51f98..3a6f4e6 100644 --- a/json_object_iterator.c +++ b/json_object_iterator.c @@ -24,6 +24,9 @@ #include "json_object_iterator.h" +#include "debug.h" +#include "linkhash.h" + /** * How It Works * From 6fafb53cacf777f08914ec66bcc22666c22f801e Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Thu, 7 Apr 2016 15:09:51 +0200 Subject: [PATCH 6/7] build: fix test suite after changes to json.h Since json.h after commit 25daae30fdd6c39b94468f67ece9af9403bcd892 no longer includes the private headers, make the test suite include the individual headers as needed. An alternative would be to create a "json_internal.h", which the tests can include and which reference all internal headers. --- tests/parse_flags.c | 1 + tests/test1.c | 2 ++ tests/test2.c | 1 + tests/testReplaceExisting.c | 2 ++ tests/test_charcase.c | 1 + tests/test_locale.c | 1 + tests/test_parse.c | 1 + tests/test_set_serializer.c | 1 + 8 files changed, 10 insertions(+) diff --git a/tests/parse_flags.c b/tests/parse_flags.c index 5bd4957..6b4a708 100644 --- a/tests/parse_flags.c +++ b/tests/parse_flags.c @@ -2,6 +2,7 @@ #include #include +#include #include "../json.h" #include "parse_flags.h" diff --git a/tests/test1.c b/tests/test1.c index 8c8f6a9..5958e48 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -6,6 +6,8 @@ #include #include "../json.h" +#include "../debug.h" +#include "../linkhash.h" #include "parse_flags.h" static int sort_fn (const void *j1, const void *j2) diff --git a/tests/test2.c b/tests/test2.c index 6c68504..b982f76 100644 --- a/tests/test2.c +++ b/tests/test2.c @@ -5,6 +5,7 @@ #include #include "../json.h" +#include "../debug.h" #include "parse_flags.h" #ifdef TEST_FORMATTED diff --git a/tests/testReplaceExisting.c b/tests/testReplaceExisting.c index 4d9ade4..3d43f64 100644 --- a/tests/testReplaceExisting.c +++ b/tests/testReplaceExisting.c @@ -5,6 +5,8 @@ #include #include "../json.h" +#include "../debug.h" +#include "../linkhash.h" int main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv) { diff --git a/tests/test_charcase.c b/tests/test_charcase.c index 8be2400..8b5c3a7 100644 --- a/tests/test_charcase.c +++ b/tests/test_charcase.c @@ -7,6 +7,7 @@ #include "../json.h" #include "../json_tokener.h" +#include "../debug.h" static void test_case_parse(void); diff --git a/tests/test_locale.c b/tests/test_locale.c index 3b82b18..1f12689 100644 --- a/tests/test_locale.c +++ b/tests/test_locale.c @@ -7,6 +7,7 @@ #include "../json.h" #include "../json_tokener.h" +#include "../debug.h" #ifdef HAVE_LOCALE_H #include diff --git a/tests/test_parse.c b/tests/test_parse.c index 6957f56..cd6ce5e 100644 --- a/tests/test_parse.c +++ b/tests/test_parse.c @@ -7,6 +7,7 @@ #include "../json.h" #include "../json_tokener.h" +#include "../debug.h" static void test_basic_parse(void); static void test_verbose_parse(void); diff --git a/tests/test_set_serializer.c b/tests/test_set_serializer.c index 2c6ef80..bee23e7 100644 --- a/tests/test_set_serializer.c +++ b/tests/test_set_serializer.c @@ -5,6 +5,7 @@ #include "../json.h" #include "../printbuf.h" +#include "../debug.h" struct myinfo { int value; From 24ac343fa05fcde201e9a24f5d159224efc25805 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 8 Apr 2016 09:06:58 +0200 Subject: [PATCH 7/7] move public API defintion to public header --- json.h | 23 +++++++++++++++++++++++ linkhash.c | 1 + linkhash.h | 21 --------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/json.h b/json.h index 81e9e07..919fbb4 100644 --- a/json.h +++ b/json.h @@ -46,6 +46,29 @@ extern void fjson_global_set_printbuf_initial_size(int size); * report the current libfastjson version */ extern const char *fjson_version(void); + +/** + * default string hash function + */ +#define FJSON_STR_HASH_DFLT 0 + +/** + * perl-like string hash function + */ +#define FJSON_STR_HASH_PERLLIKE 1 + +/** + * This function sets the hash function to be used for strings. + * Must be one of the FJSON_STR_HASH_* values. + * @returns 0 - ok, -1 if parameter was invalid + */ +int fjson_global_set_string_hash(const int h); + +#ifndef FJSON_NATIVE_API_ONLY +#define JSON_C_STR_HASH_PERLLIKE FJSON_STR_HASH_PERLLIKE +#define json_global_set_string_hash fjson_global_set_string_hash +#endif + #ifdef __cplusplus } #endif diff --git a/linkhash.c b/linkhash.c index 6e2d0a9..0cc4215 100644 --- a/linkhash.c +++ b/linkhash.c @@ -21,6 +21,7 @@ # include /* attempt to define endianness */ #endif +#include "json.h" #include "random_seed.h" #include "linkhash.h" diff --git a/linkhash.h b/linkhash.h index f9033ac..05ef187 100644 --- a/linkhash.h +++ b/linkhash.h @@ -43,22 +43,6 @@ extern "C" { */ #define LH_FREED (void*)-2 -/** - * default string hash function - */ -#define FJSON_STR_HASH_DFLT 0 - -/** - * perl-like string hash function - */ -#define FJSON_STR_HASH_PERLLIKE 1 - -/** - * This function sets the hash function to be used for strings. - * Must be one of the FJSON_STR_HASH_* values. - * @returns 0 - ok, -1 if parameter was invalid - */ -int fjson_global_set_string_hash(const int h); struct lh_entry; @@ -331,11 +315,6 @@ static inline unsigned long lh_get_hash(const struct lh_table *t, const void *k) return t->hash_fn(k); } -#ifndef FJSON_NATIVE_API_ONLY -#define JSON_C_STR_HASH_PERLLIKE FJSON_STR_HASH_PERLLIKE -#define json_global_set_string_hash fjson_global_set_string_hash -#endif - #ifdef __cplusplus }