Message ID | 1350249368-10846-2-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On Mon, Oct 15, 2012 at 5:16 AM, Colin King <colin.king@canonical.com> wrote: > From: Colin Ian King <colin.king@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@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 > Acked-by: Keng-Yu Lin <kengyu@canonical.com>
On 10/15/2012 05:16 AM, Colin King wrote: > From: Colin Ian King <colin.king@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@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 > Acked-by: Ivan Hu <ivan.hu@canonical.com>
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