Browse Source

Modifications so it compiles on Windows correctly

pull/715/head
HexTheDragon 4 years ago
parent
commit
65e0969db0
3 changed files with 30 additions and 28 deletions
  1. +12
    -13
      json_object.c
  2. +17
    -14
      json_object.h
  3. +1
    -1
      json_object_private.h

+ 12
- 13
json_object.c View File

@@ -574,13 +574,13 @@ int json_object_object_add_ex(struct json_object *jso, const char *const key,
return json_object_object_add_ex_len(jso, key, strlen(key), val, opts); return json_object_object_add_ex_len(jso, key, strlen(key), val, opts);
} }


int json_object_object_add_ex_len(struct json_object *jso, const char *const key, const int len,
int json_object_object_add_ex_len(struct json_object *jso, const char *const key, const size_t len,
struct json_object *const val, const unsigned opts) struct json_object *const val, const unsigned opts)
{ {
// Created on the stack rather than calling `json_key_new_ptr` // Created on the stack rather than calling `json_key_new_ptr`
// or `json_key_new_imm` since this saves copying `key` if it turns // or `json_key_new_imm` since this saves copying `key` if it turns
// out the value already exists in the hash table // out the value already exists in the hash table
const struct json_key hashable = {.length = len, .str = {.pdata = key}};
struct json_key hashable = {len, {key}};
return json_object_object_add_key(jso, &hashable, val, opts); return json_object_object_add_key(jso, &hashable, val, opts);
} }


@@ -646,7 +646,7 @@ int json_object_object_add(struct json_object *jso, const char *key, struct json
return json_object_object_add_ex_len(jso, key, strlen(key), val, 0); return json_object_object_add_ex_len(jso, key, strlen(key), val, 0);
} }


int json_object_object_add_len(struct json_object *jso, const char *key, const int len,
int json_object_object_add_len(struct json_object *jso, const char *key, const size_t len,
struct json_object *val) struct json_object *val)
{ {
return json_object_object_add_ex_len(jso, key, len, val, 0); return json_object_object_add_ex_len(jso, key, len, val, 0);
@@ -671,7 +671,7 @@ struct json_object *json_object_object_get(const struct json_object *jso, const
} }


struct json_object *json_object_object_get_len(const struct json_object *jso, const char *key, struct json_object *json_object_object_get_len(const struct json_object *jso, const char *key,
const int len)
const size_t len)
{ {
struct json_object *result = NULL; struct json_object *result = NULL;
json_object_object_get_ex_len(jso, key, len, &result); json_object_object_get_ex_len(jso, key, len, &result);
@@ -685,7 +685,7 @@ json_bool json_object_object_get_ex(const struct json_object *jso, const char *k
} }


json_bool json_object_object_get_ex_len(const struct json_object *jso, const char *key, json_bool json_object_object_get_ex_len(const struct json_object *jso, const char *key,
const int len, struct json_object **value)
const size_t len, struct json_object **value)
{ {
if (value != NULL) if (value != NULL)
*value = NULL; *value = NULL;
@@ -697,7 +697,7 @@ json_bool json_object_object_get_ex_len(const struct json_object *jso, const cha
{ {
case json_type_object: case json_type_object:
{ {
const struct json_key hashable = {.length = len, .str = {.pdata = key}};
const struct json_key hashable = {len, {key}};
return json_object_object_get_key(jso, &hashable, value); return json_object_object_get_key(jso, &hashable, value);
} }
default: default:
@@ -719,9 +719,9 @@ void json_object_object_del(struct json_object *jso, const char *key)
json_object_object_del_len(jso, key, strlen(key)); json_object_object_del_len(jso, key, strlen(key));
} }


void json_object_object_del_len(struct json_object *jso, const char *key, const int len)
void json_object_object_del_len(struct json_object *jso, const char *key, const size_t len)
{ {
const struct json_key hashable = {.length = len, .str = {.pdata = key}};
const struct json_key hashable = {len, {key}};
json_object_object_del_key(jso, &hashable); json_object_object_del_key(jso, &hashable);
} }


@@ -1888,7 +1888,7 @@ struct json_key *json_key_new_ptr(const size_t length, const char *data)
{ {
return NULL; return NULL;
} }
result->length = length;
result->length = (ssize_t)length;
result->str.pdata = data; result->str.pdata = data;
return result; return result;
} }
@@ -1907,9 +1907,8 @@ struct json_key *json_key_new_imm(const size_t length, const char *data)
{ {
return NULL; return NULL;
} }
result->length = -length;
char *unconst = _LH_UNCONST(result->str.idata);
memcpy(unconst, data, length);
unconst[length] = '\0';
result->length = -((ssize_t)length);
memcpy(result->str.idata, data, length);
result->str.idata[length] = '\0';
return result; return result;
} }

+ 17
- 14
json_object.h View File

@@ -357,7 +357,8 @@ JSON_EXPORT int json_object_object_length(const struct json_object *obj);
*/ */
JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void)); JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void));


/** Add an object field to a json_object of type json_type_object
/**
* @brief Add an object field to a json_object of type json_type_object
* *
* The reference count of `val` will *not* be incremented, in effect * The reference count of `val` will *not* be incremented, in effect
* transferring ownership that object to `obj`, and thus `val` will be * transferring ownership that object to `obj`, and thus `val` will be
@@ -385,7 +386,8 @@ JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void));
JSON_EXPORT int json_object_object_add(struct json_object *obj, const char *key, JSON_EXPORT int json_object_object_add(struct json_object *obj, const char *key,
struct json_object *val); struct json_object *val);


/** Add an object field to a json_object of type json_type_object
/**
* @brief Add an object field to a json_object of type json_type_object
* *
* The reference count of `val` will *not* be incremented, in effect * The reference count of `val` will *not* be incremented, in effect
* transferring ownership that object to `obj`, and thus `val` will be * transferring ownership that object to `obj`, and thus `val` will be
@@ -412,10 +414,11 @@ JSON_EXPORT int json_object_object_add(struct json_object *obj, const char *key,
* @return On success, @c 0 is returned. * @return On success, @c 0 is returned.
* On error, a negative value is returned. * On error, a negative value is returned.
*/ */
JSON_EXPORT int json_object_object_add_len(struct json_object *obj, const char *key, const int len,
struct json_object *val);
JSON_EXPORT int json_object_object_add_len(struct json_object *obj, const char *key,
const size_t len, struct json_object *val);


