Make json_error_t opaque
All decoding functions now accept a json_error_t** parameter and set it to point to a heap-allocated json_error_t structure if an error occurs. The contents of json_error_t are no longer exposed directly, a few functions to do it have been added instead. If an error occurs, the user must free the json_error_t value. This makes it possible to enhance the error reporting facilities in the future without breaking ABI compatibility with older versions. This is a backwards incompatible change.
This commit is contained in:
@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
|
||||
size_t flags = 0;
|
||||
|
||||
json_t *json;
|
||||
json_error_t error;
|
||||
json_error_t *error;
|
||||
|
||||
if(argc != 1) {
|
||||
fprintf(stderr, "usage: %s\n", argv[0]);
|
||||
@@ -61,7 +61,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
json = json_loadf(stdin, 0, &error);
|
||||
if(!json) {
|
||||
fprintf(stderr, "%d\n%s\n", error.line, error.text);
|
||||
fprintf(stderr, "%d\n%s\n",
|
||||
json_error_line(error),
|
||||
json_error_msg(error));
|
||||
free(error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user