[PATCH 1/3] lib: fwts_json: wrapper for json error returns
Colin King
colin.king at canonical.com
Sun Oct 14 21:16:06 UTC 2012
From: Colin Ian King <colin.king at canonical.com>
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 <colin.king at canonical.com>
---
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 <json/json.h>
+
+#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
--
1.7.10.4
More information about the fwts-devel
mailing list