forked from organicmaps/organicmaps
[3party][jansson] Updated to 2.2.1
This commit is contained in:
parent
09eaa84faf
commit
2951325da5
46 changed files with 699 additions and 176 deletions
|
@ -1,5 +1,55 @@
|
|||
Version 2.1 (in development)
|
||||
============================
|
||||
Version 2.2.1
|
||||
=============
|
||||
|
||||
Released 2011-10-06
|
||||
|
||||
* Bug fixes:
|
||||
|
||||
- Fix real number encoding and decoding under non-C locales. (#32)
|
||||
|
||||
- Fix identifier decoding under non-UTF-8 locales. (#35)
|
||||
|
||||
- `json_load_file()`: Open the input file in binary mode for maximum
|
||||
compatiblity.
|
||||
|
||||
* Documentation:
|
||||
|
||||
- Clarify the lifecycle of the result of the ``s`` fromat of
|
||||
`json_unpack()`. (#31)
|
||||
|
||||
- Add some portability info. (#36)
|
||||
|
||||
- Little clarifications here and there.
|
||||
|
||||
* Other:
|
||||
|
||||
- Some style fixes, issues detected by static analyzers.
|
||||
|
||||
|
||||
Version 2.2
|
||||
===========
|
||||
|
||||
Released 2011-09-03
|
||||
|
||||
* New features:
|
||||
|
||||
- `json_dump_callback()`: Pass the encoder output to a callback
|
||||
function in chunks.
|
||||
|
||||
* Bug fixes:
|
||||
|
||||
- `json_string_set()`: Check that target is a string and value is
|
||||
not NULL.
|
||||
|
||||
* Other:
|
||||
|
||||
- Documentation typo fixes and clarifications.
|
||||
|
||||
|
||||
Version 2.1
|
||||
===========
|
||||
|
||||
Released 2011-06-10
|
||||
|
||||
* New features:
|
||||
|
||||
|
|
|
@ -216,6 +216,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
|
|
@ -6,12 +6,21 @@
|
|||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `localeconv' function. */
|
||||
#undef HAVE_LOCALECONV
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#undef HAVE_LOCALE_H
|
||||
|
||||
/* Define to 1 if the system has the type `long long int'. */
|
||||
#undef HAVE_LONG_LONG_INT
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `setlocale' function. */
|
||||
#undef HAVE_SETLOCALE
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
|
|
169
3party/jansson/configure
vendored
169
3party/jansson/configure
vendored
|
@ -1,6 +1,6 @@
|
|||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.67 for jansson 2.1.
|
||||
# Generated by GNU Autoconf 2.67 for jansson 2.2.1.
|
||||
#
|
||||
# Report bugs to <petri@digip.org>.
|
||||
#
|
||||
|
@ -701,8 +701,8 @@ MAKEFLAGS=
|
|||
# Identity of this package.
|
||||
PACKAGE_NAME='jansson'
|
||||
PACKAGE_TARNAME='jansson'
|
||||
PACKAGE_VERSION='2.1'
|
||||
PACKAGE_STRING='jansson 2.1'
|
||||
PACKAGE_VERSION='2.2.1'
|
||||
PACKAGE_STRING='jansson 2.2.1'
|
||||
PACKAGE_BUGREPORT='petri@digip.org'
|
||||
PACKAGE_URL=''
|
||||
|
||||
|
@ -747,6 +747,7 @@ ac_subst_vars='am__EXEEXT_FALSE
|
|||
am__EXEEXT_TRUE
|
||||
LTLIBOBJS
|
||||
LIBOBJS
|
||||
json_have_localeconv
|
||||
json_inline
|
||||
json_have_long_long
|
||||
GCC_FALSE
|
||||
|
@ -1418,7 +1419,7 @@ if test "$ac_init_help" = "long"; then
|
|||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures jansson 2.1 to adapt to many kinds of systems.
|
||||
\`configure' configures jansson 2.2.1 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
|
@ -1488,7 +1489,7 @@ fi
|
|||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of jansson 2.1:";;
|
||||
short | recursive ) echo "Configuration of jansson 2.2.1:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
|
@ -1587,7 +1588,7 @@ fi
|
|||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
jansson configure 2.1
|
||||
jansson configure 2.2.1
|
||||
generated by GNU Autoconf 2.67
|
||||
|
||||
Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
|
@ -1862,6 +1863,97 @@ $as_echo "$ac_res" >&6; }
|
|||
|
||||
} # ac_fn_c_check_func
|
||||
|
||||
# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
|
||||
# -------------------------------------------------------
|
||||
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
|
||||
# the include files in INCLUDES and setting the cache variable VAR
|
||||
# accordingly.
|
||||
ac_fn_c_check_header_mongrel ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if eval "test \"\${$3+set}\"" = set; then :
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
|
||||
$as_echo_n "checking for $2... " >&6; }
|
||||
if eval "test \"\${$3+set}\"" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
fi
|
||||
eval ac_res=\$$3
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
|
||||
$as_echo "$ac_res" >&6; }
|
||||
else
|
||||
# Is the header compilable?
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
|
||||
$as_echo_n "checking $2 usability... " >&6; }
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
$4
|
||||
#include <$2>
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
ac_header_compiler=yes
|
||||
else
|
||||
ac_header_compiler=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
|
||||
$as_echo "$ac_header_compiler" >&6; }
|
||||
|
||||
# Is the header present?
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
|
||||
$as_echo_n "checking $2 presence... " >&6; }
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <$2>
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"; then :
|
||||
ac_header_preproc=yes
|
||||
else
|
||||
ac_header_preproc=no
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
|
||||
$as_echo "$ac_header_preproc" >&6; }
|
||||
|
||||
# So? What about this header?
|
||||
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
|
||||
yes:no: )
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
|
||||
$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
|
||||
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
|
||||
;;
|
||||
no:yes:* )
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
|
||||
$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5
|
||||
$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
|
||||
$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5
|
||||
$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
|
||||
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
|
||||
( $as_echo "## ------------------------------ ##
|
||||
## Report this to petri@digip.org ##
|
||||
## ------------------------------ ##"
|
||||
) | sed "s/^/$as_me: WARNING: /" >&2
|
||||
;;
|
||||
esac
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
|
||||
$as_echo_n "checking for $2... " >&6; }
|
||||
if eval "test \"\${$3+set}\"" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
eval "$3=\$ac_header_compiler"
|
||||
fi
|
||||
eval ac_res=\$$3
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
|
||||
$as_echo "$ac_res" >&6; }
|
||||
fi
|
||||
eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
|
||||
|
||||
} # ac_fn_c_check_header_mongrel
|
||||
|
||||
# ac_fn_c_find_intX_t LINENO BITS VAR
|
||||
# -----------------------------------
|
||||
# Finds a signed integer type with width BITS, setting cache variable VAR
|
||||
|
@ -1939,7 +2031,7 @@ cat >config.log <<_ACEOF
|
|||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by jansson $as_me 2.1, which was
|
||||
It was created by jansson $as_me 2.2.1, which was
|
||||
generated by GNU Autoconf 2.67. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
|
@ -2755,7 +2847,7 @@ fi
|
|||
|
||||
# Define the identity of the package.
|
||||
PACKAGE='jansson'
|
||||
VERSION='2.1'
|
||||
VERSION='2.2.1'
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
|
@ -4460,13 +4552,13 @@ if test "${lt_cv_nm_interface+set}" = set; then :
|
|||
else
|
||||
lt_cv_nm_interface="BSD nm"
|
||||
echo "int some_variable = 0;" > conftest.$ac_ext
|
||||
(eval echo "\"\$as_me:4463: $ac_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:4555: $ac_compile\"" >&5)
|
||||
(eval "$ac_compile" 2>conftest.err)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:4466: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval echo "\"\$as_me:4558: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:4469: output\"" >&5)
|
||||
(eval echo "\"\$as_me:4561: output\"" >&5)
|
||||
cat conftest.out >&5
|
||||
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
|
||||
lt_cv_nm_interface="MS dumpbin"
|
||||
|
@ -5672,7 +5764,7 @@ ia64-*-hpux*)
|
|||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 5675 "configure"' > conftest.$ac_ext
|
||||
echo '#line 5767 "configure"' > conftest.$ac_ext
|
||||
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
|
@ -7197,11 +7289,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7200: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7292: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7204: \$? = $ac_status" >&5
|
||||
echo "$as_me:7296: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
|
@ -7536,11 +7628,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7539: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7631: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7543: \$? = $ac_status" >&5
|
||||
echo "$as_me:7635: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
|
@ -7641,11 +7733,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7644: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7736: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7648: \$? = $ac_status" >&5
|
||||
echo "$as_me:7740: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
|
@ -7696,11 +7788,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7699: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7791: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7703: \$? = $ac_status" >&5
|
||||
echo "$as_me:7795: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
|
@ -10080,7 +10172,7 @@ else
|
|||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 10083 "configure"
|
||||
#line 10175 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
|
@ -10176,7 +10268,7 @@ else
|
|||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 10179 "configure"
|
||||
#line 10271 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
|
@ -10415,6 +10507,18 @@ fi
|
|||
# Checks for libraries.
|
||||
|
||||
# Checks for header files.
|
||||
for ac_header in locale.h
|
||||
do :
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "locale.h" "ac_cv_header_locale_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_locale_h" = x""yes; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_LOCALE_H 1
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
ac_fn_c_find_intX_t "$LINENO" "32" "ac_cv_c_int32_t"
|
||||
|
@ -10576,6 +10680,23 @@ esac
|
|||
|
||||
|
||||
# Checks for library functions.
|
||||
for ac_func in setlocale localeconv
|
||||
do :
|
||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
done
|
||||
|
||||
case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in
|
||||
yesyes) json_have_localeconv=1;;
|
||||
*) json_have_localeconv=0;;
|
||||
esac
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files jansson.pc Makefile doc/Makefile src/Makefile src/jansson_config.h test/Makefile test/bin/Makefile test/suites/Makefile test/suites/api/Makefile"
|
||||
|
||||
|
@ -11105,7 +11226,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
|||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by jansson $as_me 2.1, which was
|
||||
This file was extended by jansson $as_me 2.2.1, which was
|
||||
generated by GNU Autoconf 2.67. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
|
@ -11171,7 +11292,7 @@ _ACEOF
|
|||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
jansson config.status 2.1
|
||||
jansson config.status 2.2.1
|
||||
configured by $0, generated by GNU Autoconf 2.67,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
AC_PREREQ([2.60])
|
||||
AC_INIT([jansson], [2.1], [petri@digip.org])
|
||||
AC_INIT([jansson], [2.2.1], [petri@digip.org])
|
||||
|
||||
AM_INIT_AUTOMAKE([1.10 foreign])
|
||||
|
||||
|
@ -14,6 +14,7 @@ AM_CONDITIONAL([GCC], [test x$GCC = xyes])
|
|||
# Checks for libraries.
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([locale.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_TYPE_INT32_T
|
||||
|
@ -34,6 +35,12 @@ esac
|
|||
AC_SUBST([json_inline])
|
||||
|
||||
# Checks for library functions.
|
||||
AC_CHECK_FUNCS([setlocale localeconv])
|
||||
case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in
|
||||
yesyes) json_have_localeconv=1;;
|
||||
*) json_have_localeconv=0;;
|
||||
esac
|
||||
AC_SUBST([json_have_localeconv])
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
jansson.pc
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
EXTRA_DIST = conf.py apiref.rst changes.rst conformance.rst \
|
||||
gettingstarted.rst github_commits.c index.rst tutorial.rst \
|
||||
upgrading.rst ext/refcounting.py
|
||||
gettingstarted.rst github_commits.c index.rst portability.rst \
|
||||
tutorial.rst upgrading.rst ext/refcounting.py
|
||||
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXOPTS = -d _build/doctrees $(SPHINXOPTS_EXTRA)
|
||||
|
|
|
@ -137,6 +137,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
@ -160,8 +161,8 @@ top_build_prefix = @top_build_prefix@
|
|||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
EXTRA_DIST = conf.py apiref.rst changes.rst conformance.rst \
|
||||
gettingstarted.rst github_commits.c index.rst tutorial.rst \
|
||||
upgrading.rst ext/refcounting.py
|
||||
gettingstarted.rst github_commits.c index.rst portability.rst \
|
||||
tutorial.rst upgrading.rst ext/refcounting.py
|
||||
|
||||
SPHINXBUILD = sphinx-build
|
||||
SPHINXOPTS = -d _build/doctrees $(SPHINXOPTS_EXTRA)
|
||||
|
|
|
@ -481,12 +481,13 @@ A JSON array is an ordered collection of other JSON values.
|
|||
|
||||
Removes the element in *array* at position *index*, shifting the
|
||||
elements after *index* one position towards the start of the array.
|
||||
Returns 0 on success and -1 on error.
|
||||
Returns 0 on success and -1 on error. The reference count of the
|
||||
removed value is decremented.
|
||||
|
||||
.. function:: int json_array_clear(json_t *array)
|
||||
|
||||
Removes all elements from *array*. Returns 0 on sucess and -1 on
|
||||
error.
|
||||
error. The reference count of all removed values are decremented.
|
||||
|
||||
.. function:: int json_array_extend(json_t *array, json_t *other_array)
|
||||
|
||||
|
@ -549,13 +550,14 @@ Unicode string and the value is any JSON value.
|
|||
.. 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.
|
||||
|
||||
-1 if *key* was not found. The reference count of the removed value
|
||||
is decremented.
|
||||
|
||||
.. 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.
|
||||
*object* is not a JSON object. The reference count of all removed
|
||||
values are decremented.
|
||||
|
||||
.. function:: int json_object_update(json_t *object, json_t *other)
|
||||
|
||||
|
@ -566,7 +568,7 @@ Unicode string and the value is any JSON value.
|
|||
The following functions implement an iteration protocol for objects,
|
||||
allowing to iterate through all key-value pairs in an object. The
|
||||
items are not returned in any particular order, as this would require
|
||||
sorting due to the internal object representation.
|
||||
sorting due to the internal hashtable implementation.
|
||||
|
||||
.. function:: void *json_object_iter(json_t *object)
|
||||
|
||||
|
@ -701,9 +703,9 @@ 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 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.
|
||||
between 0 and 31 (inclusive), 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.
|
||||
|
||||
``JSON_COMPACT``
|
||||
This flag enables a compact representation, i.e. sets the separator
|
||||
|
@ -763,6 +765,30 @@ is in UTF-8.
|
|||
*path* already exists, it is overwritten. *flags* is described
|
||||
above. Returns 0 on success and -1 on error.
|
||||
|
||||
.. type:: json_dump_callback_t
|
||||
|
||||
A typedef for a function that's called by
|
||||
:func:`json_dump_callback()`::
|
||||
|
||||
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
|
||||
|
||||
*buffer* points to a buffer containing a chunk of output, *size* is
|
||||
the length of the buffer, and *data* is the corresponding
|
||||
:func:`json_dump_callback()` argument passed through.
|
||||
|
||||
On error, the function should return -1 to stop the encoding
|
||||
process. On success, it should return 0.
|
||||
|
||||
.. versionadded:: 2.2
|
||||
|
||||
.. function:: int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags)
|
||||
|
||||
Call *callback* repeatedly, passing a chunk of the JSON
|
||||
representation of *root* each time. *flags* is described above.
|
||||
Returns 0 on success and -1 on error.
|
||||
|
||||
.. versionadded:: 2.2
|
||||
|
||||
|
||||
.. _apiref-decoding:
|
||||
|
||||
|
@ -833,6 +859,16 @@ The following functions perform the actual JSON decoding.
|
|||
filled with information about the error. *flags* is described
|
||||
above.
|
||||
|
||||
This function will start reading the input from whatever position
|
||||
the input file was, without attempting to seek first. If an error
|
||||
occurs, the file position will be left indeterminate. On success,
|
||||
the file position will be at EOF, unless ``JSON_DISABLE_EOF_CHECK``
|
||||
flag was used. In this case, the file position will be at the first
|
||||
character after the last ``]`` or ``}`` in the JSON input. This
|
||||
allows calling :func:`json_loadf()` on the same ``FILE`` object
|
||||
multiple times, if the input consists of consecutive JSON texts,
|
||||
possibly separated by whitespace.
|
||||
|
||||
.. function:: json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
|
||||
|
||||
.. refcounting:: new
|
||||
|
@ -848,14 +884,14 @@ The following functions perform the actual JSON decoding.
|
|||
Building Values
|
||||
===============
|
||||
|
||||
This sectinon describes functions that help to create, or *pack*,
|
||||
This section describes functions that help to create, or *pack*,
|
||||
complex JSON values, especially nested objects and arrays. Value
|
||||
building is based on a *format string* that is used to tell the
|
||||
functions about the expected arguments.
|
||||
|
||||
For example, the format string ``"i"`` specifies a single integer
|
||||
value, while the format string ``"[ssb]"`` or the equivalent ``"[s, s,
|
||||
b]"`` specifies an array value with two integers and a boolean as its
|
||||
b]"`` specifies an array value with two strings and a boolean as its
|
||||
items::
|
||||
|
||||
/* Create the JSON integer 42 */
|
||||
|
@ -890,7 +926,7 @@ denotes the C type that is expected as the corresponding argument.
|
|||
``o`` (any value) [json_t \*]
|
||||
Output any given JSON value as-is. If the value is added to an
|
||||
array or object, the reference to the value passed to ``o`` is
|
||||
stealed by the container.
|
||||
stolen by the container.
|
||||
|
||||
``O`` (any value) [json_t \*]
|
||||
Like ``o``, but the argument's reference count is incremented.
|
||||
|
@ -940,10 +976,10 @@ More examples::
|
|||
json_pack("{}");
|
||||
|
||||
/* Build the JSON object {"foo": 42, "bar": 7} */
|
||||
json_pack("{sisb}", "foo", 42, "bar", 7);
|
||||
json_pack("{sisi}", "foo", 42, "bar", 7);
|
||||
|
||||
/* Like above, ':', ',' and whitespace are ignored */
|
||||
json_pack("{s:i, s:b}", "foo", 42, "bar", 7);
|
||||
json_pack("{s:i, s:i}", "foo", 42, "bar", 7);
|
||||
|
||||
/* Build the JSON array [[1, 2], {"cool": true}] */
|
||||
json_pack("[[i,i],{s:b]]", 1, 2, "cool", 1);
|
||||
|
@ -971,7 +1007,9 @@ type whose address should be passed.
|
|||
|
||||
``s`` (string) [const char \*]
|
||||
Convert a JSON string to a pointer to a NULL terminated UTF-8
|
||||
string.
|
||||
string. The resulting string is extracted by using
|
||||
:func:`json_string_value()` internally, so it exists as long as
|
||||
there are still references to the corresponding JSON string.
|
||||
|
||||
``n`` (null)
|
||||
Expect a JSON null value. Nothing is extracted.
|
||||
|
@ -1045,6 +1083,20 @@ The following functions compose the parsing and validation API:
|
|||
behaviour of the unpacker, see below for the flags. Returns 0 on
|
||||
success and -1 on failure.
|
||||
|
||||
.. note::
|
||||
|
||||
The first argument of all unpack functions is ``json_t *root``
|
||||
instead of ``const json_t *root``, because the use of ``O`` format
|
||||
character causes the reference count of ``root``, or some value
|
||||
reachable from ``root``, to be increased. Furthermore, the ``o``
|
||||
format character may be used to extract a value as-is, which allows
|
||||
modifying the structure or contents of a value reachable from
|
||||
``root``.
|
||||
|
||||
If the ``O`` and ``o`` format character are not used, it's
|
||||
perfectly safe to cast a ``const json_t *`` variable to plain
|
||||
``json_t *`` when used with these functions.
|
||||
|
||||
The following unpacking flags are available:
|
||||
|
||||
``JSON_STRICT``
|
||||
|
@ -1149,6 +1201,8 @@ copied in a recursive fashion.
|
|||
Returns a deep copy of *value*, or *NULL* on error.
|
||||
|
||||
|
||||
.. _apiref-custom-memory-allocation:
|
||||
|
||||
Custom Memory Allocation
|
||||
========================
|
||||
|
||||
|
@ -1217,5 +1271,5 @@ JSON structures by zeroing all memory when freed::
|
|||
For more information about the issues of storing sensitive data in
|
||||
memory, see
|
||||
http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/protect-secrets.html.
|
||||
The page also examplains the :func:`guaranteed_memset()` function used
|
||||
The page also explains the :func:`guaranteed_memset()` function used
|
||||
in the example and gives a sample implementation for it.
|
||||
|
|
|
@ -48,9 +48,9 @@ copyright = u'2009-2011, Petri Lehtinen'
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '2.1'
|
||||
version = '2.2.1'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '2.1'
|
||||
release = version
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
|
@ -5,8 +5,7 @@ RFC Conformance
|
|||
***************
|
||||
|
||||
JSON is specified in :rfc:`4627`, *"The application/json Media Type
|
||||
for JavaScript Object Notation (JSON)"*. This chapter discusses
|
||||
Jansson's conformance to this specification.
|
||||
for JavaScript Object Notation (JSON)"*.
|
||||
|
||||
Character Encoding
|
||||
==================
|
||||
|
|
|
@ -22,6 +22,11 @@ data. Its main features and design principles are:
|
|||
Jansson is licensed under the `MIT license`_; see LICENSE in the
|
||||
source distribution for details.
|
||||
|
||||
Jansson is used in production and its API is stable. It works on
|
||||
numerous platforms, including numerous Unix like systems and Windows.
|
||||
It's suitable for use on any system, including desktop, server, and
|
||||
small embedded systems.
|
||||
|
||||
|
||||
.. _`MIT license`: http://www.opensource.org/licenses/mit-license.php
|
||||
.. _Jansson: http://www.digip.org/jansson/
|
||||
|
@ -36,6 +41,7 @@ Contents
|
|||
upgrading
|
||||
tutorial
|
||||
conformance
|
||||
portability
|
||||
apiref
|
||||
changes
|
||||
|
||||
|
|
42
3party/jansson/doc/portability.rst
Normal file
42
3party/jansson/doc/portability.rst
Normal file
|
@ -0,0 +1,42 @@
|
|||
***********
|
||||
Portability
|
||||
***********
|
||||
|
||||
Thread safety
|
||||
-------------
|
||||
|
||||
Jansson is thread safe and has no mutable global state. The only
|
||||
exception are the memory allocation functions, that should be set at
|
||||
most once, and only on program startup. See
|
||||
:ref:`apiref-custom-memory-allocation`.
|
||||
|
||||
There's no locking performed inside Jansson's code, so a multithreaded
|
||||
program must perform its own locking if JSON values are shared by
|
||||
multiple threads. Jansson's reference counting semantics may make this
|
||||
a bit harder than it seems, as it's possible to have a reference to a
|
||||
value that's also stored inside a list or object. Modifying the
|
||||
container (adding or removing values) may trigger concurrent access to
|
||||
such values, as containers manage the reference count of their
|
||||
contained values. Bugs involving concurrent incrementing or
|
||||
decrementing of deference counts may be hard to track.
|
||||
|
||||
Locale
|
||||
------
|
||||
|
||||
Jansson works fine under any locale.
|
||||
|
||||
However, if the host program is multithreaded and uses ``setlocale()``
|
||||
to switch the locale in one thread while Jansson is currently encoding
|
||||
or decoding JSON data in another thread, the result may be wrong or
|
||||
the program may even crash.
|
||||
|
||||
Jansson uses locale specific functions for certain string conversions
|
||||
in the encoder and decoder, and then converts the locale specific
|
||||
values to/from the JSON representation. This fails if the locale
|
||||
changes between the string conversion and the locale-to-JSON
|
||||
conversion. This can only happen in multithreaded programs that use
|
||||
``setlocale()``, because ``setlocale()`` switches the locale for all
|
||||
running threads, not only the thread that calls ``setlocale()``.
|
||||
|
||||
If your program uses ``setlocale()`` as described above, consider
|
||||
using the thread-safe ``uselocale()`` instead.
|
|
@ -15,6 +15,7 @@ SOURCES += \
|
|||
src/value.c \
|
||||
src/memory.c \
|
||||
src/error.c \
|
||||
src/strconv.c \
|
||||
|
||||
HEADERS += \
|
||||
myjansson.hpp \
|
||||
|
|
|
@ -12,12 +12,13 @@ libjansson_la_SOURCES = \
|
|||
pack_unpack.c \
|
||||
strbuffer.c \
|
||||
strbuffer.h \
|
||||
strconv.c \
|
||||
utf.c \
|
||||
utf.h \
|
||||
value.c
|
||||
libjansson_la_LDFLAGS = \
|
||||
-export-symbols-regex '^json_' \
|
||||
-version-info 5:0:1
|
||||
-version-info 6:1:2
|
||||
|
||||
if GCC
|
||||
# These flags are gcc specific
|
||||
|
|
|
@ -71,7 +71,8 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
|
|||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libjansson_la_LIBADD =
|
||||
am_libjansson_la_OBJECTS = dump.lo error.lo hashtable.lo load.lo \
|
||||
memory.lo pack_unpack.lo strbuffer.lo utf.lo value.lo
|
||||
memory.lo pack_unpack.lo strbuffer.lo strconv.lo utf.lo \
|
||||
value.lo
|
||||
libjansson_la_OBJECTS = $(am_libjansson_la_OBJECTS)
|
||||
libjansson_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
|
@ -186,6 +187,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
@ -221,13 +223,14 @@ libjansson_la_SOURCES = \
|
|||
pack_unpack.c \
|
||||
strbuffer.c \
|
||||
strbuffer.h \
|
||||
strconv.c \
|
||||
utf.c \
|
||||
utf.h \
|
||||
value.c
|
||||
|
||||
libjansson_la_LDFLAGS = \
|
||||
-export-symbols-regex '^json_' \
|
||||
-version-info 5:0:1
|
||||
-version-info 6:1:2
|
||||
|
||||
|
||||
# These flags are gcc specific
|
||||
|
@ -315,6 +318,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pack_unpack.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strbuffer.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strconv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utf.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/value.Plo@am__quote@
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#define MAX_INTEGER_STR_LENGTH 100
|
||||
#define MAX_REAL_STR_LENGTH 100
|
||||
|
||||
typedef int (*dump_func)(const char *buffer, int size, void *data);
|
||||
|
||||
struct string
|
||||
{
|
||||
char *buffer;
|
||||
|
@ -28,12 +26,12 @@ struct string
|
|||
int size;
|
||||
};
|
||||
|
||||
static int dump_to_strbuffer(const char *buffer, int size, void *data)
|
||||
static int dump_to_strbuffer(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
|
||||
}
|
||||
|
||||
static int dump_to_file(const char *buffer, int size, void *data)
|
||||
static int dump_to_file(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
FILE *dest = (FILE *)data;
|
||||
if(fwrite(buffer, size, 1, dest) != 1)
|
||||
|
@ -44,7 +42,7 @@ static int dump_to_file(const char *buffer, int size, void *data)
|
|||
/* 32 spaces (the maximum indentation size) */
|
||||
static char whitespace[] = " ";
|
||||
|
||||
static int dump_indent(size_t flags, int depth, int space, dump_func dump, void *data)
|
||||
static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump, void *data)
|
||||
{
|
||||
if(JSON_INDENT(flags) > 0)
|
||||
{
|
||||
|
@ -66,7 +64,7 @@ static int dump_indent(size_t flags, int depth, int space, dump_func dump, void
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int dump_string(const char *str, int ascii, dump_func dump, void *data)
|
||||
static int dump_string(const char *str, int ascii, json_dump_callback_t dump, void *data)
|
||||
{
|
||||
const char *pos, *end;
|
||||
int32_t codepoint;
|
||||
|
@ -166,7 +164,7 @@ static int object_key_compare_serials(const void *key1, const void *key2)
|
|||
}
|
||||
|
||||
static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
dump_func dump, void *data)
|
||||
json_dump_callback_t dump, void *data)
|
||||
{
|
||||
int ascii = flags & JSON_ENSURE_ASCII ? 1 : 0;
|
||||
|
||||
|
@ -198,26 +196,12 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||
{
|
||||
char buffer[MAX_REAL_STR_LENGTH];
|
||||
int size;
|
||||
double value = json_real_value(json);
|
||||
|
||||
size = snprintf(buffer, MAX_REAL_STR_LENGTH, "%.17g",
|
||||
json_real_value(json));
|
||||
if(size >= MAX_REAL_STR_LENGTH)
|
||||
size = jsonp_dtostr(buffer, MAX_REAL_STR_LENGTH, value);
|
||||
if(size < 0)
|
||||
return -1;
|
||||
|
||||
/* Make sure there's a dot or 'e' in the output. Otherwise
|
||||
a real is converted to an integer when decoding */
|
||||
if(strchr(buffer, '.') == NULL &&
|
||||
strchr(buffer, 'e') == NULL)
|
||||
{
|
||||
if(size + 2 >= MAX_REAL_STR_LENGTH) {
|
||||
/* No space to append ".0" */
|
||||
return -1;
|
||||
}
|
||||
buffer[size] = '.';
|
||||
buffer[size + 1] = '0';
|
||||
size += 2;
|
||||
}
|
||||
|
||||
return dump(buffer, size, data);
|
||||
}
|
||||
|
||||
|
@ -415,39 +399,26 @@ static int do_dump(const json_t *json, size_t flags, int depth,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
char *json_dumps(const json_t *json, size_t flags)
|
||||
{
|
||||
strbuffer_t strbuff;
|
||||
char *result;
|
||||
|
||||
if(!(flags & JSON_ENCODE_ANY)) {
|
||||
if(!json_is_array(json) && !json_is_object(json))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strbuffer_init(&strbuff))
|
||||
return NULL;
|
||||
|
||||
if(do_dump(json, flags, 0, dump_to_strbuffer, (void *)&strbuff)) {
|
||||
strbuffer_close(&strbuff);
|
||||
return NULL;
|
||||
}
|
||||
if(json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags))
|
||||
result = NULL;
|
||||
else
|
||||
result = jsonp_strdup(strbuffer_value(&strbuff));
|
||||
|
||||
result = jsonp_strdup(strbuffer_value(&strbuff));
|
||||
strbuffer_close(&strbuff);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int json_dumpf(const json_t *json, FILE *output, size_t flags)
|
||||
{
|
||||
if(!(flags & JSON_ENCODE_ANY)) {
|
||||
if(!json_is_array(json) && !json_is_object(json))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return do_dump(json, flags, 0, dump_to_file, (void *)output);
|
||||
return json_dump_callback(json, dump_to_file, (void *)output, flags);
|
||||
}
|
||||
|
||||
int json_dump_file(const json_t *json, const char *path, size_t flags)
|
||||
|
@ -463,3 +434,13 @@ int json_dump_file(const json_t *json, const char *path, size_t flags)
|
|||
fclose(output);
|
||||
return result;
|
||||
}
|
||||
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags)
|
||||
{
|
||||
if(!(flags & JSON_ENCODE_ANY)) {
|
||||
if(!json_is_array(json) && !json_is_object(json))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return do_dump(json, flags, 0, callback, data);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ static size_t primes[] = {
|
|||
12582917, 25165843, 50331653, 100663319, 201326611, 402653189,
|
||||
805306457, 1610612741
|
||||
};
|
||||
static const size_t num_primes = sizeof(primes) / sizeof(size_t);
|
||||
|
||||
static JSON_INLINE size_t num_buckets(hashtable_t *hashtable)
|
||||
{
|
||||
|
|
|
@ -21,11 +21,11 @@ extern "C" {
|
|||
/* version */
|
||||
|
||||
#define JANSSON_MAJOR_VERSION 2
|
||||
#define JANSSON_MINOR_VERSION 1
|
||||
#define JANSSON_MICRO_VERSION 0
|
||||
#define JANSSON_MINOR_VERSION 2
|
||||
#define JANSSON_MICRO_VERSION 1
|
||||
|
||||
/* Micro version is omitted if it's 0 */
|
||||
#define JANSSON_VERSION "2.1"
|
||||
#define JANSSON_VERSION "2.2.1"
|
||||
|
||||
/* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this
|
||||
for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */
|
||||
|
@ -234,10 +234,12 @@ json_t *json_load_file(const char *path, size_t flags, json_error_t *error);
|
|||
#define JSON_PRESERVE_ORDER 0x100
|
||||
#define JSON_ENCODE_ANY 0x200
|
||||
|
||||
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
|
||||
|
||||
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);
|
||||
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags);
|
||||
|
||||
/* custom memory allocation */
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#ifndef JANSSON_CONFIG_H
|
||||
#define JANSSON_CONFIG_H
|
||||
|
||||
#include "../../../std/target_os.hpp"
|
||||
|
||||
/* If your compiler supports the inline keyword in C, JSON_INLINE is
|
||||
defined to `inline', otherwise empty. In C++, the inline is always
|
||||
supported. */
|
||||
|
@ -38,5 +40,12 @@
|
|||
#ifdef _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
/* If locale.h and localeconv() are available, define to 1,
|
||||
otherwise to 0. */
|
||||
#ifdef OMIM_OS_ANDROID
|
||||
#define JSON_HAVE_LOCALECONV 0
|
||||
#else
|
||||
#define JSON_HAVE_LOCALECONV 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,4 +31,8 @@
|
|||
JSON_INTEGER_IS_LONG_LONG is defined to 1, otherwise to 0. */
|
||||
#define JSON_INTEGER_IS_LONG_LONG @json_have_long_long@
|
||||
|
||||
/* If locale.h and localeconv() are available, define to 1,
|
||||
otherwise to 0. */
|
||||
#define JSON_HAVE_LOCALECONV @json_have_localeconv@
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <stddef.h>
|
||||
#include "jansson.h"
|
||||
#include "hashtable.h"
|
||||
#include "strbuffer.h"
|
||||
|
||||
#define container_of(ptr_, type_, member_) \
|
||||
((type_ *)((char *)ptr_ - offsetof(type_, member_)))
|
||||
|
@ -83,6 +84,10 @@ void jsonp_error_set(json_error_t *error, int line, int column,
|
|||
void jsonp_error_vset(json_error_t *error, int line, int column,
|
||||
size_t position, const char *msg, va_list ap);
|
||||
|
||||
/* Locale independent string<->double conversions */
|
||||
int jsonp_strtod(strbuffer_t *strbuffer, double *out);
|
||||
int jsonp_dtostr(char *buffer, size_t size, double value);
|
||||
|
||||
/* Wrappers for custom memory functions */
|
||||
void* jsonp_malloc(size_t size);
|
||||
void jsonp_free(void *ptr);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
@ -32,6 +31,14 @@
|
|||
#define TOKEN_FALSE 260
|
||||
#define TOKEN_NULL 261
|
||||
|
||||
/* Locale independent versions of isxxx() functions */
|
||||
#define l_isupper(c) ('A' <= c && c <= 'Z')
|
||||
#define l_islower(c) ('a' <= c && c <= 'z')
|
||||
#define l_isalpha(c) (l_isupper(c) || l_islower(c))
|
||||
#define l_isdigit(c) ('0' <= c && c <= '9')
|
||||
#define l_isxdigit(c) \
|
||||
(l_isdigit(c) || 'A' <= c || c <= 'F' || 'a' <= c || c <= 'f')
|
||||
|
||||
/* Read one byte from stream, convert to unsigned char, then int, and
|
||||
return. return EOF on end of file. This corresponds to the
|
||||
behaviour of fgetc(). */
|
||||
|
@ -69,6 +76,7 @@ static void error_set(json_error_t *error, const lex_t *lex,
|
|||
{
|
||||
va_list ap;
|
||||
char msg_text[JSON_ERROR_TEXT_LENGTH];
|
||||
char msg_with_context[JSON_ERROR_TEXT_LENGTH];
|
||||
|
||||
int line = -1, col = -1;
|
||||
size_t pos = 0;
|
||||
|
@ -84,7 +92,6 @@ static void error_set(json_error_t *error, const lex_t *lex,
|
|||
if(lex)
|
||||
{
|
||||
const char *saved_text = strbuffer_value(&lex->saved_text);
|
||||
char msg_with_context[JSON_ERROR_TEXT_LENGTH];
|
||||
|
||||
line = lex->stream.line;
|
||||
col = lex->stream.column;
|
||||
|
@ -268,11 +275,11 @@ static int32_t decode_unicode_escape(const char *str)
|
|||
for(i = 1; i <= 4; i++) {
|
||||
char c = str[i];
|
||||
value <<= 4;
|
||||
if(isdigit(c))
|
||||
if(l_isdigit(c))
|
||||
value += c - '0';
|
||||
else if(islower(c))
|
||||
else if(l_islower(c))
|
||||
value += c - 'a' + 10;
|
||||
else if(isupper(c))
|
||||
else if(l_isupper(c))
|
||||
value += c - 'A' + 10;
|
||||
else
|
||||
assert(0);
|
||||
|
@ -317,7 +324,7 @@ static void lex_scan_string(lex_t *lex, json_error_t *error)
|
|||
if(c == 'u') {
|
||||
c = lex_get_save(lex, error);
|
||||
for(i = 0; i < 4; i++) {
|
||||
if(!isxdigit(c)) {
|
||||
if(!l_isxdigit(c)) {
|
||||
error_set(error, lex, "invalid escape");
|
||||
goto out;
|
||||
}
|
||||
|
@ -455,14 +462,14 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
|
|||
|
||||
if(c == '0') {
|
||||
c = lex_get_save(lex, error);
|
||||
if(isdigit(c)) {
|
||||
if(l_isdigit(c)) {
|
||||
lex_unget_unsave(lex, c);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
else if(isdigit(c)) {
|
||||
else if(l_isdigit(c)) {
|
||||
c = lex_get_save(lex, error);
|
||||
while(isdigit(c))
|
||||
while(l_isdigit(c))
|
||||
c = lex_get_save(lex, error);
|
||||
}
|
||||
else {
|
||||
|
@ -496,14 +503,14 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
|
|||
|
||||
if(c == '.') {
|
||||
c = lex_get(lex, error);
|
||||
if(!isdigit(c)) {
|
||||
if(!l_isdigit(c)) {
|
||||
lex_unget(lex, c);
|
||||
goto out;
|
||||
}
|
||||
lex_save(lex, c);
|
||||
|
||||
c = lex_get_save(lex, error);
|
||||
while(isdigit(c))
|
||||
while(l_isdigit(c))
|
||||
c = lex_get_save(lex, error);
|
||||
}
|
||||
|
||||
|
@ -512,24 +519,19 @@ static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
|
|||
if(c == '+' || c == '-')
|
||||
c = lex_get_save(lex, error);
|
||||
|
||||
if(!isdigit(c)) {
|
||||
if(!l_isdigit(c)) {
|
||||
lex_unget_unsave(lex, c);
|
||||
goto out;
|
||||
}
|
||||
|
||||
c = lex_get_save(lex, error);
|
||||
while(isdigit(c))
|
||||
while(l_isdigit(c))
|
||||
c = lex_get_save(lex, error);
|
||||
}
|
||||
|
||||
lex_unget_unsave(lex, c);
|
||||
|
||||
saved_text = strbuffer_value(&lex->saved_text);
|
||||
errno = 0;
|
||||
value = strtod(saved_text, &end);
|
||||
assert(end == saved_text + lex->saved_text.length);
|
||||
|
||||
if(errno == ERANGE && value != 0) {
|
||||
if(jsonp_strtod(&lex->saved_text, &value)) {
|
||||
error_set(error, lex, "real number overflow");
|
||||
goto out;
|
||||
}
|
||||
|
@ -575,17 +577,17 @@ static int lex_scan(lex_t *lex, json_error_t *error)
|
|||
else if(c == '"')
|
||||
lex_scan_string(lex, error);
|
||||
|
||||
else if(isdigit(c) || c == '-') {
|
||||
else if(l_isdigit(c) || c == '-') {
|
||||
if(lex_scan_number(lex, c, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
else if(isupper(c) || islower(c)) {
|
||||
else if(l_isalpha(c)) {
|
||||
/* eat up the whole identifier for clearer error messages */
|
||||
const char *saved_text;
|
||||
|
||||
c = lex_get_save(lex, error);
|
||||
while(isupper(c) || islower(c))
|
||||
while(l_isalpha(c))
|
||||
c = lex_get_save(lex, error);
|
||||
lex_unget_unsave(lex, c);
|
||||
|
||||
|
@ -945,7 +947,7 @@ json_t *json_load_file(const char *path, size_t flags, json_error_t *error)
|
|||
|
||||
jsonp_error_init(error, path);
|
||||
|
||||
fp = fopen(path, "r");
|
||||
fp = fopen(path, "rb");
|
||||
if(!fp)
|
||||
{
|
||||
error_set(error, NULL, "unable to open %s: %s",
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#define STRBUFFER_MIN_SIZE 16
|
||||
#define STRBUFFER_FACTOR 2
|
||||
#define STRBUFFER_SIZE_MAX ((size_t)-1)
|
||||
|
||||
int strbuffer_init(strbuffer_t *strbuff)
|
||||
{
|
||||
|
@ -64,13 +65,19 @@ int strbuffer_append_byte(strbuffer_t *strbuff, char byte)
|
|||
return strbuffer_append_bytes(strbuff, &byte, 1);
|
||||
}
|
||||
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size)
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
|
||||
{
|
||||
if(strbuff->length + size >= strbuff->size)
|
||||
if(size >= strbuff->size - strbuff->length)
|
||||
{
|
||||
size_t new_size;
|
||||
char *new_value;
|
||||
|
||||
/* avoid integer overflow */
|
||||
if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR
|
||||
|| size > STRBUFFER_SIZE_MAX - 1
|
||||
|| strbuff->length > STRBUFFER_SIZE_MAX - 1 - size)
|
||||
return -1;
|
||||
|
||||
new_size = max(strbuff->size * STRBUFFER_FACTOR,
|
||||
strbuff->length + size + 1);
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
typedef struct {
|
||||
char *value;
|
||||
int length; /* bytes used */
|
||||
int size; /* bytes allocated */
|
||||
size_t length; /* bytes used */
|
||||
size_t size; /* bytes allocated */
|
||||
} strbuffer_t;
|
||||
|
||||
int strbuffer_init(strbuffer_t *strbuff);
|
||||
|
@ -24,7 +24,7 @@ char *strbuffer_steal_value(strbuffer_t *strbuff);
|
|||
|
||||
int strbuffer_append(strbuffer_t *strbuff, const char *string);
|
||||
int strbuffer_append_byte(strbuffer_t *strbuff, char byte);
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size);
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size);
|
||||
|
||||
char strbuffer_pop(strbuffer_t *strbuff);
|
||||
|
||||
|
|
108
3party/jansson/src/strconv.c
Normal file
108
3party/jansson/src/strconv.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "jansson_private.h"
|
||||
#include "strbuffer.h"
|
||||
|
||||
#if JSON_HAVE_LOCALECONV
|
||||
#include <locale.h>
|
||||
|
||||
/*
|
||||
- This code assumes that the decimal separator is exactly one
|
||||
character.
|
||||
|
||||
- If setlocale() is called by another thread between the call to
|
||||
localeconv() and the call to sprintf() or strtod(), the result may
|
||||
be wrong. setlocale() is not thread-safe and should not be used
|
||||
this way. Multi-threaded programs should use uselocale() instead.
|
||||
*/
|
||||
|
||||
static void to_locale(strbuffer_t *strbuffer)
|
||||
{
|
||||
const char *point;
|
||||
char *pos;
|
||||
|
||||
point = localeconv()->decimal_point;
|
||||
if(*point == '.') {
|
||||
/* No conversion needed */
|
||||
return;
|
||||
}
|
||||
|
||||
pos = strchr(strbuffer->value, '.');
|
||||
if(pos)
|
||||
*pos = *point;
|
||||
}
|
||||
|
||||
static void from_locale(char *buffer)
|
||||
{
|
||||
const char *point;
|
||||
char *pos;
|
||||
|
||||
point = localeconv()->decimal_point;
|
||||
if(*point == '.') {
|
||||
/* No conversion needed */
|
||||
return;
|
||||
}
|
||||
|
||||
pos = strchr(buffer, *point);
|
||||
if(pos)
|
||||
*pos = '.';
|
||||
}
|
||||
#endif
|
||||
|
||||
int jsonp_strtod(strbuffer_t *strbuffer, double *out)
|
||||
{
|
||||
double value;
|
||||
char *end;
|
||||
|
||||
#if JSON_HAVE_LOCALECONV
|
||||
to_locale(strbuffer);
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
value = strtod(strbuffer->value, &end);
|
||||
assert(end == strbuffer->value + strbuffer->length);
|
||||
|
||||
if(errno == ERANGE && value != 0) {
|
||||
/* Overflow */
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jsonp_dtostr(char *buffer, size_t size, double value)
|
||||
{
|
||||
int ret;
|
||||
size_t length;
|
||||
|
||||
ret = snprintf(buffer, size, "%.17g", value);
|
||||
if(ret < 0)
|
||||
return -1;
|
||||
|
||||
length = (size_t)ret;
|
||||
if(length >= size)
|
||||
return -1;
|
||||
|
||||
#if JSON_HAVE_LOCALECONV
|
||||
from_locale(buffer);
|
||||
#endif
|
||||
|
||||
/* Make sure there's a dot or 'e' in the output. Otherwise
|
||||
a real is converted to an integer when decoding */
|
||||
if(strchr(buffer, '.') == NULL &&
|
||||
strchr(buffer, 'e') == NULL)
|
||||
{
|
||||
if(length + 2 >= size) {
|
||||
/* No space to append ".0" */
|
||||
return -1;
|
||||
}
|
||||
buffer[length] = '.';
|
||||
buffer[length + 1] = '0';
|
||||
length += 2;
|
||||
}
|
||||
|
||||
return (int)length;
|
||||
}
|
|
@ -703,6 +703,9 @@ int json_string_set_nocheck(json_t *json, const char *value)
|
|||
char *dup;
|
||||
json_string_t *string;
|
||||
|
||||
if(!json_is_string(json) || !value)
|
||||
return -1;
|
||||
|
||||
dup = jsonp_strdup(value);
|
||||
if(!dup)
|
||||
return -1;
|
||||
|
|
|
@ -179,6 +179,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
|
|
@ -157,6 +157,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
|
|
@ -5,12 +5,20 @@
|
|||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
static int getenv_int(const char *name)
|
||||
{
|
||||
char *value, *end;
|
||||
|
@ -55,6 +63,10 @@ int main(int argc, char *argv[])
|
|||
json_t *json;
|
||||
json_error_t error;
|
||||
|
||||
#if HAVE_SETLOCALE
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
|
||||
if(argc != 1) {
|
||||
fprintf(stderr, "usage: %s\n", argv[0]);
|
||||
return 2;
|
||||
|
|
|
@ -177,6 +177,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
|
|
@ -4,6 +4,7 @@ check_PROGRAMS = \
|
|||
test_array \
|
||||
test_copy \
|
||||
test_dump \
|
||||
test_dump_callback \
|
||||
test_equal \
|
||||
test_load \
|
||||
test_loadb \
|
||||
|
@ -17,6 +18,7 @@ check_PROGRAMS = \
|
|||
test_array_SOURCES = test_array.c util.h
|
||||
test_copy_SOURCES = test_copy.c util.h
|
||||
test_dump_SOURCES = test_dump.c util.h
|
||||
test_dump_callback_SOURCES = test_dump_callback.c util.h
|
||||
test_load_SOURCES = test_load.c util.h
|
||||
test_loadb_SOURCES = test_loadb.c util.h
|
||||
test_memory_funcs_SOURCES = test_memory_funcs.c util.h
|
||||
|
|
|
@ -34,10 +34,11 @@ POST_UNINSTALL = :
|
|||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
check_PROGRAMS = test_array$(EXEEXT) test_copy$(EXEEXT) \
|
||||
test_dump$(EXEEXT) test_equal$(EXEEXT) test_load$(EXEEXT) \
|
||||
test_loadb$(EXEEXT) test_memory_funcs$(EXEEXT) \
|
||||
test_number$(EXEEXT) test_object$(EXEEXT) test_pack$(EXEEXT) \
|
||||
test_simple$(EXEEXT) test_unpack$(EXEEXT)
|
||||
test_dump$(EXEEXT) test_dump_callback$(EXEEXT) \
|
||||
test_equal$(EXEEXT) test_load$(EXEEXT) test_loadb$(EXEEXT) \
|
||||
test_memory_funcs$(EXEEXT) test_number$(EXEEXT) \
|
||||
test_object$(EXEEXT) test_pack$(EXEEXT) test_simple$(EXEEXT) \
|
||||
test_unpack$(EXEEXT)
|
||||
subdir = test/suites/api
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
|
@ -60,6 +61,10 @@ am_test_dump_OBJECTS = test_dump.$(OBJEXT)
|
|||
test_dump_OBJECTS = $(am_test_dump_OBJECTS)
|
||||
test_dump_LDADD = $(LDADD)
|
||||
test_dump_DEPENDENCIES = $(top_builddir)/src/libjansson.la
|
||||
am_test_dump_callback_OBJECTS = test_dump_callback.$(OBJEXT)
|
||||
test_dump_callback_OBJECTS = $(am_test_dump_callback_OBJECTS)
|
||||
test_dump_callback_LDADD = $(LDADD)
|
||||
test_dump_callback_DEPENDENCIES = $(top_builddir)/src/libjansson.la
|
||||
test_equal_SOURCES = test_equal.c
|
||||
test_equal_OBJECTS = test_equal.$(OBJEXT)
|
||||
test_equal_LDADD = $(LDADD)
|
||||
|
@ -110,17 +115,17 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
|||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(test_array_SOURCES) $(test_copy_SOURCES) \
|
||||
$(test_dump_SOURCES) test_equal.c $(test_load_SOURCES) \
|
||||
$(test_loadb_SOURCES) $(test_memory_funcs_SOURCES) \
|
||||
$(test_number_SOURCES) $(test_object_SOURCES) \
|
||||
$(test_pack_SOURCES) $(test_simple_SOURCES) \
|
||||
$(test_unpack_SOURCES)
|
||||
$(test_dump_SOURCES) $(test_dump_callback_SOURCES) \
|
||||
test_equal.c $(test_load_SOURCES) $(test_loadb_SOURCES) \
|
||||
$(test_memory_funcs_SOURCES) $(test_number_SOURCES) \
|
||||
$(test_object_SOURCES) $(test_pack_SOURCES) \
|
||||
$(test_simple_SOURCES) $(test_unpack_SOURCES)
|
||||
DIST_SOURCES = $(test_array_SOURCES) $(test_copy_SOURCES) \
|
||||
$(test_dump_SOURCES) test_equal.c $(test_load_SOURCES) \
|
||||
$(test_loadb_SOURCES) $(test_memory_funcs_SOURCES) \
|
||||
$(test_number_SOURCES) $(test_object_SOURCES) \
|
||||
$(test_pack_SOURCES) $(test_simple_SOURCES) \
|
||||
$(test_unpack_SOURCES)
|
||||
$(test_dump_SOURCES) $(test_dump_callback_SOURCES) \
|
||||
test_equal.c $(test_load_SOURCES) $(test_loadb_SOURCES) \
|
||||
$(test_memory_funcs_SOURCES) $(test_number_SOURCES) \
|
||||
$(test_object_SOURCES) $(test_pack_SOURCES) \
|
||||
$(test_simple_SOURCES) $(test_unpack_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
@ -215,6 +220,7 @@ htmldir = @htmldir@
|
|||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
json_have_localeconv = @json_have_localeconv@
|
||||
json_have_long_long = @json_have_long_long@
|
||||
json_inline = @json_inline@
|
||||
libdir = @libdir@
|
||||
|
@ -241,6 +247,7 @@ EXTRA_DIST = run
|
|||
test_array_SOURCES = test_array.c util.h
|
||||
test_copy_SOURCES = test_copy.c util.h
|
||||
test_dump_SOURCES = test_dump.c util.h
|
||||
test_dump_callback_SOURCES = test_dump_callback.c util.h
|
||||
test_load_SOURCES = test_load.c util.h
|
||||
test_loadb_SOURCES = test_loadb.c util.h
|
||||
test_memory_funcs_SOURCES = test_memory_funcs.c util.h
|
||||
|
@ -304,6 +311,9 @@ test_copy$(EXEEXT): $(test_copy_OBJECTS) $(test_copy_DEPENDENCIES)
|
|||
test_dump$(EXEEXT): $(test_dump_OBJECTS) $(test_dump_DEPENDENCIES)
|
||||
@rm -f test_dump$(EXEEXT)
|
||||
$(LINK) $(test_dump_OBJECTS) $(test_dump_LDADD) $(LIBS)
|
||||
test_dump_callback$(EXEEXT): $(test_dump_callback_OBJECTS) $(test_dump_callback_DEPENDENCIES)
|
||||
@rm -f test_dump_callback$(EXEEXT)
|
||||
$(LINK) $(test_dump_callback_OBJECTS) $(test_dump_callback_LDADD) $(LIBS)
|
||||
test_equal$(EXEEXT): $(test_equal_OBJECTS) $(test_equal_DEPENDENCIES)
|
||||
@rm -f test_equal$(EXEEXT)
|
||||
$(LINK) $(test_equal_OBJECTS) $(test_equal_LDADD) $(LIBS)
|
||||
|
@ -341,6 +351,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_array.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_copy.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dump.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_dump_callback.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_equal.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_load.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_loadb.Po@am__quote@
|
||||
|
|
|
@ -387,7 +387,7 @@ static void test_circular()
|
|||
}
|
||||
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
test_misc();
|
||||
test_insert();
|
||||
|
@ -395,6 +395,4 @@ int main()
|
|||
test_clear();
|
||||
test_extend();
|
||||
test_circular();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ static void test_deep_copy_object(void)
|
|||
json_decref(copy);
|
||||
}
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
test_copy_simple();
|
||||
test_deep_copy_simple();
|
||||
|
@ -315,5 +315,4 @@ int main()
|
|||
test_deep_copy_array();
|
||||
test_copy_object();
|
||||
test_deep_copy_object();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -133,10 +133,9 @@ static void encode_other_than_array_or_object()
|
|||
|
||||
}
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
encode_twice();
|
||||
circular_references();
|
||||
encode_other_than_array_or_object();
|
||||
return 0;
|
||||
}
|
||||
|
|
81
3party/jansson/test/suites/api/test_dump_callback.c
Normal file
81
3party/jansson/test/suites/api/test_dump_callback.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2011 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.
|
||||
*/
|
||||
|
||||
#include <jansson.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "util.h"
|
||||
|
||||
struct my_sink {
|
||||
char *buf;
|
||||
size_t off;
|
||||
size_t cap;
|
||||
};
|
||||
|
||||
static int my_writer(const char *buffer, size_t len, void *data) {
|
||||
struct my_sink *s = data;
|
||||
if (len > s->cap - s->off) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(s->buf + s->off, buffer, len);
|
||||
s->off += len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void run_tests()
|
||||
{
|
||||
struct my_sink s;
|
||||
json_t *json;
|
||||
const char str[] = "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
|
||||
char *dumped_to_string;
|
||||
|
||||
json = json_loads(str, 0, NULL);
|
||||
if(!json) {
|
||||
fail("json_loads failed");
|
||||
}
|
||||
|
||||
dumped_to_string = json_dumps(json, 0);
|
||||
if (!dumped_to_string) {
|
||||
json_decref(json);
|
||||
fail("json_dumps failed");
|
||||
}
|
||||
|
||||
s.off = 0;
|
||||
s.cap = strlen(dumped_to_string);
|
||||
s.buf = malloc(s.cap);
|
||||
if (!s.buf) {
|
||||
json_decref(json);
|
||||
free(dumped_to_string);
|
||||
fail("malloc failed");
|
||||
}
|
||||
|
||||
if (json_dump_callback(json, my_writer, &s, 0) == -1) {
|
||||
json_decref(json);
|
||||
free(dumped_to_string);
|
||||
free(s.buf);
|
||||
fail("json_dump_callback failed on an exact-length sink buffer");
|
||||
}
|
||||
|
||||
if (strncmp(dumped_to_string, s.buf, s.off) != 0) {
|
||||
json_decref(json);
|
||||
free(dumped_to_string);
|
||||
free(s.buf);
|
||||
fail("json_dump_callback and json_dumps did not produce identical output");
|
||||
}
|
||||
|
||||
s.off = 1;
|
||||
if (json_dump_callback(json, my_writer, &s, 0) != -1) {
|
||||
json_decref(json);
|
||||
free(dumped_to_string);
|
||||
free(s.buf);
|
||||
fail("json_dump_callback succeeded on a short buffer when it should have failed");
|
||||
}
|
||||
|
||||
json_decref(json);
|
||||
free(dumped_to_string);
|
||||
free(s.buf);
|
||||
}
|
|
@ -180,11 +180,10 @@ static void test_equal_complex()
|
|||
/* TODO: There's no negative test case here */
|
||||
}
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
test_equal_simple();
|
||||
test_equal_array();
|
||||
test_equal_object();
|
||||
test_equal_complex();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -50,11 +50,9 @@ static void disable_eof_check()
|
|||
json_decref(json);
|
||||
}
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
file_not_found();
|
||||
reject_duplicates();
|
||||
disable_eof_check();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <string.h>
|
||||
#include "util.h"
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
json_t *json;
|
||||
json_error_t error;
|
||||
|
@ -33,6 +33,4 @@ int main()
|
|||
if(strcmp(error.text, "']' expected near end of file") != 0) {
|
||||
fail("json_loadb returned an invalid error message for an unclosed top-level array");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -75,10 +75,8 @@ static void test_secure_funcs(void)
|
|||
create_and_free_complex_object();
|
||||
}
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
test_simple();
|
||||
test_secure_funcs();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <jansson.h>
|
||||
#include "util.h"
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
json_t *integer, *real;
|
||||
int i;
|
||||
|
@ -39,6 +39,4 @@ int main()
|
|||
|
||||
json_decref(integer);
|
||||
json_decref(real);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ static void test_preserve_order()
|
|||
json_decref(object);
|
||||
}
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
test_misc();
|
||||
test_clear();
|
||||
|
@ -446,6 +446,4 @@ int main()
|
|||
test_set_nocheck();
|
||||
test_iterators();
|
||||
test_preserve_order();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <stdio.h>
|
||||
#include "util.h"
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
json_t *value;
|
||||
int i;
|
||||
|
@ -227,6 +227,4 @@ int main()
|
|||
if(json_pack_ex(&error, 0, "{s:s}", "foo", "\xff\xff"))
|
||||
fail("json_pack failed to catch invalid UTF-8 in a string");
|
||||
check_error("Invalid UTF-8 string", "<args>", 1, 4, 4);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "util.h"
|
||||
|
||||
/* Call the simple functions not covered by other tests of the public API */
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
json_t *value;
|
||||
|
||||
|
@ -180,6 +180,4 @@ int main()
|
|||
json_incref(value);
|
||||
if(value->refcount != (size_t)-1)
|
||||
fail("refcounting null works incorrectly");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <stdio.h>
|
||||
#include "util.h"
|
||||
|
||||
int main()
|
||||
static void run_tests()
|
||||
{
|
||||
json_t *j, *j2;
|
||||
int i1, i2, i3;
|
||||
|
@ -336,6 +336,4 @@ int main()
|
|||
fail("json_unpack nested array with strict validation failed");
|
||||
check_error("1 array item(s) left unpacked", "<validation>", 1, 5, 5);
|
||||
json_decref(j);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,8 +8,16 @@
|
|||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#define failhdr fprintf(stderr, "%s:%s:%d: ", __FILE__, __FUNCTION__, __LINE__)
|
||||
|
@ -52,4 +60,15 @@
|
|||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
static void run_tests();
|
||||
|
||||
int main() {
|
||||
#ifdef HAVE_SETLOCALE
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
run_tests();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue