Merge branch '1.3'
authorPetri Lehtinen <petri@digip.org>
Mon, 6 Sep 2010 17:48:25 +0000 (20:48 +0300)
committerPetri Lehtinen <petri@digip.org>
Mon, 6 Sep 2010 17:48:25 +0000 (20:48 +0300)
34 files changed:
.gitignore
configure.ac
doc/apiref.rst
doc/conf.py
doc/conformance.rst
doc/gettingstarted.rst
doc/github_commits.c
doc/tutorial.rst
src/Makefile.am
src/dump.c
src/hashtable.c
src/hashtable.h
src/jansson.h [moved from src/jansson.h.in with 72% similarity]
src/jansson_config.h.in [new file with mode: 0644]
src/jansson_config.h.win32 [new file with mode: 0644]
src/jansson_private.h
src/load.c
src/strbuffer.c
src/utf.h
src/util.h [deleted file]
src/value.c
test/bin/json_process.c
test/suites/api/test_copy.c
test/suites/api/test_equal.c
test/suites/api/test_load.c
test/suites/api/test_simple.c
test/suites/invalid-strip/too-big-negative-integer/error
test/suites/invalid-strip/too-big-negative-integer/input
test/suites/invalid-strip/too-big-positive-integer/error
test/suites/invalid-strip/too-big-positive-integer/input
test/suites/invalid/too-big-negative-integer/error
test/suites/invalid/too-big-negative-integer/input
test/suites/invalid/too-big-positive-integer/error
test/suites/invalid/too-big-positive-integer/input

index db44e75..3b4bffe 100644 (file)
@@ -24,4 +24,4 @@ missing
 stamp-h1
 *.pyc
 *.pc
-/src/jansson.h
+/src/jansson_config.h
index a46fc27..cabc732 100644 (file)
@@ -1,5 +1,5 @@
 AC_PREREQ([2.60])
-AC_INIT([jansson], [1.3], [petri@digip.org])
+AC_INIT([jansson], [2.0pre], [petri@digip.org])
 
 AM_INIT_AUTOMAKE([1.10 foreign])
 
@@ -18,6 +18,13 @@ AM_CONDITIONAL([GCC], [test x$GCC = xyes])
 # Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_INT32_T
 
+AC_TYPE_LONG_LONG_INT
+case $ac_cv_type_long_long_int in
+     yes) json_have_long_long=1;;
+     *) json_have_long_long=0;;
+esac
+AC_SUBST([json_have_long_long])
+
 AC_C_INLINE
 case $ac_cv_c_inline in
     yes) json_inline=inline;;
