Add a flags parameter to all decoding functions for future needs
authorPetri Lehtinen <petri@digip.org>
Fri, 13 Aug 2010 19:19:20 +0000 (22:19 +0300)
committerPetri Lehtinen <petri@digip.org>
Sat, 14 Aug 2010 14:28:09 +0000 (17:28 +0300)
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
doc/github_commits.c
doc/tutorial.rst
src/jansson.h
src/load.c
test/bin/json_process.c
test/suites/api/test_copy.c
test/suites/api/test_equal.c
test/suites/api/test_load.c

index aad0d6c..3e5f9f2 100644 (file)
@@ -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
index 0fc1a1b..707aac4 100644 (file)
@@ -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)
index caa11c2..eded745 100644 (file)
@@ -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)
index 5d335ae..41f9c9d 100644 (file)
@@ -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
index 2a360ff..0576080 100644 (file)
@@ -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;
index a32f1d0..cff820b 100644 (file)
@@ -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;
index e4705f4..1c8a066 100644 (file)
@@ -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");
 
index 111ee26..3b4ec2a 100644 (file)
@@ -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))
index 0934ea8..b022a3a 100644 (file)
@@ -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)