diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-04-07 22:10:41 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-04-07 22:12:58 +0200 |
commit | 33f1e0b0926e973fb5ae445e9a995848762143bb (patch) | |
tree | 86f04814801f275c955e97e16e39736bc6186121 | |
parent | 72292e9a86ac32e64da54bf27d38553f52161b89 (diff) |
treewide: move json-c compat shims into internal header file
Do not expose the json-c compat functions in ucode's public headers to
avoid clashes when building on systems with modern json-c.
Also remove some explicit json-c/json-c.h includes in places where it is
not needed.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | include/ucode/compiler.h | 1 | ||||
-rw-r--r-- | include/ucode/util.h | 26 | ||||
-rw-r--r-- | include/ucode/vallist.h | 1 | ||||
-rw-r--r-- | json-c-compat.h | 50 | ||||
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | types.c | 2 |
7 files changed, 56 insertions, 29 deletions
diff --git a/include/ucode/compiler.h b/include/ucode/compiler.h index a85b48b..15b77b3 100644 --- a/include/ucode/compiler.h +++ b/include/ucode/compiler.h @@ -20,7 +20,6 @@ #include <stddef.h> #include <stdint.h> #include <stdbool.h> -#include <json-c/json.h> #include "source.h" #include "lexer.h" diff --git a/include/ucode/util.h b/include/ucode/util.h index 35c1e56..3203499 100644 --- a/include/ucode/util.h +++ b/include/ucode/util.h @@ -159,30 +159,4 @@ static inline struct printbuf *xprintbuf_new(void) { return pb; } - -/* json-c compat */ - -#ifndef HAVE_PARSE_END -static inline size_t json_tokener_get_parse_end(struct json_tokener *tok) { - return (size_t)tok->char_offset; -} -#endif - -#ifndef HAVE_ARRAY_EXT -static inline struct json_object *json_object_new_array_ext(int size) { - (void) size; - return json_object_new_array(); -} -#endif - -#ifndef HAVE_JSON_UINT64 -static inline struct json_object *json_object_new_uint64(uint64_t i) { - return json_object_new_int64((int64_t)i); -} - -static inline uint64_t json_object_get_uint64(const struct json_object *obj) { - return (uint64_t)json_object_get_int64(obj); -} -#endif - #endif /* UCODE_UTIL_H */ diff --git a/include/ucode/vallist.h b/include/ucode/vallist.h index 53750bd..fb46677 100644 --- a/include/ucode/vallist.h +++ b/include/ucode/vallist.h @@ -21,7 +21,6 @@ #include <stddef.h> #include <stdbool.h> #include <stdio.h> -#include <json-c/json.h> #include "types.h" diff --git a/json-c-compat.h b/json-c-compat.h new file mode 100644 index 0000000..da24a0f --- /dev/null +++ b/json-c-compat.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 Jo-Philipp Wich <jo@mein.io> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef JSON_C_COMPAT_H +#define JSON_C_COMPAT_H + +#include <stddef.h> +#include <stdint.h> +#include <json-c/json.h> + + +/* json-c compat */ + +#ifndef HAVE_PARSE_END +static inline size_t json_tokener_get_parse_end(struct json_tokener *tok) { + return (size_t)tok->char_offset; +} +#endif + +#ifndef HAVE_ARRAY_EXT +static inline struct json_object *json_object_new_array_ext(int size) { + (void) size; + return json_object_new_array(); +} +#endif + +#ifndef HAVE_JSON_UINT64 +static inline struct json_object *json_object_new_uint64(uint64_t i) { + return json_object_new_int64((int64_t)i); +} + +static inline uint64_t json_object_get_uint64(const struct json_object *obj) { + return (uint64_t)json_object_get_int64(obj); +} +#endif + +#endif /* JSON_C_COMPAT_H */ @@ -33,6 +33,8 @@ #include <fnmatch.h> #include <assert.h> +#include "json-c-compat.h" + #include "ucode/lexer.h" #include "ucode/compiler.h" #include "ucode/vm.h" @@ -23,7 +23,8 @@ #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> -#include <json-c/json.h> + +#include "json-c-compat.h" #include "ucode/compiler.h" #include "ucode/lexer.h" @@ -23,6 +23,8 @@ #include <ctype.h> #include <float.h> +#include "json-c-compat.h" + #include "ucode/types.h" #include "ucode/util.h" #include "ucode/vm.h" |