@@ -33,7 +40,7 @@ AC_CONFIG_FILES([
         Makefile
         doc/Makefile
         src/Makefile
-        src/jansson.h
+        src/jansson_config.h
         test/Makefile
         test/bin/Makefile
         test/suites/Makefile
index 2c6cf3b..397f418 100644 (file)
@@ -32,14 +32,14 @@ type, including themselves. For this reason, Jansson's type system is
 also dynamic in nature. There's one C type to represent all JSON
 values, and this structure knows the type of the JSON value it holds.
 
-.. ctype:: json_t
+.. type:: json_t
 
   This data structure is used throughout the library to represent all
   JSON values. It always contains the type of the JSON value it holds
   and the value's reference count. The rest depends on the type of the
   value.
 
-Objects of :ctype:`json_t` are always used through a pointer. There
+Objects of :type:`json_t` are always used through a pointer. There
 are APIs for querying the type, manipulating the reference count, and
 for constructing and manipulating values of different types.
 
@@ -56,42 +56,41 @@ Type
 The type of a JSON value is queried and tested using the following
 functions:
 
-.. ctype:: enum json_type
+.. type:: enum json_type
 
    The type of a JSON value. The following members are defined:
 
-   +-------------------------+
-   | :const:`JSON_OBJECT`    |
-   +-------------------------+
-   | :const:`JSON_ARRAY`     |
-   +-------------------------+
-   | :const:`JSON_STRING`    |
-   +-------------------------+
-   | :const:`JSON_INTEGER`   |
-   +-------------------------+
-   | :const:`JSON_REAL`      |
-   +-------------------------+
-   | :const:`JSON_TRUE`      |
-   +-------------------------+
-   | :const:`JSON_FALSE`     |
-   +-------------------------+
-   | :const:`JSON_NULL`      |
-   +-------------------------+
+   +--------------------+
+   | ``JSON_OBJECT``    |
+   +--------------------+
+   | ``JSON_ARRAY``     |
+   +--------------------+
+   | ``JSON_STRING``    |
+   +--------------------+
+   | ``JSON_INTEGER``   |
+   +--------------------+
+   | ``JSON_REAL``      |
+   +--------------------+
+   | ``JSON_TRUE``      |
+   +--------------------+
+   | ``JSON_FALSE``     |
+   +--------------------+
+   | ``JSON_NULL``      |
+   +--------------------+
 
    These correspond to JSON object, array, string, number, boolean and
    null. A number is represented by either a value of the type
-   :const:`JSON_INTEGER` or of the type :const:`JSON_REAL`. A true
-   boolean value is represented by a value of the type
-   :const:`JSON_TRUE` and false by a value of the type
-   :const:`JSON_FALSE`.
+   ``JSON_INTEGER`` or of the type ``JSON_REAL``. A true boolean value
+   is represented by a value of the type ``JSON_TRUE`` and false by a
+   value of the type ``JSON_FALSE``.
 
-.. cfunction:: int json_typeof(const json_t *json)
+.. function:: int json_typeof(const json_t *json)
 
-   Return the type of the JSON value (a :ctype:`json_type` cast to
-   :ctype:`int`). *json* MUST NOT be *NULL*. This function is actually
+   Return the type of the JSON value (a :type:`json_type` cast to
+   :type:`int`). *json* MUST NOT be *NULL*. This function is actually
    implemented as a macro for speed.
 
-.. cfunction:: json_is_object(const json_t *json)
+.. function:: json_is_object(const json_t *json)
                json_is_array(const json_t *json)
                json_is_string(const json_t *json)
                json_is_integer(const json_t *json)
@@ -104,15 +103,15 @@ functions:
    of the given type, and false (zero) for values of other types and
    for *NULL*.
 
-.. cfunction:: json_is_number(const json_t *json)
+.. function:: json_is_number(const json_t *json)
 
-   Returns true for values of types :const:`JSON_INTEGER` and
-   :const:`JSON_REAL`, and false for other types and for *NULL*.
+   Returns true for values of types ``JSON_INTEGER`` and
+   ``JSON_REAL``, and false for other types and for *NULL*.
 
-.. cfunction:: json_is_boolean(const json_t *json)
+.. function:: json_is_boolean(const json_t *json)
 
-   Returns true for types :const:`JSON_TRUE` and :const:`JSON_FALSE`,
-   and false for values of other types and for *NULL*.
+   Returns true for types ``JSON_TRUE`` and ``JSON_FALSE``, and false
+   for values of other types and for *NULL*.
 
 
 .. _apiref-reference-count:
@@ -130,15 +129,15 @@ value can be destroyed.
 
 The following functions are used to manipulate the reference count.
 
-.. cfunction:: json_t *json_incref(json_t *json)
+.. function:: json_t *json_incref(json_t *json)
 
    Increment the reference count of *json* if it's not non-*NULL*.
    Returns *json*.
 
-.. cfunction:: void json_decref(json_t *json)
+.. function:: void json_decref(json_t *json)
 
    Decrement the reference count of *json*. As soon as a call to
-   :cfunc:`json_decref()` drops the reference count to zero, the value
+   :func:`json_decref()` drops the reference count to zero, the value
    is destroyed and it can no longer be used.
 
 Functions creating new JSON values set the reference count to 1. These
@@ -146,14 +145,14 @@ functions are said to return a **new reference**. Other functions
 returning (existing) JSON values do not normally increase the
 reference count. These functions are said to return a **borrowed
 reference**. So, if the user will hold a reference to a value returned
-as a borrowed reference, he must call :cfunc:`json_incref`. As soon as
-the value is no longer needed, :cfunc:`json_decref` should be called
+as a borrowed reference, he must call :func:`json_incref`. As soon as
+the value is no longer needed, :func:`json_decref` should be called
 to release the reference.
 
 Normally, all functions accepting a JSON value as an argument will
 manage the reference, i.e. increase and decrease the reference count
 as needed. However, some functions **steal** the reference, i.e. they
-have the same result as if the user called :cfunc:`json_decref()` on
+have the same result as if the user called :func:`json_decref()` on
 the argument right after calling the function. These functions are
 suffixed with ``_new`` or have ``_new_`` somewhere in their name.
 
@@ -169,15 +168,15 @@ an integer to it::
   json_decref(integer);
 
 Note how the caller has to release the reference to the integer value
-by calling :cfunc:`json_decref()`. By using a reference stealing
-function :cfunc:`json_array_append_new()` instead of
-:cfunc:`json_array_append()`, the code becomes much simpler::
+by calling :func:`json_decref()`. By using a reference stealing
+function :func:`json_array_append_new()` instead of
+:func:`json_array_append()`, the code becomes much simpler::
 
   json_t *array = json_array();
   json_array_append_new(array, json_integer(42));
 
 In this case, the user doesn't have to explicitly release the
-reference to the integer value, as :cfunc:`json_array_append_new()`
+reference to the integer value, as :func:`json_array_append_new()`
 steals the reference when appending the value to the array.
 
 In the following sections it is clearly documented whether a function
@@ -195,7 +194,7 @@ simple::
   json_t *obj = json_object();
   json_object_set(obj, "foo", obj);
 
-Jansson will refuse to do this, and :cfunc:`json_object_set()` (and
+Jansson will refuse to do this, and :func:`json_object_set()` (and
 all the other such functions for objects and arrays) will return with
 an error status. The indirect case is the dangerous one::
 
@@ -209,11 +208,11 @@ indirect circular references without a performance hit, so it's up to
 the user to avoid them.
 
 If a circular reference is created, the memory consumed by the values
-cannot be freed by :cfunc:`json_decref()`. The reference counts never
-drops to zero because the values are keeping the circular reference to
-themselves. Moreover, trying to encode the values with any of the
-encoding functions will fail. The encoder detects circular references
-and returns an error status.
+cannot be freed by :func:`json_decref()`. The reference counts never
+drops to zero because the values are keeping the references to each
+other. Moreover, trying to encode the values with any of the encoding
+functions will fail. The encoder detects circular references and
+returns an error status.
 
 
 True, False and Null
@@ -222,19 +221,19 @@ True, False and Null
 These values are implemented as singletons, so each of these functions
 returns the same value each time.
 
-.. cfunction:: json_t *json_true(void)
+.. function:: json_t *json_true(void)
 
    .. refcounting:: new
 
    Returns the JSON true value.
 
-.. cfunction:: json_t *json_false(void)
+.. function:: json_t *json_false(void)
 
    .. refcounting:: new
 
    Returns the JSON false value.
 
-.. cfunction:: json_t *json_null(void)
+.. function:: json_t *json_null(void)
 
    .. refcounting:: new
 
@@ -250,29 +249,29 @@ 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)
+.. function:: json_t *json_string(const char *value)
 
    .. refcounting:: new
 
    Returns a new JSON string, or *NULL* on error. *value* must be a
    valid UTF-8 encoded Unicode string.
 
-.. cfunction:: json_t *json_string_nocheck(const char *value)
+.. function:: json_t *json_string_nocheck(const char *value)
 
    .. refcounting:: new
 
-   Like :cfunc:`json_string`, but doesn't check that *value* is valid
+   Like :func:`json_string`, but doesn't check that *value* is valid
    UTF-8. Use this function only if you are certain that this really
    is the case (e.g. you have already checked it by other means).
 
    .. versionadded:: 1.2
 
-.. cfunction:: const char *json_string_value(const json_t *string)
+.. function:: const char *json_string_value(const json_t *string)
 
    Returns the associated value of *string* as a null terminated UTF-8
    encoded string, or *NULL* if *string* is not a JSON string.
 
-.. cfunction:: int json_string_set(const json_t *string, const char *value)
+.. function:: int json_string_set(const json_t *string, const char *value)
 
    Sets the associated value of *string* to *value*. *value* must be a
    valid UTF-8 encoded Unicode string. Returns 0 on success and -1 on
@@ -280,9 +279,9 @@ U+10FFFF are allowed.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_string_set_nocheck(const json_t *string, const char *value)
+.. function:: int json_string_set_nocheck(const json_t *string, const char *value)
 
-   Like :cfunc:`json_string_set`, but doesn't check that *value* is
+   Like :func:`json_string_set`, but doesn't check that *value* is
    valid UTF-8. Use this function only if you are certain that this
    really is the case (e.g. you have already checked it by other
    means).
@@ -299,36 +298,75 @@ 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)
+.. type:: json_int_t
+
+   This is the C type that is used to store JSON integer values. It
+   represents the widest integer type available on your system. In
+   practice it's just a typedef of ``long long`` if your compiler
+   supports it, otherwise ``long``.
+
+   Usually, you can safely use plain ``int`` in place of
+   ``json_int_t``, and the implicit C integer conversion handles the
+   rest. Only when you know that you need the full 64-bit range, you
+   should use ``json_int_t`` explicitly.
+
+``JSON_INTEGER_IS_LONG_LONG``
+
+   This is a preprocessor variable that holds the value 1 if
+   :type:`json_int_t` is ``long long``, and 0 if it's ``long``. It
+   can be used as follows::
+
+       #if JSON_INTEGER_IS_LONG_LONG
+       /* Code specific for long long */
+       #else
+       /* Code specific for long */
+       #endif
+
+``JSON_INTEGER_FORMAT``
+
+   This is a macro that expands to a :func:`printf()` conversion
+   specifier that corresponds to :type:`json_int_t`, without the
+   leading ``%`` sign, i.e. either ``"lld"`` or ``"ld"``. This macro
+   is required because the actual type of :type:`json_int_t` can be
+   either ``long`` or ``long long``, and :func:`printf()` reuiqres
+   different length modifiers for the two.
+
+   Example::
+
+       json_int_t x = 123123123;
+       printf("x is %" JSON_INTEGER_FORMAT "\n", x);
+
+
+.. function:: json_t *json_integer(json_int_t value)
 
    .. refcounting:: new
 
    Returns a new JSON integer, or *NULL* on error.
 
-.. cfunction:: int json_integer_value(const json_t *integer)
+.. function:: json_int_t json_integer_value(const json_t *integer)
 
    Returns the associated value of *integer*, or 0 if *json* is not a
    JSON integer.
 
-.. cfunction:: int json_integer_set(const json_t *integer, int value)
+.. function:: int json_integer_set(const json_t *integer, json_int_t value)
 
    Sets the associated value of *integer* to *value*. Returns 0 on
    success and -1 if *integer* is not a JSON integer.
 
    .. versionadded:: 1.1
 
-.. cfunction:: json_t *json_real(double value)
+.. function:: json_t *json_real(double value)
 
    .. refcounting:: new
 
    Returns a new JSON real, or *NULL* on error.
 
-.. cfunction:: double json_real_value(const json_t *real)
+.. function:: double json_real_value(const json_t *real)
 
    Returns the associated value of *real*, or 0.0 if *real* is not a
    JSON real.
 
-.. cfunction:: int json_real_set(const json_t *real, double value)
+.. function:: int json_real_set(const json_t *real, double value)
 
    Sets the associated value of *real* to *value*. Returns 0 on
    success and -1 if *real* is not a JSON real.
@@ -338,7 +376,7 @@ information, see :ref:`rfc-conformance`.
 In addition to the functions above, there's a common query function
 for integers and reals:
 
-.. cfunction:: double json_number_value(const json_t *json)
+.. function:: double json_number_value(const json_t *json)
 
    Returns the associated value of the JSON integer or JSON real
    *json*, cast to double regardless of the actual type. If *json* is
@@ -350,57 +388,57 @@ Array
 
 A JSON array is an ordered collection of other JSON values.
 
-.. cfunction:: json_t *json_array(void)
+.. function:: json_t *json_array(void)
 
    .. refcounting:: new
 
    Returns a new JSON array, or *NULL* on error. Initially, the array
    is empty.
 
-.. cfunction:: unsigned int json_array_size(const json_t *array)
+.. function:: size_t json_array_size(const json_t *array)
 
    Returns the number of elements in *array*, or 0 if *array* is NULL
    or not a JSON array.
 
-.. cfunction:: json_t *json_array_get(const json_t *array, unsigned int index)
+.. function:: json_t *json_array_get(const json_t *array, size_t index)
 
    .. refcounting:: borrow
 
    Returns the element in *array* at position *index*. The valid range
    for *index* is from 0 to the return value of
-   :cfunc:`json_array_size()` minus 1. If *array* is not a JSON array,
+   :func:`json_array_size()` minus 1. If *array* is not a JSON array,
    if *array* is *NULL*, or if *index* is out of range, *NULL* is
    returned.
 
-.. cfunction:: int json_array_set(json_t *array, unsigned int index, json_t *value)
+.. function:: int json_array_set(json_t *array, size_t index, json_t *value)
 
    Replaces the element in *array* at position *index* with *value*.
    The valid range for *index* is from 0 to the return value of
-   :cfunc:`json_array_size()` minus 1. Returns 0 on success and -1 on
+   :func:`json_array_size()` minus 1. Returns 0 on success and -1 on
    error.
 
-.. cfunction:: int json_array_set_new(json_t *array, unsigned int index, json_t *value)
+.. function:: int json_array_set_new(json_t *array, size_t index, json_t *value)
 
-   Like :cfunc:`json_array_set()` but steals the reference to *value*.
+   Like :func:`json_array_set()` but steals the reference to *value*.
    This is useful when *value* is newly created and not used after
    the call.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_array_append(json_t *array, json_t *value)
+.. function:: int json_array_append(json_t *array, json_t *value)
 
    Appends *value* to the end of *array*, growing the size of *array*
    by 1. Returns 0 on success and -1 on error.
 
-.. cfunction:: int json_array_append_new(json_t *array, json_t *value)
+.. function:: int json_array_append_new(json_t *array, json_t *value)
 
-   Like :cfunc:`json_array_append()` but steals the reference to
+   Like :func:`json_array_append()` but steals the reference to
    *value*. This is useful when *value* is newly created and not used
    after the call.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_array_insert(json_t *array, unsigned int index, json_t *value)
+.. function:: int json_array_insert(json_t *array, size_t index, json_t *value)
 
    Inserts *value* to *array* at position *index*, shifting the
    elements at *index* and after it one position towards the end of
@@ -408,15 +446,15 @@ A JSON array is an ordered collection of other JSON values.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_array_insert_new(json_t *array, unsigned int index, json_t *value)
+.. function:: int json_array_insert_new(json_t *array, size_t index, json_t *value)
 
-   Like :cfunc:`json_array_insert()` but steals the reference to
+   Like :func:`json_array_insert()` but steals the reference to
    *value*. This is useful when *value* is newly created and not used
    after the call.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_array_remove(json_t *array, unsigned int index)
+.. function:: int json_array_remove(json_t *array, size_t index)
 
    Removes the element in *array* at position *index*, shifting the
    elements after *index* one position towards the start of the array.
@@ -424,14 +462,14 @@ A JSON array is an ordered collection of other JSON values.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_array_clear(json_t *array)
+.. function:: int json_array_clear(json_t *array)
 
    Removes all elements from *array*. Returns 0 on sucess and -1 on
    error.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_array_extend(json_t *array, json_t *other_array)
+.. function:: int json_array_extend(json_t *array, json_t *other_array)
 
    Appends all elements in *other_array* to the end of *array*.
    Returns 0 on success and -1 on error.
@@ -445,74 +483,74 @@ Object
 A JSON object is a dictionary of key-value pairs, where the key is a
 Unicode string and the value is any JSON value.
 
-.. cfunction:: json_t *json_object(void)
+.. function:: json_t *json_object(void)
 
    .. refcounting:: new
 
    Returns a new JSON object, or *NULL* on error. Initially, the
    object is empty.
 
-.. cfunction:: unsigned int json_object_size(const json_t *object)
+.. function:: size_t json_object_size(const json_t *object)
 
    Returns the number of elements in *object*, or 0 if *object* is not
    a JSON object.
 
    .. versionadded:: 1.1
 
-.. cfunction:: json_t *json_object_get(const json_t *object, const char *key)
+.. function:: json_t *json_object_get(const json_t *object, const char *key)
 
    .. refcounting:: borrow
 
    Get a value corresponding to *key* from *object*. Returns *NULL* if
    *key* is not found and on error.
 
-.. cfunction:: int json_object_set(json_t *object, const char *key, json_t *value)
+.. function:: int json_object_set(json_t *object, const char *key, json_t *value)
 
    Set the value of *key* to *value* in *object*. *key* must be a
    valid null terminated UTF-8 encoded Unicode string. If there
    already is a value for *key*, it is replaced by the new value.
    Returns 0 on success and -1 on error.
 
-.. cfunction:: int json_object_set_nocheck(json_t *object, const char *key, json_t *value)
+.. function:: int json_object_set_nocheck(json_t *object, const char *key, json_t *value)
 
-   Like :cfunc:`json_object_set`, but doesn't check that *key* is
+   Like :func:`json_object_set`, but doesn't check that *key* is
    valid UTF-8. Use this function only if you are certain that this
    really is the case (e.g. you have already checked it by other
    means).
 
    .. versionadded:: 1.2
 
-.. cfunction:: int json_object_set_new(json_t *object, const char *key, json_t *value)
+.. function:: int json_object_set_new(json_t *object, const char *key, json_t *value)
 
-   Like :cfunc:`json_object_set()` but steals the reference to
+   Like :func:`json_object_set()` but steals the reference to
    *value*. This is useful when *value* is newly created and not used
    after the call.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value)
