From bfac1972e25b40f849852ce3c10e0a8ad47f79d7 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Fri, 13 Aug 2010 22:19:20 +0300 Subject: [PATCH] Add a flags parameter to all decoding functions for future needs As of now, the parameter is unused, but may be needed in the future. I'm adding it now so that in the future both API and ABI remain backwards compatible as long as possible. This is a backwards incompatible change. --- doc/apiref.rst | 17 ++++++++++------- doc/github_commits.c | 2 +- doc/tutorial.rst | 2 +- src/jansson.h | 6 +++--- src/load.c | 10 ++++++---- test/bin/json_process.c | 2 +- test/suites/api/test_copy.c | 8 ++++---- test/suites/api/test_equal.c | 4 ++-- test/suites/api/test_load.c | 2 +- 9 files changed, 29 insertions(+), 24 deletions(-) diff --git a/doc/apiref.rst b/doc/apiref.rst index aad0d6c..3e5f9f2 100644 --- a/doc/apiref.rst +++ b/doc/apiref.rst @@ -713,7 +713,7 @@ subset of). json_t *json; json_error_t error; - json = json_load_file("/path/to/file.json", &error); + json = json_load_file("/path/to/file.json", 0, &error); if(!json) { /* the error variable contains error information */ } @@ -729,32 +729,35 @@ subset of). The following functions perform the actual JSON decoding. -.. cfunction:: json_t *json_loads(const char *input, json_error_t *error) +.. cfunction:: json_t *json_loads(const char *input, size_t flags, json_error_t *error) .. refcounting:: new Decodes the JSON string *input* and returns the array or object it contains, or *NULL* on error, in which case *error* is filled with information about the error. See above for discussion on the - *error* parameter. + *error* parameter. *flags* is currently unused, and should be set + to 0. -.. cfunction:: json_t *json_loadf(FILE *input, json_error_t *error) +.. cfunction:: json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) .. refcounting:: new Decodes the JSON text in stream *input* and returns the array or object it contains, or *NULL* on error, in which case *error* is filled with information about the error. See above for discussion - on the *error* parameter. + on the *error* parameter. *flags* is currently unused, and should + be set to 0. -.. cfunction:: json_t *json_load_file(const char *path, json_error_t *error) +.. cfunction:: json_t *json_load_file(const char *path, size_t flags, json_error_t *error) .. refcounting:: new Decodes the JSON text in file *path* and returns the array or object it contains, or *NULL* on error, in which case *error* is filled with information about the error. See above for discussion - on the *error* parameter. + on the *error* parameter. *flags* is currently unused, and should + be set to 0. Equality diff --git a/doc/github_commits.c b/doc/github_commits.c index 0fc1a1b..707aac4 100644 --- a/doc/github_commits.c +++ b/doc/github_commits.c @@ -117,7 +117,7 @@ int main(int argc, char *argv[]) if(!text) return 1; - root = json_loads(text, &error); + root = json_loads(text, 0, &error); free(text); if(!root) diff --git a/doc/tutorial.rst b/doc/tutorial.rst index caa11c2..eded745 100644 --- a/doc/tutorial.rst +++ b/doc/tutorial.rst @@ -152,7 +152,7 @@ function. Next we'll call :cfunc:`json_loads()` to decode the JSON text we got as a response:: - root = json_loads(text, &error); + root = json_loads(text, 0, &error); free(text); if(!root) diff --git a/src/jansson.h b/src/jansson.h index 5d335ae..41f9c9d 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -177,9 +177,9 @@ typedef struct { int line; } json_error_t; -json_t *json_loads(const char *input, json_error_t *error); -json_t *json_loadf(FILE *input, json_error_t *error); -json_t *json_load_file(const char *path, json_error_t *error); +json_t *json_loads(const char *input, size_t flags, json_error_t *error); +json_t *json_loadf(FILE *input, size_t flags, json_error_t *error); +json_t *json_load_file(const char *path, size_t flags, json_error_t *error); #define JSON_INDENT(n) (n & 0x1F) #define JSON_COMPACT 0x20 diff --git a/src/load.c b/src/load.c index 2a360ff..0576080 100644 --- a/src/load.c +++ b/src/load.c @@ -811,10 +811,11 @@ static int string_eof(void *data) return (stream->data[stream->pos] == '\0'); } -json_t *json_loads(const char *string, json_error_t *error) +json_t *json_loads(const char *string, size_t flags, json_error_t *error) { lex_t lex; json_t *result; + (void)flags; /* unused */ string_data_t stream_data = { .data = string, @@ -840,10 +841,11 @@ out: return result; } -json_t *json_loadf(FILE *input, json_error_t *error) +json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) { lex_t lex; json_t *result; + (void)flags; /* unused */ if(lex_init(&lex, (get_func)fgetc, (eof_func)feof, input)) return NULL; @@ -864,7 +866,7 @@ out: return result; } -json_t *json_load_file(const char *path, json_error_t *error) +json_t *json_load_file(const char *path, size_t flags, json_error_t *error) { json_t *result; FILE *fp; @@ -879,7 +881,7 @@ json_t *json_load_file(const char *path, json_error_t *error) return NULL; } - result = json_loadf(fp, error); + result = json_loadf(fp, flags, error); fclose(fp); return result; diff --git a/test/bin/json_process.c b/test/bin/json_process.c index a32f1d0..cff820b 100644 --- a/test/bin/json_process.c +++ b/test/bin/json_process.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) if(getenv_int("JSON_SORT_KEYS")) flags |= JSON_SORT_KEYS; - json = json_loadf(stdin, &error); + json = json_loadf(stdin, 0, &error); if(!json) { fprintf(stderr, "%d\n%s\n", error.line, error.text); return 1; diff --git a/test/suites/api/test_copy.c b/test/suites/api/test_copy.c index e4705f4..1c8a066 100644 --- a/test/suites/api/test_copy.c +++ b/test/suites/api/test_copy.c @@ -176,7 +176,7 @@ static void test_copy_array(void) json_t *array, *copy; size_t i; - array = json_loads(json_array_text, NULL); + array = json_loads(json_array_text, 0, NULL); if(!array) fail("unable to parse an array"); @@ -205,7 +205,7 @@ static void test_deep_copy_array(void) json_t *array, *copy; size_t i; - array = json_loads(json_array_text, NULL); + array = json_loads(json_array_text, 0, NULL); if(!array) fail("unable to parse an array"); @@ -235,7 +235,7 @@ static void test_copy_object(void) json_t *object, *copy; void *iter; - object = json_loads(json_object_text, NULL); + object = json_loads(json_object_text, 0, NULL); if(!object) fail("unable to parse an object"); @@ -275,7 +275,7 @@ static void test_deep_copy_object(void) json_t *object, *copy; void *iter; - object = json_loads(json_object_text, NULL); + object = json_loads(json_object_text, 0, NULL); if(!object) fail("unable to parse an object"); diff --git a/test/suites/api/test_equal.c b/test/suites/api/test_equal.c index 111ee26..3b4ec2a 100644 --- a/test/suites/api/test_equal.c +++ b/test/suites/api/test_equal.c @@ -167,8 +167,8 @@ static void test_equal_complex() " \"array\": [\"foo\", false, null, 1.234]" "}"; - value1 = json_loads(complex_json, NULL); - value2 = json_loads(complex_json, NULL); + value1 = json_loads(complex_json, 0, NULL); + value2 = json_loads(complex_json, 0, NULL); if(!value1 || !value2) fail("unable to parse JSON"); if(!json_equal(value1, value2)) diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c index 0934ea8..b022a3a 100644 --- a/test/suites/api/test_load.c +++ b/test/suites/api/test_load.c @@ -14,7 +14,7 @@ int main() json_t *json; json_error_t error; - json = json_load_file("/path/to/nonexistent/file.json", &error); + json = json_load_file("/path/to/nonexistent/file.json", 0, &error); if(error.line != -1) fail("json_load_file returned an invalid line number"); if(strcmp(error.text, "unable to open /path/to/nonexistent/file.json: No such file or directory") != 0) -- 2.1.4