diff --git a/CHANGES b/CHANGES index 73d149c..0cadf5c 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,14 @@ Version 1.3 Released 2010-06-13 +* New functions: + + - `json_object_iter_set()`, `json_object_iter_set_new()`: Change + object contents while iterating over it. + + - `json_object_iter_at()`: Return an iterator that points to a + specific object item. + * New encoding flags: - ``JSON_PRESERVE_ORDER``: Preserve the insertion order of object diff --git a/configure.ac b/configure.ac index 572a633..cabc732 100644 --- a/configure.ac +++ b/configure.ac @@ -8,8 +8,8 @@ AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_CC -AC_PROG_CXX AC_PROG_LIBTOOL +AM_CONDITIONAL([GCC], [test x$GCC = xyes]) # Checks for libraries. diff --git a/doc/apiref.rst b/doc/apiref.rst index 1d67881..c3a0554 100644 --- a/doc/apiref.rst +++ b/doc/apiref.rst @@ -244,6 +244,12 @@ returns the same value each time. String ====== +Jansson uses UTF-8 as the character encoding. All JSON strings must be +valid UTF-8 (or ASCII, as it's a subset of UTF-8). Normal null +terminated C strings are used, so JSON strings may not contain +embedded null characters. All other Unicode codepoints U+0001 through +U+10FFFF are allowed. + .. cfunction:: json_t *json_string(const char *value) .. refcounting:: new @@ -287,6 +293,12 @@ String Number ====== +The JSON specification only contains one numeric type, "number". The C +programming language has distinct types for integer and floating-point +numbers, so for practical reasons Jansson also has distinct types for +the two. They are called "integer" and "real", respectively. For more +information, see :ref:`rfc-conformance`. + .. ctype:: json_int_t This is the C type that is used to store JSON integer values. It @@ -695,10 +707,12 @@ This sections describes the functions that can be used to decode JSON text to the Jansson representation of JSON data. The JSON specification requires that a JSON text is either a serialized array or object, and this requirement is also enforced with the following -functions. +functions. In other words, the top level value in the JSON text being +decoded must be either array or object. -The only supported character encoding is UTF-8 (which ASCII is a -subset of). +See :ref:`rfc-conformance` for a discussion on Jansson's conformance +to the JSON specification. It explains many design decisions that +affect especially the behavior of the decoder. .. ctype:: json_error_t @@ -786,7 +800,8 @@ only if they are exactly the same value, but also if they have equal values are equal. An integer value is never equal to a real value, though. -* Two strings are equal if their contained UTF-8 strings are equal. +* Two strings are equal if their contained UTF-8 strings are equal, + byte by byte. Unicode comparison algorithms are not implemented. * Two arrays are equal if they have the same number of elements and each element in the first array is equal to the corresponding diff --git a/doc/conformance.rst b/doc/conformance.rst index 1cb6f44..6359f22 100644 --- a/doc/conformance.rst +++ b/doc/conformance.rst @@ -1,3 +1,5 @@ +.. _rfc-conformance: + *************** RFC Conformance *************** diff --git a/src/Makefile.am b/src/Makefile.am index c7a3927..907631d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,4 +17,7 @@ libjansson_la_LDFLAGS = \ -export-symbols-regex '^json_' \ -version-info 3:0:3 +if GCC +# These flags are gcc specific AM_CFLAGS = -Wall -Wextra -Werror +endif diff --git a/src/jansson.h b/src/jansson.h index 41f9c9d..78a2222 100644 --- a/src/jansson.h +++ b/src/jansson.h @@ -113,7 +113,7 @@ int json_object_set_nocheck(json_t *object, const char *key, json_t *value) return json_object_set_new_nocheck(object, key, json_incref(value)); } -static inline +static JSON_INLINE int json_object_iter_set(json_t *object, void *iter, json_t *value) { return json_object_iter_set_new(object, iter, json_incref(value)); diff --git a/src/jansson_private.h b/src/jansson_private.h index bd80346..e9e0097 100644 --- a/src/jansson_private.h +++ b/src/jansson_private.h @@ -8,11 +8,12 @@ #ifndef JANSSON_PRIVATE_H #define JANSSON_PRIVATE_H +#include #include "jansson.h" #include "hashtable.h" #define container_of(ptr_, type_, member_) \ - ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) + ((type_ *)((char *)ptr_ - offsetof(type_, member_))) typedef struct { json_t json; @@ -52,7 +53,7 @@ typedef struct { typedef struct { size_t serial; - char key[]; + char key[1]; } object_key_t; const object_key_t *jsonp_object_iter_fullkey(void *iter); diff --git a/src/value.c b/src/value.c index 0f2ae65..3895882 100644 --- a/src/value.c +++ b/src/value.c @@ -9,6 +9,7 @@ #include +#include #include #include @@ -124,9 +125,11 @@ int json_object_set_new_nocheck(json_t *json, const char *key, json_t *value) } object = json_to_object(json); - k = malloc(sizeof(object_key_t) + strlen(key) + 1); - if(!k) - return -1; + /* offsetof(...) returns the size of object_key_t without the + last, flexible member. This way, the correct amount is + allocated. */ + k = malloc(offsetof(object_key_t, key) + + strlen(key) + 1); if(!k) return -1; k->serial = object->serial++; strcpy(k->key, key);