Prechádzať zdrojové kódy

Updated to Jansson with fractional precision support

woollybah 6 rokov pred
rodič
commit
06af91f69b

+ 4 - 1
jansson.mod/jansson.bmx

@@ -22,11 +22,13 @@ SuperStrict
 
 Module Pub.Jansson
 
-ModuleInfo "Version: 1.04"
+ModuleInfo "Version: 1.05"
 ModuleInfo "Author: Bruce A Henderson"
 ModuleInfo "License: MIT"
 ModuleInfo "Copyright: 2014-2019 Bruce A Henderson"
 
+ModuleInfo "History: 1.05"
+ModuleInfo "History: Updated to Jansson with fractional precision support."
 ModuleInfo "History: 1.04"
 ModuleInfo "History: Fix for NX"
 ModuleInfo "History: 1.03"
@@ -70,3 +72,4 @@ Import "jansson/src/strbuffer.c"
 Import "jansson/src/strconv.c"
 Import "jansson/src/utf.c"
 Import "jansson/src/value.c"
+Import "jansson/src/version.c"

+ 7 - 0
jansson.mod/jansson/CMakeLists.txt

@@ -100,6 +100,13 @@ include (CheckFunctionKeywords)
 include (CheckIncludeFiles)
 include (CheckTypeSize)
 
+# supress format-truncation warning
+include (CheckCCompilerFlag)
+check_c_compiler_flag(-Wno-format-truncation HAS_NO_FORMAT_TRUNCATION)
+if (HAS_NO_FORMAT_TRUNCATION)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-truncation")
+endif()
+
 if (MSVC)
    # Turn off Microsofts "security" warnings.
    add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo" )

+ 15 - 0
jansson.mod/jansson/configure.ac

@@ -9,6 +9,7 @@ AC_CONFIG_HEADERS([jansson_private_config.h])
 
 # Checks for programs.
 AC_PROG_CC
+AC_PROG_CXX
 AC_PROG_LIBTOOL
 AM_CONDITIONAL([GCC], [test x$GCC = xyes])
 
