aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2019-10-19 20:35:28 +0300
committerPetri Lehtinen <petri@digip.org>2019-10-21 08:56:03 +0300
commita8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b (patch)
tree366ad4f7e39808675d35d9c941fd51a8c86b0bda
parent7c0297abe8f4fb4aafd642c3130628185dc78978 (diff)
downloadjansson-a8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b.zip
jansson-a8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b.tar.gz
jansson-a8f5fa5f5a2b7613aa2aa27b4a4df83b5a0ecd1b.tar.bz2
Tweak clang-format configuration a bit
Set ColumnLimit to 90, remove AllowShortCaseLabelsOnASingleLine.
-rw-r--r--.clang-format2
-rw-r--r--doc/github_commits.c19
-rw-r--r--examples/simple_parse.c38
-rw-r--r--src/dump.c89
-rw-r--r--src/error.c5
-rw-r--r--src/hashtable.c21
-rw-r--r--src/hashtable.h2
-rw-r--r--src/hashtable_seed.c15
-rw-r--r--src/jansson.h76
-rw-r--r--src/jansson_private.h17
-rw-r--r--src/load.c121
-rw-r--r--src/pack_unpack.c103
-rw-r--r--src/strbuffer.c10
-rw-r--r--src/strconv.c4
-rw-r--r--src/utf.c3
-rw-r--r--src/value.c109
-rw-r--r--test/bin/json_process.c14
-rw-r--r--test/suites/api/test_array.c4
-rw-r--r--test/suites/api/test_chaos.c55
-rw-r--r--test/suites/api/test_dump.c20
-rw-r--r--test/suites/api/test_dump_callback.c3
-rw-r--r--test/suites/api/test_equal.c31
-rw-r--r--test/suites/api/test_load.c13
-rw-r--r--test/suites/api/test_load_callback.c3
-rw-r--r--test/suites/api/test_memory_funcs.c7
-rw-r--r--test/suites/api/test_object.c63
-rw-r--r--test/suites/api/test_pack.c110
-rw-r--r--test/suites/api/test_unpack.c119
-rw-r--r--test/suites/api/test_version.c3
-rw-r--r--test/suites/api/util.h104
30 files changed, 577 insertions, 606 deletions
diff --git a/.clang-format b/.clang-format
index 01b288a..0870245 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,5 +1,5 @@
BasedOnStyle: LLVM
AlignConsecutiveMacros: true
-AllowShortCaseLabelsOnASingleLine: true
+ColumnLimit: 90
IndentCaseLabels: true
IndentWidth: 4
diff --git a/doc/github_commits.c b/doc/github_commits.c
index 09923cd..c020f46 100644
--- a/doc/github_commits.c
+++ b/doc/github_commits.c
@@ -31,8 +31,7 @@ struct write_result {
int pos;
};
-static size_t write_response(void *ptr, size_t size, size_t nmemb,
- void *stream) {
+static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream) {
struct write_result *result = (struct write_result *)stream;
if (result->pos + size * nmemb >= BUFFER_SIZE - 1) {
@@ -146,38 +145,34 @@ int main(int argc, char *argv[]) {
data = json_array_get(root, i);
if (!json_is_object(data)) {
- fprintf(stderr, "error: commit data %d is not an object\n",
- (int)(i + 1));
+ fprintf(stderr, "error: commit data %d is not an object\n", (int)(i + 1));
json_decref(root);
return 1;
}
sha = json_object_get(data, "sha");
if (!json_is_string(sha)) {
- fprintf(stderr, "error: commit %d: sha is not a string\n",
- (int)(i + 1));
+ fprintf(stderr, "error: commit %d: sha is not a string\n", (int)(i + 1));
return 1;
}
commit = json_object_get(data, "commit");
if (!json_is_object(commit)) {
- fprintf(stderr, "error: commit %d: commit is not an object\n",
- (int)(i + 1));
+ fprintf(stderr, "error: commit %d: commit is not an object\n", (int)(i + 1));
json_decref(root);
return 1;
}
message = json_object_get(commit, "message");
if (!json_is_string(message)) {
- fprintf(stderr, "error: commit %d: message is not a string\n",
- (int)(i + 1));
+ fprintf(stderr, "error: commit %d: message is not a string\n", (int)(i + 1));
json_decref(root);
return 1;
}
message_text = json_string_value(message);
- printf("%.8s %.*s\n", json_string_value(sha),
- newline_offset(message_text), message_text);
+ printf("%.8s %.*s\n", json_string_value(sha), newline_offset(message_text),
+ message_text);
}
json_decref(root);
diff --git a/examples/simple_parse.c b/examples/simple_parse.c
index d20e1de..4554e4f 100644
--- a/examples/simple_parse.c
+++ b/examples/simple_parse.c
@@ -44,17 +44,32 @@ void print_json(json_t *root) { print_json_aux(root, 0); }
void print_json_aux(json_t *element, int indent) {
switch (json_typeof(element)) {
- case JSON_OBJECT: print_json_object(element, indent); break;
- case JSON_ARRAY: print_json_array(element, indent); break;
- case JSON_STRING: print_json_string(element, indent); break;
- case JSON_INTEGER: print_json_integer(element, indent); break;
- case JSON_REAL: print_json_real(element, indent); break;
- case JSON_TRUE: print_json_true(element, indent); break;
- case JSON_FALSE: print_json_false(element, indent); break;
- case JSON_NULL: print_json_null(element, indent); break;
+ case JSON_OBJECT:
+ print_json_object(element, indent);
+ break;
+ case JSON_ARRAY:
+ print_json_array(element, indent);
+ break;
+ case JSON_STRING:
+ print_json_string(element, indent);
+ break;
+ case JSON_INTEGER:
+ print_json_integer(element, indent);
+ break;
+ case JSON_REAL:
+ print_json_real(element, indent);
+ break;
+ case JSON_TRUE:
+ print_json_true(element, indent);
+ break;
+ case JSON_FALSE:
+ print_json_false(element, indent);
+ break;
+ case JSON_NULL:
+ print_json_null(element, indent);
+ break;
default:
- fprintf(stderr, "unrecognized JSON type %d\n",
- json_typeof(element));
+ fprintf(stderr, "unrecognized JSON type %d\n", json_typeof(element));
}
}
@@ -101,8 +116,7 @@ void print_json_string(json_t *element, int indent) {
void print_json_integer(json_t *element, int indent) {
print_json_indent(indent);
- printf("JSON Integer: \"%" JSON_INTEGER_FORMAT "\"\n",
- json_integer_value(element));
+ printf("JSON Integer: \"%" JSON_INTEGER_FORMAT "\"\n", json_integer_value(element));
}
void print_json_real(json_t *element, int indent) {
diff --git a/src/dump.c b/src/dump.c
index d03e0e0..1baa248 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -68,19 +68,17 @@ static int dump_to_fd(const char *buffer, size_t size, void *data) {
/* 32 spaces (the maximum indentation size) */
static const char whitespace[] = " ";
-static int dump_indent(size_t flags, int depth, int space,
- json_dump_callback_t dump, void *data) {
+static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump,
+ void *data) {
if (FLAGS_TO_INDENT(flags) > 0) {
- unsigned int ws_count = FLAGS_TO_INDENT(flags),
- n_spaces = depth * ws_count;
+ unsigned int ws_count = FLAGS_TO_INDENT(flags), n_spaces = depth * ws_count;
if (dump("\n", 1, data))
return -1;
while (n_spaces > 0) {
- int cur_n = n_spaces < sizeof whitespace - 1
- ? n_spaces
- : sizeof whitespace - 1;
+ int cur_n =
+ n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1;
if (dump(whitespace, cur_n, data))
return -1;
@@ -93,8 +91,8 @@ static int dump_indent(size_t flags, int depth, int space,
return 0;
}
-static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
- void *data, size_t flags) {
+static int dump_string(const char *str, size_t len, json_dump_callback_t dump, void *data,
+ size_t flags) {
const char *pos, *end, *lim;
int32_t codepoint = 0;
@@ -139,19 +137,34 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
/* handle \, /, ", and control codes */
length = 2;
switch (codepoint) {
- case '\\': text = "\\\\"; break;
- case '\"': text = "\\\""; break;
- case '\b': text = "\\b"; break;
- case '\f': text = "\\f"; break;
- case '\n': text = "\\n"; break;
- case '\r': text = "\\r"; break;
- case '\t': text = "\\t"; break;
- case '/': text = "\\/"; break;
+ case '\\':
+ text = "\\\\";
+ break;
+ case '\"':
+ text = "\\\"";
+ break;
+ case '\b':
+ text = "\\b";
+ break;
+ case '\f':
+ text = "\\f";
+ break;
+ case '\n':
+ text = "\\n";
+ break;
+ case '\r':
+ text = "\\r";
+ break;
+ case '\t':
+ text = "\\t";
+ break;
+ case '/':
+ text = "\\/";
+ break;
default: {
/* codepoint is in BMP */
if (codepoint < 0x10000) {
- snprintf(seq, sizeof(seq), "\\u%04X",
- (unsigned int)codepoint);
+ snprintf(seq, sizeof(seq), "\\u%04X", (unsigned int)codepoint);
length = 6;
}
@@ -163,8 +176,8 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump,
first = 0xD800 | ((codepoint & 0xffc00) >> 10);
last = 0xDC00 | (codepoint & 0x003ff);
- snprintf(seq, sizeof(seq), "\\u%04X\\u%04X",
- (unsigned int)first, (unsigned int)last);
+ snprintf(seq, sizeof(seq), "\\u%04X\\u%04X", (unsigned int)first,
+ (unsigned int)last);
length = 12;
}
@@ -186,9 +199,8 @@ static int compare_keys(const void *key1, const void *key2) {
return strcmp(*(const char **)key1, *(const char **)key2);
}
-static int do_dump(const json_t *json, size_t flags, int depth,
- hashtable_t *parents, json_dump_callback_t dump,
- void *data) {
+static int do_dump(const json_t *json, size_t flags, int depth, hashtable_t *parents,
+ json_dump_callback_t dump, void *data) {
int embed = flags & JSON_EMBED;
flags &= ~JSON_EMBED;
@@ -197,18 +209,21 @@ static int do_dump(const json_t *json, size_t flags, int depth,
return -1;
switch (json_typeof(json)) {
- case JSON_NULL: return dump("null", 4, data);
+ case JSON_NULL:
+ return dump("null", 4, data);
- case JSON_TRUE: return dump("true", 4, data);
+ case JSON_TRUE:
+ return dump("true", 4, data);
- case JSON_FALSE: return dump("false", 5, data);
+ case JSON_FALSE:
+ return dump("false", 5, data);
case JSON_INTEGER: {
char buffer[MAX_INTEGER_STR_LENGTH];
int size;
- size = snprintf(buffer, MAX_INTEGER_STR_LENGTH,
- "%" JSON_INTEGER_FORMAT, json_integer_value(json));
+ size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%" JSON_INTEGER_FORMAT,
+ json_integer_value(json));
if (size < 0 || size >= MAX_INTEGER_STR_LENGTH)
return -1;
@@ -229,8 +244,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
}
case JSON_STRING:
- return dump_string(json_string_value(json),
- json_string_length(json), dump, data, flags);
+ return dump_string(json_string_value(json), json_string_length(json), dump,
+ data, flags);
case JSON_ARRAY: {
size_t n;
@@ -255,8 +270,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
return -1;
for (i = 0; i < n; ++i) {
- if (do_dump(json_array_get(json, i), flags, depth + 1, parents,
- dump, data))
+ if (do_dump(json_array_get(json, i), flags, depth + 1, parents, dump,
+ data))
return -1;
if (i < n - 1) {
@@ -360,8 +375,8 @@ static int do_dump(const json_t *json, size_t flags, int depth,
dump_string(key, strlen(key), dump, data, flags);
if (dump(separator, separator_length, data) ||
- do_dump(json_object_iter_value(iter), flags, depth + 1,
- parents, dump, data))
+ do_dump(json_object_iter_value(iter), flags, depth + 1, parents,
+ dump, data))
return -1;
if (next) {
@@ -435,8 +450,8 @@ int json_dump_file(const json_t *json, const char *path, size_t flags) {
return result;
}
-int json_dump_callback(const json_t *json, json_dump_callback_t callback,
- void *data, size_t flags) {
+int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data,
+ size_t flags) {
int res;
hashtable_t parents_set;
diff --git a/src/error.c b/src/error.c
index af2b7f8..14d0047 100644
--- a/src/error.c
+++ b/src/error.c
@@ -39,9 +39,8 @@ void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
va_end(ap);
}
-void jsonp_error_vset(json_error_t *error, int line, int column,
- size_t position, enum json_error_code code,
- const char *msg, va_list ap) {
+void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
+ enum json_error_code code, const char *msg, va_list ap) {
if (!error)
return;
diff --git a/src/hashtable.c b/src/hashtable.c
index 0785e4f..fd1e706 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -54,13 +54,11 @@ static JSON_INLINE void list_remove(list_t *list) {
list->next->prev = list->prev;
}
-static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable,
- bucket_t *bucket) {
+static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket) {
return bucket->first == &hashtable->list && bucket->first == bucket->last;
}
-static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
- list_t *list) {
+static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket, list_t *list) {
if (bucket_is_empty(hashtable, bucket)) {
list_insert(&hashtable->list, list);
bucket->first = bucket->last = list;
@@ -94,8 +92,7 @@ static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
}
/* returns 0 on success, -1 if key was not found */
-static int hashtable_do_del(hashtable_t *hashtable, const char *key,
- size_t hash) {
+static int hashtable_do_del(hashtable_t *hashtable, const char *key, size_t hash) {
pair_t *pair;
bucket_t *bucket;
size_t index;
@@ -156,8 +153,7 @@ static int hashtable_do_rehash(hashtable_t *hashtable) {
hashtable->order = new_order;
for (i = 0; i < hashsize(hashtable->order); i++) {
- hashtable->buckets[i].first = hashtable->buckets[i].last =
- &hashtable->list;
+ hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list;
}
list = hashtable->list.next;
@@ -178,8 +174,7 @@ int hashtable_init(hashtable_t *hashtable) {
hashtable->size = 0;
hashtable->order = INITIAL_HASHTABLE_ORDER;
- hashtable->buckets =
- jsonp_malloc(hashsize(hashtable->order) * sizeof(bucket_t));
+ hashtable->buckets = jsonp_malloc(hashsize(hashtable->order) * sizeof(bucket_t));
if (!hashtable->buckets)
return -1;
@@ -187,8 +182,7 @@ int hashtable_init(hashtable_t *hashtable) {
list_init(&hashtable->ordered_list);
for (i = 0; i < hashsize(hashtable->order); i++) {
- hashtable->buckets[i].first = hashtable->buckets[i].last =
- &hashtable->list;
+ hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list;
}
return 0;
@@ -272,8 +266,7 @@ void hashtable_clear(hashtable_t *hashtable) {
hashtable_do_clear(hashtable);
for (i = 0; i < hashsize(hashtable->order); i++) {
- hashtable->buckets[i].first = hashtable->buckets[i].last =
- &hashtable->list;
+ hashtable->buckets[i].first = hashtable->buckets[i].last = &hashtable->list;
}
list_init(&hashtable->list);
diff --git a/src/hashtable.h b/src/hashtable.h
index 8833c96..6c4845d 100644
--- a/src/hashtable.h
+++ b/src/hashtable.h
@@ -40,7 +40,7 @@ typedef struct hashtable {
struct hashtable_list ordered_list;
} hashtable_t;
-#define hashtable_key_to_iter(key_) \
+#define hashtable_key_to_iter(key_) \
(&(container_of(key_, struct hashtable_pair, key)->ordered_list))
/**
diff --git a/src/hashtable_seed.c b/src/hashtable_seed.c
index b7f4b94..d156b40 100644
--- a/src/hashtable_seed.c
+++ b/src/hashtable_seed.c
@@ -94,12 +94,10 @@ static int seed_from_urandom(uint32_t *seed) {
#if defined(_WIN32) && defined(USE_WINDOWS_CRYPTOAPI)
#include <wincrypt.h>
-typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,
- LPCSTR pszContainer,
+typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv, LPCSTR pszContainer,
LPCSTR pszProvider, DWORD dwProvType,
DWORD dwFlags);
-typedef BOOL(WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen,
- BYTE *pbBuffer);
+typedef BOOL(WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer);
typedef BOOL(WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV hProv, DWORD dwFlags);
static int seed_from_windows_cryptoapi(uint32_t *seed) {
@@ -120,8 +118,7 @@ static int seed_from_windows_cryptoapi(uint32_t *seed) {
if (!pCryptAcquireContext)
return 1;
- pCryptGenRandom =
- (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, "CryptGenRandom");
+ pCryptGenRandom = (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, "CryptGenRandom");
if (!pCryptGenRandom)
return 1;
@@ -196,8 +193,7 @@ static uint32_t generate_seed() {
volatile uint32_t hashtable_seed = 0;
-#if defined(HAVE_ATOMIC_BUILTINS) && \
- (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
+#if defined(HAVE_ATOMIC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
static volatile char seed_initialized = 0;
void json_object_seed(size_t seed) {
@@ -220,8 +216,7 @@ void json_object_seed(size_t seed) {
}
}
}
-#elif defined(HAVE_SYNC_BUILTINS) && \
- (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
+#elif defined(HAVE_SYNC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
void json_object_seed(size_t seed) {
uint32_t new_seed = (uint32_t)seed;
diff --git a/src/jansson.h b/src/jansson.h
index 4796595..ae1842c 100644
--- a/src/jansson.h
+++ b/src/jansson.h
@@ -29,8 +29,8 @@ extern "C" {
/* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this
for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */
-#define JANSSON_VERSION_HEX \
- ((JANSSON_MAJOR_VERSION << 16) | (JANSSON_MINOR_VERSION << 8) | \
+#define JANSSON_VERSION_HEX \
+ ((JANSSON_MAJOR_VERSION << 16) | (JANSSON_MINOR_VERSION << 8) | \
(JANSSON_MICRO_VERSION << 0))
/* If __atomic or __sync builtins are available the library is thread
@@ -107,9 +107,9 @@ json_t *json_null(void);
/* do not call JSON_INTERNAL_INCREF or JSON_INTERNAL_DECREF directly */
#if JSON_HAVE_ATOMIC_BUILTINS
-#define JSON_INTERNAL_INCREF(json) \
+#define JSON_INTERNAL_INCREF(json) \
__atomic_add_fetch(&json->refcount, 1, __ATOMIC_ACQUIRE)
-#define JSON_INTERNAL_DECREF(json) \
+#define JSON_INTERNAL_DECREF(json) \
__atomic_sub_fetch(&json->refcount, 1, __ATOMIC_RELEASE)
#elif JSON_HAVE_SYNC_BUILTINS
#define JSON_INTERNAL_INCREF(json) __sync_add_and_fetch(&json->refcount, 1)
@@ -204,28 +204,25 @@ const char *json_object_iter_key(void *iter);
json_t *json_object_iter_value(void *iter);
int json_object_iter_set_new(json_t *object, void *iter, json_t *value);
-#define json_object_foreach(object, key, value) \
- for (key = json_object_iter_key(json_object_iter(object)); \
- key && \
- (value = json_object_iter_value(json_object_key_to_iter(key))); \
- key = json_object_iter_key( \
+#define json_object_foreach(object, key, value) \
+ for (key = json_object_iter_key(json_object_iter(object)); \
+ key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
+ key = json_object_iter_key( \
json_object_iter_next(object, json_object_key_to_iter(key))))
-#define json_object_foreach_safe(object, n, key, value) \
- for (key = json_object_iter_key(json_object_iter(object)), \
- n = json_object_iter_next(object, json_object_key_to_iter(key)); \
- key && \
- (value = json_object_iter_value(json_object_key_to_iter(key))); \
- key = json_object_iter_key(n), \
+#define json_object_foreach_safe(object, n, key, value) \
+ for (key = json_object_iter_key(json_object_iter(object)), \
+ n = json_object_iter_next(object, json_object_key_to_iter(key)); \
+ key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
+ key = json_object_iter_key(n), \
n = json_object_iter_next(object, json_object_key_to_iter(key)))
-#define json_array_foreach(array, index, value) \
- for (index = 0; index < json_array_size(array) && \
- (value = json_array_get(array, index)); \
+#define json_array_foreach(array, index, value) \
+ for (index = 0; \
+ index < json_array_size(array) && (value = json_array_get(array, index)); \
index++)
-static JSON_INLINE int json_object_set(json_t *object, const char *key,
- json_t *value) {
+static JSON_INLINE int json_object_set(json_t *object, const char *key, json_t *value) {
return json_object_set_new(object, key, json_incref(value));
}
@@ -234,8 +231,7 @@ static JSON_INLINE int json_object_set_nocheck(json_t *object, const char *key,
return json_object_set_new_nocheck(object, key, json_incref(value));
}
-static JSON_INLINE int json_object_iter_set(json_t *object, void *iter,
- json_t *value) {
+static JSON_INLINE int json_object_iter_set(json_t *object, void *iter, json_t *value) {
return json_object_iter_set_new(object, iter, json_incref(value));
}
@@ -267,8 +263,7 @@ int json_array_remove(json_t *array, size_t index);
int json_array_clear(json_t *array);
int json_array_extend(json_t *array, json_t *other);
-static JSON_INLINE int json_array_set(json_t *array, size_t ind,
- json_t *value) {
+static JSON_INLINE int json_array_set(json_t *array, size_t ind, json_t *value) {
return json_array_set_new(array, ind, json_incref(value));
}
@@ -276,8 +271,7 @@ static JSON_INLINE int json_array_append(json_t *array, json_t *value) {
return json_array_append_new(array, json_incref(value));
}
-static JSON_INLINE int json_array_insert(json_t *array, size_t ind,
- json_t *value) {
+static JSON_INLINE int json_array_insert(json_t *array, size_t ind, json_t *value) {
return json_array_insert_new(array, ind, json_incref(value));
}
@@ -299,17 +293,16 @@ int json_real_set(json_t *real, double value);
json_t *json_pack(const char *fmt, ...) JANSSON_ATTRS((warn_unused_result));
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...)
JANSSON_ATTRS((warn_unused_result));
-json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt,
- va_list ap) JANSSON_ATTRS((warn_unused_result));
+json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap)
+ JANSSON_ATTRS((warn_unused_result));
#define JSON_VALIDATE_ONLY 0x1
#define JSON_STRICT 0x2
int json_unpack(json_t *root, const char *fmt, ...);
-int json_unpack_ex(json_t *root, json_error_t *error, size_t flags,
- const char *fmt, ...);
-int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
- const char *fmt, va_list ap);
+int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...);
+int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt,
+ va_list ap);
/* sprintf */
@@ -339,17 +332,16 @@ typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);
json_t *json_loads(const char *input, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
-json_t *json_loadb(const char *buffer, size_t buflen, size_t flags,
- json_error_t *error) JANSSON_ATTRS((warn_unused_result));
+json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error)
+ JANSSON_ATTRS((warn_unused_result));
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_loadfd(int input, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
JANSSON_ATTRS((warn_unused_result));
-json_t *json_load_callback(json_load_callback_t callback, void *data,
- size_t flags, json_error_t *error)
- JANSSON_ATTRS((warn_unused_result));
+json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags,
+ json_error_t *error) JANSSON_ATTRS((warn_unused_result));
/* encoding */
@@ -364,17 +356,15 @@ json_t *json_load_callback(json_load_callback_t callback, void *data,
#define JSON_REAL_PRECISION(n) (((n)&0x1F) << 11)
#define JSON_EMBED 0x10000
-typedef int (*json_dump_callback_t)(const char *buffer, size_t size,
- void *data);
+typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
-char *json_dumps(const json_t *json, size_t flags)
- JANSSON_ATTRS((warn_unused_result));
+char *json_dumps(const json_t *json, size_t flags) JANSSON_ATTRS((warn_unused_result));
size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags);
int json_dumpf(const json_t *json, FILE *output, size_t flags);
int json_dumpfd(const json_t *json, int output, size_t flags);
int json_dump_file(const json_t *json, const char *path, size_t flags);
-int json_dump_callback(const json_t *json, json_dump_callback_t callback,
- void *data, size_t flags);
+int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data,
+ size_t flags);
/* custom memory allocation */
diff --git a/src/jansson_private.h b/src/jansson_private.h
index 1e281ba..d3b2a64 100644
--- a/src/jansson_private.h
+++ b/src/jansson_private.h
@@ -14,7 +14,7 @@
#include "strbuffer.h"
#include <stddef.h>
-#define container_of(ptr_, type_, member_) \
+#define container_of(ptr_, type_, member_) \
((type_ *)((char *)ptr_ - offsetof(type_, member_)))
/* On some platforms, max() may already be defined */
@@ -74,9 +74,8 @@ void jsonp_error_init(json_error_t *error, const char *source);
void jsonp_error_set_source(json_error_t *error, const char *source);
void jsonp_error_set(json_error_t *error, int line, int column, size_t position,
enum json_error_code code, const char *msg, ...);
-void jsonp_error_vset(json_error_t *error, int line, int column,
- size_t position, enum json_error_code code,
- const char *msg, va_list ap);
+void jsonp_error_vset(json_error_t *error, int line, int column, size_t position,
+ enum json_error_code code, const char *msg, va_list ap);
/* Locale independent string<->double conversions */
int jsonp_strtod(strbuffer_t *strbuffer, double *out);
@@ -85,11 +84,9 @@ int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
/* Wrappers for custom memory functions */
void *jsonp_malloc(size_t size) JANSSON_ATTRS((warn_unused_result));
void jsonp_free(void *ptr);
-char *jsonp_strndup(const char *str, size_t length)
- JANSSON_ATTRS((warn_unused_result));
+char *jsonp_strndup(const char *str, size_t length) JANSSON_ATTRS((warn_unused_result));
char *jsonp_strdup(const char *str) JANSSON_ATTRS((warn_unused_result));
-char *jsonp_strndup(const char *str, size_t len)
- JANSSON_ATTRS((warn_unused_result));
+char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS((warn_unused_result));
/* Circular reference check*/
/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */
@@ -100,11 +97,11 @@ int jsonp_loop_check(hashtable_t *parents, const json_t *json, char *key,
/* Windows compatibility */
#if defined(_WIN32) || defined(WIN32)
#if defined(_MSC_VER) /* MS compiller */
-#if (_MSC_VER < 1900) && \
+#if (_MSC_VER < 1900) && \
!defined(snprintf) /* snprintf not defined yet & not introduced */
#define snprintf _snprintf
#endif
-#if (_MSC_VER < 1500) && \
+#if (_MSC_VER < 1500) && \
!defined(vsnprintf) /* vsnprintf not defined yet & not introduced */
#define vsnprintf(b, c, f, a) _vsnprintf(b, c, f, a)
#endif
diff --git a/src/load.c b/src/load.c
index 67dd6ef..ea6692f 100644
--- a/src/load.c
+++ b/src/load.c
@@ -43,7 +43,7 @@
#define l_islower(c) ('a' <= (c) && (c) <= 'z')
#define l_isalpha(c) (l_isupper(c) || l_islower(c))
#define l_isdigit(c) ('0' <= (c) && (c) <= '9')
-#define l_isxdigit(c) \
+#define l_isxdigit(c) \
(l_isdigit(c) || ('A' <= (c) && (c) <= 'F') || ('a' <= (c) && (c) <= 'f'))
/* Read one byte from stream, convert to unsigned char, then int, and
@@ -82,8 +82,8 @@ typedef struct {
/*** error reporting ***/
-static void error_set(json_error_t *error, const lex_t *lex,
- enum json_error_code code, const char *msg, ...) {
+static void error_set(json_error_t *error, const lex_t *lex, enum json_error_code code,
+ const char *msg, ...) {
va_list ap;
char msg_text[JSON_ERROR_TEXT_LENGTH];
char msg_with_context[JSON_ERROR_TEXT_LENGTH];
@@ -109,8 +109,8 @@ static void error_set(json_error_t *error, const lex_t *lex,
if (saved_text && saved_text[0]) {
if (lex->saved_text.length <= 20) {
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
- "%s near '%s'", msg_text, saved_text);
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near '%s'",
+ msg_text, saved_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
}
@@ -123,8 +123,8 @@ static void error_set(json_error_t *error, const lex_t *lex,
/* No context for UTF-8 decoding errors */
result = msg_text;
} else {
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
- "%s near end of file", msg_text);
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH, "%s near end of file",
+ msg_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
}
@@ -227,9 +227,7 @@ static int lex_get(lex_t *lex, json_error_t *error) {
return stream_get(&lex->stream, error);
}
-static void lex_save(lex_t *lex, int c) {
- strbuffer_append_byte(&lex->saved_text, c);
-}
+static void lex_save(lex_t *lex, int c) { strbuffer_append_byte(&lex->saved_text, c); }
static int lex_get_save(lex_t *lex, json_error_t *error) {
int c = stream_get(&lex->stream, error);
@@ -320,11 +318,10 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
/* control character */
lex_unget_unsave(lex, c);
if (c == '\n')
- error_set(error, lex, json_error_invalid_syntax,
- "unexpected newline");
+ error_set(error, lex, json_error_invalid_syntax, "unexpected newline");
else
- error_set(error, lex, json_error_invalid_syntax,
- "control character 0x%x", c);
+ error_set(error, lex, json_error_invalid_syntax, "control character 0x%x",
+ c);
goto out;
}
@@ -340,12 +337,11 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
}
c = lex_get_save(lex, error);
}
- } else if (c == '"' || c == '\\' || c == '/' || c == 'b' ||
- c == 'f' || c == 'n' || c == 'r' || c == 't')
+ } else if (c == '"' || c == '\\' || c == '/' || c == 'b' || c == 'f' ||
+ c == 'n' || c == 'r' || c == 't')
c = lex_get_save(lex, error);
else {
- error_set(error, lex, json_error_invalid_syntax,
- "invalid escape");
+ error_set(error, lex, json_error_invalid_syntax, "invalid escape");
goto out;
}
} else
@@ -397,13 +393,12 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
if (0xDC00 <= value2 && value2 <= 0xDFFF) {
/* valid second surrogate */
- value = ((value - 0xD800) << 10) +
- (value2 - 0xDC00) + 0x10000;
+ value =
+ ((value - 0xD800) << 10) + (value2 - 0xDC00) + 0x10000;
} else {
/* invalid second surrogate */
error_set(error, lex, json_error_invalid_syntax,
- "invalid Unicode '\\u%04X\\u%04X'", value,
- value2);
+ "invalid Unicode '\\u%04X\\u%04X'", value, value2);
goto out;
}
} else {
@@ -425,13 +420,26 @@ static void lex_scan_string(lex_t *lex, json_error_t *error) {
switch (*p) {
case '"':
case '\\':
- case '/': *t = *p; break;
- case 'b': *t = '\b'; break;
- case 'f': *t = '\f'; break;
- case 'n': *t = '\n'; break;
- case 'r': *t = '\r'; break;
- case 't': *t = '\t'; break;
- default: assert(0);
+ case '/':
+ *t = *p;
+ break;
+ case 'b':
+ *t = '\b';
+ break;
+ case 'f':
+ *t = '\f';
+ break;
+ case 'n':
+ *t = '\n';
+ break;
+ case 'r':
+ *t = '\r';
+ break;
+ case 't':
+ *t = '\t';
+ break;
+ default:
+ assert(0);
}
t++;
p++;
@@ -485,8 +493,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
goto out;
}
- if (!(lex->flags & JSON_DECODE_INT_AS_REAL) && c != '.' && c != 'E' &&
- c != 'e') {
+ if (!(lex->flags & JSON_DECODE_INT_AS_REAL) && c != '.' && c != 'E' && c != 'e') {
json_int_t intval;
lex_unget_unsave(lex, c);
@@ -500,8 +507,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
error_set(error, lex, json_error_numeric_overflow,
"too big negative integer");
else
- error_set(error, lex, json_error_numeric_overflow,
- "too big integer");
+ error_set(error, lex, json_error_numeric_overflow, "too big integer");
goto out;
}
@@ -543,8 +549,7 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error) {
lex_unget_unsave(lex, c);
if (jsonp_strtod(&lex->saved_text, &doubleval)) {
- error_set(error, lex, json_error_numeric_overflow,
- "real number overflow");
+ error_set(error, lex, json_error_numeric_overflow, "real number overflow");
goto out;
}
@@ -669,8 +674,7 @@ static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) {
json_t *value;
if (lex->token != TOKEN_STRING) {
- error_set(error, lex, json_error_invalid_syntax,
- "string or '}' expected");
+ error_set(error, lex, json_error_invalid_syntax, "string or '}' expected");
goto error;
}
@@ -687,8 +691,7 @@ static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error) {
if (flags & JSON_REJECT_DUPLICATES) {
if (json_object_get(object, key)) {
jsonp_free(key);
- error_set(error, lex, json_error_duplicate_key,
- "duplicate object key");
+ error_set(error, lex, json_error_duplicate_key, "duplicate object key");
goto error;
}
}
@@ -775,8 +778,7 @@ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) {
lex->depth++;
if (lex->depth > JSON_PARSER_MAX_DEPTH) {
- error_set(error, lex, json_error_stack_overflow,
- "maximum parsing depth reached");
+ error_set(error, lex, json_error_stack_overflow, "maximum parsing depth reached");
return NULL;
}
@@ -809,23 +811,32 @@ static json_t *parse_value(lex_t *lex, size_t flags, json_error_t *error) {
break;
}
- case TOKEN_TRUE: json = json_true(); break;
+ case TOKEN_TRUE:
+ json = json_true();
+ break;
- case TOKEN_FALSE: json = json_false(); break;
+ case TOKEN_FALSE:
+ json = json_false();
+ break;
- case TOKEN_NULL: json = json_null(); break;
+ case TOKEN_NULL:
+ json = json_null();
+ break;
- case '{': json = parse_object(lex, flags, error); break;
+ case '{':
+ json = parse_object(lex, flags, error);
+ break;
- case '[': json = parse_array(lex, flags, error); break;
+ case '[':
+ json = parse_array(lex, flags, error);
+ break;
case TOKEN_INVALID:
error_set(error, lex, json_error_invalid_syntax, "invalid token");
return NULL;
default:
- error_set(error, lex, json_error_invalid_syntax,
- "unexpected token");
+ error_set(error, lex, json_error_invalid_syntax, "unexpected token");
return NULL;
}
@@ -844,8 +855,7 @@ static json_t *parse_json(lex_t *lex, size_t flags, json_error_t *error) {
lex_scan(lex, error);
if (!(flags & JSON_DECODE_ANY)) {
if (lex->token != '[' && lex->token != '{') {
- error_set(error, lex, json_error_invalid_syntax,
- "'[' or '{' expected");
+ error_set(error, lex, json_error_invalid_syntax, "'[' or '{' expected");
return NULL;
}
}
@@ -930,8 +940,7 @@ static int buffer_get(void *data) {
return (unsigned char)c;
}
-json_t *json_loadb(const char *buffer, size_t buflen, size_t flags,
- json_error_t *error) {
+json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error) {
lex_t lex;
json_t *result;
buffer_data_t stream_data;
@@ -1032,8 +1041,8 @@ json_t *json_load_file(const char *path, size_t flags, json_error_t *error) {
fp = fopen(path, "rb");
if (!fp) {
- error_set(error, NULL, json_error_cannot_open_file,
- "unable to open %s: %s", path, strerror(errno));
+ error_set(error, NULL, json_error_cannot_open_file, "unable to open %s: %s", path,
+ strerror(errno));
return NULL;
}
@@ -1069,8 +1078,8 @@ static int callback_get(void *data) {
return (unsigned char)c;
}
-json_t *json_load_callback(json_load_callback_t callback, void *arg,
- size_t flags, json_error_t *error) {
+json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flags,
+ json_error_t *error) {
lex_t lex;
json_t *result;
diff --git a/src/pack_unpack.c b/src/pack_unpack.c
index 6b46860..a89be58 100644
--- a/src/pack_unpack.c
+++ b/src/pack_unpack.c
@@ -99,13 +99,13 @@ static void prev_token(scanner_t *s) {
s->token = s->prev_token;
}
-static void set_error(scanner_t *s, const char *source,
- enum json_error_code code, const char *fmt, ...) {
+static void set_error(scanner_t *s, const char *source, enum json_error_code code,
+ const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
- jsonp_error_vset(s->error, s->token.line, s->token.column, s->token.pos,
- code, fmt, ap);
+ jsonp_error_vset(s->error, s->token.line, s->token.column, s->token.pos, code, fmt,
+ ap);
jsonp_error_set_source(s->error, source);
@@ -116,8 +116,8 @@ static json_t *pack(scanner_t *s, va_list *ap);
/* ours will be set to 1 if jsonp_free() must be called for the result
afterwards */
-static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
- size_t *out_len, int *ours, int optional) {
+static char *read_string(scanner_t *s, va_list *ap, const char *purpose, size_t *out_len,
+ int *ours, int optional) {
char t;
strbuffer_t strbuff;
const char *str;
@@ -134,8 +134,7 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
if (!str) {
if (!optional) {
- set_error(s, "<args>", json_error_null_value, "NULL %s",
- purpose);
+ set_error(s, "<args>", json_error_null_value, "NULL %s", purpose);
s->has_error = 1;
}
return NULL;
@@ -144,8 +143,7 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
length = strlen(str);
if (!utf8_check_string(str, length)) {
- set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s",
- purpose);
+ set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s", purpose);
s->has_error = 1;
return NULL;
}
@@ -183,10 +181,8 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
length = s->has_error ? 0 : strlen(str);
}
- if (!s->has_error &&
- strbuffer_append_bytes(&strbuff, str, length) == -1) {
- set_error(s, "<internal>", json_error_out_of_memory,
- "Out of memory");
+ if (!s->has_error && strbuffer_append_bytes(&strbuff, str, length) == -1) {
+ set_error(s, "<internal>", json_error_out_of_memory, "Out of memory");
s->has_error = 1;
}
@@ -203,8 +199,7 @@ static char *read_string(scanner_t *s, va_list *ap, const char *purpose,
}
if (!utf8_check_string(strbuff.value, strbuff.length)) {
- set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s",
- purpose);
+ set_error(s, "<args>", json_error_invalid_utf8, "Invalid UTF-8 %s", purpose);
strbuffer_close(&strbuff);
s->has_error = 1;
return NULL;
@@ -252,8 +247,7 @@ static json_t *pack_object(scanner_t *s, va_list *ap) {
jsonp_free(key);
if (valueOptional != '*') {
- set_error(s, "<args>", json_error_null_value,
- "NULL object value");
+ set_error(s, "<args>", json_error_null_value, "NULL object value");
s->has_error = 1;
}
@@ -378,9 +372,12 @@ static json_t *pack_object_inter(scanner_t *s, va_list *ap, int need_incref) {
return need_incref ? json_incref(json) : json;
switch (ntoken) {
- case '?': return json_null();
- case '*': return NULL;
- default: break;
+ case '?':
+ return json_null();
+ case '*':
+ return NULL;
+ default:
+ break;
}
set_error(s, "<args>", json_error_null_value, "NULL object");
@@ -425,13 +422,17 @@ static json_t *pack_real(scanner_t *s, double value) {
static json_t *pack(scanner_t *s, va_list *ap) {
switch (token(s)) {
- case '{': return pack_object(s, ap);
+ case '{':
+ return pack_object(s, ap);
- case '[': return pack_array(s, ap);
+ case '[':
+ return pack_array(s, ap);
- case 's': /* string */ return pack_string(s, ap);
+ case 's': /* string */
+ return pack_string(s, ap);
- case 'n': /* null */ return json_null();
+ case 'n': /* null */
+ return json_null();
case 'b': /* boolean */
return va_arg(*ap, int) ? json_true() : json_false();
@@ -442,7 +443,8 @@ static json_t *pack(scanner_t *s, va_list *ap) {
case 'I': /* integer from json_int_t */
return pack_integer(s, va_arg(*ap, json_int_t));
- case 'f': /* real */ return pack_real(s, va_arg(*ap, double));
+ case 'f': /* real */
+ return pack_real(s, va_arg(*ap, double));
case 'O': /* a json_t object; increments refcount */
return pack_object_inter(s, ap, 1);
@@ -478,8 +480,8 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
}
if (root && !json_is_object(root)) {
- set_error(s, "<validation>", json_error_wrong_type,
- "Expected object, got %s", type_name(root));
+ set_error(s, "<validation>", json_error_wrong_type, "Expected object, got %s",
+ type_name(root));
goto out;
}
next_token(s);
@@ -491,8 +493,8 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (strict != 0) {
set_error(s, "<format>", json_error_invalid_format,
- "Expected '}' after '%c', got '%c'",
- (strict == 1 ? '!' : '*'), token(s));
+ "Expected '}' after '%c', got '%c'", (strict == 1 ? '!' : '*'),
+ token(s));
goto out;
}
@@ -567,21 +569,19 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (keys_res == 1) {
keys_res = strbuffer_init(&unrecognized_keys);
} else if (!keys_res) {
- keys_res =
- strbuffer_append_bytes(&unrecognized_keys, ", ", 2);
+ keys_res = strbuffer_append_bytes(&unrecognized_keys, ", ", 2);
}
if (!keys_res)
- keys_res = strbuffer_append_bytes(&unrecognized_keys,
- key, strlen(key));
+ keys_res =
+ strbuffer_append_bytes(&unrecognized_keys, key, strlen(key));
}
}
}
if (unpacked) {
set_error(s, "<validation>", json_error_end_of_input_expected,
"%li object item(s) left unpacked: %s", unpacked,
- keys_res ? "<unknown>"
- : strbuffer_value(&unrecognized_keys));
+ keys_res ? "<unknown>" : strbuffer_value(&unrecognized_keys));
strbuffer_close(&unrecognized_keys);
goto out;
}
@@ -599,8 +599,8 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
int strict = 0;
if (root && !json_is_array(root)) {
- set_error(s, "<validation>", json_error_wrong_type,
- "Expected array, got %s", type_name(root));
+ set_error(s, "<validation>", json_error_wrong_type, "Expected array, got %s",
+ type_name(root));
return -1;
}
next_token(s);
@@ -610,8 +610,8 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
if (strict != 0) {
set_error(s, "<format>", json_error_invalid_format,
- "Expected ']' after '%c', got '%c'",
- (strict == 1 ? '!' : '*'), token(s));
+ "Expected ']' after '%c', got '%c'", (strict == 1 ? '!' : '*'),
+ token(s));
return -1;
}
@@ -667,9 +667,11 @@ static int unpack_array(scanner_t *s, json_t *root, va_list *ap) {
static int unpack(scanner_t *s, json_t *root, va_list *ap) {
switch (token(s)) {
- case '{': return unpack_object(s, root, ap);
+ case '{':
+ return unpack_object(s, root, ap);
- case '[': return unpack_array(s, root, ap);
+ case '[':
+ return unpack_array(s, root, ap);
case 's':
if (root && !json_is_string(root)) {
@@ -684,8 +686,7 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap) {
str_target = va_arg(*ap, const char **);
if (!str_target) {
- set_error(s, "<args>", json_error_null_value,
- "NULL string argument");
+ set_error(s, "<args>", json_error_null_value, "NULL string argument");
return -1;
}
@@ -814,8 +815,7 @@ static int unpack(scanner_t *s, json_t *root, va_list *ap) {
}
}
-json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt,
- va_list ap) {
+json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap) {
scanner_t s;
va_list ap_copy;
json_t *value;
@@ -872,15 +872,14 @@ json_t *json_pack(const char *fmt, ...) {
return value;
}
-int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
- const char *fmt, va_list ap) {
+int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt,
+ va_list ap) {
scanner_t s;
va_list ap_copy;
if (!root) {
jsonp_error_init(error, "<root>");
- jsonp_error_set(error, -1, -1, 0, json_error_null_value,
- "NULL root value");
+ jsonp_error_set(error, -1, -1, 0, json_error_null_value, "NULL root value");
return -1;
}
@@ -912,8 +911,8 @@ int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
return 0;
}
-int json_unpack_ex(json_t *root, json_error_t *error, size_t flags,
- const char *fmt, ...) {
+int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt,
+ ...) {
int ret;
va_list ap;
diff --git a/src/strbuffer.c b/src/strbuffer.c
index 8d61bbd..d9bcd43 100644
--- a/src/strbuffer.c
+++ b/src/strbuffer.c
@@ -45,9 +45,7 @@ void strbuffer_clear(strbuffer_t *strbuff) {
strbuff->value[0] = '\0';
}
-const char *strbuffer_value(const strbuffer_t *strbuff) {
- return strbuff->value;
-}
+const char *strbuffer_value(const strbuffer_t *strbuff) { return strbuff->value; }
char *strbuffer_steal_value(strbuffer_t *strbuff) {
char *result = strbuff->value;
@@ -59,8 +57,7 @@ int strbuffer_append_byte(strbuffer_t *strbuff, char byte) {
return strbuffer_append_bytes(strbuff, &byte, 1);
}
-int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data,
- size_t size) {
+int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) {
if (size >= strbuff->size - strbuff->length) {
size_t new_size;
char *new_value;
@@ -71,8 +68,7 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data,
strbuff->length > STRBUFFER_SIZE_MAX - 1 - size)
return -1;
- new_size =
- max(strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1);
+ new_size = max(strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1);
new_value = jsonp_malloc(new_size);
if (!new_value)
diff --git a/src/strconv.c b/src/strconv.c
index ff6db6a..c6f4fd1 100644
--- a/src/strconv.c
+++ b/src/strconv.c
@@ -1,10 +1,10 @@
+#include "jansson_private.h"
+#include "strbuffer.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
-#include "jansson_private.h"
-#include "strbuffer.h"
/* need jansson_private_config.h to get the correct snprintf */
#ifdef HAVE_CONFIG_H
diff --git a/src/utf.c b/src/utf.c
index 43310b7..28b2f7d 100644
--- a/src/utf.c
+++ b/src/utf.c
@@ -113,8 +113,7 @@ size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint) {
return 1;
}
-const char *utf8_iterate(const char *buffer, size_t bufsize,
- int32_t *codepoint) {
+const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint) {
size_t count;
int32_t value;
diff --git a/src/value.c b/src/value.c
index a3e496d..a1a4705 100644
--- a/src/value.c
+++ b/src/value.c
@@ -198,8 +198,7 @@ int json_object_update_missing(json_t *object, json_t *other) {
return 0;
}
-int do_object_update_recursive(json_t *object, json_t *other,
- hashtable_t *parents) {
+int do_object_update_recursive(json_t *object, json_t *other, hashtable_t *parents) {
const char *key;
json_t *value;
char loop_key[LOOP_KEY_LEN];
@@ -332,14 +331,12 @@ static json_t *json_object_copy(json_t *object) {
if (!result)
return NULL;
- json_object_foreach(object, key, value)
- json_object_set_nocheck(result, key, value);
+ json_object_foreach(object, key, value) json_object_set_nocheck(result, key, value);
return result;
}
-static json_t *json_object_deep_copy(const json_t *object,
- hashtable_t *parents) {
+static json_t *json_object_deep_copy(const json_t *object, hashtable_t *parents) {
json_t *result;
void *iter;
char loop_key[LOOP_KEY_LEN];
@@ -360,8 +357,7 @@ static json_t *json_object_deep_copy(const json_t *object,
key = json_object_iter_key(iter);
value = json_object_iter_value(iter);
- if (json_object_set_new_nocheck(result, key,
- do_deep_copy(value, parents))) {
+ if (json_object_set_new_nocheck(result, key, do_deep_copy(value, parents))) {
json_decref(result);
result = NULL;
break;
@@ -447,8 +443,7 @@ int json_array_set_new(json_t *json, size_t index, json_t *value) {
return 0;
}
-static void array_move(json_array_t *array, size_t dest, size_t src,
- size_t count) {
+static void array_move(json_array_t *array, size_t dest, size_t src, size_t count) {
memmove(&array->table[dest], &array->table[src], count * sizeof(json_t *));
}
@@ -532,8 +527,7 @@ int json_array_insert_new(json_t *json, size_t index, json_t *value) {
if (old_table != array->table) {
array_copy(array->table, 0, old_table, 0, index);
- array_copy(array->table, index + 1, old_table, index,
- array->entries - index);
+ array_copy(array->table, index + 1, old_table, index, array->entries - index);
jsonp_free(old_table);
} else
array_move(array, index + 1, index, array->entries - index);
@@ -648,8 +642,8 @@ static json_t *json_array_deep_copy(const json_t *array, hashtable_t *parents) {
goto out;
for (i = 0; i < json_array_size(array); i++) {
- if (json_array_append_new(
- result, do_deep_copy(json_array_get(array, i), parents))) {
+ if (json_array_append_new(result,
+ do_deep_copy(json_array_get(array, i), parents))) {
json_decref(result);
result = NULL;
break;
@@ -785,8 +779,7 @@ static int json_string_equal(const json_t *string1, const json_t *string2) {
s1 = json_to_string(string1);
s2 = json_to_string(string2);
- return s1->length == s2->length &&
- !memcmp(s1->value, s2->value, s1->length);
+ return s1->length == s2->length && !memcmp(s1->value, s2->value, s1->length);
}
static json_t *json_string_copy(const json_t *string) {
@@ -865,9 +858,7 @@ int json_integer_set(json_t *json, json_int_t value) {
return 0;
}
-static void json_delete_integer(json_integer_t *integer) {
- jsonp_free(integer);
-}
+static void json_delete_integer(json_integer_t *integer) { jsonp_free(integer); }
static int json_integer_equal(const json_t *integer1, const json_t *integer2) {
return json_integer_value(integer1) == json_integer_value(integer2);
@@ -955,12 +946,23 @@ void json_delete(json_t *json) {
return;
switch (json_typeof(json)) {
- case JSON_OBJECT: json_delete_object(json_to_object(json)); break;
- case JSON_ARRAY: json_delete_array(json_to_array(json)); break;
- case JSON_STRING: json_delete_string(json_to_string(json)); break;
- case JSON_INTEGER: json_delete_integer(json_to_integer(json)); break;
- case JSON_REAL: json_delete_real(json_to_real(json)); break;
- default: return;
+ case JSON_OBJECT:
+ json_delete_object(json_to_object(json));
+ break;
+ case JSON_ARRAY:
+ json_delete_array(json_to_array(json));
+ break;
+ case JSON_STRING:
+ json_delete_string(json_to_string(json));
+ break;
+ case JSON_INTEGER:
+ json_delete_integer(json_to_integer(json));
+ break;
+ case JSON_REAL:
+ json_delete_real(json_to_real(json));
+ break;
+ default:
+ return;
}
/* json_delete is not called for true, false or null */
@@ -980,12 +982,18 @@ int json_equal(const json_t *json1, const json_t *json2) {
return 1;
switch (json_typeof(json1)) {
- case JSON_OBJECT: return json_object_equal(json1, json2);
- case JSON_ARRAY: return json_array_equal(json1, json2);
- case JSON_STRING: return json_string_equal(json1, json2);
- case JSON_INTEGER: return json_integer_equal(json1, json2);
- case JSON_REAL: return json_real_equal(json1, json2);
- default: return 0;
+ case JSON_OBJECT:
+ return json_object_equal(json1, json2);
+ case JSON_ARRAY:
+ return json_array_equal(json1, json2);
+ case JSON_STRING:
+ return json_string_equal(json1, json2);
+ case JSON_INTEGER:
+ return json_integer_equal(json1, json2);
+ case JSON_REAL:
+ return json_real_equal(json1, json2);
+ default:
+ return 0;
}
}
@@ -996,15 +1004,22 @@ json_t *json_copy(json_t *json) {
return NULL;
switch (json_typeof(json)) {
- case JSON_OBJECT: return json_object_copy(json);
- case JSON_ARRAY: return json_array_copy(json);
- case JSON_STRING: return json_string_copy(json);
- case JSON_INTEGER: return json_integer_copy(json);
- case JSON_REAL: return json_real_copy(json);
+ case JSON_OBJECT:
+ return json_object_copy(json);
+ case JSON_ARRAY:
+ return json_array_copy(json);
+ case JSON_STRING:
+ return json_string_copy(json);
+ case JSON_INTEGER:
+ return json_integer_copy(json);
+ case JSON_REAL:
+ return json_real_copy(json);
case JSON_TRUE:
case JSON_FALSE:
- case JSON_NULL: return json;
- default: return NULL;
+ case JSON_NULL:
+ return json;
+ default:
+ return NULL;
}
}
@@ -1025,17 +1040,23 @@ json_t *do_deep_copy(const json_t *json, hashtable_t *parents) {
return NULL;
switch (json_typeof(json)) {
- case JSON_OBJECT: return json_object_deep_copy(json, parents);
+ case JSON_OBJECT:
+ return json_object_deep_copy(json, parents);
case JSON_ARRAY:
return json_array_deep_copy(json, parents);
/* for the rest of the types, deep copying doesn't differ from
shallow copying */
- case JSON_STRING: return json_string_copy(json);
- case JSON_INTEGER: return json_integer_copy(json);
- case JSON_REAL: return json_real_copy(json);
+ case JSON_STRING:
+ return json_string_copy(json);
+ case JSON_INTEGER:
+ return json_integer_copy(json);
+ case JSON_REAL:
+ return json_real_copy(json);
case JSON_TRUE:
case JSON_FALSE:
- case JSON_NULL: return (json_t *)json;
- default: return NULL;
+ case JSON_NULL:
+ return (json_t *)json;
+ default:
+ return NULL;
}
}
diff --git a/test/bin/json_process.c b/test/bin/json_process.c
index b1f0775..f7f46d0 100644
--- a/test/bin/json_process.c
+++ b/test/bin/json_process.c
@@ -191,8 +191,7 @@ int use_conf(char *test_path) {
flags |= JSON_SORT_KEYS;
if (conf.precision < 0 || conf.precision > 31) {
- fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n",
- conf.precision);
+ fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n", conf.precision);
fclose(infile);
return 2;
}
@@ -213,8 +212,8 @@ int use_conf(char *test_path) {
fclose(infile);
if (!json) {
- sprintf(errstr, "%d %d %d\n%s\n", error.line, error.column,
- error.position, error.text);
+ sprintf(errstr, "%d %d %d\n%s\n", error.line, error.column, error.position,
+ error.text);
ret = cmpfile(errstr, test_path, "error");
return ret;
@@ -278,8 +277,7 @@ int use_env() {
precision = getenv_int("JSON_REAL_PRECISION");
if (precision < 0 || precision > 31) {
- fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n",
- precision);
+ fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n", precision);
return 2;
}
@@ -320,8 +318,8 @@ int use_env() {
json = json_loadf(stdin, 0, &error);
if (!json) {
- fprintf(stderr, "%d %d %d\n%s\n", error.line, error.column,
- error.position, error.text);
+ fprintf(stderr, "%d %d %d\n%s\n", error.line, error.column, error.position,
+ error.text);
return 1;
}
diff --git a/test/suites/api/test_array.c b/test/suites/api/test_array.c
index bb89c4b..e5d9d1a 100644
--- a/test/suites/api/test_array.c
+++ b/test/suites/api/test_array.c
@@ -387,9 +387,7 @@ static void test_array_foreach() {
array1 = json_pack("[sisisi]", "foo", 1, "bar", 2, "baz", 3);
array2 = json_array();
- json_array_foreach(array1, index, value) {
- json_array_append(array2, value);
- }
+ json_array_foreach(array1, index, value) { json_array_append(array2, value); }
if (!json_equal(array1, array2))
fail("json_array_foreach failed to iterate all elements");
diff --git a/test/suites/api/test_chaos.c b/test/suites/api/test_chaos.c
index 6c1878e..8687243 100644
--- a/test/suites/api/test_chaos.c
+++ b/test/suites/api/test_chaos.c
@@ -23,19 +23,19 @@ void *chaos_malloc(size_t size) {
void chaos_free(void *obj) { free(obj); }
/* Test all potential allocation failures. */
-#define chaos_loop(condition, code, cleanup) \
- { \
- chaos_pos = chaos_fail = 0; \
- while (condition) { \
- if (chaos_fail > CHAOS_MAX_FAILURE) \
- fail("too many chaos failures"); \
- code chaos_pos = 0; \
- chaos_fail++; \
- } \
- cleanup \
+#define chaos_loop(condition, code, cleanup) \
+ { \
+ chaos_pos = chaos_fail = 0; \
+ while (condition) { \
+ if (chaos_fail > CHAOS_MAX_FAILURE) \
+ fail("too many chaos failures"); \
+ code chaos_pos = 0; \
+ chaos_fail++; \
+ } \
+ cleanup \
}
-#define chaos_loop_new_value(json, initcall) \
+#define chaos_loop_new_value(json, initcall) \
chaos_loop(!json, json = initcall;, json_decref(json); json = NULL;)
int test_unpack() {
@@ -43,14 +43,12 @@ int test_unpack() {
int v1;
int v2;
json_error_t error;
- json_t *root =
- json_pack("{s:i, s:i, s:i, s:i}", "n1", 1, "n2", 2, "n3", 3, "n4", 4);
+ json_t *root = json_pack("{s:i, s:i, s:i, s:i}", "n1", 1, "n2", 2, "n3", 3, "n4", 4);
if (!root)
return -1;
- if (!json_unpack_ex(root, &error, JSON_STRICT, "{s:i, s:i}", "n1", &v1,
- "n2", &v2))
+ if (!json_unpack_ex(root, &error, JSON_STRICT, "{s:i, s:i}", "n1", &v1, "n2", &v2))
fail("Unexpected success");
if (json_error_code(&error) != json_error_end_of_input_expected) {
@@ -96,8 +94,7 @@ static void test_chaos() {
json_t *intnum = json_integer(1);
json_t *dblnum = json_real(0.5);
char *dumptxt = NULL;
- json_t *dumpobj =
- json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2");
+ json_t *dumpobj = json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2");
int keyno;
if (!obj || !arr1 || !arr2 || !txt || !intnum || !dblnum || !dumpobj)
@@ -112,22 +109,20 @@ static void test_chaos() {
chaos_loop_new_value(json, json_pack("[s*,s*]", "v1", "v2"));
chaos_loop_new_value(json, json_pack("o", json_incref(txt)));
chaos_loop_new_value(json, json_pack("O", txt));
- chaos_loop_new_value(json,
- json_pack("s++", "a", "long string to force realloc",
- "another long string to force yet another "
- "reallocation of the string because "
- "that's what we are testing."));
+ chaos_loop_new_value(json, json_pack("s++", "a", "long string to force realloc",
+ "another long string to force yet another "
+ "reallocation of the string because "
+ "that's what we are testing."));
chaos_loop(test_unpack(), , );
- chaos_loop(
- json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)),
- , );
+ chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)),
+ , );
chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL,
JSON_INDENT(1) | JSON_SORT_KEYS),
, );
- chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);
- , free(dumptxt); dumptxt = NULL;);
+ chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);, free(dumptxt);
+ dumptxt = NULL;);
chaos_loop_new_value(json, json_copy(obj));
chaos_loop_new_value(json, json_deep_copy(obj));
@@ -141,8 +136,7 @@ static void test_chaos() {
#define JSON_LOAD_TXT "{\"n\":[1,2,3,4,5,6,7,8,9,10]}"
chaos_loop_new_value(json, json_loads(JSON_LOAD_TXT, 0, NULL));
- chaos_loop_new_value(
- json, json_loadb(JSON_LOAD_TXT, strlen(JSON_LOAD_TXT), 0, NULL));
+ chaos_loop_new_value(json, json_loadb(JSON_LOAD_TXT, strlen(JSON_LOAD_TXT), 0, NULL));
chaos_loop_new_value(json, json_sprintf("%s", "string"));
@@ -152,8 +146,7 @@ static void test_chaos() {
char testkey[10];
snprintf(testkey, sizeof(testkey), "test%d", keyno);
- chaos_loop(json_object_set_new_nocheck(obj, testkey, json_object()),
- , );
+ chaos_loop(json_object_set_new_nocheck(obj, testkey, json_object()), , );
#endif
chaos_loop(json_array_append_new(arr1, json_null()), , );
chaos_loop(json_array_insert_new(arr2, 0, json_null()), , );
diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c
index de90dc6..e8cb519 100644
--- a/test/suites/api/test_dump.c
+++ b/test/suites/api/test_dump.c
@@ -42,8 +42,7 @@ static void encode_null() {
/* Don't test json_dump_file to avoid creating a file */
- if (json_dump_callback(NULL, encode_null_callback, NULL, JSON_ENCODE_ANY) !=
- -1)
+ if (json_dump_callback(NULL, encode_null_callback, NULL, JSON_ENCODE_ANY) != -1)
fail("json_dump_callback didn't fail for NULL");
}
@@ -176,20 +175,17 @@ static void escape_slashes() {
char *result;
json = json_object();
- json_object_set_new(json, "url",
- json_string("https://github.com/akheron/jansson"));
+ json_object_set_new(json, "url", json_string("https://github.com/akheron/jansson"));
result = json_dumps(json, 0);
- if (!result ||
- strcmp(result, "{\"url\": \"https://github.com/akheron/jansson\"}"))
+ if (!result || strcmp(result, "{\"url\": \"https://github.com/akheron/jansson\"}"))
fail("json_dumps failed to not escape slashes");
free(result);
result = json_dumps(json, JSON_ESCAPE_SLASH);
if (!result ||
- strcmp(result,
- "{\"url\": \"https:\\/\\/github.com\\/akheron\\/jansson\"}"))
+ strcmp(result, "{\"url\": \"https:\\/\\/github.com\\/akheron\\/jansson\"}"))
fail("json_dumps failed to escape slashes");
free(result);
@@ -275,8 +271,8 @@ static void dumpfd() {
}
static void embed() {
- static const char *plains[] = {"{\"bar\":[],\"foo\":{}}", "[[],{}]", "{}",
- "[]", NULL};
+ static const char *plains[] = {"{\"bar\":[],\"foo\":{}}", "[[],{}]", "{}", "[]",
+ NULL};
size_t i;
@@ -290,8 +286,8 @@ static void embed() {
psize = strlen(plain) - 2;
embed = calloc(1, psize);
parse = json_loads(plain, 0, NULL);
- esize = json_dumpb(parse, embed, psize,
- JSON_COMPACT | JSON_SORT_KEYS | JSON_EMBED);
+ esize =
+ json_dumpb(parse, embed, psize, JSON_COMPACT | JSON_SORT_KEYS | JSON_EMBED);
json_decref(parse);
if (esize != psize)
fail("json_dumpb(JSON_EMBED) returned an invalid size");
diff --git a/test/suites/api/test_dump_callback.c b/test/suites/api/test_dump_callback.c
index 77e9a50..80ea008 100644
--- a/test/suites/api/test_dump_callback.c
+++ b/test/suites/api/test_dump_callback.c
@@ -29,8 +29,7 @@ static int my_writer(const char *buffer, size_t len, void *data) {
static void run_tests() {
struct my_sink s;
json_t *json;
- const char str[] =
- "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
+ const char str[] = "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
char *dumped_to_string;
json = json_loads(str, 0, NULL);
diff --git a/test/suites/api/test_equal.c b/test/suites/api/test_equal.c
index 9bcd392..d068b7b 100644
--- a/test/suites/api/test_equal.c
+++ b/test/suites/api/test_equal.c
@@ -157,18 +157,17 @@ static void test_equal_object() {
static void test_equal_complex() {
json_t *value1, *value2, *value3;
- const char *complex_json =
- "{"
- " \"integer\": 1, "
- " \"real\": 3.141592, "
- " \"string\": \"foobar\", "
- " \"true\": true, "
- " \"object\": {"
- " \"array-in-object\": [1,true,\"foo\",{}],"
- " \"object-in-object\": {\"foo\": \"bar\"}"
- " },"
- " \"array\": [\"foo\", false, null, 1.234]"
- "}";
+ const char *complex_json = "{"
+ " \"integer\": 1, "
+ " \"real\": 3.141592, "
+ " \"string\": \"foobar\", "
+ " \"true\": true, "
+ " \"object\": {"
+ " \"array-in-object\": [1,true,\"foo\",{}],"
+ " \"object-in-object\": {\"foo\": \"bar\"}"
+ " },"
+ " \"array\": [\"foo\", false, null, 1.234]"
+ "}";
value1 = json_loads(complex_json, 0, NULL);
value2 = json_loads(complex_json, 0, NULL);
@@ -179,14 +178,14 @@ static void test_equal_complex() {
fail("json_equal fails for two equal objects");
json_array_set_new(
- json_object_get(json_object_get(value2, "object"), "array-in-object"),
- 1, json_false());
+ json_object_get(json_object_get(value2, "object"), "array-in-object"), 1,
+ json_false());
if (json_equal(value1, value2))
fail("json_equal fails for two inequal objects");
json_object_set_new(
- json_object_get(json_object_get(value3, "object"), "object-in-object"),
- "foo", json_string("baz"));
+ json_object_get(json_object_get(value3, "object"), "object-in-object"), "foo",
+ json_string("baz"));
if (json_equal(value1, value3))
fail("json_equal fails for two inequal objects");
diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c
index 8eaf355..1c64b0c 100644
--- a/test/suites/api/test_load.c
+++ b/test/suites/api/test_load.c
@@ -29,8 +29,7 @@ static void file_not_found() {
*pos = '\0';
- if (strcmp(error.text, "unable to open /path/to/nonexistent/file.json") !=
- 0)
+ if (strcmp(error.text, "unable to open /path/to/nonexistent/file.json") != 0)
fail("json_load_file returned an invalid error message");
if (json_error_code(&error) != json_error_cannot_open_file)
fail("json_load_file returned an invalid error code");
@@ -71,8 +70,8 @@ static void disable_eof_check() {
if (json_loads(text, 0, &error))
fail("json_loads did not detect garbage after JSON text");
- check_error(json_error_end_of_input_expected,
- "end of file expected near 'garbage'", "<string>", 1, 18, 18);
+ check_error(json_error_end_of_input_expected, "end of file expected near 'garbage'",
+ "<string>", 1, 18, 18);
json = json_loads(text, JSON_DISABLE_EOF_CHECK, &error);
if (!json)
@@ -127,10 +126,8 @@ static void decode_int_as_real() {
imprecise = "9007199254740993";
expected = 9007199254740992ll;
- json = json_loads(imprecise, JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY,
- &error);
- if (!json || !json_is_real(json) ||
- expected != (json_int_t)json_real_value(json))
+ json = json_loads(imprecise, JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY, &error);
+ if (!json || !json_is_real(json) || expected != (json_int_t)json_real_value(json))
fail("json_load decode int as real failed - expected imprecision");
json_decref(json);
#endif
diff --git a/test/suites/api/test_load_callback.c b/test/suites/api/test_load_callback.c
index 1e27601..b292fcf 100644
--- a/test/suites/api/test_load_callback.c
+++ b/test/suites/api/test_load_callback.c
@@ -16,8 +16,7 @@ struct my_source {
size_t cap;
};
-static const char my_str[] =
- "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
+static const char my_str[] = "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
static size_t greedy_reader(void *buf, size_t buflen, void *arg) {
struct my_source *s = arg;
diff --git a/test/suites/api/test_memory_funcs.c b/test/suites/api/test_memory_funcs.c
index 9fc34fc..4fd6166 100644
--- a/test/suites/api/test_memory_funcs.c
+++ b/test/suites/api/test_memory_funcs.c
@@ -11,8 +11,8 @@ static size_t malloc_used = 0;
static void create_and_free_complex_object() {
json_t *obj;
- obj = json_pack("{s:i,s:n,s:b,s:b,s:{s:s},s:[i,i,i]}", "foo", 42, "bar",
- "baz", 1, "qux", 0, "alice", "bar", "baz", "bob", 9, 8, 7);
+ obj = json_pack("{s:i,s:n,s:b,s:b,s:{s:s},s:[i,i,i]}", "foo", 42, "bar", "baz", 1,
+ "qux", 0, "alice", "bar", "baz", "bob", 9, 8, 7);
json_decref(obj);
}
@@ -48,8 +48,7 @@ static void test_simple() {
json_get_alloc_funcs(&mfunc, &ffunc);
create_and_free_complex_object();
- if (malloc_called != 1 || free_called != 1 || mfunc != my_malloc ||
- ffunc != my_free)
+ if (malloc_called != 1 || free_called != 1 || mfunc != my_malloc || ffunc != my_free)
fail("Custom allocation failed");
}
diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c
index 033db21..331edf2 100644
--- a/test/suites/api/test_object.c
+++ b/test/suites/api/test_object.c
@@ -20,10 +20,9 @@ static void test_clear() {
if (!ten)
fail("unable to create integer");
- if (json_object_set(object, "a", ten) ||
- json_object_set(object, "b", ten) ||
- json_object_set(object, "c", ten) ||
- json_object_set(object, "d", ten) || json_object_set(object, "e", ten))
+ if (json_object_set(object, "a", ten) || json_object_set(object, "b", ten) ||
+ json_object_set(object, "c", ten) || json_object_set(object, "d", ten) ||
+ json_object_set(object, "e", ten))
fail("unable to set value");
if (json_object_size(object) != 5)
@@ -76,10 +75,8 @@ static void test_update() {
if (json_object_size(object) != 5)
fail("invalid size after update");
- if (json_object_get(object, "a") != ten ||
- json_object_get(object, "b") != ten ||
- json_object_get(object, "c") != ten ||
- json_object_get(object, "d") != ten ||
+ if (json_object_get(object, "a") != ten || json_object_get(object, "b") != ten ||
+ json_object_get(object, "c") != ten || json_object_get(object, "d") != ten ||
json_object_get(object, "e") != ten)
fail("update works incorrectly");
@@ -91,10 +88,8 @@ static void test_update() {
if (json_object_size(object) != 5)
fail("invalid size after update");
- if (json_object_get(object, "a") != ten ||
- json_object_get(object, "b") != ten ||
- json_object_get(object, "c") != ten ||
- json_object_get(object, "d") != ten ||
+ if (json_object_get(object, "a") != ten || json_object_get(object, "b") != ten ||
+ json_object_get(object, "c") != ten || json_object_get(object, "d") != ten ||
json_object_get(object, "e") != ten)
fail("update works incorrectly");
@@ -104,10 +99,9 @@ static void test_update() {
if (json_object_clear(other))
fail("clear failed");
- if (json_object_set(other, "a", nine) ||
- json_object_set(other, "b", nine) ||
- json_object_set(other, "f", nine) ||
- json_object_set(other, "g", nine) || json_object_set(other, "h", nine))
+ if (json_object_set(other, "a", nine) || json_object_set(other, "b", nine) ||
+ json_object_set(other, "f", nine) || json_object_set(other, "g", nine) ||
+ json_object_set(other, "h", nine))
fail("unable to set value");
if (json_object_update(object, other))
@@ -116,10 +110,8 @@ static void test_update() {
if (json_object_size(object) != 8)
fail("invalid size after update");
- if (json_object_get(object, "a") != nine ||
- json_object_get(object, "b") != nine ||
- json_object_get(object, "f") != nine ||
- json_object_get(object, "g") != nine ||
+ if (json_object_get(object, "a") != nine || json_object_get(object, "b") != nine ||
+ json_object_get(object, "f") != nine || json_object_get(object, "g") != nine ||
json_object_get(object, "h") != nine)
fail("update works incorrectly");
@@ -301,8 +293,7 @@ static void test_recursive_updates() {
if (!json_object_get(object, "foo"))
fail("json_object_update_recursive removed existing key");
- if (json_integer_value(
- json_object_get(json_object_get(object, "bar"), "baz")) != 3)
+ if (json_integer_value(json_object_get(json_object_get(object, "bar"), "baz")) != 3)
fail("json_object_update_recursive failed to update nested value");
barAfter = json_object_get(object, "bar");
@@ -318,14 +309,14 @@ static void test_recursive_updates() {
/* check circular reference */
object = json_pack("{s{s{s{si}}}}", "foo", "bar", "baz", "xxx", 2);
other = json_pack("{s{s{si}}}", "foo", "bar", "baz", 2);
- json_object_set(json_object_get(json_object_get(other, "foo"), "bar"),
- "baz", json_object_get(other, "foo"));
+ json_object_set(json_object_get(json_object_get(other, "foo"), "bar"), "baz",
+ json_object_get(other, "foo"));
if (!json_object_update_recursive(object, other))
fail("json_object_update_recursive update a circular reference!");
- json_object_set_new(json_object_get(json_object_get(other, "foo"), "bar"),
- "baz", json_integer(1));
+ json_object_set_new(json_object_get(json_object_get(other, "foo"), "bar"), "baz",
+ json_integer(1));
if (json_object_update_recursive(object, other))
fail("json_object_update_recursive failed!");
@@ -347,8 +338,7 @@ static void test_circular() {
fail("able to set self");
/* create circular references */
- if (json_object_set(object1, "a", object2) ||
- json_object_set(object2, "a", object1))
+ if (json_object_set(object1, "a", object2) || json_object_set(object2, "a", object1))
fail("unable to set value");
/* circularity is detected when dumping */
@@ -418,8 +408,8 @@ static void test_iterators() {
if (json_object_iter_next(object, NULL))
fail("able to increment a NULL iterator");
- if (json_object_set(object, "a", foo) ||
- json_object_set(object, "b", bar) || json_object_set(object, "c", baz))
+ if (json_object_set(object, "a", foo) || json_object_set(object, "b", bar) ||
+ json_object_set(object, "c", baz))
fail("unable to populate object");
iter = json_object_iter(object);
@@ -518,8 +508,7 @@ static void test_misc() {
fail("got different value than what was added");
/* "a", "lp" and "px" collide in a five-bucket hashtable */
- if (json_object_set(object, "b", string) ||
- json_object_set(object, "lp", string) ||
+ if (json_object_set(object, "b", string) || json_object_set(object, "lp", string) ||
json_object_set(object, "px", string))
fail("unable to set value");
@@ -630,8 +619,7 @@ static void test_object_foreach() {
object1 = json_pack("{sisisi}", "foo", 1, "bar", 2, "baz", 3);
object2 = json_object();
- json_object_foreach(object1, key, value)
- json_object_set(object2, key, value);
+ json_object_foreach(object1, key, value) json_object_set(object2, key, value);
if (!json_equal(object1, object2))
fail("json_object_foreach failed to iterate all key-value pairs");
@@ -647,9 +635,7 @@ static void test_object_foreach_safe() {
object = json_pack("{sisisi}", "foo", 1, "bar", 2, "baz", 3);
- json_object_foreach_safe(object, tmp, key, value) {
- json_object_del(object, key);
- }
+ json_object_foreach_safe(object, tmp, key, value) { json_object_del(object, key); }
if (json_object_size(object) != 0)
fail("json_object_foreach_safe failed to iterate all key-value pairs");
@@ -762,8 +748,7 @@ static void test_bad_args(void) {
if (json_object_iter_next(obj, NULL) != NULL)
fail("json_object_iter_next with NULL iter returned non-NULL");
if (json_object_iter_next(num, iter) != NULL)
- fail(
- "json_object_iter_next with non-object argument returned non-NULL");
+ fail("json_object_iter_next with non-object argument returned non-NULL");
if (json_object_iter_key(NULL) != NULL)
fail("json_object_iter_key with NULL iter returned non-NULL");
diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c
index dd510a4..865f60b 100644
--- a/test/suites/api/test_pack.c
+++ b/test/suites/api/test_pack.c
@@ -31,18 +31,18 @@ static void test_inifity() {
if (json_pack_ex(&error, 0, "f", INFINITY))
fail("json_pack infinity incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 1, 1);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 1, 1);
if (json_pack_ex(&error, 0, "[f]", INFINITY))
fail("json_pack infinity array element incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 2, 2);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 2, 2);
if (json_pack_ex(&error, 0, "{s:f}", "key", INFINITY))
fail("json_pack infinity object value incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 4, 4);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 4, 4);
#ifdef _MSC_VER
#pragma warning(pop)
@@ -300,8 +300,8 @@ static void run_tests() {
if (json_pack_ex(&error, 0, "{s:i*}", "a", 1))
fail("json_pack object optional invalid incorrectly succeeded");
- check_error(json_error_invalid_format, "Expected format 's', got '*'",
- "<format>", 1, 5, 5);
+ check_error(json_error_invalid_format, "Expected format 's', got '*'", "<format>", 1,
+ 5, 5);
value = json_pack("{s:s*,s:o*,s:O*}", "a", NULL, "b", NULL, "c", NULL);
if (!json_is_object(value) || json_object_size(value) != 0)
@@ -342,8 +342,8 @@ static void run_tests() {
if (json_pack_ex(&error, 0, "[i*]", 1))
fail("json_pack array optional invalid incorrectly succeeded");
- check_error(json_error_invalid_format, "Unexpected format character '*'",
- "<format>", 1, 3, 3);
+ check_error(json_error_invalid_format, "Unexpected format character '*'", "<format>",
+ 1, 3, 3);
value = json_pack("[**]", NULL);
if (value)
@@ -357,18 +357,18 @@ static void run_tests() {
/* Invalid float values */
if (json_pack_ex(&error, 0, "f", NAN))
fail("json_pack NAN incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 1, 1);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 1, 1);
if (json_pack_ex(&error, 0, "[f]", NAN))
fail("json_pack NAN array element incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 2, 2);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 2, 2);
if (json_pack_ex(&error, 0, "{s:f}", "key", NAN))
fail("json_pack NAN object value incorrectly succeeded");
- check_error(json_error_numeric_overflow, "Invalid floating point value",
- "<args>", 1, 4, 4);
+ check_error(json_error_numeric_overflow, "Invalid floating point value", "<args>", 1,
+ 4, 4);
#endif
#ifdef INFINITY
@@ -400,42 +400,42 @@ static void run_tests() {
/* newline in format string */
if (json_pack_ex(&error, 0, "{\n\n1"))
fail("json_pack failed to catch invalid format '1'");
- check_error(json_error_invalid_format, "Expected format 's', got '1'",
- "<format>", 3, 1, 4);
+ check_error(json_error_invalid_format, "Expected format 's', got '1'", "<format>", 3,
+ 1, 4);
/* mismatched open/close array/object */
if (json_pack_ex(&error, 0, "[}"))
fail("json_pack failed to catch mismatched '}'");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 2, 2);
if (json_pack_ex(&error, 0, "{]"))
fail("json_pack failed to catch mismatched ']'");
- check_error(json_error_invalid_format, "Expected format 's', got ']'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Expected format 's', got ']'", "<format>", 1,
+ 2, 2);
/* missing close array */
if (json_pack_ex(&error, 0, "["))
fail("json_pack failed to catch missing ']'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
/* missing close object */
if (json_pack_ex(&error, 0, "{"))
fail("json_pack failed to catch missing '}'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
/* garbage after format string */
if (json_pack_ex(&error, 0, "[i]a", 42))
fail("json_pack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 4, 4);
if (json_pack_ex(&error, 0, "ia", 42))
fail("json_pack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 2, 2);
/* NULL string */
if (json_pack_ex(&error, 0, "s", NULL))
@@ -445,20 +445,20 @@ static void run_tests() {
/* + on its own */
if (json_pack_ex(&error, 0, "+", NULL))
fail("json_pack failed to a lone +");
- check_error(json_error_invalid_format, "Unexpected format character '+'",
- "<format>", 1, 1, 1);
+ check_error(json_error_invalid_format, "Unexpected format character '+'", "<format>",
+ 1, 1, 1);
/* Empty format */
if (json_pack_ex(&error, 0, ""))
fail("json_pack failed to catch empty format string");
- check_error(json_error_invalid_argument, "NULL or empty format string",
- "<format>", -1, -1, 0);
+ check_error(json_error_invalid_argument, "NULL or empty format string", "<format>",
+ -1, -1, 0);
/* NULL format */
if (json_pack_ex(&error, 0, NULL))
fail("json_pack failed to catch NULL format string");
- check_error(json_error_invalid_argument, "NULL or empty format string",
- "<format>", -1, -1, 0);
+ check_error(json_error_invalid_argument, "NULL or empty format string", "<format>",
+ -1, -1, 0);
/* NULL key */
if (json_pack_ex(&error, 0, "{s:i}", NULL, 1))
@@ -467,8 +467,7 @@ static void run_tests() {
/* NULL value followed by object still steals the object's ref */
value = json_incref(json_object());
- if (json_pack_ex(&error, 0, "{s:s,s:o}", "badnull", NULL, "dontleak",
- value))
+ if (json_pack_ex(&error, 0, "{s:s,s:o}", "badnull", NULL, "dontleak", value))
fail("json_pack failed to catch NULL value");
check_error(json_error_null_value, "NULL string", "<args>", 1, 4, 4);
if (value->refcount != (size_t)1)
@@ -478,52 +477,47 @@ static void run_tests() {
/* More complicated checks for row/columns */
if (json_pack_ex(&error, 0, "{ {}: s }", "foo"))
fail("json_pack failed to catch object as key");
- check_error(json_error_invalid_format, "Expected format 's', got '{'",
- "<format>", 1, 3, 3);
+ check_error(json_error_invalid_format, "Expected format 's', got '{'", "<format>", 1,
+ 3, 3);
/* Complex object */
if (json_pack_ex(&error, 0, "{ s: {}, s:[ii{} }", "foo", "bar", 12, 13))
fail("json_pack failed to catch missing ]");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 19, 19);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 19, 19);
/* Complex array */
if (json_pack_ex(&error, 0, "[[[[[ [[[[[ [[[[ }]]]] ]]]] ]]]]]"))
fail("json_pack failed to catch extra }");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 21, 21);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 21, 21);
/* Invalid UTF-8 in object key */
if (json_pack_ex(&error, 0, "{s:i}", "\xff\xff", 42))
fail("json_pack failed to catch invalid UTF-8 in an object key");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>",
- 1, 2, 2);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>", 1, 2, 2);
/* Invalid UTF-8 in a string */
if (json_pack_ex(&error, 0, "{s:s}", "foo", "\xff\xff"))
fail("json_pack failed to catch invalid UTF-8 in a string");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 4,
- 4);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 4, 4);
/* Invalid UTF-8 in an optional '?' string */
if (json_pack_ex(&error, 0, "{s:s?}", "foo", "\xff\xff"))
fail("json_pack failed to catch invalid UTF-8 in an optional '?' "
"string");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5,
- 5);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5, 5);
/* Invalid UTF-8 in an optional '*' string */
if (json_pack_ex(&error, 0, "{s:s*}", "foo", "\xff\xff"))
fail("json_pack failed to catch invalid UTF-8 in an optional '*' "
"string");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5,
- 5);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 string", "<args>", 1, 5, 5);
/* Invalid UTF-8 in a concatenated key */
if (json_pack_ex(&error, 0, "{s+:i}", "\xff\xff", "concat", 42))
fail("json_pack failed to catch invalid UTF-8 in an object key");
- check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>",
- 1, 3, 3);
+ check_error(json_error_invalid_utf8, "Invalid UTF-8 object key", "<args>", 1, 3, 3);
if (json_pack_ex(&error, 0, "{s:o}", "foo", NULL))
fail("json_pack failed to catch nullable object");
@@ -539,13 +533,13 @@ static void run_tests() {
if (json_pack_ex(&error, 0, "[1s", "Hi"))
fail("json_pack failed to catch invalid format");
- check_error(json_error_invalid_format, "Unexpected format character '1'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '1'", "<format>",
+ 1, 2, 2);
if (json_pack_ex(&error, 0, "[1s+", "Hi", "ya"))
fail("json_pack failed to catch invalid format");
- check_error(json_error_invalid_format, "Unexpected format character '1'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '1'", "<format>",
+ 1, 2, 2);
if (json_pack_ex(&error, 0, "[so]", NULL, json_object()))
fail("json_pack failed to catch NULL value");
diff --git a/test/suites/api/test_unpack.c b/test/suites/api/test_unpack.c
index df5a856..139ec6f 100644
--- a/test/suites/api/test_unpack.c
+++ b/test/suites/api/test_unpack.c
@@ -143,8 +143,8 @@ static void run_tests() {
j = json_integer(42);
if (!json_unpack_ex(j, &error, 0, "z"))
fail("json_unpack succeeded with invalid format character");
- check_error(json_error_invalid_format, "Unexpected format character 'z'",
- "<format>", 1, 1, 1);
+ check_error(json_error_invalid_format, "Unexpected format character 'z'", "<format>",
+ 1, 1, 1);
if (!json_unpack_ex(NULL, &error, 0, "[i]"))
fail("json_unpack succeeded with NULL root");
@@ -155,62 +155,61 @@ static void run_tests() {
j = json_pack("[]");
if (!json_unpack_ex(j, &error, 0, "[}"))
fail("json_unpack failed to catch mismatched ']'");
- check_error(json_error_invalid_format, "Unexpected format character '}'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected format character '}'", "<format>",
+ 1, 2, 2);
json_decref(j);
j = json_pack("{}");
if (!json_unpack_ex(j, &error, 0, "{]"))
fail("json_unpack failed to catch mismatched '}'");
- check_error(json_error_invalid_format, "Expected format 's', got ']'",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Expected format 's', got ']'", "<format>", 1,
+ 2, 2);
json_decref(j);
/* missing close array */
j = json_pack("[]");
if (!json_unpack_ex(j, &error, 0, "["))
fail("json_unpack failed to catch missing ']'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
json_decref(j);
/* missing close object */
j = json_pack("{}");
if (!json_unpack_ex(j, &error, 0, "{"))
fail("json_unpack failed to catch missing '}'");
- check_error(json_error_invalid_format, "Unexpected end of format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Unexpected end of format string", "<format>",
+ 1, 2, 2);
json_decref(j);
/* garbage after format string */
j = json_pack("[i]", 42);
if (!json_unpack_ex(j, &error, 0, "[i]a", &i1))
fail("json_unpack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 4, 4);
json_decref(j);
j = json_integer(12345);
if (!json_unpack_ex(j, &error, 0, "ia", &i1))
fail("json_unpack failed to catch garbage after format string");
- check_error(json_error_invalid_format, "Garbage after format string",
- "<format>", 1, 2, 2);
+ check_error(json_error_invalid_format, "Garbage after format string", "<format>", 1,
+ 2, 2);
json_decref(j);
/* NULL format string */
j = json_pack("[]");
if (!json_unpack_ex(j, &error, 0, NULL))
fail("json_unpack failed to catch null format string");
- check_error(json_error_invalid_argument, "NULL or empty format string",
- "<format>", -1, -1, 0);
+ check_error(json_error_invalid_argument, "NULL or empty format string", "<format>",
+ -1, -1, 0);
json_decref(j);
/* NULL string pointer */
j = json_string("foobie");
if (!json_unpack_ex(j, &error, 0, "s", NULL))
fail("json_unpack failed to catch null string pointer");
- check_error(json_error_null_value, "NULL string argument", "<args>", 1, 1,
- 1);
+ check_error(json_error_null_value, "NULL string argument", "<args>", 1, 1, 1);
json_decref(j);
/* invalid types */
@@ -218,13 +217,13 @@ static void run_tests() {
j2 = json_string("foo");
if (!json_unpack_ex(j, &error, 0, "s"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected string, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected string, got integer", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j, &error, 0, "n"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected null, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected null, got integer", "<validation>", 1, 1,
+ 1);
if (!json_unpack_ex(j, &error, 0, "b"))
fail("json_unpack failed to catch invalid type");
@@ -233,18 +232,18 @@ static void run_tests() {
if (!json_unpack_ex(j2, &error, 0, "i"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected integer, got string",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected integer, got string", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j2, &error, 0, "I"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected integer, got string",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected integer, got string", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j, &error, 0, "f"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected real, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected real, got integer", "<validation>", 1, 1,
+ 1);
if (!json_unpack_ex(j2, &error, 0, "F"))
fail("json_unpack failed to catch invalid type");
@@ -253,13 +252,13 @@ static void run_tests() {
if (!json_unpack_ex(j, &error, 0, "[i]"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected array, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected array, got integer", "<validation>", 1,
+ 1, 1);
if (!json_unpack_ex(j, &error, 0, "{si}", "foo"))
fail("json_unpack failed to catch invalid type");
- check_error(json_error_wrong_type, "Expected object, got integer",
- "<validation>", 1, 1, 1);
+ check_error(json_error_wrong_type, "Expected object, got integer", "<validation>", 1,
+ 1, 1);
json_decref(j);
json_decref(j2);
@@ -283,8 +282,8 @@ static void run_tests() {
j = json_pack("{si}", "foo", 42);
if (!json_unpack_ex(j, &error, 0, "{si}", "baz", &i1))
fail("json_unpack failed to catch null string pointer");
- check_error(json_error_item_not_found, "Object item not found: baz",
- "<validation>", 1, 3, 3);
+ check_error(json_error_item_not_found, "Object item not found: baz", "<validation>",
+ 1, 3, 3);
json_decref(j);
/*
@@ -300,16 +299,16 @@ static void run_tests() {
j = json_pack("[iii]", 1, 2, 3);
if (!json_unpack_ex(j, &error, 0, "[ii!]", &i1, &i2))
fail("json_unpack array with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 array item(s) left unpacked", "<validation>", 1, 5, 5);
+ check_error(json_error_end_of_input_expected, "1 array item(s) left unpacked",
+ "<validation>", 1, 5, 5);
json_decref(j);
/* Like above, but with JSON_STRICT instead of '!' format */
j = json_pack("[iii]", 1, 2, 3);
if (!json_unpack_ex(j, &error, JSON_STRICT, "[ii]", &i1, &i2))
fail("json_unpack array with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 array item(s) left unpacked", "<validation>", 1, 4, 4);
+ check_error(json_error_end_of_input_expected, "1 array item(s) left unpacked",
+ "<validation>", 1, 4, 4);
json_decref(j);
j = json_pack("{s:s, s:i}", "foo", "bar", "baz", 42);
@@ -323,17 +322,16 @@ static void run_tests() {
if (!json_unpack_ex(j, &error, 0, "{s:s,s:s!}", "foo", &s, "foo", &s))
fail("json_unpack object with strict validation failed");
{
- const char *possible_errors[] = {
- "2 object item(s) left unpacked: baz, quux",
- "2 object item(s) left unpacked: quux, baz"};
- check_errors(json_error_end_of_input_expected, possible_errors, 2,
- "<validation>", 1, 10, 10);
+ const char *possible_errors[] = {"2 object item(s) left unpacked: baz, quux",
+ "2 object item(s) left unpacked: quux, baz"};
+ check_errors(json_error_end_of_input_expected, possible_errors, 2, "<validation>",
+ 1, 10, 10);
}
json_decref(j);
j = json_pack("[i,{s:i,s:n},[i,i]]", 1, "foo", 2, "bar", 3, 4);
- if (json_unpack_ex(j, NULL, JSON_STRICT | JSON_VALIDATE_ONLY,
- "[i{sisn}[ii]]", "foo", "bar"))
+ if (json_unpack_ex(j, NULL, JSON_STRICT | JSON_VALIDATE_ONLY, "[i{sisn}[ii]]", "foo",
+ "bar"))
fail("json_unpack complex value with strict validation failed");
json_decref(j);
@@ -341,41 +339,41 @@ static void run_tests() {
j = json_pack("[ii]", 1, 2);
if (!json_unpack_ex(j, &error, 0, "[i!i]", &i1, &i2))
fail("json_unpack failed to catch ! in the middle of an array");
- check_error(json_error_invalid_format, "Expected ']' after '!', got 'i'",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Expected ']' after '!', got 'i'", "<format>",
+ 1, 4, 4);
if (!json_unpack_ex(j, &error, 0, "[i*i]", &i1, &i2))
fail("json_unpack failed to catch * in the middle of an array");
- check_error(json_error_invalid_format, "Expected ']' after '*', got 'i'",
- "<format>", 1, 4, 4);
+ check_error(json_error_invalid_format, "Expected ']' after '*', got 'i'", "<format>",
+ 1, 4, 4);
json_decref(j);
j = json_pack("{sssi}", "foo", "bar", "baz", 42);
if (!json_unpack_ex(j, &error, 0, "{ss!si}", "foo", &s, "baz", &i1))
fail("json_unpack failed to catch ! in the middle of an object");
- check_error(json_error_invalid_format, "Expected '}' after '!', got 's'",
- "<format>", 1, 5, 5);
+ check_error(json_error_invalid_format, "Expected '}' after '!', got 's'", "<format>",
+ 1, 5, 5);
if (!json_unpack_ex(j, &error, 0, "{ss*si}", "foo", &s, "baz", &i1))
fail("json_unpack failed to catch ! in the middle of an object");
- check_error(json_error_invalid_format, "Expected '}' after '*', got 's'",
- "<format>", 1, 5, 5);
+ check_error(json_error_invalid_format, "Expected '}' after '*', got 's'", "<format>",
+ 1, 5, 5);
json_decref(j);
/* Error in nested object */
j = json_pack("{s{snsn}}", "foo", "bar", "baz");
if (!json_unpack_ex(j, &error, 0, "{s{sn!}}", "foo", "bar"))
fail("json_unpack nested object with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 object item(s) left unpacked: baz", "<validation>", 1, 7, 7);
+ check_error(json_error_end_of_input_expected, "1 object item(s) left unpacked: baz",
+ "<validation>", 1, 7, 7);
json_decref(j);
/* Error in nested array */
j = json_pack("[[ii]]", 1, 2);
if (!json_unpack_ex(j, &error, 0, "[[i!]]", &i1))
fail("json_unpack nested array with strict validation failed");
- check_error(json_error_end_of_input_expected,
- "1 array item(s) left unpacked", "<validation>", 1, 5, 5);
+ check_error(json_error_end_of_input_expected, "1 array item(s) left unpacked",
+ "<validation>", 1, 5, 5);
json_decref(j);
/* Optional values */
@@ -397,8 +395,7 @@ static void run_tests() {
j = json_object();
i1 = i2 = i3 = 0;
- if (json_unpack(j, "{s?[ii]s?{s{si}}}", "foo", &i1, &i2, "bar", "baz",
- "quux", &i3))
+ if (json_unpack(j, "{s?[ii]s?{s{si}}}", "foo", &i1, &i2, "bar", "baz", "quux", &i3))
fail("json_unpack failed for complex optional values");
if (i1 != 0 || i2 != 0 || i3 != 0)
fail("json_unpack unexpectedly unpacked something");
@@ -428,7 +425,7 @@ static void run_tests() {
if (!json_unpack_ex(j, &error, 0, "{sis?i!}", "foo", &i1, "bar", &i2))
fail("json_unpack failed for optional values with strict mode and "
"compensation");
- check_error(json_error_end_of_input_expected,
- "1 object item(s) left unpacked: baz", "<validation>", 1, 8, 8);
+ check_error(json_error_end_of_input_expected, "1 object item(s) left unpacked: baz",
+ "<validation>", 1, 8, 8);
json_decref(j);
}
diff --git a/test/suites/api/test_version.c b/test/suites/api/test_version.c
index 5083157..05e0e96 100644
--- a/test/suites/api/test_version.c
+++ b/test/suites/api/test_version.c
@@ -26,8 +26,7 @@ static void test_version_cmp() {
}
if (JANSSON_MINOR_VERSION) {
- if (jansson_version_cmp(JANSSON_MAJOR_VERSION,
- JANSSON_MINOR_VERSION - 1,
+ if (jansson_version_cmp(JANSSON_MAJOR_VERSION, JANSSON_MINOR_VERSION - 1,
JANSSON_MICRO_VERSION) <= 0) {
fail("jansson_version_cmp less than check failed");
}
diff --git a/test/suites/api/util.h b/test/suites/api/util.h
index cf8a4dd..d964c49 100644
--- a/test/suites/api/util.h
+++ b/test/suites/api/util.h
@@ -22,66 +22,62 @@
#define failhdr fprintf(stderr, "%s:%d: ", __FILE__, __LINE__)
-#define fail(msg) \
- do { \
- failhdr; \
- fprintf(stderr, "%s\n", msg); \
- exit(1); \
+#define fail(msg) \
+ do { \
+ failhdr; \
+ fprintf(stderr, "%s\n", msg); \
+ exit(1); \
} while (0)
/* Assumes json_error_t error */
-#define check_errors(code_, texts_, num_, source_, line_, column_, position_) \
- do { \
- int i_, found_ = 0; \
- if (json_error_code(&error) != code_) { \
- failhdr; \
- fprintf(stderr, "code: %d != %d\n", json_error_code(&error), \
- code_); \
- exit(1); \
- } \
- for (i_ = 0; i_ < num_; i_++) { \
- if (strcmp(error.text, texts_[i_]) == 0) { \
- found_ = 1; \
- break; \
- } \
- } \
- if (!found_) { \
- failhdr; \
- if (num_ == 1) { \
- fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, \
- texts_[0]); \
- } else { \
- fprintf(stderr, "text: \"%s\" does not match\n", error.text); \
- } \
- exit(1); \
- } \
- if (strcmp(error.source, source_) != 0) { \
- failhdr; \
- \
- fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, \
- source_); \
- exit(1); \
- } \
- if (error.line != line_) { \
- failhdr; \
- fprintf(stderr, "line: %d != %d\n", error.line, line_); \
- exit(1); \
- } \
- if (error.column != column_) { \
- failhdr; \
- fprintf(stderr, "column: %d != %d\n", error.column, column_); \
- exit(1); \
- } \
- if (error.position != position_) { \
- failhdr; \
- fprintf(stderr, "position: %d != %d\n", error.position, \
- position_); \
- exit(1); \
- } \
+#define check_errors(code_, texts_, num_, source_, line_, column_, position_) \
+ do { \
+ int i_, found_ = 0; \
+ if (json_error_code(&error) != code_) { \
+ failhdr; \
+ fprintf(stderr, "code: %d != %d\n", json_error_code(&error), code_); \
+ exit(1); \
+ } \
+ for (i_ = 0; i_ < num_; i_++) { \
+ if (strcmp(error.text, texts_[i_]) == 0) { \
+ found_ = 1; \
+ break; \
+ } \
+ } \
+ if (!found_) { \
+ failhdr; \
+ if (num_ == 1) { \
+ fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, texts_[0]); \
+ } else { \
+ fprintf(stderr, "text: \"%s\" does not match\n", error.text); \
+ } \
+ exit(1); \
+ } \
+ if (strcmp(error.source, source_) != 0) { \
+ failhdr; \
+ \
+ fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, source_); \
+ exit(1); \
+ } \
+ if (error.line != line_) { \
+ failhdr; \
+ fprintf(stderr, "line: %d != %d\n", error.line, line_); \
+ exit(1); \
+ } \
+ if (error.column != column_) { \
+ failhdr; \
+ fprintf(stderr, "column: %d != %d\n", error.column, column_); \
+ exit(1); \
+ } \
+ if (error.position != position_) { \
+ failhdr; \
+ fprintf(stderr, "position: %d != %d\n", error.position, position_); \
+ exit(1); \
+ } \
} while (0)
/* Assumes json_error_t error */
-#define check_error(code_, text_, source_, line_, column_, position_) \
+#define check_error(code_, text_, source_, line_, column_, position_) \
check_errors(code_, &text_, 1, source_, line_, column_, position_)
static void run_tests();