diff mbox

fwts: json_object_object_get is deprecated

Message ID 1398322395.358595.605987685137.1.gpush@pablo
State Rejected
Headers show

Commit Message

Jeremy Kerr April 24, 2014, 6:53 a.m. UTC
I'm currently getting a build failure:

src/lib/src/fwts_klog.c: In function 'fwts_json_str':
src/lib/src/fwts_klog.c:340:2: error: 'json_object_object_get' is deprecated (declared at /usr/include/json/json_object.h:271) [-Werror=deprecated-declarations]
_object_get_string(json_object_object_get(obj, key));

src/lib/src/fwts_klog.c: In function 'fwts_klog_check':
src/lib/src/fwts_klog.c:383:2: error: 'json_object_object_get' is deprecated (declared at /usr/include/json/json_object.h:271) [-Werror=deprecated-declarations]
  klog_table = json_object_object_get(klog_objs, table);
  ^
cc1: all warnings being treated as errors

Looks like json_object_object_get has been deprecated in favour of
json_object_object_get_ex

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

---
 src/acpi/syntaxcheck/syntaxcheck.c |   19 ++++++++++++-------
 src/lib/src/fwts_klog.c            |   26 ++++++++++++++------------
 src/utilities/kernelscan.c         |   20 +++++++++++---------
 3 files changed, 37 insertions(+), 28 deletions(-)

Comments