+.. function:: int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value)
 
-   Like :cfunc:`json_object_set_new`, but doesn't check that *key* is
+   Like :func:`json_object_set_new`, but doesn't check that *key* is
    valid UTF-8. Use this function only if you are certain that this
    really is the case (e.g. you have already checked it by other
    means).
 
    .. versionadded:: 1.2
 
-.. cfunction:: int json_object_del(json_t *object, const char *key)
+.. function:: int json_object_del(json_t *object, const char *key)
 
    Delete *key* from *object* if it exists. Returns 0 on success, or
    -1 if *key* was not found.
 
 
-.. cfunction:: int json_object_clear(json_t *object)
+.. function:: int json_object_clear(json_t *object)
 
    Remove all elements from *object*. Returns 0 on success and -1 if
    *object* is not a JSON object.
 
    .. versionadded:: 1.1
 
-.. cfunction:: int json_object_update(json_t *object, json_t *other)
+.. function:: int json_object_update(json_t *object, json_t *other)
 
    Update *object* with the key-value pairs from *other*, overwriting
    existing keys. Returns 0 on success or -1 on error.
@@ -522,14 +560,14 @@ Unicode string and the value is any JSON value.
 
 The following functions implement an iteration protocol for objects:
 
-.. cfunction:: void *json_object_iter(json_t *object)
+.. function:: void *json_object_iter(json_t *object)
 
    Returns an opaque iterator which can be used to iterate over all
    key-value pairs in *object*, or *NULL* if *object* is empty.
 
-.. cfunction:: void *json_object_iter_at(json_t *object, const char *key)
+.. function:: void *json_object_iter_at(json_t *object, const char *key)
 
-   Like :cfunc:`json_object_iter()`, but returns an iterator to the
+   Like :func:`json_object_iter()`, but returns an iterator to the
    key-value pair in *object* whose key is equal to *key*, or NULL if
    *key* is not found in *object*. Iterating forward to the end of
    *object* only yields all key-value pairs of the object if *key*
@@ -537,32 +575,32 @@ The following functions implement an iteration protocol for objects:
 
    .. versionadded:: 1.3
 
-.. cfunction:: void *json_object_iter_next(json_t *object, void *iter)
+.. function:: void *json_object_iter_next(json_t *object, void *iter)
 
    Returns an iterator pointing to the next key-value pair in *object*
    after *iter*, or *NULL* if the whole object has been iterated
    through.
 
-.. cfunction:: const char *json_object_iter_key(void *iter)
+.. function:: const char *json_object_iter_key(void *iter)
 
    Extract the associated key from *iter*.
 
-.. cfunction:: json_t *json_object_iter_value(void *iter)
+.. function:: json_t *json_object_iter_value(void *iter)
 
    .. refcounting:: borrow
 
    Extract the associated value from *iter*.
 
-.. cfunction:: int json_object_iter_set(json_t *object, void *iter, json_t *value)
+.. function:: int json_object_iter_set(json_t *object, void *iter, json_t *value)
 
    Set the value of the key-value pair in *object*, that is pointed to
    by *iter*, to *value*.
 
    .. versionadded:: 1.3
 
-.. cfunction:: int json_object_iter_set_new(json_t *object, void *iter, json_t *value)
+.. function:: int json_object_iter_set_new(json_t *object, void *iter, json_t *value)
 
-   Like :cfunc:`json_object_iter_set()`, but steals the reference to
+   Like :func:`json_object_iter_set()`, but steals the reference to
    *value*. This is useful when *value* is newly created and not used
    after the call.
 
@@ -603,7 +641,7 @@ can be ORed together to obtain *flags*.
 ``JSON_INDENT(n)``
    Pretty-print the result, using newlines between array and object
    items, and indenting with *n* spaces. The valid range for *n* is
-   between 0 and 255, other values result in an undefined output. If
+   between 0 and 32, other values result in an undefined output. If
    ``JSON_INDENT`` is not used or *n* is 0, no newlines are inserted
    between array and object items.
 
@@ -640,13 +678,13 @@ can be ORed together to obtain *flags*.
 The following functions perform the actual JSON encoding. The result
 is in UTF-8.
 
-.. cfunction:: char *json_dumps(const json_t *root, unsigned long flags)
+.. function:: char *json_dumps(const json_t *root, size_t flags)
 
    Returns the JSON representation of *root* as a string, or *NULL* on
    error. *flags* is described above. The return value must be freed
-   by the caller using :cfunc:`free()`.
+   by the caller using :func:`free()`.
 
-.. cfunction:: int json_dumpf(const json_t *root, FILE *output, unsigned long flags)
+.. function:: int json_dumpf(const json_t *root, FILE *output, size_t flags)
 
    Write the JSON representation of *root* to the stream *output*.
    *flags* is described above. Returns 0 on success and -1 on error.
@@ -654,7 +692,7 @@ is in UTF-8.
    *output*. In this case, the output is undefined and most likely not
    valid JSON.
 
-.. cfunction:: int json_dump_file(const json_t *json, const char *path, unsigned long flags)
+.. function:: int json_dump_file(const json_t *json, const char *path, size_t flags)
 
    Write the JSON representation of *root* to the file *path*. If
    *path* already exists, it is overwritten. *flags* is described
@@ -675,7 +713,7 @@ 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
+.. type:: json_error_t
 
    This data structure is used to return information on decoding
    errors from the decoding functions. Its definition is repeated
@@ -693,14 +731,14 @@ affect especially the behavior of the decoder.
    message (in UTF-8), or an empty string if a message is not
    available.
 
-   The normal usef of :ctype:`json_error_t` is to allocate it normally
+   The normal usef of :type:`json_error_t` is to allocate it normally
    on the stack, and pass a pointer to a decoding function. Example::
 
       int main() {
           json_t *json;
           json_error_t error;
 
-          json = json_load_file("/path/to/file.json", &error);
+          json = json_load_file("/path/to/file.json", 0, &error);
           if(!json) {
               /* the error variable contains error information */
           }
@@ -711,37 +749,40 @@ affect especially the behavior of the decoder.
    above example), the contents of ``error`` are unspecified.
 
    All decoding functions also accept *NULL* as the
-   :ctype:`json_error_t` pointer, in which case no error information
+   :type:`json_error_t` pointer, in which case no error information
    is returned to the caller.
 
 The following functions perform the actual JSON decoding.
 
-.. cfunction:: json_t *json_loads(const char *input, json_error_t *error)
+.. function:: json_t *json_loads(const char *input, size_t flags, json_error_t *error)
 
    .. refcounting:: new
 
    Decodes the JSON string *input* and returns the array or object it
    contains, or *NULL* on error, in which case *error* is filled with
    information about the error. See above for discussion on the
-   *error* parameter.
+   *error* parameter. *flags* is currently unused, and should be set
+   to 0.
 
-.. cfunction:: json_t *json_loadf(FILE *input, json_error_t *error)
+.. function:: json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
 
    .. refcounting:: new
 
    Decodes the JSON text in stream *input* and returns the array or
    object it contains, or *NULL* on error, in which case *error* is
    filled with information about the error. See above for discussion
-   on the *error* parameter.
+   on the *error* parameter. *flags* is currently unused, and should
+   be set to 0.
 
-.. cfunction:: json_t *json_load_file(const char *path, json_error_t *error)
+.. function:: json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
 
    .. refcounting:: new
 
    Decodes the JSON text in file *path* and returns the array or
    object it contains, or *NULL* on error, in which case *error* is
    filled with information about the error. See above for discussion
