Skip to content

Commit

Permalink
Final sync of jparse before code freeze
Browse files Browse the repository at this point in the history
.. or at least it's hopefully the last sync :-)

Sync jparse from jparse repo (https://github.com/xexyl/jparse/). This
cleans up some code, removes code that's unnecessary and syncs the versions of
all tools to the same: 1.2.0 2024-10-09. A new version string was added as
well, JPARSE_UTF8_VERSION.

A bug in a script was also fixed. As the use of this script in this repo
(in soup/) already uses the option to set the path of the tool and the
correct path is set already this should not be a problem.

Run make release to test this under macOS.
  • Loading branch information
xexyl committed Oct 9, 2024
1 parent ddb8d81 commit 88aac02
Show file tree
Hide file tree
Showing 29 changed files with 132 additions and 432 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Major changes to the IOCCC entry toolkit


## Release 1.5.24 2024-10-09

Synced `jparse` from [jparse repo](https://github.com/xexyl/jparse/). This
cleans up some code, removes code that's unnecessary and syncs the versions of
all tools to the same: `1.2.0 2024-10-09`. A new version string was added as
well, `JPARSE_UTF8_VERSION`. A bug in a script was also fixed.


## Release 1.5.23 2024-10-08

Noted dependency of `MAX_SUBMIT_SLOT` and `MAX_TARBALL_LEN` defines
Expand Down
19 changes: 19 additions & 0 deletions jparse/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Significant changes in the JSON parser repo

## Release 1.2.0 2024-10-09

Remove `has_nul` in `struct json_string` as UTF-8 should, it is my
understanding, not have a NUL byte.

Fix path in `jsemcgen.sh`.

Update all tools and the release to be the same version after issue #13 was
resolved: `1.2.0 2024-10-09`. `1.2.0` was chosen because it was the first one >
some of the versions and the others could be bumped up to it without any harm.

Do a final clean up of `json_utf8.[ch]`: removed all unnecessary code and macros
as well as clean up comments.

Added a `JPARSE_UTF8_VERSION` in order to keep track of the current UTF-8 code.
Set this version to the same as the other versions at this time: `1.2.0
2024-10-09`.


## Release 1.0.23 2024-10-08

Fix surrogate pair decoding in `json_decode()` / `decode_json_string()`. Now one
Expand Down
2 changes: 1 addition & 1 deletion jparse/jparse_bug_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if [[ -z "$MAKE" ]]; then
MAKE="$(type -P make)"
fi
export MAKE
export BUG_REPORT_VERSION="1.0.4 2024-06-26"
export BUG_REPORT_VERSION="1.2.0 2024-10-09"
export FAILURE_SUMMARY=
export NOTICE_SUMMARY=
export DBG_LEVEL="0"
Expand Down
4 changes: 2 additions & 2 deletions jparse/jsemcgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export MEMBER_FUNC=
export OBJECT_FUNC=
export ARRAY_FUNC=
export UNKNOWN_FUNC=
export JSEMTBLGEN="../jparse/jsemtblgen"
export JSEMTBLGEN="./jsemtblgen"
export JSEMTBLGEN_ARGS=
export PATCH_TOOL=
export JSEMCGEN_VERSION="1.3 2023-02-04"
export JSEMCGEN_VERSION="1.2.0 2024-10-09"

# attempt to fetch system specific paths to tools we need
#
Expand Down
2 changes: 1 addition & 1 deletion jparse/jsemtblgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
/*
* official jsemtblgen version
*/
#define JSEMTBLGEN_VERSION "1.0.1 2024-03-02" /* format: major.minor YYYY-MM-DD */
#define JSEMTBLGEN_VERSION "1.2.0 2024-10-09" /* format: major.minor YYYY-MM-DD */

/*
* jsemtblgen tool basename
Expand Down
29 changes: 15 additions & 14 deletions jparse/json_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ struct byte2asciistr byte2asciistr[JSON_BYTE_VALUES] = {


/* for json string decoding */
static char *decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen, bool *has_nul);
static char *decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen);
/* for json number strings */
static bool json_process_decimal(struct json_number *item, char const *str, size_t len);
static bool json_process_floating(struct json_number *item, char const *str, size_t len);
Expand Down Expand Up @@ -808,7 +808,6 @@ chkbyte2asciistr(void)
* len length of block
* mlen length of decoded bytes to allocate
* retlen address of where to store allocated length, if retlen != NULL
* has_nul if != NULL and we find an encoded NUL byte we will do *has_nul = true
*
* returns:
* allocated JSON decoding of a block, or NULL ==> error
Expand All @@ -817,7 +816,7 @@ chkbyte2asciistr(void)
* NOTE: this function is used by json_decode().
*/
char *
decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen, bool *has_nul)
decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen)
{
char *ret = NULL; /* allocated encoding string or NULL */
char *beyond = NULL; /* beyond the end of the allocated encoding string */
Expand Down Expand Up @@ -1017,6 +1016,10 @@ decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen, boo
* however, for p we need to update the entire amount
*/
p += bytes;
/*
* we increment by 5 because LITLEN("uxxxx") is 5: the for() loop
* increments by 1 at the increment/update phase.
*/
i += 5;
} else if (scanned == 2) {
/*
Expand Down Expand Up @@ -1047,12 +1050,12 @@ decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen, boo
free(ret);
ret = NULL;
}
/* utf8encode warns on error */
/* utf8encode() warns on error */
return NULL;
}