@@ -136,6 +137,19 @@ fi
 AS_IF([test "x$with_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
 AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)
 
+
+AC_ARG_ENABLE([ossfuzzers],
+  [AS_HELP_STRING([--enable-ossfuzzers],
+    [Whether to generate the fuzzers for OSS-Fuzz])],
+  [have_ossfuzzers=yes], [have_ossfuzzers=no])
+AM_CONDITIONAL([USE_OSSFUZZERS], [test "x$have_ossfuzzers" = "xyes"])
+
+
+AC_SUBST([LIB_FUZZING_ENGINE])
+AM_CONDITIONAL([USE_OSSFUZZ_FLAG], [test "x$LIB_FUZZING_ENGINE" = "x-fsanitize=fuzzer"])
+AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"])
+
+
 if test x$GCC = xyes; then
     AC_MSG_CHECKING(for -Wno-format-truncation)
     wnoformat_truncation="-Wno-format-truncation"
@@ -156,6 +170,7 @@ AC_CONFIG_FILES([
         src/jansson_config.h
         test/Makefile
         test/bin/Makefile
+        test/ossfuzz/Makefile
         test/suites/Makefile
         test/suites/api/Makefile
 ])

+ 26 - 0
jansson.mod/jansson/doc/apiref.rst

@@ -58,6 +58,25 @@ the library:
       /* Code specific to version 1.3 and above */
       #endif
 
+Additionally, there are functions to determine the version of Jansson at
+runtime:
+
+.. function:: const char *jansson_version_str()
+
+   Return the version of the Jansson library, in the same format as
+   the ``JANSSON_VERSION`` preprocessor constant.
+
+   .. versionadded:: 2.13
+
+.. function:: int jansson_version_cmp(int major, int minor, int micro)
+
+   Returns an integer less than, equal to, or greater than zero if
+   the runtime version of Jansson is found, respectively, to be less
+   than, to match, or be greater than the provided *major*, *minor*, and
+   *micro*.
+
+   .. versionadded:: 2.13
+
 ``JANSSON_THREAD_SAFE_REFCOUNT``
   If this value is defined all read-only operations and reference counting in
   Jansson are thread safe.  This value is not defined for versions older than
@@ -1066,6 +1085,13 @@ can be ORed together to obtain *flags*.
 
    .. versionadded:: 2.10
 
+``JSON_FRACTIONAL_DIGITS``
+   When combined with `JSON_REAL_PRECISION(n), output all real numbers
+   with at most *n* digits after the decimal (rather than *n* total
+   digits).
+
+   .. versionadded:: 2.13
+
 These functions output UTF-8:
 
 .. function:: char *json_dumps(const json_t *json, size_t flags)

+ 2 - 1
jansson.mod/jansson/src/Makefile.am

@@ -20,7 +20,8 @@ libjansson_la_SOURCES = \
 	strconv.c \
 	utf.c \
 	utf.h \
-	value.c
+	value.c \
+	version.c
 libjansson_la_LDFLAGS = \
 	-no-undefined \
 	-export-symbols-regex '^json_' \

+ 1 - 1
jansson.mod/jansson/src/dump.c

@@ -246,7 +246,7 @@ static int do_dump(const json_t *json, size_t flags, int depth,
             double value = json_real_value(json);
 
             size = jsonp_dtostr(buffer, MAX_REAL_STR_LENGTH, value,
-                                FLAGS_TO_PRECISION(flags));
+                                FLAGS_TO_PRECISION(flags), flags & JSON_FRACTIONAL_DIGITS);
             if(size < 0)
                 return -1;
 

+ 2 - 0
jansson.mod/jansson/src/jansson.def

@@ -72,4 +72,6 @@ EXPORTS
     json_vunpack_ex
     json_set_alloc_funcs
     json_get_alloc_funcs
+    jansson_version_str
+    jansson_version_cmp
 

+ 6 - 0
jansson.mod/jansson/src/jansson.h

@@ -342,6 +342,7 @@ json_t *json_load_callback(json_load_callback_t callback, void *data, size_t fla
 #define JSON_ESCAPE_SLASH       0x400
 #define JSON_REAL_PRECISION(n)  (((n) & 0x1F) << 11)
 #define JSON_EMBED              0x10000
+#define JSON_FRACTIONAL_DIGITS  0x20000
 
 typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
 
@@ -360,6 +361,11 @@ typedef void (*json_free_t)(void *);
 void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn);
 void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn);
 
+/* runtime version checking */
+
+const char *jansson_version_str(void);
+int jansson_version_cmp(int major, int minor, int micro);
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 1
jansson.mod/jansson/src/jansson_private.h

@@ -81,7 +81,7 @@ void jsonp_error_vset(json_error_t *error, int line, int column,
 
 /* Locale independent string<->double conversions */
 int jsonp_strtod(strbuffer_t *strbuffer, double *out);
-int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
+int jsonp_dtostr(char *buffer, size_t size, double value, int prec, int frac_digits);
 
 /* Wrappers for custom memory functions */
 void* jsonp_malloc(size_t size) JANSSON_ATTRS(warn_unused_result);

+ 2 - 2
jansson.mod/jansson/src/strconv.c

@@ -86,7 +86,7 @@ int jsonp_strtod(strbuffer_t *strbuffer, double *out)
     return 0;
 }
 
-int jsonp_dtostr(char *buffer, size_t size, double value, int precision)
+int jsonp_dtostr(char *buffer, size_t size, double value, int precision, int fractional_digits)
 {
     int ret;
     char *start, *end;
@@ -95,7 +95,7 @@ int jsonp_dtostr(char *buffer, size_t size, double value, int precision)
     if (precision == 0)
         precision = 17;
 
-    ret = snprintf(buffer, size, "%.*g", precision, value);
+    ret = snprintf(buffer, size, fractional_digits ? "%.*f" : "%.*g", precision, value);
     if(ret < 0)
         return -1;