Skip to content

Commit

Permalink
modules/kvs/kvs_util: Remove unused functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chu11 committed Nov 3, 2017
1 parent 036ed34 commit bebc347
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 138 deletions.
45 changes: 1 addition & 44 deletions src/modules/kvs/kvs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,8 @@
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include <ctype.h>
#include <flux/core.h>
#include <jansson.h>

#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 <string.h>

char *kvs_util_normalize_key (const char *key, bool *want_directory)
{
Expand Down
15 changes: 0 additions & 15 deletions src/modules/kvs/kvs_util.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
#ifndef _FLUX_KVS_UTIL_H
#define _FLUX_KVS_UTIL_H
#include <jansson.h>

#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.
Expand Down
83 changes: 4 additions & 79 deletions src/modules/kvs/test/kvs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
#include "config.h"
#endif
#include <stdbool.h>
#include <jansson.h>
#include <string.h>

#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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bebc347

Please sign in to comment.