]> granicus.if.org Git - json-c/commitdiff
Move the json_min() and json_max() macros to json_util.h and mark everything else...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sun, 4 May 2014 02:29:10 +0000 (22:29 -0400)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 5 May 2014 02:33:26 +0000 (22:33 -0400)
Eliminate all uses of bits.h within the json-c code.

arraylist.c
bits.h
json.h
json_tokener.c
json_util.c
json_util.h
printbuf.c

index 81b6fa2b64a4f4d0fe7b51745ba87684d9ecbec6..1d899fa907e61579445d9b129398d35ce6aa384a 100644 (file)
@@ -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 6feee9e916ef640c627bef2e6e7cdaa052043de3..d14a1db0d7dc4b8144e73febd432c361f58973e2 100644 (file)
--- 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.
 #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 4339b20e9060fbcc28c3ed18b452cb402ef244de..e198f5da0692c51be9ba5e2321a6c4d539adbe4d 100644 (file)
--- 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"
index 9a7629323fec80b9c3eb51b13f5b60227c6e43cc..60e81f279d3e666c1b6b9a804442af90eed27a35 100644 (file)
@@ -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];
 
index 531f9afb3a03fb1499ba284a25cac75dcb7df2d7..2a5621b00019cf8503e9392049f04d27fae52b54 100644 (file)
@@ -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"
index 1005e58c5b0d89b3c65cfd3e2edecf3596e4e387..387dbc47d48c30893bc0411d159f1818d2906b3a 100644 (file)
 
 #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
index 9d565220007e6a887925772fe0fe20334e604cb4..fe952b4522d91ce44c3f7c4b67b1b79c8a64f98a 100644 (file)
@@ -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",