From patchwork Sun Oct 14 21:16:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 191434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id DA1D62C0097 for ; Mon, 15 Oct 2012 08:16:13 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TNVXg-0000mP-OR; Sun, 14 Oct 2012 21:16:12 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TNVXd-0000m0-ME for fwts-devel@lists.ubuntu.com; Sun, 14 Oct 2012 21:16:09 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TNVXd-0004t7-J0 for fwts-devel@lists.ubuntu.com; Sun, 14 Oct 2012 21:16:09 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/3] lib: fwts_json: wrapper for json error returns Date: Sun, 14 Oct 2012 22:16:06 +0100 Message-Id: <1350249368-10846-2-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1350249368-10846-1-git-send-email-colin.king@canonical.com> References: <1350249368-10846-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Older versions of json-c may return an error in an object as a ((json_object*)-1), where as newer versions return NULL. To cope with this API change we create a macro FWTS_JSON_ERROR that will return true if an object pointer is flagging an error condition as a NULL or a ((json_object*)-1) pointer. This way we can cope with errors no matter which version of json-c we use. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- src/lib/include/fwts.h | 1 + src/lib/include/fwts_json.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/lib/include/fwts_json.h diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h index a0f3c1b..a1e0fd2 100644 --- a/src/lib/include/fwts.h +++ b/src/lib/include/fwts.h @@ -75,5 +75,6 @@ #include "fwts_ac_adapter.h" #include "fwts_battery.h" #include "fwts_button.h" +#include "fwts_json.h" #endif diff --git a/src/lib/include/fwts_json.h b/src/lib/include/fwts_json.h new file mode 100644 index 0000000..a9be1af --- /dev/null +++ b/src/lib/include/fwts_json.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2012 Canonical + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef __FWTS_JSON_H__ +#define __FWTS_JSON_H__ + +#include + +#define __FWTS_JSON_ERR_PTR__ ((json_object*) -1) +/* + * Older versions of json-c may return an error in an + * object as a ((json_object*)-1), where as newer + * versions return NULL, so check for these. Sigh. + */ +#define FWTS_JSON_ERROR(ptr) \ + ( (ptr == NULL) || ((json_object*)ptr == __FWTS_JSON_ERR_PTR__) ) + +#endif