Browse Source

Merge pull request #1 from json-c/master

sync with upstream
pull/476/head
Mehmet Akif TAŞOVA GitHub 6 years ago
parent
commit
c27791ae3f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 20 deletions
  1. +26
    -11
      CMakeLists.txt
  2. +1
    -1
      cmake/Config.cmake.in
  3. +7
    -2
      configure.ac
  4. +8
    -3
      json_object.c
  5. +2
    -1
      tests/test_deep_copy.c
  6. +7
    -2
      tests/test_double_serializer.c
  7. +1
    -0
      tests/test_double_serializer.expected

+ 26
- 11
CMakeLists.txt View File

@@ -166,12 +166,6 @@ message(STATUS "Written ${PROJECT_BINARY_DIR}/config.h")
configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h) configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h)
message(STATUS "Written ${PROJECT_BINARY_DIR}/json_config.h") message(STATUS "Written ${PROJECT_BINARY_DIR}/json_config.h")


configure_package_config_file(
"cmake/Config.cmake.in"
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
# There's a catch here. # There's a catch here.
@@ -248,14 +242,35 @@ add_library(${PROJECT_NAME}


# If json-c is used as subroject it set to target correct interface -I flags and allow # If json-c is used as subroject it set to target correct interface -I flags and allow
# to build external target without extra include_directories(...) # to build external target without extra include_directories(...)
set_property(TARGET ${PROJECT_NAME} PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
) )


install(TARGETS ${PROJECT_NAME} install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

configure_package_config_file(
"cmake/Config.cmake.in"
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(
FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
) )


if (UNIX OR MINGW OR CYGWIN) if (UNIX OR MINGW OR CYGWIN)


+ 1
- 1
cmake/Config.cmake.in View File

@@ -1,4 +1,4 @@
@PACKAGE_INIT@ @PACKAGE_INIT@


include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
check_required_components("@PROJECT_NAME@") check_required_components("@PROJECT_NAME@")

+ 7
- 2
configure.ac View File

@@ -165,8 +165,13 @@ AS_IF([test "x$enable_Bsymbolic" = "xcheck"],
AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions]) AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
AC_SUBST(JSON_BSYMBOLIC_LDFLAGS) AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)


AX_APPEND_COMPILE_FLAGS([-Wall -Werror -Wcast-qual -Wno-error=deprecated-declarations])
AX_APPEND_COMPILE_FLAGS([-Wextra -Wwrite-string -Wno-unused-parameter])
AC_ARG_ENABLE([werror],
AS_HELP_STRING([--disable-werror], [avoid treating compiler warnings as fatal errors]))

AS_IF([test "x$enable_werror" != "xno"], [AX_APPEND_COMPILE_FLAGS([-Werror])])

AX_APPEND_COMPILE_FLAGS([-Wall -Wcast-qual -Wno-error=deprecated-declarations])
AX_APPEND_COMPILE_FLAGS([-Wextra -Wwrite-strings -Wno-unused-parameter])
AX_APPEND_COMPILE_FLAGS([-D_GNU_SOURCE]) AX_APPEND_COMPILE_FLAGS([-D_GNU_SOURCE])


AC_LANG_PUSH([C]) AC_LANG_PUSH([C])


+ 8
- 3
json_object.c View File