Colin Ian King April 24, 2014, 6:31 p.m. UTC | #1
On 24/04/14 07:53, Jeremy Kerr wrote:
> I'm currently getting a build failure:
> 
> src/lib/src/fwts_klog.c: In function 'fwts_json_str':
> src/lib/src/fwts_klog.c:340:2: error: 'json_object_object_get' is deprecated (declared at /usr/include/json/json_object.h:271) [-Werror=deprecated-declarations]
> _object_get_string(json_object_object_get(obj, key));
> 
> src/lib/src/fwts_klog.c: In function 'fwts_klog_check':
> src/lib/src/fwts_klog.c:383:2: error: 'json_object_object_get' is deprecated (declared at /usr/include/json/json_object.h:271) [-Werror=deprecated-declarations]
>   klog_table = json_object_object_get(klog_objs, table);
>   ^
> cc1: all warnings being treated as errors
> 
> Looks like json_object_object_get has been deprecated in favour of
> json_object_object_get_ex
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
> 
> ---
>  src/acpi/syntaxcheck/syntaxcheck.c |   19 ++++++++++++-------
>  src/lib/src/fwts_klog.c            |   26 ++++++++++++++------------
>  src/utilities/kernelscan.c         |   20 +++++++++++---------
>  3 files changed, 37 insertions(+), 28 deletions(-)
> 
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index 9234c33..504e5c6 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -331,6 +331,7 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>  	int ret = FWTS_ERROR;
>  	int n;
>  	int i;
> +	bool found;
>  	json_object *syntaxcheck_table;
>  	json_object *syntaxcheck_objs;
>  	char json_data_path[PATH_MAX];
> @@ -343,8 +344,9 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>  		return FWTS_ERROR;
>  	}
>  
> -        syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice");
> -        if (FWTS_JSON_ERROR(syntaxcheck_table)) {
> +        found = json_object_object_get_ex(syntaxcheck_objs, "erroradvice",
> +			&syntaxcheck_table);
> +        if (!found) {
>                  fwts_log_error(fw, "Cannot fetch syntaxcheck table from %s.", json_data_path);
>                  goto fail_put;
>          }
> @@ -354,7 +356,7 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>  	/* Now fetch json objects */
>  	for (i = 0; i < n; i++) {
>  		const char *advice, *id_str;
> -		json_object *obj;
> +		json_object *obj, *val;
>  		int j;
>  
>  		obj = json_object_array_get_idx(syntaxcheck_table, i);
> @@ -362,16 +364,19 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>  			fwts_log_error(fw, "Cannot fetch %d item from syntaxcheck table.", i);
>  			break;
>  		}
> -		advice = json_object_get_string(json_object_object_get(obj, "advice"));
> -		if (FWTS_JSON_ERROR(advice)) {
> +		found = json_object_object_get_ex(obj, "advice", &val);
> +		if (!found) {
>                  	fwts_log_error(fw, "Cannot fetch advice from item %d.", i);
>  			break;
>  		}
> -		id_str = json_object_get_string(json_object_object_get(obj, "id"));
> -		if (FWTS_JSON_ERROR(id_str)) {
> +		advice = json_object_get_string(val);
> +
> +		found = json_object_object_get_ex(obj, "id", &val);
> +		if (!found) {
>                  	fwts_log_error(fw, "Cannot fetch ID from item %d.", i);
>  			break;
>  		}
> +		id_str = json_object_get_string(val);
>  
>  		for (j = 0; syntaxcheck_error_map[j].id_str != NULL; j++) {
>  			if (strcmp(id_str, syntaxcheck_error_map[j].id_str) == 0) {
> diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
> index cfe7dcf..eafa8ae 100644
> --- a/src/lib/src/fwts_klog.c
> +++ b/src/lib/src/fwts_klog.c
> @@ -335,16 +335,17 @@ static const char *fwts_json_str(
>  	const char *key,
>  	bool log_error)
>  {
> -	const char *str;
> -
> -	str = json_object_get_string(json_object_object_get(obj, key));
> -	if (FWTS_JSON_ERROR(str)) {
> -		if (log_error)
> -			fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.",
> -				key, index, table);
> -		return NULL;
> -	}
> -	return str;
> +	json_object *val;
> +	bool found;
> +
> +	found = json_object_object_get_ex(obj, key, &val);
> +	if (found)
> +		return json_object_get_string(val);
> +	if (log_error)
> +		fwts_log_error(fw,
> +			"Cannot fetch %s val from item %d, table %s.",
> +			key, index, table);
> +	return NULL;
>  }
>  
>  static int fwts_klog_check(fwts_framework *fw,
> @@ -361,6 +362,7 @@ static int fwts_klog_check(fwts_framework *fw,
>  	json_object *klog_table;
>  	fwts_klog_pattern *patterns;
>  	char json_data_path[PATH_MAX];
> +	bool found;
>  
>  	snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, KLOG_DATA_JSON_FILE);
>  
> @@ -380,8 +382,8 @@ static int fwts_klog_check(fwts_framework *fw,
>  		return FWTS_ERROR;
>  	}
>  
> -	klog_table = json_object_object_get(klog_objs, table);
> -	if (FWTS_JSON_ERROR(klog_table)) {
> +	found = json_object_object_get_ex(klog_objs, table, &klog_table);
> +	if (!found) {
>  		fwts_log_error(fw, "Cannot fetch klog table object '%s' from %s.", table, json_data_path);
>  		goto fail_put;
>  	}
> diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c
> index 2aad38d..4ed3152 100644
> --- a/src/utilities/kernelscan.c
> +++ b/src/utilities/kernelscan.c
> @@ -238,6 +238,7 @@ static klog_pattern *klog_load(const char *table)
>  {
>  	int n;
>  	int i;
> +	bool found;
>  	json_object *klog_objs;
>  	json_object *klog_table;
>  	klog_pattern *patterns;
> @@ -248,8 +249,8 @@ static klog_pattern *klog_load(const char *table)
>  		exit(EXIT_FAILURE);
>  	}
>  
> -	klog_table = json_object_object_get(klog_objs, table);
> -	if (JSON_ERROR(klog_table)) {
> +	found = json_object_object_get_ex(klog_objs, table, &klog_table);
> +	if (!found) {
>  		fprintf(stderr, "Cannot fetch klog table object from %s.\n", table);
>  		exit(EXIT_FAILURE);
>  	}
> @@ -264,10 +265,9 @@ static klog_pattern *klog_load(const char *table)
>  
>  	/* Now fetch json objects and compile regex */
>  	for (i = 0; i < n; i++) {
> -		const char *error;
> -		char *str;
> +		const char *error, *str;
>  		int erroffset;
> -		json_object *obj;
> +		json_object *obj, *val;
>  
>  		obj = json_object_array_get_idx(klog_table, i);
>  		if (JSON_ERROR(obj)) {
> @@ -275,18 +275,20 @@ static klog_pattern *klog_load(const char *table)
>  			exit(EXIT_FAILURE);
>  		}
>  
> -		str = (char*)json_object_get_string(json_object_object_get(obj, "compare_mode"));
> -		if (JSON_ERROR(str)) {
> +		found = json_object_object_get_ex(obj, "compare_mode", &val);
> +		if (!found) {
>  			fprintf(stderr, "Cannot fetch compare_mode  object, item %d from table %s.\n", i, table);
>  			exit(EXIT_FAILURE);
>  		}
> +		str = json_object_get_string(val);
>  		patterns[i].cm = klog_compare_mode_str_to_val(str);
>  
> -		str = (char*)json_object_get_string(json_object_object_get(obj, "pattern"));
> -		if (JSON_ERROR(str)) {
> +		found = json_object_object_get_ex(obj, "pattern", &val);
> +		if (!found) {
>  			fprintf(stderr, "Cannot fetch pattern object, item %d from table %s.\n", i, table);
>  			exit(EXIT_FAILURE);
>  		}
> +		str = json_object_get_string(val);
>  		patterns[i].pattern = strdup(str);
>  		if (patterns[i].pattern == NULL) {
>  			fprintf(stderr, "Failed to strdup regex pattern %d from table %s.\n", i, table);
> 

I need to think about this as we're trying to support different json
libs across various releases and distros.  I'll try and get back to you
on this once I've done some more build tests etc.

Colin
diff mbox

Patch

diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
index 9234c33..504e5c6 100644
--- a/src/acpi/syntaxcheck/syntaxcheck.c
+++ b/src/acpi/syntaxcheck/syntaxcheck.c
@@ -331,6 +331,7 @@  static int syntaxcheck_load_advice(fwts_framework *fw)
 	int ret = FWTS_ERROR;
 	int n;
 	int i;
+	bool found;
 	json_object *syntaxcheck_table;
 	json_object *syntaxcheck_objs;
 	char json_data_path[PATH_MAX];
@@ -343,8 +344,9 @@  static int syntaxcheck_load_advice(fwts_framework *fw)
 		return FWTS_ERROR;
 	}
 
-        syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice");
-        if (FWTS_JSON_ERROR(syntaxcheck_table)) {
+        found = json_object_object_get_ex(syntaxcheck_objs, "erroradvice",
+			&syntaxcheck_table);
+        if (!found) {
                 fwts_log_error(fw, "Cannot fetch syntaxcheck table from %s.", json_data_path);
                 goto fail_put;
         }
@@ -354,7 +356,7 @@  static int syntaxcheck_load_advice(fwts_framework *fw)
 	/* Now fetch json objects */
 	for (i = 0; i < n; i++) {
 		const char *advice, *id_str;
-		json_object *obj;
+		json_object *obj, *val;
 		int j;
 
 		obj = json_object_array_get_idx(syntaxcheck_table, i);
@@ -362,16 +364,19 @@  static int syntaxcheck_load_advice(fwts_framework *fw)
 			fwts_log_error(fw, "Cannot fetch %d item from syntaxcheck table.", i);
 			break;
 		}
-		advice = json_object_get_string(json_object_object_get(obj, "advice"));
-		if (FWTS_JSON_ERROR(advice)) {
+		found = json_object_object_get_ex(obj, "advice", &val);
+		if (!found) {
                 	fwts_log_error(fw, "Cannot fetch advice from item %d.", i);
 			break;
 		}
-		id_str = json_object_get_string(json_object_object_get(obj, "id"));
-		if (FWTS_JSON_ERROR(id_str)) {
+		advice = json_object_get_string(val);
+
+		found = json_object_object_get_ex(obj, "id", &val);
+		if (!found) {
                 	fwts_log_error(fw, "Cannot fetch ID from item %d.", i);
 			break;
 		}
+		id_str = json_object_get_string(val);
 
 		for (j = 0; syntaxcheck_error_map[j].id_str != NULL; j++) {
 			if (strcmp(id_str, syntaxcheck_error_map[j].id_str) == 0) {
diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
index cfe7dcf..eafa8ae 100644
--- a/src/lib/src/fwts_klog.c
+++ b/src/lib/src/fwts_klog.c
@@ -335,16 +335,17 @@  static const char *fwts_json_str(
 	const char *key,
 	bool log_error)
 {
-	const char *str;
-
-	str = json_object_get_string(json_object_object_get(obj, key));
-	if (FWTS_JSON_ERROR(str)) {
-		if (log_error)
-			fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.",
-				key, index, table);
-		return NULL;
-	}
-	return str;
+	json_object *val;
+	bool found;
+
+	found = json_object_object_get_ex(obj, key, &val);
+	if (found)
+		return json_object_get_string(val);
+	if (log_error)
+		fwts_log_error(fw,
+			"Cannot fetch %s val from item %d, table %s.",
+			key, index, table);
+	return NULL;
 }
 
 static int fwts_klog_check(fwts_framework *fw,
@@ -361,6 +362,7 @@  static int fwts_klog_check(fwts_framework *fw,
 	json_object *klog_table;
 	fwts_klog_pattern *patterns;
 	char json_data_path[PATH_MAX];
+	bool found;
 
 	snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, KLOG_DATA_JSON_FILE);
 
@@ -380,8 +382,8 @@  static int fwts_klog_check(fwts_framework *fw,
 		return FWTS_ERROR;
 	}
 
-	klog_table = json_object_object_get(klog_objs, table);
-	if (FWTS_JSON_ERROR(klog_table)) {
+	found = json_object_object_get_ex(klog_objs, table, &klog_table);
+	if (!found) {
 		fwts_log_error(fw, "Cannot fetch klog table object '%s' from %s.", table, json_data_path);
 		goto fail_put;
 	}
diff --git a/src/utilities/kernelscan.c b/src/utilities/kernelscan.c
index 2aad38d..4ed3152 100644
--- a/src/utilities/kernelscan.c
+++ b/src/utilities/kernelscan.c
@@ -238,6 +238,7 @@  static klog_pattern *klog_load(const char *table)
 {
 	int n;
 	int i;
+	bool found;
 	json_object *klog_objs;
 	json_object *klog_table;
 	klog_pattern *patterns;
@@ -248,8 +249,8 @@  static klog_pattern *klog_load(const char *table)
 		exit(EXIT_FAILURE);
 	}
 
-	klog_table = json_object_object_get(klog_objs, table);
-	if (JSON_ERROR(klog_table)) {
+	found = json_object_object_get_ex(klog_objs, table, &klog_table);
+	if (!found) {
 		fprintf(stderr, "Cannot fetch klog table object from %s.\n", table);
 		exit(EXIT_FAILURE);
 	}
@@ -264,10 +265,9 @@  static klog_pattern *klog_load(const char *table)
 
 	/* Now fetch json objects and compile regex */
 	for (i = 0; i < n; i++) {
-		const char *error;
-		char *str;
+		const char *error, *str;
 		int erroffset;
-		json_object *obj;
+		json_object *obj, *val;
 
 		obj = json_object_array_get_idx(klog_table, i);
 		if (JSON_ERROR(obj)) {
@@ -275,18 +275,20 @@  static klog_pattern *klog_load(const char *table)
 			exit(EXIT_FAILURE);
 		}
 
-		str = (char*)json_object_get_string(json_object_object_get(obj, "compare_mode"));
-		if (JSON_ERROR(str)) {
+		found = json_object_object_get_ex(obj, "compare_mode", &val);
+		if (!found) {
 			fprintf(stderr, "Cannot fetch compare_mode  object, item %d from table %s.\n", i, table);
 			exit(EXIT_FAILURE);
 		}
+		str = json_object_get_string(val);
 		patterns[i].cm = klog_compare_mode_str_to_val(str);
 
-		str = (char*)json_object_get_string(json_object_object_get(obj, "pattern"));
-		if (JSON_ERROR(str)) {
+		found = json_object_object_get_ex(obj, "pattern", &val);
+		if (!found) {
 			fprintf(stderr, "Cannot fetch pattern object, item %d from table %s.\n", i, table);
 			exit(EXIT_FAILURE);
 		}
+		str = json_object_get_string(val);
 		patterns[i].pattern = strdup(str);
 		if (patterns[i].pattern == NULL) {
 			fprintf(stderr, "Failed to strdup regex pattern %d from table %s.\n", i, table);