aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2014-05-03 22:29:10 -0400
committerEric Haszlakiewicz <erh+git@nimenees.com>2014-05-04 22:33:26 -0400
commitd4e81f9ec8273914739808737fa0a27a3f0589fb (patch)
tree43c0763e296e9c763457fad9fd5b338ea36cfb35
parent1da0599e0ebd60a5038c0a43345fdb249a5a3ea3 (diff)
downloadandroid_external_json-c-d4e81f9ec8273914739808737fa0a27a3f0589fb.tar.gz
android_external_json-c-d4e81f9ec8273914739808737fa0a27a3f0589fb.tar.bz2
android_external_json-c-d4e81f9ec8273914739808737fa0a27a3f0589fb.zip
Move the json_min() and json_max() macros to json_util.h and mark everything else in bits.h deprecated.
Eliminate all uses of bits.h within the json-c code.
-rw-r--r--arraylist.c5
-rw-r--r--bits.h25
-rw-r--r--json.h1
-rw-r--r--json_tokener.c5
-rw-r--r--json_util.c1
-rw-r--r--json_util.h9
-rw-r--r--printbuf.c5
7 files changed, 34 insertions, 17 deletions
diff --git a/arraylist.c b/arraylist.c
index 81b6fa2..1d899fa 100644
--- a/arraylist.c
+++ b/arraylist.c
@@ -20,7 +20,6 @@
# include <strings.h>
#endif /* HAVE_STRINGS_H */
-#include "bits.h"
#include "arraylist.h"
struct array_list*
@@ -63,7 +62,9 @@ static int array_list_expand_internal(struct array_list *arr, int max)
int new_size;
if(max < arr->size) return 0;
- new_size = json_max(arr->size << 1, max);
+ new_size = arr->size << 1;
+ if (new_size < max)
+ new_size = max;
if(!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1;
arr->array = (void**)t;
(void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
diff --git a/bits.h b/bits.h
index 6feee9e..d14a1db 100644
--- a/bits.h
+++ b/bits.h
@@ -1,4 +1,7 @@
-/*
+/**
+ * @file
+ * @deprecated Use json_util.h instead.
+ *
* $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $
*
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
@@ -12,17 +15,21 @@
#ifndef _bits_h_
#define _bits_h_
-#ifndef json_min
-#define json_min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-#ifndef json_max
-#define json_max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
+/**
+ * @deprecated
+ */
#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
+/**
+ * @deprecated
+ */
#define error_ptr(error) ((void*)error)
+/**
+ * @deprecated
+ */
#define error_description(error) (json_tokener_get_error(error))
+/**
+ * @deprecated
+ */
#define is_error(ptr) (ptr == NULL)
#endif
diff --git a/json.h b/json.h
index 4339b20..e198f5d 100644
--- a/json.h
+++ b/json.h
@@ -17,7 +17,6 @@
extern "C" {
#endif
-#include "bits.h"
#include "debug.h"
#include "linkhash.h"
#include "arraylist.h"
diff --git a/json_tokener.c b/json_tokener.c
index 9a76293..60e81f2 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -23,7 +23,6 @@
#include <string.h>
#include <limits.h>
-#include "bits.h"
#include "debug.h"
#include "printbuf.h"
#include "arraylist.h"
@@ -36,6 +35,8 @@
#include <locale.h>
#endif /* HAVE_LOCALE_H */
+#define jt_hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
+
#if !HAVE_STRDUP && defined(_MSC_VER)
/* MSC has the version as _strdup */
# define strdup _strdup
@@ -536,7 +537,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
/* Handle a 4-byte sequence, or two sequences if a surrogate pair */
while(1) {
if(strchr(json_hex_chars, c)) {
- tok->ucs_char += ((unsigned int)hexdigit(c) << ((3-tok->st_pos++)*4));
+ tok->ucs_char += ((unsigned int)jt_hexdigit(c) << ((3-tok->st_pos++)*4));
if(tok->st_pos == 4) {
unsigned char unescaped_utf[4];
diff --git a/json_util.c b/json_util.c
index 531f9af..2a5621b 100644
--- a/json_util.c
+++ b/json_util.c
@@ -53,7 +53,6 @@
# error You do not have snprintf on your system.
#endif /* HAVE_SNPRINTF */
-#include "bits.h"
#include "debug.h"
#include "printbuf.h"
#include "json_inttypes.h"
diff --git a/json_util.h b/json_util.h
index 1005e58..387dbc4 100644
--- a/json_util.h
+++ b/json_util.h
@@ -14,6 +14,15 @@
#include "json_object.h"
+#ifndef json_min
+#define json_min(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef json_max
+#define json_max(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/printbuf.c b/printbuf.c
index 9d56522..fe952b4 100644
--- a/printbuf.c
+++ b/printbuf.c
@@ -25,7 +25,6 @@
# error Not enough var arg support!
#endif /* HAVE_STDARG_H */
-#include "bits.h"
#include "debug.h"
#include "printbuf.h"
@@ -63,7 +62,9 @@ static int printbuf_extend(struct printbuf *p, int min_size)
if (p->size >= min_size)
return 0;
- new_size = json_max(p->size * 2, min_size + 8);
+ new_size = p->size * 2;
+ if (new_size < min_size + 8)
+ new_size = min_size + 8;
#ifdef PRINTBUF_DEBUG
MC_DEBUG("printbuf_memappend: realloc "
"bpos=%d min_size=%d old_size=%d new_size=%d\n",