Patchwork [3/3] acpi: syntaxcheck: use FWTS_JSON_ERROR macro for error checking

login
register
mail settings
Submitter Colin King
Date Oct. 14, 2012, 9:16 p.m.
Message ID <1350249368-10846-4-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/191436/
State Accepted
Headers show

Comments

Colin King - Oct. 14, 2012, 9:16 p.m.
From: Colin Ian King <colin.king@canonical.com>

Use the new FWTS_JSON_ERROR macro to check for error
conditions to cope with the API change on json-c.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/syntaxcheck/syntaxcheck.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
Keng-Yu Lin - Oct. 17, 2012, 8:15 a.m.
On Mon, Oct 15, 2012 at 5:16 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Use the new FWTS_JSON_ERROR macro to check for error
> conditions to cope with the API change on json-c.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/syntaxcheck/syntaxcheck.c |   14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index 4f5d43b..5ae7411 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -29,8 +29,6 @@
>
>  #include <json/json.h>
>
> -#define JSON_ERROR      ((json_object*)-1)
> -
>  typedef struct {
>         uint16_t        error;
>         char            *advice;
> @@ -137,12 +135,14 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>
>         snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, SYNTAXCHECK_JSON_FILE);
>
> -       if ((syntaxcheck_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
> +       syntaxcheck_objs = json_object_from_file(json_data_path);
> +       if (FWTS_JSON_ERROR(syntaxcheck_objs)) {
>                 fwts_log_error(fw, "Cannot load objects table from %s.", json_data_path);
>                 return FWTS_ERROR;
>         }
>
> -        if ((syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice")) == JSON_ERROR) {
> +        syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice");
> +        if (FWTS_JSON_ERROR(syntaxcheck_table)) {
>                  fwts_log_error(fw, "Cannot fetch syntaxcheck table from %s.", json_data_path);
>                  goto fail_put;
>          }
> @@ -160,13 +160,15 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>                 const char *str;
>                 json_object *obj;
>
> -               if ((obj = json_object_array_get_idx(syntaxcheck_table, i)) == JSON_ERROR) {
> +               obj = json_object_array_get_idx(syntaxcheck_table, i);
> +               if (FWTS_JSON_ERROR(obj)) {
>                         fwts_log_error(fw, "Cannot fetch %d item from syntaxcheck table.", i);
>                         free(adviceinfo);
>                         adviceinfo = NULL;
>                         break;
>                 }
> -               if ((str = json_object_get_string(json_object_object_get(obj, "advice"))) == NULL) {
> +               str = json_object_get_string(json_object_object_get(obj, "advice"));
> +               if (FWTS_JSON_ERROR(str)) {
>                         fwts_log_error(fw, "Cannot fetch advice from item %d.", i);
>                         free(adviceinfo);
>                         adviceinfo = NULL;
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Ivan Hu - Oct. 22, 2012, 8:48 a.m.
On 10/15/2012 05:16 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Use the new FWTS_JSON_ERROR macro to check for error
> conditions to cope with the API change on json-c.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/syntaxcheck/syntaxcheck.c |   14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
> index 4f5d43b..5ae7411 100644
> --- a/src/acpi/syntaxcheck/syntaxcheck.c
> +++ b/src/acpi/syntaxcheck/syntaxcheck.c
> @@ -29,8 +29,6 @@
>
>   #include <json/json.h>
>
> -#define JSON_ERROR      ((json_object*)-1)
> -
>   typedef struct {
>   	uint16_t	error;
>   	char 		*advice;
> @@ -137,12 +135,14 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>
>   	snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, SYNTAXCHECK_JSON_FILE);
>
> -	if ((syntaxcheck_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
> +	syntaxcheck_objs = json_object_from_file(json_data_path);
> +	if (FWTS_JSON_ERROR(syntaxcheck_objs)) {
>   		fwts_log_error(fw, "Cannot load objects table from %s.", json_data_path);
>   		return FWTS_ERROR;
>   	}
>
> -        if ((syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice")) == JSON_ERROR) {
> +        syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice");
> +        if (FWTS_JSON_ERROR(syntaxcheck_table)) {
>                   fwts_log_error(fw, "Cannot fetch syntaxcheck table from %s.", json_data_path);
>                   goto fail_put;
>           }
> @@ -160,13 +160,15 @@ static int syntaxcheck_load_advice(fwts_framework *fw)
>   		const char *str;
>   		json_object *obj;
>
> -		if ((obj = json_object_array_get_idx(syntaxcheck_table, i)) == JSON_ERROR) {
> +		obj = json_object_array_get_idx(syntaxcheck_table, i);
> +		if (FWTS_JSON_ERROR(obj)) {
>   			fwts_log_error(fw, "Cannot fetch %d item from syntaxcheck table.", i);
>   			free(adviceinfo);
>   			adviceinfo = NULL;
>   			break;
>   		}
> -		if ((str = json_object_get_string(json_object_object_get(obj, "advice"))) == NULL) {
> +		str = json_object_get_string(json_object_object_get(obj, "advice"));
> +		if (FWTS_JSON_ERROR(str)) {
>                   	fwts_log_error(fw, "Cannot fetch advice from item %d.", i);
>   			free(adviceinfo);
>   			adviceinfo = NULL;
>
Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/acpi/syntaxcheck/syntaxcheck.c b/src/acpi/syntaxcheck/syntaxcheck.c
index 4f5d43b..5ae7411 100644
--- a/src/acpi/syntaxcheck/syntaxcheck.c
+++ b/src/acpi/syntaxcheck/syntaxcheck.c
@@ -29,8 +29,6 @@ 
 
 #include <json/json.h>
 
-#define JSON_ERROR      ((json_object*)-1)
-
 typedef struct {
 	uint16_t	error;
 	char 		*advice;
@@ -137,12 +135,14 @@  static int syntaxcheck_load_advice(fwts_framework *fw)
 
 	snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, SYNTAXCHECK_JSON_FILE);
 
-	if ((syntaxcheck_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
+	syntaxcheck_objs = json_object_from_file(json_data_path);
+	if (FWTS_JSON_ERROR(syntaxcheck_objs)) {
 		fwts_log_error(fw, "Cannot load objects table from %s.", json_data_path);
 		return FWTS_ERROR;
 	}
 
-        if ((syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice")) == JSON_ERROR) {
+        syntaxcheck_table = json_object_object_get(syntaxcheck_objs, "erroradvice");
+        if (FWTS_JSON_ERROR(syntaxcheck_table)) {
                 fwts_log_error(fw, "Cannot fetch syntaxcheck table from %s.", json_data_path);
                 goto fail_put;
         }
@@ -160,13 +160,15 @@  static int syntaxcheck_load_advice(fwts_framework *fw)
 		const char *str;
 		json_object *obj;
 
-		if ((obj = json_object_array_get_idx(syntaxcheck_table, i)) == JSON_ERROR) {
+		obj = json_object_array_get_idx(syntaxcheck_table, i);
+		if (FWTS_JSON_ERROR(obj)) {
 			fwts_log_error(fw, "Cannot fetch %d item from syntaxcheck table.", i);
 			free(adviceinfo);
 			adviceinfo = NULL;
 			break;
 		}
-		if ((str = json_object_get_string(json_object_object_get(obj, "advice"))) == NULL) {
+		str = json_object_get_string(json_object_object_get(obj, "advice"));
+		if (FWTS_JSON_ERROR(str)) {
                 	fwts_log_error(fw, "Cannot fetch advice from item %d.", i);
 			free(adviceinfo);
 			adviceinfo = NULL;