diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-10 12:11:35 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-10 15:08:54 +0200 |
commit | 439136c15a5d0b5a95f49dab7c8e7513315839c4 (patch) | |
tree | 8150220db173e46b07cb749f4a8d52ed7ea7c18a | |
parent | 4631259c83351bb99bfde85fef9cfa6ab233f069 (diff) |
build: test whether json_object_array_shrink() is available
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | lib.c | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d6252c5..6d9461a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 2.6) include(CheckFunctionExists) +include(CheckSymbolExists) PROJECT(utpl C) ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-error=unused-variable -ffunction-sections -D_GNU_SOURCE) @@ -58,6 +59,18 @@ IF (NOT DLOPEN_FUNCTION_EXISTS) TARGET_LINK_LIBRARIES(utpl dl) ENDIF() +SET(CMAKE_REQUIRED_LIBRARIES json-c) +CHECK_SYMBOL_EXISTS(json_object_array_shrink "json.h" HAVE_ARRAY_SHRINK) +IF(HAVE_ARRAY_SHRINK) + ADD_DEFINITIONS(-DHAVE_ARRAY_SHRINK) +ELSE() + CHECK_SYMBOL_EXISTS(json_object_array_shrink "json-c/json.h" HAVE_ARRAY_SHRINK2) + IF(HAVE_ARRAY_SHRINK2) + ADD_DEFINITIONS(-DHAVE_ARRAY_SHRINK) + ENDIF() +ENDIF() +UNSET(CMAKE_REQUIRED_LIBRARIES) + SET(LIBRARIES "") IF(FS_SUPPORT) @@ -437,7 +437,9 @@ ut_pop(struct ut_state *s, uint32_t off, struct json_object *args) if (arrlen > 0) { item = json_object_array_get_idx(arr, arrlen - 1); json_object_array_del_idx(arr, arrlen - 1, 1); +#ifdef HAVE_ARRAY_SHRINK json_object_array_shrink(arr, 0); +#endif } return json_object_get(item); @@ -461,7 +463,9 @@ ut_shift(struct ut_state *s, uint32_t off, struct json_object *args) json_object_array_get_idx(arr, arridx + 1)); json_object_array_del_idx(arr, arrlen - 1, 1); +#ifdef HAVE_ARRAY_SHRINK json_object_array_shrink(arr, 0); +#endif return item; } |