/** Add an object field to a json_object of type json_type_object
/**
* @brief Add an object field to a json_object of type json_type_object
* *
* The semantics are identical to json_object_object_add, except that an * The semantics are identical to json_object_object_add, except that an
* additional flag fields gives you more control over some detail aspects * additional flag fields gives you more control over some detail aspects
@@ -434,7 +437,8 @@ JSON_EXPORT int json_object_object_add_len(struct json_object *obj, const char *
JSON_EXPORT int json_object_object_add_ex(struct json_object *obj, const char *const key, JSON_EXPORT int json_object_object_add_ex(struct json_object *obj, const char *const key,
struct json_object *const val, const unsigned opts); struct json_object *const val, const unsigned opts);


/** Add an object field to a json_object of type json_type_object
/**
* @brief Add an object field to a json_object of type json_type_object
* *
* The semantics are identical to json_object_object_add, except that an * The semantics are identical to json_object_object_add, except that an
* additional flag fields gives you more control over some detail aspects * additional flag fields gives you more control over some detail aspects
@@ -453,7 +457,7 @@ JSON_EXPORT int json_object_object_add_ex(struct json_object *obj, const char *c
* On error, a negative value is returned. * On error, a negative value is returned.
*/ */
JSON_EXPORT int json_object_object_add_ex_len(struct json_object *obj, const char *const key, JSON_EXPORT int json_object_object_add_ex_len(struct json_object *obj, const char *const key,
const int len, struct json_object *const val,
const size_t len, struct json_object *const val,
const unsigned opts); const unsigned opts);


/** /**
@@ -515,7 +519,7 @@ JSON_EXPORT struct json_object *json_object_object_get(const struct json_object
*/ */


JSON_EXPORT struct json_object *json_object_object_get_len(const struct json_object *obj, JSON_EXPORT struct json_object *json_object_object_get_len(const struct json_object *obj,
const char *key, const int len);
const char *key, const size_t len);


/** /**
* @brief Get the json_object associated with a given object field. * @brief Get the json_object associated with a given object field.
@@ -557,7 +561,7 @@ JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object *obj, c
* @returns whether or not the key exists * @returns whether or not the key exists
*/ */
JSON_EXPORT json_bool json_object_object_get_ex_len(const struct json_object *obj, const char *key, JSON_EXPORT json_bool json_object_object_get_ex_len(const struct json_object *obj, const char *key,
const int len, struct json_object **value);
const size_t len, struct json_object **value);


/** /**
* @brief Get the json_object associated with a given object field. * @brief Get the json_object associated with a given object field.
@@ -605,7 +609,7 @@ JSON_EXPORT void json_object_object_del(struct json_object *obj, const char *key
* @param len the length of @p key * @param len the length of @p key
*/ */
JSON_EXPORT void json_object_object_del_len(struct json_object *jso, const char *key, JSON_EXPORT void json_object_object_del_len(struct json_object *jso, const char *key,
const int len);
const size_t len);


/** /**
* @brief Delete the given json_object field * @brief Delete the given json_object field
@@ -617,8 +621,7 @@ JSON_EXPORT void json_object_object_del_len(struct json_object *jso, const char
* @param obj the json_object instance * @param obj the json_object instance
* @param key the object field name * @param key the object field name
*/ */
JSON_EXPORT int json_object_object_del_key(struct json_object *jso_base,
const struct json_key *key);
JSON_EXPORT int json_object_object_del_key(struct json_object *obj, const struct json_key *key);


/** /**
* @brief Iterate through all keys and values of an object. * @brief Iterate through all keys and values of an object.
@@ -655,12 +658,12 @@ JSON_EXPORT int json_object_object_del_key(struct json_object *jso_base,
#else /* ANSI C or MSC */ #else /* ANSI C or MSC */


#define json_object_object_foreach(obj, key, val) \ #define json_object_object_foreach(obj, key, val) \
char *key = NULL; \
struct json_key *key = NULL; \
struct json_object *val = NULL; \ struct json_object *val = NULL; \
struct lh_entry *entry##key; \ struct lh_entry *entry##key; \
struct lh_entry *entry_next##key = NULL; \ struct lh_entry *entry_next##key = NULL; \
for (entry##key = json_object_get_object(obj)->head; \ for (entry##key = json_object_get_object(obj)->head; \
(entry##key ? (key = (char *)lh_entry_k(entry##key), \
(entry##key ? (key = (struct json_key *)lh_entry_k(entry##key), \
val = (struct json_object *)lh_entry_v(entry##key), \ val = (struct json_object *)lh_entry_v(entry##key), \
entry_next##key = entry##key->next, entry##key) \ entry_next##key = entry##key->next, entry##key) \
: 0); \ : 0); \


+ 1
- 1
json_object_private.h View File

@@ -141,7 +141,7 @@ struct json_key
* enough space to store the whole string (of length `len`) * enough space to store the whole string (of length `len`)
* and one additional null character. * and one additional null character.
*/ */
const char idata[0];
char idata[0];
} str; } str;
}; };




Loading…
Cancel
Save