]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Add const correctness to public interfaces
authorMichael Clark <michael@metaparadigm.com>
Tue, 6 Jan 2009 22:56:57 +0000 (22:56 +0000)
committerMichael Clark <michael@metaparadigm.com>
Tue, 6 Jan 2009 22:56:57 +0000 (22:56 +0000)
    Gerard Krol, g dot c dot krol at student dot tudelft dot nl

Update version number to 0.9

git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@27 327403b1-1117-474d-bef2-5cb71233fd97

ChangeLog
configure.in
json_object.c
json_object.h
json_util.c
linkhash.c
linkhash.h
printbuf.c
printbuf.h

index 784663a733d1c3485fb9d7675325ddf88cb04847..c91e2c7c993b23d1643daf1ff64b0116d757b47f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+0.9
+  * Add const correctness to public interfaces
+    Gerard Krol, g dot c dot krol at student dot tudelft dot nl
+
 0.8
   * Add va_end for every va_start
     Dotan Barak, dotanba at gmail dot com
index 7bcf3dc3f68cda467c8e7d81229791fd9d59663f..8f0fff386fb52454b336117878503a9d4e7eb572 100644 (file)
@@ -1,7 +1,7 @@
 AC_PREREQ(2.52)
 
 # Process this file with autoconf to produce a configure script.
-AC_INIT([json-c], 0.8, [michael@metaparadigm.com])
+AC_INIT([json-c], 0.9, [michael@metaparadigm.com])
 
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 
index c702c26739c19c78d65cb111698d23427fc50c5c..f0ce5f71cecced0a86e0909b8e2841791dc9032c 100644 (file)
 
 #define REFCOUNT_DEBUG 1
 
-char *json_number_chars = "0123456789.+-eE";
-char *json_hex_chars = "0123456789abcdef";
+const char *json_number_chars = "0123456789.+-eE";
+const char *json_hex_chars = "0123456789abcdef";
 
 #ifdef REFCOUNT_DEBUG
