+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
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)
#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",
/* 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) {
}
}
-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);
}
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;
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;
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) {
#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 */
* @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 */
* @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
* @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
*
* @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
* @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
*
* @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
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;
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;
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)
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);
}
-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;
}
-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;
}
-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;
}
-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;
/**
* 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
/**
* The value.
*/
- void *v;
+ const void *v;
/**
* The next entry
*/
/**
* Name of the hash table.
*/
- char *name;
+ const char *name;
/**
* The first entry.
/**
* 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);
/**
* 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);
* @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);
* @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);
* @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);
/**
* @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
* @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);
/**
* @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, ...);
}
-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) {
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, ...);