-   on the *error* parameter.
+   on the *error* parameter. *flags* is currently unused, and should
+   be set to 0.
 
 
 Equality
@@ -749,7 +790,7 @@ Equality
 
 Testing for equality of two JSON values cannot, in general, be
 achieved using the ``==`` operator. Equality in the terms of the
-``==`` operator states that the two :ctype:`json_t` pointers point to
+``==`` operator states that the two :type:`json_t` pointers point to
 exactly the same JSON value. However, two JSON values can be equal not
 only if they are exactly the same value, but also if they have equal
 "contents":
@@ -776,7 +817,7 @@ only if they are exactly the same value, but also if they have equal
 The following function can be used to test whether two JSON values are
 equal.
 
-.. cfunction:: int json_equal(json_t *value1, json_t *value2)
+.. function:: int json_equal(json_t *value1, json_t *value2)
 
    Returns 1 if *value1* and *value2* are equal, as defined above.
    Returns 0 if they are inequal or one or both of the pointers are
@@ -800,7 +841,7 @@ the same child values in the copied value. Deep copying makes a fresh
 copy of the child values, too. Moreover, all the child values are deep
 copied in a recursive fashion.
 
-.. cfunction:: json_t *json_copy(json_t *value)
+.. function:: json_t *json_copy(json_t *value)
 
    .. refcounting:: new
 
@@ -808,7 +849,7 @@ copied in a recursive fashion.
 
    .. versionadded:: 1.2
 
-.. cfunction:: json_t *json_deep_copy(json_t *value)
+.. function:: json_t *json_deep_copy(json_t *value)
 
    .. refcounting:: new
 
index f0e8cc0..2f05848 100644 (file)
@@ -1,13 +1,10 @@
 # -*- coding: utf-8 -*-
 #
 # Jansson documentation build configuration file, created by
-# sphinx-quickstart on Thu Jul 30 11:35:32 2009.
+# sphinx-quickstart on Sun Sep  5 21:47:20 2010.
 #
 # This file is execfile()d with the current directory set to its containing dir.
 #
-# The contents of this file are pickled, so don't put values in the namespace
-# that aren't pickleable (module imports are okay, they're removed automatically).
-#
 # Note that not all possible configuration values are present in this
 # autogenerated file.
 #
 # serve to show the default.
 
 import sys, os
-sys.path.insert(0, os.path.abspath('ext'))
 
-# If your extensions (or modules documented by autodoc) are in another directory,
+# If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+sys.path.insert(0, os.path.abspath('ext'))
+
+# -- General configuration -----------------------------------------------------
 
-# General configuration
-# ---------------------
+# If your documentation needs a minimal Sphinx version, state it here.
+needs_sphinx = '1.0'
 
 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = ['refcounting']
 
 # Add any paths that contain templates here, relative to this directory.
-templates_path = []
+templates_path = ['_templates']
 
 # The suffix of source filenames.
 source_suffix = '.rst'
 
 # The encoding of source files.
-#source_encoding = 'utf-8'
+#source_encoding = 'utf-8-sig'
 
 # The master toctree document.
 master_doc = 'index'
 
 # General information about the project.
 project = u'Jansson'
-copyright = u'2009, 2010 Petri Lehtinen'
+copyright = u'2010, Petri Lehtinen'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
 # built documents.
 #
 # The short X.Y version.
-version = '1.3'
+version = '2.0'
 # The full version, including alpha/beta/rc tags.
-release = '1.3'
+release = '2.0pre'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
@@ -64,15 +62,13 @@ release = '1.3'
 # Else, today_fmt is used as the format for a strftime call.
 #today_fmt = '%B %d, %Y'
 
-# List of documents that shouldn't be included in the build.
-#unused_docs = []
-
-# List of directories, relative to source directory, that shouldn't be searched
-# for source files.
-exclude_trees = ['_build']
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
 
 # The reST default role (used for this markup: `text`) to use for all documents.
-default_role = 'cfunc'
+default_role = 'c:func'
+primary_domain = 'c'
 
 # If true, '()' will be appended to :func: etc. cross-reference text.
 #add_function_parentheses = True
@@ -88,14 +84,23 @@ default_role = 'cfunc'
 # The name of the Pygments (syntax highlighting) style to use.
 pygments_style = 'sphinx'
 
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+html_theme = 'haiku'
 
-# Options for HTML output
-# -----------------------
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
 
-# The style sheet to use for HTML and HTML Help pages. A file of that name
-# must exist either in Sphinx' static/ path, or in one of the custom paths
-# given in html_static_path.
-html_style = 'default.css'
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
 
 # The name for this set of Sphinx documents.  If None, it defaults to
 # "<project> v<release> documentation".
@@ -116,7 +121,7 @@ html_style = 'default.css'
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = []
+#html_static_path = ['_static']
 
 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
 # using the given strftime format.
@@ -134,7 +139,7 @@ html_static_path = []
 #html_additional_pages = {}
 
 # If false, no module index is generated.
-#html_use_modindex = True
+#html_domain_indices = True
 
 # If false, no index is generated.
 #html_use_index = True
@@ -142,23 +147,28 @@ html_static_path = []
 # If true, the index is split into individual pages for each letter.
 #html_split_index = False
 
-# If true, the reST sources are included in the HTML build as _sources/<name>.
-#html_copy_source = True
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
 
 # If true, an OpenSearch description file will be output, and all pages will
 # contain a <link> tag referring to it.  The value of this option must be the
 # base URL from which the finished HTML is served.
 #html_use_opensearch = ''
 
-# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = ''
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
 
 # Output file base name for HTML help builder.
 htmlhelp_basename = 'Janssondoc'
 
 
-# Options for LaTeX output
-# ------------------------
+# -- Options for LaTeX output --------------------------------------------------
 
 # The paper size ('letter' or 'a4').
 #latex_paper_size = 'letter'
@@ -167,10 +177,10 @@ htmlhelp_basename = 'Janssondoc'
 #latex_font_size = '10pt'
 
 # Grouping the document tree into LaTeX files. List of tuples
