Skip to content

Commit

Permalink
Update yyjson to v0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chad-earthscope committed May 27, 2024
1 parent fe03da7 commit b485daf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024.148:
- Update yyjson to v0.9.0.
- Simplify mstl3_addmsr_recordptr() a bit.

2024.146:
- Replace ms_dabs() with macro to use system fabs(), document as deprecated.
- Add CRC values to diagnostic message when header values does not match calculated.
Expand Down
1 change: 1 addition & 0 deletions yyjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ bool yyjson_mut_doc_set_val_pool_size(yyjson_mut_doc *doc, size_t count) {
void yyjson_mut_doc_free(yyjson_mut_doc *doc) {
if (doc) {
yyjson_alc alc = doc->alc;
memset(&doc->alc, 0, sizeof(alc));
unsafe_yyjson_str_pool_release(&doc->str_pool, &alc);
unsafe_yyjson_val_pool_release(&doc->val_pool, &alc);
alc.free(alc.ctx, doc);
Expand Down
48 changes: 29 additions & 19 deletions yyjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,16 @@ extern "C" {
#define YYJSON_VERSION_MAJOR 0

/** The minor version of yyjson. */
#define YYJSON_VERSION_MINOR 8
#define YYJSON_VERSION_MINOR 9

/** The patch version of yyjson. */
#define YYJSON_VERSION_PATCH 0

/** The version of yyjson in hex: `(major << 16) | (minor << 8) | (patch)`. */
#define YYJSON_VERSION_HEX 0x000800
#define YYJSON_VERSION_HEX 0x000900

/** The version string of yyjson. */
#define YYJSON_VERSION_STRING "0.8.0"
#define YYJSON_VERSION_STRING "0.9.0"

/** The version of yyjson in hex, same as `YYJSON_VERSION_HEX`. */
yyjson_api uint32_t yyjson_version(void);
Expand Down Expand Up @@ -3699,7 +3699,7 @@ yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc,
The `len` should be the length of the `val`, in bytes.
This function allows duplicated key in one object.
@warning The key/value strings are not copied, you should keep these strings
@warning The key strings are not copied, you should keep these strings
unmodified for the lifetime of this JSON document. */
yyjson_api_inline bool yyjson_mut_obj_add_strncpy(yyjson_mut_doc *doc,
yyjson_mut_val *obj,
Expand Down Expand Up @@ -4833,6 +4833,7 @@ yyjson_api_inline size_t yyjson_doc_get_val_count(yyjson_doc *doc) {
yyjson_api_inline void yyjson_doc_free(yyjson_doc *doc) {
if (doc) {
yyjson_alc alc = doc->alc;
memset(&doc->alc, 0, sizeof(alc));
if (doc->str_pool) alc.free(alc.ctx, doc->str_pool);
alc.free(alc.ctx, doc);
}
Expand Down Expand Up @@ -5672,6 +5673,7 @@ yyjson_api_inline yyjson_mut_val *yyjson_mut_bool(yyjson_mut_doc *doc,
if (yyjson_likely(doc)) {
yyjson_mut_val *val = unsafe_yyjson_mut_val(doc, 1);
if (yyjson_likely(val)) {
_val = !!_val;
val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)_val << 3);
return val;
}
Expand Down Expand Up @@ -5924,7 +5926,8 @@ yyjson_api_inline yyjson_mut_val *yyjson_mut_arr(yyjson_mut_doc *doc) {
yyjson_api_inline yyjson_mut_val *yyjson_mut_arr_with_bool(
yyjson_mut_doc *doc, const bool *vals, size_t count) {
yyjson_mut_arr_with_func({
val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)vals[i] << 3);
bool _val = !!vals[i];
val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)_val << 3);
});
}

Expand Down Expand Up @@ -6876,6 +6879,7 @@ yyjson_api_inline bool yyjson_mut_obj_add_bool(yyjson_mut_doc *doc,
const char *_key,
bool _val) {
yyjson_mut_obj_add_func({
_val = !!_val;
val->tag = YYJSON_TYPE_BOOL | (uint8_t)((uint8_t)(_val) << 3);
});
}
Expand Down Expand Up @@ -7734,33 +7738,39 @@ yyjson_api_inline bool yyjson_ptr_get_bool(
}

/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is type uint.
Returns true if value at `ptr` exists and is the correct type, otherwise false.
Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer
that fits in `uint64_t`. Returns true if successful, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_uint(
yyjson_val *root, const char *ptr, uint64_t *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && yyjson_is_uint(val)) {
*value = unsafe_yyjson_get_uint(val);
return true;
} else {
return false;
if (value && val) {
uint64_t ret = val->uni.u64;
if (unsafe_yyjson_is_uint(val) ||
(unsafe_yyjson_is_sint(val) && !(ret >> 63))) {
*value = ret;
return true;
}
}
return false;
}

/**
Set provided `value` if the JSON Pointer (RFC 6901) exists and is type sint.
Returns true if value at `ptr` exists and is the correct type, otherwise false.
Set provided `value` if the JSON Pointer (RFC 6901) exists and is an integer
that fits in `int64_t`. Returns true if successful, otherwise false.
*/
yyjson_api_inline bool yyjson_ptr_get_sint(
yyjson_val *root, const char *ptr, int64_t *value) {
yyjson_val *val = yyjson_ptr_get(root, ptr);
if (value && yyjson_is_sint(val)) {
*value = unsafe_yyjson_get_sint(val);
return true;
} else {
return false;
if (value && val) {
int64_t ret = val->uni.i64;
if (unsafe_yyjson_is_sint(val) ||
(unsafe_yyjson_is_uint(val) && ret >= 0)) {
*value = ret;
return true;
}
}
return false;
}

/**
Expand Down

0 comments on commit b485daf

Please sign in to comment.