@@ -810,6 +810,7 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
{ {
const char *std_format = "%.17g"; const char *std_format = "%.17g";
int format_drops_decimals = 0; int format_drops_decimals = 0;
int looks_numeric = 0;


if (!format) if (!format)
{ {
@@ -837,11 +838,15 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
if (format == std_format || strstr(format, ".0f") == NULL) if (format == std_format || strstr(format, ".0f") == NULL)
format_drops_decimals = 1; format_drops_decimals = 1;


looks_numeric = /* Looks like *some* kind of number */
isdigit((unsigned char)buf[0]) ||
(size > 1 && buf[0] == '-' && isdigit((unsigned char)buf[1]));

if (size < (int)sizeof(buf) - 2 && if (size < (int)sizeof(buf) - 2 &&
isdigit((unsigned char)buf[0]) && /* Looks like *some* kind of number */
!p && /* Has no decimal point */
looks_numeric &&
!p && /* Has no decimal point */
strchr(buf, 'e') == NULL && /* Not scientific notation */ strchr(buf, 'e') == NULL && /* Not scientific notation */
format_drops_decimals)
format_drops_decimals)
{ {
// Ensure it looks like a float, even if snprintf didn't, // Ensure it looks like a float, even if snprintf didn't,
// unless a custom format is set to omit the decimal. // unless a custom format is set to omit the decimal.


+ 2
- 1
tests/test_deep_copy.c View File

@@ -186,7 +186,8 @@ int main(int argc, char **argv)
printf("\nTesting deep_copy with a custom serializer set\n"); printf("\nTesting deep_copy with a custom serializer set\n");
json_object *with_serializer = json_object_new_string("notemitted"); json_object *with_serializer = json_object_new_string("notemitted");


json_object_set_serializer(with_serializer, my_custom_serializer, "dummy userdata", NULL);
char udata[] = "dummy userdata";
json_object_set_serializer(with_serializer, my_custom_serializer, udata, NULL);
json_object_object_add(src1, "with_serializer", with_serializer); json_object_object_add(src1, "with_serializer", with_serializer);
dst1 = NULL; dst1 = NULL;
/* With a custom serializer in use, a custom shallow_copy function must also be used */ /* With a custom serializer in use, a custom shallow_copy function must also be used */


+ 7
- 2
tests/test_double_serializer.c View File

@@ -11,16 +11,17 @@
int main() int main()
{ {
struct json_object *obj = json_object_new_double(0.5); struct json_object *obj = json_object_new_double(0.5);
char udata[] = "test";


printf("Test default serializer:\n"); printf("Test default serializer:\n");
printf("obj.to_string(standard)=%s\n", json_object_to_json_string(obj)); printf("obj.to_string(standard)=%s\n", json_object_to_json_string(obj));


printf("Test default serializer with custom userdata:\n"); printf("Test default serializer with custom userdata:\n");
obj->_userdata = "test";
obj->_userdata = udata;
printf("obj.to_string(userdata)=%s\n", json_object_to_json_string(obj)); printf("obj.to_string(userdata)=%s\n", json_object_to_json_string(obj));


printf("Test explicit serializer with custom userdata:\n"); printf("Test explicit serializer with custom userdata:\n");
json_object_set_serializer(obj, json_object_double_to_json_string, "test", NULL);
json_object_set_serializer(obj, json_object_double_to_json_string, udata, NULL);
printf("obj.to_string(custom)=%s\n", json_object_to_json_string(obj)); printf("obj.to_string(custom)=%s\n", json_object_to_json_string(obj));


printf("Test reset serializer:\n"); printf("Test reset serializer:\n");
@@ -74,4 +75,8 @@ int main()
printf("ERROR: json_c_set_serialization_double_format() failed"); printf("ERROR: json_c_set_serialization_double_format() failed");


json_object_put(obj); json_object_put(obj);

obj = json_object_new_double(-12.0);
printf("obj(-12.0).to_string(default format)=%s\n", json_object_to_json_string(obj));

} }

+ 1
- 0
tests/test_double_serializer.expected View File

@@ -16,3 +16,4 @@ obj(12.0).to_string(default format)=12.0
obj(12.0).to_string(%.0f)=12 obj(12.0).to_string(%.0f)=12
obj(12.0).to_string(%.0g)=1e+01 obj(12.0).to_string(%.0g)=1e+01
obj(12.0).to_string(%.1g)=12.0 obj(12.0).to_string(%.1g)=12.0
obj(-12.0).to_string(default format)=-12.0

Loading…
Cancel
Save