Patchwork [2/3] lib: fwts_klog: 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-3-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/191435/
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/lib/src/fwts_klog.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/lib/src/fwts_klog.c |   14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
> index 7787599..22f3b10 100644
> --- a/src/lib/src/fwts_klog.c
> +++ b/src/lib/src/fwts_klog.c
> @@ -277,8 +277,6 @@ static fwts_compare_mode fwts_klog_compare_mode_str_to_val(const char *str)
>                 return FWTS_COMPARE_UNKNOWN;
>  }
>
> -#define JSON_ERROR     ((json_object*)-1)
> -
>  /*
>   *  fwts_json_str()
>   *     given a key, fetch the string value associated with this object
> @@ -288,7 +286,8 @@ static const char *fwts_json_str(fwts_framework *fw, const char *table, int inde
>  {
>         const char *str;
>
> -       if ((str = json_object_get_string(json_object_object_get(obj, key))) == NULL) {
> +       str = json_object_get_string(json_object_object_get(obj, key));
> +       if (FWTS_JSON_ERROR(str)) {
>                 fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.", key, index, table);
>                 return NULL;
>         }
> @@ -322,12 +321,14 @@ static int fwts_klog_check(fwts_framework *fw,
>         }
>         close(fd);
>
> -       if ((klog_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
> +       klog_objs = json_object_from_file(json_data_path);
> +       if (FWTS_JSON_ERROR(klog_objs)) {
>                 fwts_log_error(fw, "Cannot load klog data from %s.", json_data_path);
>                 return FWTS_ERROR;
>         }
>
> -       if ((klog_table = json_object_object_get(klog_objs, table)) == JSON_ERROR) {
> +       klog_table = json_object_object_get(klog_objs, table);
> +       if (FWTS_JSON_ERROR(klog_table)) {
>                 fwts_log_error(fw, "Cannot fetch klog table object '%s' from %s.", table, json_data_path);
>                 goto fail_put;
>         }
> @@ -347,7 +348,8 @@ static int fwts_klog_check(fwts_framework *fw,
>                 const char *str;
>                 json_object *obj;
>
> -               if ((obj = json_object_array_get_idx(klog_table, i)) == JSON_ERROR) {
> +               obj = json_object_array_get_idx(klog_table, i);
> +               if (FWTS_JSON_ERROR(obj)) {
>                         fwts_log_error(fw, "Cannot fetch %d item from table %s.", i, table);
>                         goto fail;
>                 }
> --
> 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/lib/src/fwts_klog.c |   14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
> index 7787599..22f3b10 100644
> --- a/src/lib/src/fwts_klog.c
> +++ b/src/lib/src/fwts_klog.c
> @@ -277,8 +277,6 @@ static fwts_compare_mode fwts_klog_compare_mode_str_to_val(const char *str)
>   		return FWTS_COMPARE_UNKNOWN;
>   }
>
> -#define JSON_ERROR	((json_object*)-1)
> -
>   /*
>    *  fwts_json_str()
>    *	given a key, fetch the string value associated with this object
> @@ -288,7 +286,8 @@ static const char *fwts_json_str(fwts_framework *fw, const char *table, int inde
>   {
>   	const char *str;
>
> -	if ((str = json_object_get_string(json_object_object_get(obj, key))) == NULL) {
> +	str = json_object_get_string(json_object_object_get(obj, key));
> +	if (FWTS_JSON_ERROR(str)) {
>   		fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.", key, index, table);
>   		return NULL;
>   	}
> @@ -322,12 +321,14 @@ static int fwts_klog_check(fwts_framework *fw,
>   	}
>   	close(fd);
>
> -	if ((klog_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
> +	klog_objs = json_object_from_file(json_data_path);
> +	if (FWTS_JSON_ERROR(klog_objs)) {
>   		fwts_log_error(fw, "Cannot load klog data from %s.", json_data_path);
>   		return FWTS_ERROR;
>   	}
>
> -	if ((klog_table = json_object_object_get(klog_objs, table)) == JSON_ERROR) {
> +	klog_table = json_object_object_get(klog_objs, table);
> +	if (FWTS_JSON_ERROR(klog_table)) {
>   		fwts_log_error(fw, "Cannot fetch klog table object '%s' from %s.", table, json_data_path);
>   		goto fail_put;
>   	}
> @@ -347,7 +348,8 @@ static int fwts_klog_check(fwts_framework *fw,
>   		const char *str;
>   		json_object *obj;
>
> -		if ((obj = json_object_array_get_idx(klog_table, i)) == JSON_ERROR) {
> +		obj = json_object_array_get_idx(klog_table, i);
> +		if (FWTS_JSON_ERROR(obj)) {
>   			fwts_log_error(fw, "Cannot fetch %d item from table %s.", i, table);
>   			goto fail;
>   		}
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
index 7787599..22f3b10 100644
--- a/src/lib/src/fwts_klog.c
+++ b/src/lib/src/fwts_klog.c
@@ -277,8 +277,6 @@  static fwts_compare_mode fwts_klog_compare_mode_str_to_val(const char *str)
 		return FWTS_COMPARE_UNKNOWN;
 }
 
-#define JSON_ERROR	((json_object*)-1)
-
 /*
  *  fwts_json_str()
  *	given a key, fetch the string value associated with this object
@@ -288,7 +286,8 @@  static const char *fwts_json_str(fwts_framework *fw, const char *table, int inde
 {
 	const char *str;
 
-	if ((str = json_object_get_string(json_object_object_get(obj, key))) == NULL) {
+	str = json_object_get_string(json_object_object_get(obj, key));
+	if (FWTS_JSON_ERROR(str)) {
 		fwts_log_error(fw, "Cannot fetch %s val from item %d, table %s.", key, index, table);
 		return NULL;
 	}
@@ -322,12 +321,14 @@  static int fwts_klog_check(fwts_framework *fw,
 	}
 	close(fd);
 
-	if ((klog_objs = json_object_from_file(json_data_path)) == JSON_ERROR) {
+	klog_objs = json_object_from_file(json_data_path);
+	if (FWTS_JSON_ERROR(klog_objs)) {
 		fwts_log_error(fw, "Cannot load klog data from %s.", json_data_path);
 		return FWTS_ERROR;
 	}
 
-	if ((klog_table = json_object_object_get(klog_objs, table)) == JSON_ERROR) {
+	klog_table = json_object_object_get(klog_objs, table);
+	if (FWTS_JSON_ERROR(klog_table)) {
 		fwts_log_error(fw, "Cannot fetch klog table object '%s' from %s.", table, json_data_path);
 		goto fail_put;
 	}
@@ -347,7 +348,8 @@  static int fwts_klog_check(fwts_framework *fw,
 		const char *str;
 		json_object *obj;
 
-		if ((obj = json_object_array_get_idx(klog_table, i)) == JSON_ERROR) {
+		obj = json_object_array_get_idx(klog_table, i);
+		if (FWTS_JSON_ERROR(obj)) {
 			fwts_log_error(fw, "Cannot fetch %d item from table %s.", i, table);
 			goto fail;
 		}