From bebc34769b94cb18e49658dd960ae36751d17e8c Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Fri, 3 Nov 2017 15:51:30 -0700 Subject: [PATCH] modules/kvs/kvs_util: Remove unused functions With recent changes, kvs_util_json_dumps() and kvs_util_json_encoded_size() are no longer used, so remove them and associated unit tests. Also remove now unnecessary header includes. --- src/modules/kvs/kvs_util.c | 45 +----------------- src/modules/kvs/kvs_util.h | 15 ------ src/modules/kvs/test/kvs_util.c | 83 ++------------------------------- 3 files changed, 5 insertions(+), 138 deletions(-) diff --git a/src/modules/kvs/kvs_util.c b/src/modules/kvs/kvs_util.c index b24f170a4d69..1683c7490022 100644 --- a/src/modules/kvs/kvs_util.c +++ b/src/modules/kvs/kvs_util.c @@ -27,51 +27,8 @@ #endif #include #include -#include -#include #include -#include -#include -#include - -#include "src/common/libutil/blobref.h" - -#include "types.h" - -char *kvs_util_json_dumps (json_t *o) -{ - /* Must pass JSON_ENCODE_ANY, can be called on any object. Must - * set JSON_SORT_KEYS, two different objects with different - * internal order should map to same string. - */ - int flags = JSON_ENCODE_ANY | JSON_COMPACT | JSON_SORT_KEYS; - char *s; - if (!o) { - if (!(s = strdup ("null"))) { - errno = ENOMEM; - return NULL; - } - return s; - } - if (!(s = json_dumps (o, flags))) { - errno = ENOMEM; - return NULL; - } - return s; -} - -int kvs_util_json_encoded_size (json_t *o, size_t *size) -{ - char *s = kvs_util_json_dumps (o); - if (!s) { - errno = ENOMEM; - return -1; - } - if (size) - *size = strlen (s); - free (s); - return 0; -} +#include char *kvs_util_normalize_key (const char *key, bool *want_directory) { diff --git a/src/modules/kvs/kvs_util.h b/src/modules/kvs/kvs_util.h index e1772655948d..9e3f74e573dd 100644 --- a/src/modules/kvs/kvs_util.h +++ b/src/modules/kvs/kvs_util.h @@ -1,20 +1,5 @@ #ifndef _FLUX_KVS_UTIL_H #define _FLUX_KVS_UTIL_H -#include - -#include "src/common/libutil/tstat.h" -#include "waitqueue.h" -#include "types.h" - -/* Get compact string representation of json object, or json null - * object if o is NULL. Use this function for consistency. - * - * Returns NULL on error - */ -char *kvs_util_json_dumps (json_t *o); - -/* returns 0 on success, -1 on failure */ -int kvs_util_json_encoded_size (json_t *o, size_t *size); /* Normalize a KVS key * Returns new key string (caller must free), or NULL with errno set. diff --git a/src/modules/kvs/test/kvs_util.c b/src/modules/kvs/test/kvs_util.c index b78a96b6cba2..f731ea7f6ac4 100644 --- a/src/modules/kvs/test/kvs_util.c +++ b/src/modules/kvs/test/kvs_util.c @@ -2,17 +2,18 @@ #include "config.h" #endif #include -#include +#include #include "src/common/libtap/tap.h" #include "src/modules/kvs/kvs_util.h" -#include "src/modules/kvs/types.h" -void test_norm (void) +int main (int argc, char *argv[]) { char *s; bool dirflag; + plan (NO_PLAN); + s = kvs_util_normalize_key ("a.b.c.d.e", &dirflag); ok (s != NULL && !strcmp (s, "a.b.c.d.e") && dirflag == false, "kvs_util_normalize_key works on normal key"); @@ -57,82 +58,6 @@ void test_norm (void) ok (s != NULL && !strcmp (s, "."), "kvs_util_normalize_key transforms several standalone separators to one"); free (s); -} - - -int main (int argc, char *argv[]) -{ - json_t *obj; - char *s1, *s2; - size_t size; - - plan (NO_PLAN); - - obj = json_object (); - json_object_set_new (obj, "A", json_string ("a")); - json_object_set_new (obj, "B", json_string ("b")); - json_object_set_new (obj, "C", json_string ("c")); - - ok ((s1 = kvs_util_json_dumps (obj)) != NULL, - "kvs_util_json_dumps works"); - - /* json object is sorted and compacted */ - s2 = "{\"A\":\"a\",\"B\":\"b\",\"C\":\"c\"}"; - - ok (!strcmp (s1, s2), - "kvs_util_json_dumps dumps correct string"); - - ok (kvs_util_json_encoded_size (obj, NULL) == 0, - "kvs_util_json_encoded_size works w/ NULL size param"); - - ok (kvs_util_json_encoded_size (obj, &size) == 0, - "kvs_util_json_encoded_size works"); - - ok (size == strlen (s2), - "kvs_util_json_encoded_size returns correct size"); - - free (s1); - s1 = NULL; - json_decref (obj); - - obj = json_null (); - - ok ((s1 = kvs_util_json_dumps (obj)) != NULL, - "kvs_util_json_dumps works"); - - s2 = "null"; - - ok (!strcmp (s1, s2), - "kvs_util_json_dumps works on null object"); - - ok (kvs_util_json_encoded_size (obj, &size) == 0, - "kvs_util_json_encoded_size works"); - - ok (size == strlen (s2), - "kvs_util_json_encoded_size returns correct size"); - - free (s1); - s1 = NULL; - json_decref (obj); - - ok ((s1 = kvs_util_json_dumps (NULL)) != NULL, - "kvs_util_json_dumps works on NULL pointer"); - - s2 = "null"; - - ok (!strcmp (s1, s2), - "kvs_util_json_dumps works on NULL pointer"); - - ok (kvs_util_json_encoded_size (NULL, &size) == 0, - "kvs_util_json_encoded_size works on NULL pointer"); - - ok (size == strlen (s2), - "kvs_util_json_encoded_size returns correct size"); - - free (s1); - s1 = NULL; - - test_norm (); done_testing (); return (0);