-static char* json_type_name[] = {
+static const char* json_type_name[] = {
   "null",
   "boolean",
   "double",
@@ -188,7 +188,7 @@ enum json_type json_object_get_type(struct json_object *this)
 
 /* json_object_to_json_string */
 
-char* json_object_to_json_string(struct json_object *this)
+const char* json_object_to_json_string(struct json_object *this)
 {
   if(!this) return "null";
   if(!this->_pb) {
@@ -259,19 +259,19 @@ struct lh_table* json_object_get_object(struct json_object *this)
   }
 }
 
-void json_object_object_add(struct json_object* this, char *key,
+void json_object_object_add(struct json_object* this, const char *key,
                            struct json_object *val)
 {
   lh_table_delete(this->o.c_object, key);
   lh_table_insert(this->o.c_object, strdup(key), val);
 }
 
-struct json_object* json_object_object_get(struct json_object* this, char *key)
+struct json_object* json_object_object_get(struct json_object* this, const char *key)
 {
   return (struct json_object*) lh_table_lookup(this->o.c_object, key);
 }
 
-void json_object_object_del(struct json_object* this, char *key)
+void json_object_object_del(struct json_object* this, const char *key)
 {
   lh_table_delete(this->o.c_object, key);
 }
@@ -404,7 +404,7 @@ static void json_object_string_delete(struct json_object* this)
   json_object_generic_delete(this);
 }
 
-struct json_object* json_object_new_string(char *s)
+struct json_object* json_object_new_string(const char *s)
 {
   struct json_object *this = json_object_new(json_type_string);
   if(!this) return NULL;
@@ -414,7 +414,7 @@ struct json_object* json_object_new_string(char *s)
   return this;
 }
 
-struct json_object* json_object_new_string_len(char *s, int len)
+struct json_object* json_object_new_string_len(const char *s, int len)
 {
   struct json_object *this = json_object_new(json_type_string);
   if(!this) return NULL;
@@ -424,7 +424,7 @@ struct json_object* json_object_new_string_len(char *s, int len)
   return this;
 }
 
-char* json_object_get_string(struct json_object *this)
+const char* json_object_get_string(struct json_object *this)
 {
   if(!this) return NULL;
   switch(this->o_type) {
index d4fc8875ad1c3ff3c41dd0b25b7ed005003ed9a9..bbfea85e2d767cd933629184bdd0a60e63e9dbf6 100644 (file)
@@ -20,8 +20,8 @@
 #undef TRUE
 #define TRUE ((boolean)1)
 
-extern char *json_number_chars;
-extern char *json_hex_chars;
+extern const char *json_number_chars;
+extern const char *json_hex_chars;
 
 /* forward structure definitions */
 
@@ -90,7 +90,7 @@ extern enum json_type json_object_get_type(struct json_object *obj);
  * @param obj the json_object instance
  * @returns a string in JSON format
  */
-extern char* json_object_to_json_string(struct json_object *obj);
+extern const char* json_object_to_json_string(struct json_object *obj);
 
 
 /* object type methods */
@@ -116,7 +116,7 @@ extern struct lh_table* json_object_get_object(struct json_object *obj);
  * @param key the object field name (a private copy will be duplicated)
  * @param val a json_object or NULL member to associate with the given field
  */
-extern void json_object_object_add(struct json_object* obj, char *key,
+extern void json_object_object_add(struct json_object* obj, const char *key,
                                   struct json_object *val);
 
 /** Get the json_object associate with a given object field
@@ -125,7 +125,7 @@ extern void json_object_object_add(struct json_object* obj, char *key,
  * @returns the json_object associated with the given field name
  */
 extern struct json_object* json_object_object_get(struct json_object* obj,
-                                                 char *key);
+                                                 const char *key);
 
 /** Delete the given json_object field
  *
@@ -134,7 +134,7 @@ extern struct json_object* json_object_object_get(struct json_object* obj,
  * @param obj the json_object instance
  * @param key the object field name
  */
-extern void json_object_object_del(struct json_object* obj, char *key);
+extern void json_object_object_del(struct json_object* obj, const char *key);
 
 /** Iterate through all keys and values of an object
  * @param obj the json_object instance
@@ -290,9 +290,9 @@ extern double json_object_get_double(struct json_object *obj);
  * @param s the string
  * @returns a json_object of type json_type_string
  */
-extern struct json_object* json_object_new_string(char *s);
+extern struct json_object* json_object_new_string(const char *s);
 
-extern struct json_object* json_object_new_string_len(char *s, int len);
+extern struct json_object* json_object_new_string_len(const char *s, int len);
 
 /** Get the string value of a json_object
  *
@@ -305,6 +305,6 @@ extern struct json_object* json_object_new_string_len(char *s, int len);
  * @param obj the json_object instance
  * @returns a string
  */
-extern char* json_object_get_string(struct json_object *obj);
+extern const char* json_object_get_string(struct json_object *obj);
 
 #endif
index 1a65596c846135bea45f24152e20faf775c8c291..0262ca24229e1d06ecea4a2d5512d1a022d622fa 100644 (file)
@@ -85,7 +85,7 @@ struct json_object* json_object_from_file(char *filename)
 
 int json_object_to_file(char *filename, struct json_object *obj)
 {
-  char *json_str;
+  const char *json_str;
   int fd, ret;
   unsigned int wpos, wsize;
 
index fc72bf667e90782092a849adf4f5cae9d25848b5..5d4e46f22b05a9f10c46450fae59ace825544d93 100644 (file)
@@ -29,18 +29,18 @@ void lh_abort(const char *msg, ...)
        exit(1);
 }
 
-unsigned long lh_ptr_hash(void *k)
+unsigned long lh_ptr_hash(const void *k)
 {
        /* CAW: refactored to be 64bit nice */
        return (unsigned long)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX);
 }
 
-int lh_ptr_equal(void *k1, void *k2)
+int lh_ptr_equal(const void *k1, const void *k2)
 {
        return (k1 == k2);
 }
 
-unsigned long lh_char_hash(void *k)
+unsigned long lh_char_hash(const void *k)
 {
        unsigned int h = 0;
        const char* data = k;
@@ -50,12 +50,12 @@ unsigned long lh_char_hash(void *k)
        return h;
 }
 
-int lh_char_equal(void *k1, void *k2)
+int lh_char_equal(const void *k1, const void *k2)
 {
-       return (strcmp((char*)k1, (char*)k2) == 0);
+       return (strcmp((const char*)k1, (const char*)k2) == 0);
 }
 
-struct lh_table* lh_table_new(int size, char *name,
+struct lh_table* lh_table_new(int size, const char *name,
                              lh_entry_free_fn *free_fn,
                              lh_hash_fn *hash_fn,
                              lh_equal_fn *equal_fn)
@@ -77,13 +77,13 @@ struct lh_table* lh_table_new(int size, char *name,
        return t;
 }
 
-struct lh_table* lh_kchar_table_new(int size, char *name,
+struct lh_table* lh_kchar_table_new(int size, const char *name,
                                    lh_entry_free_fn *free_fn)
 {
        return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal);
 }
 
-struct lh_table* lh_kptr_table_new(int size, char *name,
+struct lh_table* lh_kptr_table_new(int size, const char *name,
                                   lh_entry_free_fn *free_fn)
 {
        return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal);
@@ -122,7 +122,7 @@ void lh_table_free(struct lh_table *t)
 }
 
 
-int lh_table_insert(struct lh_table *t, void *k, void *v)
+int lh_table_insert(struct lh_table *t, void *k, const void *v)
 {
        unsigned long h, n;
 
@@ -156,7 +156,7 @@ int lh_table_insert(struct lh_table *t, void *k, void *v)
 }
 
 
-struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k)
+struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k)
 {
        unsigned long h = t->hash_fn(k);
        unsigned long n = h % t->size;
@@ -172,7 +172,7 @@ struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k)
 }
 
 
-void* lh_table_lookup(struct lh_table *t, void *k)
+const void* lh_table_lookup(struct lh_table *t, const void *k)
 {
        struct lh_entry *e = lh_table_lookup_entry(t, k);
        if(e) return e->v;
@@ -209,7 +209,7 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
 }
 
 
-int lh_table_delete(struct lh_table *t, void *k)
+int lh_table_delete(struct lh_table *t, const void *k)
 {
        struct lh_entry *e = lh_table_lookup_entry(t, k);
        if(!e) return -1;
index 785ddf43adcd01a7305278128f3d3c9803c71354..9b5ef9d28a047be4d533ef25a8b3036cad45e8c6 100644 (file)
@@ -36,11 +36,11 @@ typedef void (lh_entry_free_fn) (struct lh_entry *e);
 /**
  * callback function prototypes
  */
-typedef unsigned long (lh_hash_fn) (void *k);
+typedef unsigned long (lh_hash_fn) (const void *k);
 /**
  * callback function prototypes
  */
-typedef int (lh_equal_fn) (void *k1, void *k2);
+typedef int (lh_equal_fn) (const void *k1, const void *k2);
 
 /**
  * An entry in the hash table
@@ -53,7 +53,7 @@ struct lh_entry {
        /**
         * The value.
         */
-       void *v;
+       const void *v;
        /**
         * The next entry
         */
@@ -106,7 +106,7 @@ struct lh_table {
        /**
         * Name of the hash table.
         */
-       char *name;
+       const char *name;
 
        /**
         * The first entry.
@@ -132,11 +132,11 @@ struct lh_table {
 /**
  * Pre-defined hash and equality functions
  */
-extern unsigned long lh_ptr_hash(void *k);
-extern int lh_ptr_equal(void *k1, void *k2);
+extern unsigned long lh_ptr_hash(const void *k);
+extern int lh_ptr_equal(const void *k1, const void *k2);
 
-extern unsigned long lh_char_hash(void *k);
-extern int lh_char_equal(void *k1, void *k2);
+extern unsigned long lh_char_hash(const void *k);
+extern int lh_char_equal(const void *k1, const void *k2);
 
 
 /**
@@ -170,7 +170,7 @@ for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
  * and C strings respectively.
  * @return a pointer onto the linkhash table.
  */
-extern struct lh_table* lh_table_new(int size, char *name,
+extern struct lh_table* lh_table_new(int size, const char *name,
                                     lh_entry_free_fn *free_fn,
                                     lh_hash_fn *hash_fn,
                                     lh_equal_fn *equal_fn);
@@ -183,7 +183,7 @@ extern struct lh_table* lh_table_new(int size, char *name,
  * @param free_fn callback function used to free memory for entries.
  * @return a pointer onto the linkhash table.
  */
-extern struct lh_table* lh_kchar_table_new(int size, char *name,
+extern struct lh_table* lh_kchar_table_new(int size, const char *name,
                                           lh_entry_free_fn *free_fn);
 
 
@@ -195,7 +195,7 @@ extern struct lh_table* lh_kchar_table_new(int size, char *name,
  * @param free_fn callback function used to free memory for entries.
  * @return a pointer onto the linkhash table.
  */
-extern struct lh_table* lh_kptr_table_new(int size, char *name,
+extern struct lh_table* lh_kptr_table_new(int size, const char *name,
                                          lh_entry_free_fn *free_fn);
 
 
@@ -214,7 +214,7 @@ extern void lh_table_free(struct lh_table *t);
  * @param k a pointer to the key to insert.
  * @param v a pointer to the value to insert.
  */
-extern int lh_table_insert(struct lh_table *t, void *k, void *v);
+extern int lh_table_insert(struct lh_table *t, void *k, const void *v);
 
 
 /**
@@ -223,7 +223,7 @@ extern int lh_table_insert(struct lh_table *t, void *k, void *v);
  * @param k a pointer to the key to lookup
  * @return a pointer to the record structure of the value or NULL if it does not exist.
  */
-extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k);
+extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k);
 
 /**
  * Lookup a record into the table
@@ -231,7 +231,7 @@ extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k);
  * @param k a pointer to the key to lookup
  * @return a pointer to the found value or NULL if it does not exist.
  */
-extern void* lh_table_lookup(struct lh_table *t, void *k);
+extern const void* lh_table_lookup(struct lh_table *t, const void *k);
 
 
 /**
@@ -255,7 +255,7 @@ extern int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e);
  * @return 0 if the item was deleted.
  * @return -1 if it was not found.
  */
-extern int lh_table_delete(struct lh_table *t, void *k);
+extern int lh_table_delete(struct lh_table *t, const void *k);
 
 
 void lh_abort(const char *msg, ...);
index cdda47eda942222436a4708f01d9886fb8a50f9a..6522a690e750a2a30bb932f94e64e62e6ff4be58 100644 (file)
@@ -40,7 +40,7 @@ struct printbuf* printbuf_new()
 }
 
 
-int printbuf_memappend(struct printbuf *p, char *buf, int size)
+int printbuf_memappend(struct printbuf *p, const char *buf, int size)
 {
   char *t;
   if(p->size - p->bpos <= size) {
index 4591a58799c7ce9e93231f362eeb43c1c57b39bd..95f7a248fb4485a8cfc46ae2a48982c5c7f8a44a 100644 (file)
@@ -24,7 +24,7 @@ extern struct printbuf*
 printbuf_new(void);
 
 extern int
-printbuf_memappend(struct printbuf *p, char *buf, int size);
+printbuf_memappend(struct printbuf *p, const char *buf, int size);
 
 extern int
 sprintbuf(struct printbuf *p, const char *msg, ...);