/*
* we skip 11 forwards because 5 (like above) +
* we increment by 11 because LITLEN("uxxxx") +
* LITLEN("\\uxxxx") is 11.
*/
i += 11;
Expand Down Expand Up @@ -1099,7 +1102,7 @@ decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen, boo
*/

dbg(DBG_VVVHIGH, "returning from decode_json_string(ptr, %ju, %ju, *%ju, %s)",
(uintmax_t)len, (uintmax_t)mlen, retlen != NULL ? *retlen : 0, has_nul != NULL ? booltostr(*has_nul) : "false");
(uintmax_t)len, (uintmax_t)mlen, retlen != NULL ? *retlen : 0);
if (retlen != NULL) {
*retlen = mlen;
}
Expand All @@ -1114,14 +1117,13 @@ decode_json_string(char const *ptr, size_t len, size_t mlen, size_t *retlen, boo
* ptr start of memory block to decode
* len length of block to decode in bytes
* retlen address of where to store allocated length, if retlen != NULL
* has_nul if != NULL and we find an encoded NUL byte we will do *has_nul = true
*
* returns:
* allocated JSON decoding of a block, or NULL ==> error
* NOTE: retlen, if non-NULL, is set to 0 on error
*/
char *
json_decode(char const *ptr, size_t len, size_t *retlen, bool *has_nul)
json_decode(char const *ptr, size_t len, size_t *retlen)
{
char *ret = NULL; /* allocated encoding string or NULL */
size_t mlen = 0; /* length of allocated encoded string */
Expand Down Expand Up @@ -1339,17 +1341,17 @@ json_decode(char const *ptr, size_t len, size_t *retlen, bool *has_nul)
/*
* decode JSON string
*/
ret = decode_json_string(ptr, (uintmax_t)len, (uintmax_t)mlen, retlen, has_nul);
ret = decode_json_string(ptr, (uintmax_t)len, (uintmax_t)mlen, retlen);

/*
* return result, if not NULL
*/
if (ret != NULL) {
dbg(DBG_VVVHIGH, "returning from json_decode(ptr, %ju, *%ju, %s)",
(uintmax_t)len, (uintmax_t)mlen, has_nul != NULL ? booltostr(*has_nul) : "false");
(uintmax_t)len, (uintmax_t)mlen);
} else {
dbg(DBG_VVVHIGH, "in json_decode(): decode_json_string(ptr, %ju, *%ju, %s) returned NULL",
(uintmax_t)len, (uintmax_t)mlen, has_nul != NULL ? booltostr(*has_nul) : "false");
(uintmax_t)len, (uintmax_t)mlen);
if (retlen != NULL) {
*retlen = 0;
}
Expand Down Expand Up @@ -1410,7 +1412,7 @@ json_decode_str(char const *str, size_t *retlen)
/*
* convert to json_decode() call
*/
ret = json_decode(str, len, retlen, NULL);
ret = json_decode(str, len, retlen);
if (ret == NULL) {
dbg(DBG_VVHIGH, "returning NULL for decoding of: <%s>", str);
} else {
Expand Down Expand Up @@ -2946,7 +2948,6 @@ json_conv_string(char const *ptr, size_t len, bool quote)
item->parsed = false;
item->quote = false;
item->same = false;
item->has_nul = false;
item->slash = false;
item->posix_safe = false;
item->first_alphanum = false;
Expand Down Expand Up @@ -3007,7 +3008,7 @@ json_conv_string(char const *ptr, size_t len, bool quote)
* decode the JSON encoded string
*/
/* decode the entire string */
item->str = json_decode(item->as_str, len, &(item->str_len), &(item->has_nul));
item->str = json_decode(item->as_str, len, &(item->str_len));
if (item->str == NULL) {
warn(__func__, "quote === %s: JSON string decode failed for: <%s>",
booltostr(quote), item->as_str);
Expand Down
3 changes: 1 addition & 2 deletions jparse/json_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ struct json_string
bool quote; /* The original JSON string included surrounding '"'s */

bool same; /* true => as_str same as str, JSON decoding not required */
bool has_nul; /* true ==> decoded JSON string has a NUL byte inside it */

bool slash; /* true ==> / was found after decoding */
bool posix_safe; /* true ==> all chars are POSIX portable safe plus + and maybe / after decoding */
Expand Down Expand Up @@ -491,7 +490,7 @@ extern struct byte2asciistr byte2asciistr[];
extern char *json_encode(char const *ptr, size_t len, size_t *retlen, bool skip_quote);
extern char *json_encode_str(char const *str, size_t *retlen, bool skip_quote);
extern void chkbyte2asciistr(void);
extern char *json_decode(char const *ptr, size_t len, size_t *retlen, bool *has_nul);
extern char *json_decode(char const *ptr, size_t len, size_t *retlen);
extern char *json_decode_str(char const *str, size_t *retlen);
extern struct json *parse_json_string(char const *string, size_t len);
extern struct json *parse_json_bool(char const *string);
Expand Down
Loading

0 comments on commit 88aac02

Please sign in to comment.