X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=doc%2Fapiref.rst;h=ea38343438553278508bdfe4addaf2220af0fc70;hb=234ee4728124d8d07412d159b45dd10854b6d6d8;hp=903b48c48f9799c5c2642c5c0f8b4a6c788b555e;hpb=251722d499cc2ec0962580f6cf60ed0acdc5330e;p=jansson.git diff --git a/doc/apiref.rst b/doc/apiref.rst index 903b48c..ea38343 100644 --- a/doc/apiref.rst +++ b/doc/apiref.rst @@ -41,6 +41,12 @@ Objects of :ctype:`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. +Unless noted otherwise, all API functions return an error value if an +error occurs. Depending on the function's signature, the error value +is either *NULL* or -1. Invalid arguments or invalid input are +apparent sources for errors. Memory allocation and I/O operations may +also cause errors. + Type ---- @@ -80,8 +86,8 @@ functions: .. cfunction:: int json_typeof(const json_t *json) Return the type of the JSON value (a :ctype:`json_type` cast to - :ctype:`int`). This function is actually implemented as a macro for - speed. + :ctype:`int`). *json* MUST NOT be *NULL*. This function is actually + implemented as a macro for speed. .. cfunction:: json_is_object(const json_t *json) json_is_array(const json_t *json) @@ -121,7 +127,7 @@ The following functions are used to manipulate the reference count. .. cfunction:: json_t *json_incref(json_t *json) - Increment the reference count of *json*. + Increment the reference count of *json*. Returns *json*. .. cfunction:: void json_decref(json_t *json) @@ -259,11 +265,27 @@ A JSON array is an ordered collection of other JSON values. range for *index* is from 0 to the return value of :cfunc:`json_array_size()` minus 1. +.. cfunction:: int json_array_set_new(json_t *array, unsigned int index, json_t *value) + + Like :cfunc:`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) 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) + + Like :cfunc:`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 + Object ====== @@ -288,9 +310,17 @@ Unicode string and the value is any JSON value. .. cfunction:: 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 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. + 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_new(json_t *object, const char *key, json_t *value) + + Like :cfunc:`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_del(json_t *object, const char *key)