-# (source start file, target name, title, author, document class [howto/manual]).
+# (source start file, target name, title, author, documentclass [howto/manual]).
 latex_documents = [
-  ('index', 'Jansson.tex', ur'Jansson Documentation',
-   ur'Petri Lehtinen', 'manual'),
+  ('index', 'Jansson.tex', u'Jansson Documentation',
+   u'Petri Lehtinen', 'manual'),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
@@ -181,6 +191,12 @@ latex_documents = [
 # not chapters.
 #latex_use_parts = False
 
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
 # Additional stuff for the LaTeX preamble.
 #latex_preamble = ''
 
@@ -188,4 +204,14 @@ latex_documents = [
 #latex_appendices = []
 
 # If false, no module index is generated.
-#latex_use_modindex = True
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'jansson', u'Jansson Documentation',
+     [u'Petri Lehtinen'], 1)
+]
index 3bfe51d..6359f22 100644 (file)
@@ -38,7 +38,9 @@ Real vs. Integer
 
 JSON makes no distinction between real and integer numbers; Jansson
 does. Real numbers are mapped to the ``double`` type and integers to
-the ``int`` type.
+the ``json_int_t`` type, which is a typedef of ``long long`` or
+``long``, depending on whether ``long long`` is supported by your
+compiler or not.
 
 A JSON number is considered to be a real number if its lexical
 representation includes one of ``e``, ``E``, or ``.``; regardless if
@@ -56,19 +58,19 @@ Overflow, Underflow & Precision
 -------------------------------
 
 Real numbers whose absolute values are too small to be represented in
-a C double will be silently estimated with 0.0. Thus, depending on
+a C ``double`` will be silently estimated with 0.0. Thus, depending on
 platform, JSON numbers very close to zero such as 1E-999 may result in
 0.0.
 
 Real numbers whose absolute values are too large to be represented in
-a C ``double`` type will result in an overflow error (a JSON decoding
+a C ``double`` will result in an overflow error (a JSON decoding
 error). Thus, depending on platform, JSON numbers like 1E+999 or
 -1E+999 may result in a parsing error.
 
 Likewise, integer numbers whose absolute values are too large to be
-represented in the ``int`` type will result in an overflow error (a
-JSON decoding error). Thus, depending on platform, JSON numbers like
-1000000000000000 may result in parsing error.
+represented in the ``json_int_t`` type (see above) will result in an
+overflow error (a JSON decoding error). Thus, depending on platform,
+JSON numbers like 1000000000000000 may result in parsing error.
 
 Parsing JSON real numbers may result in a loss of precision. As long
 as overflow does not occur (i.e. a total loss of precision), the
@@ -96,9 +98,9 @@ Types
 -----
 
 No support is provided in Jansson for any C numeric types other than
-``int`` and ``double``. This excludes things such as unsigned types,
-``long``, ``long long``, ``long double``, etc. Obviously, shorter
-types like ``short`` and ``float`` are implicitly handled via the
-ordinary C type coercion rules (subject to overflow semantics). Also,
-no support or hooks are provided for any supplemental "bignum" type
-add-on packages.
+``json_int_t`` and ``double``. This excludes things such as unsigned
+types, ``long double``, etc. Obviously, shorter types like ``short``,
+``int``, ``long`` (if ``json_int_t`` is ``long long``) and ``float``
+are implicitly handled via the ordinary C type coercion rules (subject
+to overflow semantics). Also, no support or hooks are provided for any
+supplemental "bignum" type add-on packages.
index 34d2ab9..45ec10c 100644 (file)
@@ -10,6 +10,9 @@ Compiling and Installing Jansson
 The Jansson source is available at
 http://www.digip.org/jansson/releases/.
 
+Unix-like systems
+-----------------
+
 Unpack the source tarball and change to the source directory:
 
 .. parsed-literal::
@@ -51,11 +54,31 @@ used as described above.
 .. _libtool: http://www.gnu.org/software/libtool/
 
 
+Windows
+-------
+
+On Windows (and other non-Unix-like systems), you may be unable to run
+the ``./configure`` script. In this case, follow these steps. All the
+files mentioned can be found in the ``src/`` directory.
+
+1. Rename ``jansson_config.h.win32`` to ``jansson_config.h``. This
+   file has some platform-specific parameters that are normally filled
+   in by the ``./configure`` script.
+
+2. Make ``jansson.h`` and ``jansson_config.h`` available to the
+   compiler, so that they can be found when compiling programs that
+   use Jansson.
+
+3. Compile all the ``.c`` files (in the ``src/`` directory) into a
+   library file. Make the library available to the compiler, as in
+   step 2.
+
+
 Installing Prebuilt Binary Packages
 -----------------------------------
 
-Binary ``.deb`` packages for Ubuntu are available in `this PPA`_ at
-Launchpad_. Follow the instructions in the PPA ("Technical details
+Binary ``.deb`` packages for Ubuntu Linux are available in `this PPA`_
+at Launchpad_. Follow the instructions in the PPA ("Technical details
 about this PPA" link) to take the PPA into use. Then install the -dev
 package::
 
index 8a362eb..707aac4 100644 (file)
@@ -96,7 +96,7 @@ static char *request(const char *url)
 
 int main(int argc, char *argv[])
 {
-    unsigned int i;
+    size_t i;
     char *text;
     char url[URL_SIZE];
 
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
     if(!text)
         return 1;
 
-    root = json_loads(text, &error);
+    root = json_loads(text, 0, &error);
     free(text);
 
     if(!root)
index aaeb554..dd7ae19 100644 (file)
@@ -118,7 +118,7 @@ first newline in the commit message::
 The main function follows. In the beginning, we first declare a bunch
 of variables and check the command line parameters::
 
-    unsigned int i;
+    size_t i;
     char *text;
     char url[URL_SIZE];
 
@@ -149,10 +149,10 @@ If an error occurs, our function ``request`` prints the error and
 returns *NULL*, so it's enough to just return 1 from the main
 function.
 
-Next we'll call :cfunc:`json_loads()` to decode the JSON text we got
+Next we'll call :func:`json_loads()` to decode the JSON text we got
 as a response::
 
-    root = json_loads(text, &error);
+    root = json_loads(text, 0, &error);
     free(text);
 
     if(!root)
@@ -162,8 +162,8 @@ as a response::
     }
 
 We don't need the JSON text anymore, so we can free the ``text``
-variable right after decoding it. If :cfunc:`json_loads()` fails, it
-returns *NULL* and sets error information to the :ctype:`json_error_t`
+variable right after decoding it. If :func:`json_loads()` fails, it
+returns *NULL* and sets error information to the :type:`json_error_t`
 structure given as the second parameter. In this case, our program
 prints the error information out and returns 1 from the main function.
 
@@ -182,8 +182,8 @@ First, we'll extract the ``commits`` array from the JSON response::
 
 This is the array that contains objects describing latest commits in
 the repository. We check that the returned value really is an array.
-If the key ``commits`` doesn't exist, :cfunc:`json_object_get()`
-returns *NULL*, but :cfunc:`json_is_array()` handles this case, too.
+If the key ``commits`` doesn't exist, :func:`json_object_get()`
+returns *NULL*, but :func:`json_is_array()` handles this case, too.
 
 Then we proceed to loop over all the commits in the array::
 
@@ -200,9 +200,9 @@ Then we proceed to loop over all the commits in the array::
         }
     ...
 
-The function :cfunc:`json_array_size()` returns the size of a JSON
+The function :func:`json_array_size()` returns the size of a JSON
 array. First, we again declare some variables and then extract the
-i'th element of the ``commits`` array using :cfunc:`json_array_get()`.
+i'th element of the ``commits`` array using :func:`json_array_get()`.
 We also check that the resulting value is a JSON object.
 
 Next we'll extract the commit ID and commit message, and check that
@@ -225,7 +225,7 @@ they both are JSON strings::
 
 And finally, we'll print the first 8 characters of the commit ID and
 the first line of the commit message. A C-style string is extracted
-from a JSON string using :cfunc:`json_string_value()`::
+from a JSON string using :func:`json_string_value()`::
 
         message_text = json_string_value(message);
         printf("%.8s %.*s\n",
@@ -235,9 +235,9 @@ from a JSON string using :cfunc:`json_string_value()`::
     }
 
 After sending the HTTP request, we decoded the JSON text using
-:cfunc:`json_loads()`, remember? It returns a *new reference* to the
+:func:`json_loads()`, remember? It returns a *new reference* to the
 JSON value it decodes. When we're finished with the value, we'll need
-to decrease the reference count using :cfunc:`json_decref()`. This way
+to decrease the reference count using :func:`json_decref()`. This way
 Jansson can release the resources::
 
     json_decref(root);
index 52a2e57..635176e 100644 (file)
@@ -1,4 +1,4 @@
-include_HEADERS = jansson.h
+include_HEADERS = jansson.h jansson_config.h
 
 lib_LTLIBRARIES = libjansson.la
 libjansson_la_SOURCES = \
@@ -11,7 +11,6 @@ libjansson_la_SOURCES = \
        strbuffer.h \
        utf.c \
        utf.h \
-       util.h \
        value.c
 libjansson_la_LDFLAGS = \
        -export-symbols-regex '^json_' \
index dc27fbd..42eb256 100644 (file)
@@ -41,10 +41,10 @@ static int dump_to_file(const char *buffer, int size, void *data)
     return 0;
 }
 
-/* 256 spaces (the maximum indentation size) */
-static char whitespace[] = "                                                                                                                                                                                                                                                                ";
+/* 32 spaces (the maximum indentation size) */
+static char whitespace[] = "                                ";
 
-static int dump_indent(unsigned long flags, int depth, int space, dump_func dump, void *data)
+static int dump_indent(size_t flags, int depth, int space, dump_func dump, void *data)
 {
     if(JSON_INDENT(flags) > 0)
     {
@@ -165,7 +165,7 @@ static int object_key_compare_serials(const void *key1, const void *key2)
            (*(const object_key_t **)key2)->serial;
 }
 
-static int do_dump(const json_t *json, unsigned long flags, int depth,
+static int do_dump(const json_t *json, size_t flags, int depth,
                    dump_func dump, void *data)
 {
     int ascii = flags & JSON_ENSURE_ASCII ? 1 : 0;
@@ -185,7 +185,9 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
             char buffer[MAX_INTEGER_STR_LENGTH];
             int size;
 
-            size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%d", json_integer_value(json));
+            size = snprintf(buffer, MAX_INTEGER_STR_LENGTH,
+                            "%" JSON_INTEGER_FORMAT,
+                            json_integer_value(json));
             if(size >= MAX_INTEGER_STR_LENGTH)
                 return -1;
 
@@ -307,8 +309,7 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
             if(flags & JSON_SORT_KEYS || flags & JSON_PRESERVE_ORDER)
             {
                 const object_key_t **keys;
-                unsigned int size;
-                unsigned int i;
+                size_t size, i;
                 int (*cmp_func)(const void *, const void *);
 
                 size = json_object_size(json);
@@ -415,7 +416,7 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
 }
 
 
-char *json_dumps(const json_t *json, unsigned long flags)
+char *json_dumps(const json_t *json, size_t flags)
 {
     strbuffer_t strbuff;
     char *result;
@@ -437,7 +438,7 @@ char *json_dumps(const json_t *json, unsigned long flags)
     return result;
 }
 
-int json_dumpf(const json_t *json, FILE *output, unsigned long flags)
+int json_dumpf(const json_t *json, FILE *output, size_t flags)
 {
     if(!json_is_array(json) && !json_is_object(json))
         return -1;
@@ -445,7 +446,7 @@ int json_dumpf(const json_t *json, FILE *output, unsigned long flags)
     return do_dump(json, flags, 0, dump_to_file, (void *)output);
 }
 
-int json_dump_file(const json_t *json, const char *path, unsigned long flags)
+int json_dump_file(const json_t *json, const char *path, size_t flags)
 {
     int result;
 
index a312047..77d2b80 100644 (file)
@@ -5,27 +5,24 @@
  * it under the terms of the MIT license. See LICENSE for details.
  */
 
-#include <config.h>
-
 #include <stdlib.h>
+#include <jansson_config.h>   /* for JSON_INLINE */
+#include "jansson_private.h"  /* for container_of() */
 #include "hashtable.h"
 
 typedef struct hashtable_list list_t;
 typedef struct hashtable_pair pair_t;
 typedef struct hashtable_bucket bucket_t;
 
-#define container_of(ptr_, type_, member_)                      \
-    ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_))
-
 #define list_to_pair(list_)  container_of(list_, pair_t, list)
 
-static inline void list_init(list_t *list)
+static JSON_INLINE void list_init(list_t *list)
 {
     list->next = list;
     list->prev = list;
 }
 
-static inline void list_insert(list_t *list, list_t *node)
+static JSON_INLINE void list_insert(list_t *list, list_t *node)
 {
     node->next = list;
     node->prev = list->prev;
@@ -33,13 +30,13 @@ static inline void list_insert(list_t *list, list_t *node)
     list->prev = node;
 }
 
-static inline void list_remove(list_t *list)
+static JSON_INLINE void list_remove(list_t *list)
 {
     list->prev->next = list->next;
     list->next->prev = list->prev;
 }
 
-static inline int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket)
+static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket)
 {
     return bucket->first == &hashtable->list && bucket->first == bucket->last;
 }
@@ -59,22 +56,22 @@ static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
     }
 }
 
