From b461c652b490219ccbbedc4fd663a564dd92d502 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Mon, 14 Jun 2010 14:33:44 +0300 Subject: [PATCH 1/7] Add a few missing changes to CHANGES for v1.3 These were forgotten when releasing. --- CHANGES | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From b354f8a35af3b202e73d42ba9e1a252ad41062d8 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Mon, 14 Jun 2010 22:30:15 +0300 Subject: [PATCH 2/7] configure.ac: Remove unneeded AC_PROG_CXX --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4a199e4..3191d8a 100644 --- a/configure.ac +++ b/configure.ac @@ -8,7 +8,6 @@ AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_CC -AC_PROG_CXX AC_PROG_LIBTOOL # Checks for libraries. From 6e3ca5c45c984a27d0f5c9b9249e17ef0c412e3a Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Wed, 16 Jun 2010 21:34:10 +0300 Subject: [PATCH 3/7] Clarify the documentation Couple some string and number information from the RFC conformance chapter in the API reference, and refer to the RFC conformance chapter from API reference for more information. Also, state more clearly that a JSON text must have an array or object as the top-level value, and better document the string comparison performed by json_equal(). --- doc/apiref.rst | 23 +++++++++++++++++++---- doc/conformance.rst | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/apiref.rst b/doc/apiref.rst index bacd756..2c6cf3b 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`. + .. cfunction:: json_t *json_integer(int value) .. refcounting:: new @@ -656,10 +668,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 @@ -744,7 +758,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 785a94d..3bfe51d 100644 --- a/doc/conformance.rst +++ b/doc/conformance.rst @@ -1,3 +1,5 @@ +.. _rfc-conformance: + *************** RFC Conformance *************** From f71eb7fe1749836ac45cc6c0015dd6d2aec4bef9 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 12 Aug 2010 20:59:48 +0300 Subject: [PATCH 4/7] Check for gcc before setting gcc specific CFLAGS --- configure.ac | 1 + src/Makefile.am | 3 +++ 2 files changed, 4 insertions(+) diff --git a/configure.ac b/configure.ac index 3191d8a..a46fc27 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,7 @@ AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_CC AC_PROG_LIBTOOL +AM_CONDITIONAL([GCC], [test x$GCC = xyes]) # Checks for libraries. diff --git a/src/Makefile.am b/src/Makefile.am index cb9180e..52a2e57 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 From 94182a5acc7e866e2ad56a34f0c5f74db45db86e Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 12 Aug 2010 21:10:12 +0300 Subject: [PATCH 5/7] Replace inline with JSON_INLINE in json_object_iter_set() declaration --- src/jansson.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jansson.h.in b/src/jansson.h.in index 4980d01..8032692 100644 --- a/src/jansson.h.in +++ b/src/jansson.h.in @@ -106,7 +106,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)); From 519d52e2bb6a3840100a84e826d8d8ac91e2d3d8 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 12 Aug 2010 21:34:02 +0300 Subject: [PATCH 6/7] Beautify the container_of macro Use offsetof instead of zero pointer dereference trickery. --- src/jansson_private.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jansson_private.h b/src/jansson_private.h index 4490702..6d7e46c 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; From 145032a57f7844c29f2c40415b46338ac3445207 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Thu, 12 Aug 2010 21:35:19 +0300 Subject: [PATCH 7/7] Make object_key_t portable A flexible array member is unportable. Use a table of length 1 instead. This needs some adjustment to the memory allocatio, too. --- src/jansson_private.h | 2 +- src/value.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/jansson_private.h b/src/jansson_private.h index 6d7e46c..55532eb 100644 --- a/src/jansson_private.h +++ b/src/jansson_private.h @@ -53,7 +53,7 @@ typedef struct { typedef struct { unsigned long 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 e024fdb..8e0cfa2 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);