Browse Source

Improved support for IBM operating systems

Fix compiler errors and warnings when building on IBM operating systems such as AIX and IBM i.
tags/json-c-0.15-20200726
David McCann 5 years ago
parent
commit
add7b13a9a
8 changed files with 39 additions and 11 deletions
  1. +8
    -0
      json_c_version.h
  2. +8
    -1
      json_object.c
  3. +3
    -0
      json_tokener.c
  4. +8
    -0
      json_visit.h
  5. +2
    -0
      strerror_override.c
  6. +5
    -5
      tests/test_json_pointer.c
  7. +3
    -3
      tests/test_parse.c
  8. +2
    -2
      tests/test_util_file.c

+ 8
- 0
json_c_version.h View File

@@ -12,6 +12,10 @@
#ifndef _json_c_version_h_ #ifndef _json_c_version_h_
#define _json_c_version_h_ #define _json_c_version_h_


#ifdef __cplusplus
extern "C" {
#endif

#define JSON_C_MAJOR_VERSION 0 #define JSON_C_MAJOR_VERSION 0
#define JSON_C_MINOR_VERSION 14 #define JSON_C_MINOR_VERSION 14
#define JSON_C_MICRO_VERSION 99 #define JSON_C_MICRO_VERSION 99
@@ -44,4 +48,8 @@ JSON_EXPORT const char *json_c_version(void); /* Returns JSON_C_VERSION */
*/ */
JSON_EXPORT int json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */ JSON_EXPORT int json_c_version_num(void); /* Returns JSON_C_VERSION_NUM */


#ifdef __cplusplus
}
#endif

#endif #endif

+ 8
- 1
json_object.c View File

@@ -58,6 +58,8 @@ static json_object_to_json_string_fn _json_object_userdata_to_json_string;
#ifndef JSON_NORETURN #ifndef JSON_NORETURN
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define JSON_NORETURN __declspec(noreturn) #define JSON_NORETURN __declspec(noreturn)
#elif defined(__OS400__)
#define JSON_NORETURN
#else #else
/* 'cold' attribute is for optimization, telling the computer this code /* 'cold' attribute is for optimization, telling the computer this code
* path is unlikely. * path is unlikely.
@@ -901,11 +903,15 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
* ECMA 262 section 9.8.1 defines * ECMA 262 section 9.8.1 defines
* how to handle these cases as strings * how to handle these cases as strings
*/ */
#ifdef HAVE_DECL_ISNAN
if (isnan(jso->o.c_double)) if (isnan(jso->o.c_double))
{ {
size = snprintf(buf, sizeof(buf), "NaN"); size = snprintf(buf, sizeof(buf), "NaN");
} }
else if (isinf(jso->o.c_double))
else
#endif
#ifdef HAVE_DECL_ISINF
if (isinf(jso->o.c_double))
{ {
if (jso->o.c_double > 0) if (jso->o.c_double > 0)
size = snprintf(buf, sizeof(buf), "Infinity"); size = snprintf(buf, sizeof(buf), "Infinity");
@@ -913,6 +919,7 @@ static int json_object_double_to_json_string_format(struct json_object *jso, str
size = snprintf(buf, sizeof(buf), "-Infinity"); size = snprintf(buf, sizeof(buf), "-Infinity");
} }
else else
#endif
{ {
const char *std_format = "%.17g"; const char *std_format = "%.17g";
int format_drops_decimals = 0; int format_drops_decimals = 0;


+ 3
- 0
json_tokener.c View File

@@ -40,6 +40,9 @@
#ifdef HAVE_XLOCALE_H #ifdef HAVE_XLOCALE_H
#include <xlocale.h> #include <xlocale.h>
#endif #endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */


#define jt_hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x)&7) + 9) #define jt_hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x)&7) + 9)




+ 8
- 0
json_visit.h View File

@@ -8,6 +8,10 @@
*/ */
#include "json_object.h" #include "json_object.h"


#ifdef __cplusplus
extern "C" {
#endif

typedef int(json_c_visit_userfunc)(json_object *jso, int flags, json_object *parent_jso, typedef int(json_c_visit_userfunc)(json_object *jso, int flags, json_object *parent_jso,
const char *jso_key, size_t *jso_index, void *userarg); const char *jso_key, size_t *jso_index, void *userarg);


@@ -90,4 +94,8 @@ JSON_EXPORT int json_c_visit(json_object *jso, int future_flags, json_c_visit_us
*/ */
#define JSON_C_VISIT_RETURN_ERROR -1 #define JSON_C_VISIT_RETURN_ERROR -1


#ifdef __cplusplus
}
#endif

#endif /* _json_c_json_visit_h_ */ #endif /* _json_c_json_visit_h_ */

+ 2
- 0
strerror_override.c View File

@@ -20,7 +20,9 @@ static struct
ENTRY(EIO), ENTRY(EIO),
ENTRY(ENXIO), ENTRY(ENXIO),
ENTRY(E2BIG), ENTRY(E2BIG),
#ifdef ENOEXEC
ENTRY(ENOEXEC), ENTRY(ENOEXEC),
#endif
ENTRY(EBADF), ENTRY(EBADF),
ENTRY(ECHILD), ENTRY(ECHILD),
ENTRY(EDEADLK), ENTRY(EDEADLK),


+ 5
- 5
tests/test_json_pointer.c View File

@@ -60,7 +60,7 @@ static const char *rec_input_json_str =
/* clang-format on */ /* clang-format on */


/* Example from RFC */ /* Example from RFC */
static void test_example_get()
static void test_example_get(void)
{ {
int i; int i;
struct json_object *jo1, *jo2, *jo3; struct json_object *jo1, *jo2, *jo3;
@@ -126,7 +126,7 @@ static void test_example_get()
} }


/* I'm not too happy with the RFC example to test the recusion of the json_pointer_get() function */ /* I'm not too happy with the RFC example to test the recusion of the json_pointer_get() function */
static void test_recursion_get()
static void test_recursion_get(void)
{ {
struct json_object *jo2, *jo1 = json_tokener_parse(rec_input_json_str); struct json_object *jo2, *jo1 = json_tokener_parse(rec_input_json_str);


@@ -161,7 +161,7 @@ static void test_recursion_get()
json_object_put(jo1); json_object_put(jo1);
} }


static void test_wrong_inputs_get()
static void test_wrong_inputs_get(void)
{ {
struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str); struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str);


@@ -231,7 +231,7 @@ static void test_wrong_inputs_get()
json_object_put(jo1); json_object_put(jo1);
} }


static void test_example_set()
static void test_example_set(void)
{ {
struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str); struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str);


@@ -272,7 +272,7 @@ static void test_example_set()
json_object_put(jo1); json_object_put(jo1);
} }


