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-5cb71233fd97tags/json-c-0.10-20120530
@@ -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 | 0.8 | ||||
* Add va_end for every va_start | * Add va_end for every va_start | ||||
Dotan Barak, dotanba at gmail dot com | Dotan Barak, dotanba at gmail dot com | ||||
@@ -1,7 +1,7 @@ | |||||
AC_PREREQ(2.52) | AC_PREREQ(2.52) | ||||
# Process this file with autoconf to produce a configure script. | # 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) | AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) | ||||
@@ -30,11 +30,11 @@ | |||||
#define REFCOUNT_DEBUG 1 | #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 | #ifdef REFCOUNT_DEBUG | ||||
static char* json_type_name[] = { | |||||
static const char* json_type_name[] = { | |||||
"null", | "null", | ||||
"boolean", | "boolean", | ||||
"double", | "double", | ||||
@@ -188,7 +188,7 @@ enum json_type json_object_get_type(struct json_object *this) | |||||
/* json_object_to_json_string */ | /* 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) return "null"; | ||||
if(!this->_pb) { | 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) | struct json_object *val) | ||||
{ | { | ||||
lh_table_delete(this->o.c_object, key); | lh_table_delete(this->o.c_object, key); | ||||
lh_table_insert(this->o.c_object, strdup(key), val); | 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); | 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); | 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); | 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); | struct json_object *this = json_object_new(json_type_string); | ||||
if(!this) return NULL; | if(!this) return NULL; | ||||
@@ -414,7 +414,7 @@ struct json_object* json_object_new_string(char *s) | |||||
return this; | 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); | struct json_object *this = json_object_new(json_type_string); | ||||
if(!this) return NULL; | if(!this) return NULL; | ||||
@@ -424,7 +424,7 @@ struct json_object* json_object_new_string_len(char *s, int len) | |||||
return this; | 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; | if(!this) return NULL; | ||||
switch(this->o_type) { | switch(this->o_type) { | ||||
@@ -20,8 +20,8 @@ | |||||
#undef TRUE | #undef TRUE | ||||
#define TRUE ((boolean)1) | #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 */ | /* 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 | * @param obj the json_object instance | ||||
* @returns a string in JSON format | * @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 */ | /* 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 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 | * @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); | struct json_object *val); | ||||
/** Get the json_object associate with a given object field | /** 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 | * @returns the json_object associated with the given field name | ||||
*/ | */ | ||||
extern struct json_object* json_object_object_get(struct json_object* obj, | extern struct json_object* json_object_object_get(struct json_object* obj, | ||||
char *key); | |||||
const char *key); | |||||
/** Delete the given json_object field | /** 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 obj the json_object instance | ||||
* @param key the object field name | * @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 | /** Iterate through all keys and values of an object | ||||
* @param obj the json_object instance | * @param obj the json_object instance | ||||
@@ -290,9 +290,9 @@ extern double json_object_get_double(struct json_object *obj); | |||||
* @param s the string | * @param s the string | ||||
* @returns a json_object of type json_type_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 | /** 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 | * @param obj the json_object instance | ||||
* @returns a string | * @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 | #endif |
@@ -85,7 +85,7 @@ struct json_object* json_object_from_file(char *filename) | |||||
int json_object_to_file(char *filename, struct json_object *obj) | int json_object_to_file(char *filename, struct json_object *obj) | ||||
{ | { | ||||
char *json_str; | |||||
const char *json_str; | |||||
int fd, ret; | int fd, ret; | ||||
unsigned int wpos, wsize; | unsigned int wpos, wsize; | ||||
@@ -29,18 +29,18 @@ void lh_abort(const char *msg, ...) | |||||
exit(1); | exit(1); | ||||
} | } | ||||
unsigned long lh_ptr_hash(void *k) | |||||
unsigned long lh_ptr_hash(const void *k) | |||||
{ | { | ||||
/* CAW: refactored to be 64bit nice */ | /* CAW: refactored to be 64bit nice */ | ||||
return (unsigned long)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX); | 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); | return (k1 == k2); | ||||
} | } | ||||
unsigned long lh_char_hash(void *k) | |||||
unsigned long lh_char_hash(const void *k) | |||||
{ | { | ||||
unsigned int h = 0; | unsigned int h = 0; | ||||
const char* data = k; | const char* data = k; | ||||
@@ -50,12 +50,12 @@ unsigned long lh_char_hash(void *k) | |||||
return h; | 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_entry_free_fn *free_fn, | ||||
lh_hash_fn *hash_fn, | lh_hash_fn *hash_fn, | ||||
lh_equal_fn *equal_fn) | lh_equal_fn *equal_fn) | ||||
@@ -77,13 +77,13 @@ struct lh_table* lh_table_new(int size, char *name, | |||||
return t; | 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) | lh_entry_free_fn *free_fn) | ||||
{ | { | ||||
return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal); | 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) | lh_entry_free_fn *free_fn) | ||||
{ | { | ||||
return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal); | 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; | 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 h = t->hash_fn(k); | ||||
unsigned long n = h % t->size; | 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); | struct lh_entry *e = lh_table_lookup_entry(t, k); | ||||
if(e) return e->v; | 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); | struct lh_entry *e = lh_table_lookup_entry(t, k); | ||||
if(!e) return -1; | if(!e) return -1; | ||||
@@ -36,11 +36,11 @@ typedef void (lh_entry_free_fn) (struct lh_entry *e); | |||||
/** | /** | ||||
* callback function prototypes | * callback function prototypes | ||||
*/ | */ | ||||
typedef unsigned long (lh_hash_fn) (void *k); | |||||
typedef unsigned long (lh_hash_fn) (const void *k); | |||||
/** | /** | ||||
* callback function prototypes | * 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 | * An entry in the hash table | ||||
@@ -53,7 +53,7 @@ struct lh_entry { | |||||
/** | /** | ||||
* The value. | * The value. | ||||
*/ | */ | ||||
void *v; | |||||
const void *v; | |||||
/** | /** | ||||
* The next entry | * The next entry | ||||
*/ | */ | ||||
@@ -106,7 +106,7 @@ struct lh_table { | |||||
/** | /** | ||||
* Name of the hash table. | * Name of the hash table. | ||||
*/ | */ | ||||
char *name; | |||||
const char *name; | |||||
/** | /** | ||||
* The first entry. | * The first entry. | ||||
@@ -132,11 +132,11 @@ struct lh_table { | |||||
/** | /** | ||||
* Pre-defined hash and equality functions | * 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. | * and C strings respectively. | ||||
* @return a pointer onto the linkhash table. | * @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_entry_free_fn *free_fn, | ||||
lh_hash_fn *hash_fn, | lh_hash_fn *hash_fn, | ||||
lh_equal_fn *equal_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. | * @param free_fn callback function used to free memory for entries. | ||||
* @return a pointer onto the linkhash table. | * @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); | 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. | * @param free_fn callback function used to free memory for entries. | ||||
* @return a pointer onto the linkhash table. | * @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); | 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 k a pointer to the key to insert. | ||||
* @param v a pointer to the value 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 | * @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. | * @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 | * 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 | * @param k a pointer to the key to lookup | ||||
* @return a pointer to the found value or NULL if it does not exist. | * @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 0 if the item was deleted. | ||||
* @return -1 if it was not found. | * @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, ...); | void lh_abort(const char *msg, ...); | ||||
@@ -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; | char *t; | ||||
if(p->size - p->bpos <= size) { | if(p->size - p->bpos <= size) { | ||||
@@ -24,7 +24,7 @@ extern struct printbuf* | |||||
printbuf_new(void); | printbuf_new(void); | ||||
extern int | extern int | ||||
printbuf_memappend(struct printbuf *p, char *buf, int size); | |||||
printbuf_memappend(struct printbuf *p, const char *buf, int size); | |||||
extern int | extern int | ||||
sprintbuf(struct printbuf *p, const char *msg, ...); | sprintbuf(struct printbuf *p, const char *msg, ...); | ||||