-static unsigned int primes[] = {
+static size_t primes[] = {
     5, 13, 23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593,
     49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469,
     12582917, 25165843, 50331653, 100663319, 201326611, 402653189,
     805306457, 1610612741
 };
-static const unsigned int num_primes = sizeof(primes) / sizeof(unsigned int);
+static const size_t num_primes = sizeof(primes) / sizeof(size_t);
 
-static inline unsigned int num_buckets(hashtable_t *hashtable)
+static JSON_INLINE size_t num_buckets(hashtable_t *hashtable)
 {
     return primes[hashtable->num_buckets];
 }
 
 
 static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
-                                   const void *key, unsigned int hash)
+                                   const void *key, size_t hash)
 {
     list_t *list;
     pair_t *pair;
@@ -100,11 +97,11 @@ static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
 
 /* returns 0 on success, -1 if key was not found */
 static int hashtable_do_del(hashtable_t *hashtable,
-                            const void *key, unsigned int hash)
+                            const void *key, size_t hash)
 {
     pair_t *pair;
     bucket_t *bucket;
-    unsigned int index;
+    size_t index;
 
     index = hash % num_buckets(hashtable);
     bucket = &hashtable->buckets[index];
@@ -156,7 +153,7 @@ static int hashtable_do_rehash(hashtable_t *hashtable)
 {
     list_t *list, *next;
     pair_t *pair;
-    unsigned int i, index, new_size;
+    size_t i, index, new_size;
 
     free(hashtable->buckets);
 
@@ -213,7 +210,7 @@ int hashtable_init(hashtable_t *hashtable,
                    key_hash_fn hash_key, key_cmp_fn cmp_keys,
                    free_fn free_key, free_fn free_value)
 {
-    unsigned int i;
+    size_t i;
 
     hashtable->size = 0;
     hashtable->num_buckets = 0;  /* index to primes[] */
@@ -247,7 +244,7 @@ int hashtable_set(hashtable_t *hashtable, void *key, void *value)
 {
     pair_t *pair;
     bucket_t *bucket;
-    unsigned int hash, index;
+    size_t hash, index;
 
     /* rehash if the load ratio exceeds 1 */
     if(hashtable->size >= num_buckets(hashtable))
@@ -288,7 +285,7 @@ int hashtable_set(hashtable_t *hashtable, void *key, void *value)
 void *hashtable_get(hashtable_t *hashtable, const void *key)
 {
     pair_t *pair;
-    unsigned int hash;
+    size_t hash;
     bucket_t *bucket;
 
     hash = hashtable->hash_key(key);
@@ -303,13 +300,13 @@ void *hashtable_get(hashtable_t *hashtable, const void *key)
 
 int hashtable_del(hashtable_t *hashtable, const void *key)
 {
-    unsigned int hash = hashtable->hash_key(key);
+    size_t hash = hashtable->hash_key(key);
     return hashtable_do_del(hashtable, key, hash);
 }
 
 void hashtable_clear(hashtable_t *hashtable)
 {
-    unsigned int i;
+    size_t i;
 
     hashtable_do_clear(hashtable);
 
@@ -331,7 +328,7 @@ void *hashtable_iter(hashtable_t *hashtable)
 void *hashtable_iter_at(hashtable_t *hashtable, const void *key)
 {
     pair_t *pair;
-    unsigned int hash;
+    size_t hash;
     bucket_t *bucket;
 
     hash = hashtable->hash_key(key);
index f03a769..aba5134 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef HASHTABLE_H
 #define HASHTABLE_H
 
-typedef unsigned int (*key_hash_fn)(const void *key);
+typedef size_t (*key_hash_fn)(const void *key);
 typedef int (*key_cmp_fn)(const void *key1, const void *key2);
 typedef void (*free_fn)(void *key);
 
@@ -20,7 +20,7 @@ struct hashtable_list {
 struct hashtable_pair {
     void *key;
     void *value;
-    unsigned int hash;
+    size_t hash;
     struct hashtable_list list;
 };
 
@@ -30,9 +30,9 @@ struct hashtable_bucket {
 };
 
 typedef struct hashtable {
-    unsigned int size;
+    size_t size;
     struct hashtable_bucket *buckets;
-    unsigned int num_buckets;  /* index to primes[] */
+    size_t num_buckets;  /* index to primes[] */
     struct hashtable_list list;
 
     key_hash_fn hash_key;
similarity index 72%
rename from src/jansson.h.in
rename to src/jansson.h
index 8032692..78a2222 100644 (file)
@@ -9,11 +9,10 @@
 #define JANSSON_H
 
 #include <stdio.h>
+#include <stdlib.h>  /* for size_t */
+#include <jansson_config.h>
 
-#ifndef __cplusplus
-#define JSON_INLINE @json_inline@
-#else
-#define JSON_INLINE inline
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -32,9 +31,17 @@ typedef enum {
 
 typedef struct {
     json_type type;
-    unsigned long refcount;
+    size_t refcount;
 } json_t;
 
+#if JSON_INTEGER_IS_LONG_LONG
+#define JSON_INTEGER_FORMAT "lld"
+typedef long long json_int_t;
+#else
+#define JSON_INTEGER_FORMAT "ld"
+typedef long json_int_t;
+#endif /* JSON_INTEGER_IS_LONG_LONG */
+
 #define json_typeof(json)      ((json)->type)
 #define json_is_object(json)   (json && json_typeof(json) == JSON_OBJECT)
 #define json_is_array(json)    (json && json_typeof(json) == JSON_ARRAY)
@@ -53,7 +60,7 @@ json_t *json_object(void);
 json_t *json_array(void);
 json_t *json_string(const char *value);
 json_t *json_string_nocheck(const char *value);
-json_t *json_integer(int value);
+json_t *json_integer(json_int_t value);
 json_t *json_real(double value);
 json_t *json_true(void);
 json_t *json_false(void);
@@ -62,7 +69,7 @@ json_t *json_null(void);
 static JSON_INLINE
 json_t *json_incref(json_t *json)
 {
-    if(json && json->refcount != (unsigned int)-1)
+    if(json && json->refcount != (size_t)-1)
         ++json->refcount;
     return json;
 }
@@ -73,14 +80,14 @@ void json_delete(json_t *json);
 static JSON_INLINE
 void json_decref(json_t *json)
 {
-    if(json && json->refcount != (unsigned int)-1 && --json->refcount == 0)
+    if(json && json->refcount != (size_t)-1 && --json->refcount == 0)
         json_delete(json);
 }
 
 
 /* getters, setters, manipulation */
 
-unsigned int json_object_size(const json_t *object);
+size_t json_object_size(const json_t *object);
 json_t *json_object_get(const json_t *object, const char *key);
 int json_object_set_new(json_t *object, const char *key, json_t *value);
 int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value);
@@ -112,17 +119,17 @@ int json_object_iter_set(json_t *object, void *iter, json_t *value)
     return json_object_iter_set_new(object, iter, json_incref(value));
 }
 
-unsigned int json_array_size(const json_t *array);
-json_t *json_array_get(const json_t *array, unsigned int index);
-int json_array_set_new(json_t *array, unsigned int index, json_t *value);
+size_t json_array_size(const json_t *array);
+json_t *json_array_get(const json_t *array, size_t index);
+int json_array_set_new(json_t *array, size_t index, json_t *value);
 int json_array_append_new(json_t *array, json_t *value);
-int json_array_insert_new(json_t *array, unsigned int index, json_t *value);
-int json_array_remove(json_t *array, unsigned int index);
+int json_array_insert_new(json_t *array, size_t index, json_t *value);
+int json_array_remove(json_t *array, size_t index);
 int json_array_clear(json_t *array);
 int json_array_extend(json_t *array, json_t *other);
 
 static JSON_INLINE
-int json_array_set(json_t *array, unsigned int index, json_t *value)
+int json_array_set(json_t *array, size_t index, json_t *value)
 {
     return json_array_set_new(array, index, json_incref(value));
 }
@@ -134,19 +141,19 @@ int json_array_append(json_t *array, json_t *value)
 }
 
 static JSON_INLINE
-int json_array_insert(json_t *array, unsigned int index, json_t *value)
+int json_array_insert(json_t *array, size_t index, json_t *value)
 {
     return json_array_insert_new(array, index, json_incref(value));
 }
 
 const char *json_string_value(const json_t *string);
-int json_integer_value(const json_t *integer);
+json_int_t json_integer_value(const json_t *integer);
 double json_real_value(const json_t *real);
 double json_number_value(const json_t *json);
 
 int json_string_set(json_t *string, const char *value);
 int json_string_set_nocheck(json_t *string, const char *value);
-int json_integer_set(json_t *integer, int value);
+int json_integer_set(json_t *integer, json_int_t value);
 int json_real_set(json_t *real, double value);
 
 
@@ -170,19 +177,19 @@ typedef struct {
     int line;
 } json_error_t;
 
-json_t *json_loads(const char *input, json_error_t *error);
-json_t *json_loadf(FILE *input, json_error_t *error);
-json_t *json_load_file(const char *path, json_error_t *error);
+json_t *json_loads(const char *input, size_t flags, json_error_t *error);
+json_t *json_loadf(FILE *input, size_t flags, json_error_t *error);
+json_t *json_load_file(const char *path, size_t flags, json_error_t *error);
 
-#define JSON_INDENT(n)      (n & 0xFF)
-#define JSON_COMPACT        0x100
-#define JSON_ENSURE_ASCII   0x200
-#define JSON_SORT_KEYS      0x400
-#define JSON_PRESERVE_ORDER 0x800
+#define JSON_INDENT(n)      (n & 0x1F)
+#define JSON_COMPACT        0x20
+#define JSON_ENSURE_ASCII   0x40
+#define JSON_SORT_KEYS      0x80
+#define JSON_PRESERVE_ORDER 0x100
 
-char *json_dumps(const json_t *json, unsigned long flags);
-int json_dumpf(const json_t *json, FILE *output, unsigned long flags);
-int json_dump_file(const json_t *json, const char *path, unsigned long flags);
+char *json_dumps(const json_t *json, size_t flags);
+int json_dumpf(const json_t *json, FILE *output, size_t flags);
+int json_dump_file(const json_t *json, const char *path, size_t flags);
 
 #ifdef __cplusplus
 }
diff --git a/src/jansson_config.h.in b/src/jansson_config.h.in
new file mode 100644 (file)
index 0000000..d2a9392
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010 Petri Lehtinen <petri@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ *
+ *
+ * This file specifies a part of the site-specific configuration for
+ * Jansson, namely those things that affect the public API in
+ * jansson.h.
+ *
+ * The configure script copies this file to jansson_config.h and
+ * replaces @var@ substitutions by values that fit your system. If you
+ * cannot run the configure script, you can do the value substitution
+ * by hand.
+ */
+
+#ifndef JANSSON_CONFIG_H
+#define JANSSON_CONFIG_H
+
+/* If your compiler supports the inline keyword in C, JSON_INLINE is
+   defined to `inline', otherwise empty. In C++, the inline is always
+   supported. */
+#ifdef __cplusplus
+#define JSON_INLINE inline
+#else
+#define JSON_INLINE @json_inline@
+#endif
+
+/* If your compiler supports the `long long` type,
+   JSON_INTEGER_IS_LONG_LONG is defined to 1, otherwise to 0. */
+#define JSON_INTEGER_IS_LONG_LONG @json_have_long_long@
+
+#endif
diff --git a/src/jansson_config.h.win32 b/src/jansson_config.h.win32
new file mode 100644 (file)
index 0000000..ffb512f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010 Petri Lehtinen <petri@digip.org>
+ *
+ * Jansson is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ *
+ *
+ * This file specifies a part of the site-specific configuration for
+ * Jansson, namely those things that affect the public API in
+ * jansson.h.
+ *
+ * The configure script copies this file to jansson_config.h and
+ * replaces @var@ substitutions by values that fit your system. If you
+ * cannot run the configure script, you can do the value substitution
+ * by hand.
+ */
+
+#ifndef JANSSON_CONFIG_H
+#define JANSSON_CONFIG_H
+
+/* If your compiler supports the inline keyword in C, JSON_INLINE is
+   defined to `inline', otherwise empty. In C++, the inline is always
+   supported. */
+#ifdef __cplusplus
+#define JSON_INLINE inline
+#else
+#define JSON_INLINE 
+#endif
+
+/* If your compiler supports the `long long` type,
+   JSON_INTEGER_IS_LONG_LONG is defined to 1, otherwise to 0. */
+#define JSON_INTEGER_IS_LONG_LONG 1
+
+#endif
index 55532eb..e9102ba 100644 (file)
 #define container_of(ptr_, type_, member_)  \
     ((type_ *)((char *)ptr_ - offsetof(type_, member_)))
 
+/* On some platforms, max() may already be defined */
+#ifndef max
+#define max(a, b)  ((a) > (b) ? (a) : (b))
+#endif
+
 typedef struct {
     json_t json;
     hashtable_t hashtable;
-    unsigned long serial;
+    size_t serial;
     int visited;
 } json_object_t;
 
 typedef struct {
     json_t json;
-    unsigned int size;
-    unsigned int entries;
+    size_t size;
+    size_t entries;
     json_t **table;
     int visited;
 } json_array_t;
@@ -42,7 +47,7 @@ typedef struct {
 
 typedef struct {
     json_t json;
-    int value;
+    json_int_t value;
 } json_integer_t;
 
 #define json_to_object(json_)  container_of(json_, json_object_t, json)
@@ -52,7 +57,7 @@ typedef struct {
 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
 
 typedef struct {
-    unsigned long serial;
+    size_t serial;
     char key[1];
 } object_key_t;
 
index d49a4da..925a850 100644 (file)
@@ -52,7 +52,7 @@ typedef struct {
     int line, column;
     union {
         char *string;
-        int integer;
+        json_int_t integer;
         double real;
     } value;
 } lex_t;
@@ -401,6 +401,12 @@ out:
     free(lex->value.string);
 }
 
+#if JSON_INTEGER_IS_LONG_LONG
+#define json_strtoint     strtoll
+#else
+#define json_strtoint     strtol
+#endif
+
 static int lex_scan_number(lex_t *lex, char c, json_error_t *error)
 {
     const char *saved_text;
@@ -430,25 +436,26 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error)
     }
 
     if(c != '.' && c != 'E' && c != 'e') {
-        long value;
+        json_int_t value;
 
         lex_unget_unsave(lex, c);
 
         saved_text = strbuffer_value(&lex->saved_text);
-        value = strtol(saved_text, &end, 10);
-        assert(end == saved_text + lex->saved_text.length);
 
-        if((value == LONG_MAX && errno == ERANGE) || value > INT_MAX) {
-            error_set(error, lex, "too big integer");
-            goto out;
-        }
-        else if((value == LONG_MIN && errno == ERANGE) || value < INT_MIN) {
-            error_set(error, lex, "too big negative integer");
+        errno = 0;
+        value = json_strtoint(saved_text, &end, 10);
+        if(errno == ERANGE) {
+            if(value < 0)
+                error_set(error, lex, "too big negative integer");
+            else
+                error_set(error, lex, "too big integer");
             goto out;
         }
 
+        assert(end == saved_text + lex->saved_text.length);
+
         lex->token = TOKEN_INTEGER;
-        lex->value.integer = (int)value;
+        lex->value.integer = value;
         return 0;
     }
 
@@ -804,15 +811,13 @@ static int string_eof(void *data)
     return (stream->data[stream->pos] == '\0');
 }
 
-json_t *json_loads(const char *string, json_error_t *error)
+json_t *json_loads(const char *string, size_t flags, json_error_t *error)
 {
     lex_t lex;
     json_t *result;
+    (void)flags; /* unused */
 
-    string_data_t stream_data = {
-        .data = string,
-        .pos = 0
-    };
+    string_data_t stream_data = {string, 0};
 
     if(lex_init(&lex, string_get, string_eof, (void *)&stream_data))
         return NULL;
@@ -833,10 +838,11 @@ out:
     return result;
 }
 
-json_t *json_loadf(FILE *input, json_error_t *error)
+json_t *json_loadf(FILE *input, size_t flags, json_error_t *error)
 {
     lex_t lex;
     json_t *result;
+    (void)flags; /* unused */
 
     if(lex_init(&lex, (get_func)fgetc, (eof_func)feof, input))
         return NULL;
@@ -857,7 +863,7 @@ out:
     return result;
 }
 
-json_t *json_load_file(const char *path, json_error_t *error)
+json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
 {
     json_t *result;
     FILE *fp;
@@ -872,7 +878,7 @@ json_t *json_load_file(const char *path, json_error_t *error)
         return NULL;
     }
 
-    result = json_loadf(fp, error);
+    result = json_loadf(fp, flags, error);
 
     fclose(fp);
     return result;
index 3496024..4e866bd 100644 (file)
@@ -8,8 +8,8 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
 #include <string.h>
+#include "jansson_private.h"
 #include "strbuffer.h"
-#include "util.h"
 
 #define STRBUFFER_MIN_SIZE  16
 #define STRBUFFER_FACTOR    2
index d0ae6e9..e2d6c59 100644 (file)
--- a/src/utf.h
+++ b/src/utf.h
@@ -8,13 +8,19 @@
 #ifndef UTF_H
 #define UTF_H
 
+#ifdef HAVE_CONFIG_H
 #include <config.h>
+#endif
 
 #ifdef HAVE_INTTYPES_H
 /* inttypes.h includes stdint.h in a standard environment, so there's
 no need to include stdint.h separately. If inttypes.h doesn't define
 int32_t, it's defined in config.h. */
 #include <inttypes.h>
+#else
+#ifdef _WIN32
+typedef int int32_t;
+#endif
 #endif
 
 int utf8_encode(int codepoint, char *buffer, int *size);
diff --git a/src/util.h b/src/util.h
deleted file mode 100644 (file)
index 06a547b..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org>
- *
- * Jansson is free software; you can redistribute it and/or modify
- * it under the terms of the MIT license. See LICENSE for details.
- */
-
-#ifndef UTIL_H
-#define UTIL_H
-
-#define max(a, b)  ((a) > (b) ? (a) : (b))
-
-#endif
index 8e0cfa2..89d7b71 100644 (file)
@@ -7,8 +7,6 @@
 
 #define _GNU_SOURCE
 
-#include <config.h>
-
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include "hashtable.h"
 #include "jansson_private.h"
 #include "utf.h"
-#include "util.h"
 
 
-static inline void json_init(json_t *json, json_type type)
+static JSON_INLINE void json_init(json_t *json, json_type type)
 {
     json->type = type;
     json->refcount = 1;
@@ -35,14 +32,14 @@ static inline void json_init(json_t *json, json_type type)
    an object_key_t instance. */
 #define string_to_key(string)  container_of(string, object_key_t, key)
 
-static unsigned int hash_key(const void *ptr)
+static size_t hash_key(const void *ptr)
 {
     const char *str = ((const object_key_t *)ptr)->key;
 
-    unsigned int hash = 5381;
-    unsigned int c;
+    size_t hash = 5381;
+    size_t c;
 
-    while((c = (unsigned int)*str))
+    while((c = (size_t)*str))
     {
         hash = ((hash << 5) + hash) + c;
         str++;
@@ -88,7 +85,7 @@ static void json_delete_object(json_object_t *object)
     free(object);
 }
 
-unsigned int json_object_size(const json_t *json)
+size_t json_object_size(const json_t *json)
 {
     json_object_t *object;
 
@@ -374,7 +371,7 @@ json_t *json_array(void)
 
 static void json_delete_array(json_array_t *array)
 {
-    unsigned int i;
+    size_t i;
 
     for(i = 0; i < array->entries; i++)
         json_decref(array->table[i]);
@@ -383,7 +380,7 @@ static void json_delete_array(json_array_t *array)
     free(array);
 }
 
-unsigned int json_array_size(const json_t *json)
+size_t json_array_size(const json_t *json)
 {
     if(!json_is_array(json))
         return 0;
@@ -391,7 +388,7 @@ unsigned int json_array_size(const json_t *json)
     return json_to_array(json)->entries;
 }
 
-json_t *json_array_get(const json_t *json, unsigned int index)
+json_t *json_array_get(const json_t *json, size_t index)
 {
     json_array_t *array;
     if(!json_is_array(json))
@@ -404,7 +401,7 @@ json_t *json_array_get(const json_t *json, unsigned int index)
     return array->table[index];
 }
 
-int json_array_set_new(json_t *json, unsigned int index, json_t *value)
+int json_array_set_new(json_t *json, size_t index, json_t *value)
 {
     json_array_t *array;
 
@@ -430,24 +427,24 @@ int json_array_set_new(json_t *json, unsigned int index, json_t *value)
     return 0;
 }
 
-static void array_move(json_array_t *array, unsigned int dest,
-                       unsigned int src, unsigned int count)
+static void array_move(json_array_t *array, size_t dest,
+                       size_t src, size_t count)
 {
     memmove(&array->table[dest], &array->table[src], count * sizeof(json_t *));
 }
 
-static void array_copy(json_t **dest, unsigned int dpos,
-                       json_t **src, unsigned int spos,
-                       unsigned int count)
+static void array_copy(json_t **dest, size_t dpos,
+                       json_t **src, size_t spos,
+                       size_t count)
 {
     memcpy(&dest[dpos], &src[spos], count * sizeof(json_t *));
 }
 
 static json_t **json_array_grow(json_array_t *array,
-                                unsigned int amount,
+                                size_t amount,
                                 int copy)
 {
-    unsigned int new_size;
+    size_t new_size;
     json_t **old_table, **new_table;
 
     if(array->entries + amount <= array->size)
@@ -497,7 +494,7 @@ int json_array_append_new(json_t *json, json_t *value)
     return 0;
 }
 
-int json_array_insert_new(json_t *json, unsigned int index, json_t *value)
+int json_array_insert_new(json_t *json, size_t index, json_t *value)
 {
     json_array_t *array;
     json_t **old_table;
@@ -537,7 +534,7 @@ int json_array_insert_new(json_t *json, unsigned int index, json_t *value)
     return 0;
 }
 
-int json_array_remove(json_t *json, unsigned int index)
+int json_array_remove(json_t *json, size_t index)
 {
     json_array_t *array;
 
@@ -559,7 +556,7 @@ int json_array_remove(json_t *json, unsigned int index)
 int json_array_clear(json_t *json)
 {
     json_array_t *array;
-    unsigned int i;
+    size_t i;
 
     if(!json_is_array(json))
         return -1;
@@ -575,7 +572,7 @@ int json_array_clear(json_t *json)
 int json_array_extend(json_t *json, json_t *other_json)
 {
     json_array_t *array, *other;
-    unsigned int i;
+    size_t i;
 
     if(!json_is_array(json) || !json_is_array(other_json))
         return -1;
@@ -596,7 +593,7 @@ int json_array_extend(json_t *json, json_t *other_json)
 
 static int json_array_equal(json_t *array1, json_t *array2)
 {
-    unsigned int i, size;
+    size_t i, size;
 
     size = json_array_size(array1);
     if(size != json_array_size(array2))
@@ -619,7 +616,7 @@ static int json_array_equal(json_t *array1, json_t *array2)
 static json_t *json_array_copy(json_t *array)
 {
     json_t *result;
-    unsigned int i;
+    size_t i;
 
     result = json_array();
     if(!result)
@@ -634,7 +631,7 @@ static json_t *json_array_copy(json_t *array)
 static json_t *json_array_deep_copy(json_t *array)
 {
     json_t *result;
-    unsigned int i;
+    size_t i;
 
     result = json_array();
     if(!result)
@@ -728,7 +725,7 @@ static json_t *json_string_copy(json_t *string)
 
 /*** integer ***/
 
-json_t *json_integer(int value)
+json_t *json_integer(json_int_t value)
 {
     json_integer_t *integer = malloc(sizeof(json_integer_t));
     if(!integer)
@@ -739,7 +736,7 @@ json_t *json_integer(int value)
     return &integer->json;
 }
 
-int json_integer_value(const json_t *json)
+json_int_t json_integer_value(const json_t *json)
 {
     if(!json_is_integer(json))
         return 0;
@@ -747,7 +744,7 @@ int json_integer_value(const json_t *json)
     return json_to_integer(json)->value;
 }
 
-int json_integer_set(json_t *json, int value)
+int json_integer_set(json_t *json, json_int_t value)
 {
     if(!json_is_integer(json))
         return -1;
@@ -837,30 +834,21 @@ double json_number_value(const json_t *json)
 
 json_t *json_true(void)
 {
-    static json_t the_true = {
-        .type = JSON_TRUE,
-        .refcount = (unsigned int)-1
-    };
+    static json_t the_true = {JSON_TRUE, (size_t)-1};
     return &the_true;
 }
 
 
 json_t *json_false(void)
 {
-    static json_t the_false = {
-        .type = JSON_FALSE,
-        .refcount = (unsigned int)-1
-    };
+    static json_t the_false = {JSON_FALSE, (size_t)-1};
     return &the_false;
 }
 
 
 json_t *json_null(void)
 {
-    static json_t the_null = {
-        .type = JSON_NULL,
-        .refcount = (unsigned int)-1
-    };
+    static json_t the_null = {JSON_NULL, (size_t)-1};
     return &the_null;
 }
 
index 77407e5..cff820b 100644 (file)
@@ -28,7 +28,7 @@ static int getenv_int(const char *name)
 int main(int argc, char *argv[])
 {
     int indent = 0;
-    unsigned int flags = 0;
+    size_t flags = 0;
 
     json_t *json;
     json_error_t error;
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
     if(getenv_int("JSON_SORT_KEYS"))
         flags |= JSON_SORT_KEYS;
 
-    json = json_loadf(stdin, &error);
+    json = json_loadf(stdin, 0, &error);
     if(!json) {
         fprintf(stderr, "%d\n%s\n", error.line, error.text);
         return 1;
index 54c1d28..1c8a066 100644 (file)
@@ -174,9 +174,9 @@ static void test_copy_array(void)
     const char *json_array_text = "[1, \"foo\", 3.141592, {\"foo\": \"bar\"}]";
 
     json_t *array, *copy;
-    unsigned int i;
+    size_t i;
 
-    array = json_loads(json_array_text, NULL);
+    array = json_loads(json_array_text, 0, NULL);
     if(!array)
         fail("unable to parse an array");
 
@@ -203,9 +203,9 @@ static void test_deep_copy_array(void)
     const char *json_array_text = "[1, \"foo\", 3.141592, {\"foo\": \"bar\"}]";
 
     json_t *array, *copy;
-    unsigned int i;
+    size_t i;
 
-    array = json_loads(json_array_text, NULL);
+    array = json_loads(json_array_text, 0, NULL);
     if(!array)
         fail("unable to parse an array");
 
@@ -235,7 +235,7 @@ static void test_copy_object(void)
     json_t *object, *copy;
     void *iter;
 
-    object = json_loads(json_object_text, NULL);
+    object = json_loads(json_object_text, 0, NULL);
     if(!object)
         fail("unable to parse an object");
 
@@ -275,7 +275,7 @@ static void test_deep_copy_object(void)
     json_t *object, *copy;
     void *iter;
 
-    object = json_loads(json_object_text, NULL);
+    object = json_loads(json_object_text, 0, NULL);
     if(!object)
         fail("unable to parse an object");
 
index 111ee26..3b4ec2a 100644 (file)
@@ -167,8 +167,8 @@ static void test_equal_complex()
 "    \"array\": [\"foo\", false, null, 1.234]"
 "}";
 
-    value1 = json_loads(complex_json, NULL);
-    value2 = json_loads(complex_json, NULL);
+    value1 = json_loads(complex_json, 0, NULL);
+    value2 = json_loads(complex_json, 0, NULL);
     if(!value1 || !value2)
         fail("unable to parse JSON");
     if(!json_equal(value1, value2))
index 0934ea8..b022a3a 100644 (file)
@@ -14,7 +14,7 @@ int main()
     json_t *json;
     json_error_t error;
 
-    json = json_load_file("/path/to/nonexistent/file.json", &error);
+    json = json_load_file("/path/to/nonexistent/file.json", 0, &error);
     if(error.line != -1)
         fail("json_load_file returned an invalid line number");
     if(strcmp(error.text, "unable to open /path/to/nonexistent/file.json: No such file or directory") != 0)
index 1769c65..9e1dba3 100644 (file)
@@ -152,33 +152,33 @@ int main()
 
     /* Test reference counting on singletons (true, false, null) */
     value = json_true();
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting true works incorrectly");
     json_decref(value);
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting true works incorrectly");
     json_incref(value);
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting true works incorrectly");
 
     value = json_false();
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting false works incorrectly");
     json_decref(value);
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting false works incorrectly");
     json_incref(value);
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting false works incorrectly");
 
     value = json_null();
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting null works incorrectly");
     json_decref(value);
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting null works incorrectly");
     json_incref(value);
-    if(value->refcount != (unsigned int)-1)
+    if(value->refcount != (size_t)-1)
       fail("refcounting null works incorrectly");
 
     return 0;
index f2366dc..dfa3846 100644 (file)
@@ -1 +1 @@
-[-123123123123123]
\ No newline at end of file
+[-123123123123123123123123123123]
\ No newline at end of file
index a787c2c..3156f10 100644 (file)
@@ -1 +1 @@
-[123123123123123]
\ No newline at end of file
+[123123123123123123123123123123]
\ No newline at end of file