static void test_wrong_inputs_set()
static void test_wrong_inputs_set(void)
{ {
struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str); struct json_object *jo2, *jo1 = json_tokener_parse(input_json_str);




+ 3
- 3
tests/test_parse.c View File

@@ -149,8 +149,8 @@ static void test_utf8_parse()
// json_tokener_parse doesn't support checking for byte order marks. // json_tokener_parse doesn't support checking for byte order marks.
// It's the responsibility of the caller to detect and skip a BOM. // It's the responsibility of the caller to detect and skip a BOM.
// Both of these checks return null. // Both of these checks return null.
char utf8_bom[] = {0xEF, 0xBB, 0xBF, 0x00};
char utf8_bom_and_chars[] = {0xEF, 0xBB, 0xBF, '{', '}', 0x00};
char* utf8_bom = "\xEF\xBB\xBF";
char* utf8_bom_and_chars = "\xEF\xBB\xBF{}";
single_basic_parse(utf8_bom, 0); single_basic_parse(utf8_bom, 0);
single_basic_parse(utf8_bom_and_chars, 0); single_basic_parse(utf8_bom_and_chars, 0);
} }
@@ -446,7 +446,7 @@ static void test_incremental_parse()
json_tokener_set_flags(tok, step->tok_flags); json_tokener_set_flags(tok, step->tok_flags);


if (length == -1) if (length == -1)
length = strlen(step->string_to_parse);
length = (int)strlen(step->string_to_parse);
if (step->char_offset == -1) if (step->char_offset == -1)
expected_char_offset = length; expected_char_offset = length;
else else


+ 2
- 2
tests/test_util_file.c View File

@@ -24,10 +24,10 @@


static void test_read_valid_with_fd(const char *testdir); static void test_read_valid_with_fd(const char *testdir);
static void test_read_valid_nested_with_fd(const char *testdir); static void test_read_valid_nested_with_fd(const char *testdir);
static void test_read_nonexistant();
static void test_read_nonexistant(void);
static void test_read_closed(void); static void test_read_closed(void);


static void test_write_to_file();
static void test_write_to_file(void);
static void stat_and_cat(const char *file); static void stat_and_cat(const char *file);
static void test_read_fd_equal(const char *testdir); static void test_read_fd_equal(const char *testdir);




Loading…
Cancel
Save