From d5557976d5e875a2b0eca1a7774e1fdcfeff6529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 4 Jun 2023 01:30:01 +0800 Subject: [PATCH] JSON: inline json-c function wrappers --- src/common/json.c | 98 ---------------------------------------- src/common/json.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 98 deletions(-) diff --git a/src/common/json.c b/src/common/json.c index 053854675..8ca285d5b 100644 --- a/src/common/json.c +++ b/src/common/json.c @@ -2,28 +2,8 @@ #ifdef FF_HAVE_JSONC -#include "common/library.h" #include "common/thread.h" -#include - -typedef struct FFJsonLibrary -{ - FF_LIBRARY_SYMBOL(json_tokener_parse) - FF_LIBRARY_SYMBOL(json_object_is_type) - FF_LIBRARY_SYMBOL(json_object_get_array) - FF_LIBRARY_SYMBOL(json_object_get_boolean) - FF_LIBRARY_SYMBOL(json_object_get_double) - FF_LIBRARY_SYMBOL(json_object_get_int) - FF_LIBRARY_SYMBOL(json_object_get_string_len) - FF_LIBRARY_SYMBOL(json_object_get_string) - FF_LIBRARY_SYMBOL(json_object_get_object) - FF_LIBRARY_SYMBOL(json_object_object_del) - FF_LIBRARY_SYMBOL(json_object_object_get) - FF_LIBRARY_SYMBOL(json_object_object_length) - FF_LIBRARY_SYMBOL(json_object_put) -} FFJsonLibrary; - static const FFJsonLibrary* loadLibSymbols(const FFinstance* instance) { assert(instance); @@ -74,82 +54,4 @@ bool ffJsonLoadLibrary(const FFinstance* instance) return !!ffJsonLib; } -struct json_object *json_tokener_parse(const char *str) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_tokener_parse(str); -} - -int json_object_is_type(const json_object *obj, enum json_type type) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_is_type(obj, type); -} - -struct array_list *json_object_get_array(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_array(obj); -} - -json_bool json_object_get_boolean(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_boolean(obj); -} - -double json_object_get_double(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_double(obj); -} - -int32_t json_object_get_int(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_int(obj); -} - -int json_object_get_string_len(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_string_len(obj); -} - -const char *json_object_get_string(json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_string(obj); -} - -struct lh_table *json_object_get_object(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_get_object(obj); -} - -void json_object_object_del(struct json_object *obj, const char *key) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_object_del(obj, key); -} - -struct json_object *json_object_object_get(const json_object *obj, const char *key) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_object_get(obj, key); -} - -int json_object_object_length(const json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_object_length(obj); -} - -int json_object_put(json_object *obj) -{ - assert(ffJsonLib); - return ffJsonLib->ffjson_object_put(obj); -} - #endif diff --git a/src/common/json.h b/src/common/json.h index e1bb3ad59..cf4ffe14f 100644 --- a/src/common/json.h +++ b/src/common/json.h @@ -3,9 +3,30 @@ #ifdef FF_HAVE_JSONC #include "fastfetch.h" +#include "common/library.h" +#include #include +typedef struct FFJsonLibrary +{ + FF_LIBRARY_SYMBOL(json_tokener_parse) + FF_LIBRARY_SYMBOL(json_object_is_type) + FF_LIBRARY_SYMBOL(json_object_get_array) + FF_LIBRARY_SYMBOL(json_object_get_boolean) + FF_LIBRARY_SYMBOL(json_object_get_double) + FF_LIBRARY_SYMBOL(json_object_get_int) + FF_LIBRARY_SYMBOL(json_object_get_string_len) + FF_LIBRARY_SYMBOL(json_object_get_string) + FF_LIBRARY_SYMBOL(json_object_get_object) + FF_LIBRARY_SYMBOL(json_object_object_del) + FF_LIBRARY_SYMBOL(json_object_object_get) + FF_LIBRARY_SYMBOL(json_object_object_length) + FF_LIBRARY_SYMBOL(json_object_put) +} FFJsonLibrary; + +extern const FFJsonLibrary* ffJsonLib; + bool ffJsonLoadLibrary(const FFinstance* instance); static inline void wrapJsoncFree(json_object** root) @@ -15,4 +36,95 @@ static inline void wrapJsoncFree(json_object** root) json_object_put(*root); } +extern inline __attribute__((__gnu_inline__, __always_inline__)) +struct json_object *json_tokener_parse(const char *str) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_tokener_parse(str); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +int json_object_is_type(const json_object *obj, enum json_type type) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_is_type(obj, type); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +struct array_list *json_object_get_array(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_array(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +json_bool json_object_get_boolean(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_boolean(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +double json_object_get_double(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_double(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +int32_t json_object_get_int(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_int(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +int json_object_get_string_len(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_string_len(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +const char *json_object_get_string(json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_string(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +struct lh_table *json_object_get_object(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_get_object(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +void json_object_object_del(struct json_object *obj, const char *key) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_object_del(obj, key); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +struct json_object *json_object_object_get(const json_object *obj, const char *key) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_object_get(obj, key); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +int json_object_object_length(const json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_object_length(obj); +} + +extern inline __attribute__((__gnu_inline__, __always_inline__)) +int json_object_put(json_object *obj) +{ + assert(ffJsonLib); + return ffJsonLib->ffjson_object_put(obj); +} + #endif