From patchwork Thu Apr 24 06:53:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 342109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 2EBF014011B for ; Thu, 24 Apr 2014 16:53:39 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1WdDXJ-0006at-Ip; Thu, 24 Apr 2014 06:53:33 +0000 Received: from ozlabs.org ([103.22.144.67]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1WdDXC-0006am-Ku for fwts-devel@lists.ubuntu.com; Thu, 24 Apr 2014 06:53:27 +0000 Received: by ozlabs.org (Postfix, from userid 1023) id 98E76140120; Thu, 24 Apr 2014 16:53:24 +1000 (EST) MIME-Version: 1.0 Subject: [PATCH] fwts: json_object_object_get is deprecated Message-Id: <1398322395.358595.605987685137.1.gpush@pablo> To: fwts-devel@lists.ubuntu.com From: Jeremy Kerr Date: Thu, 24 Apr 2014 14:53:15 +0800 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com 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 --- 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);