diff options
author | Luke T. Shumaker <[email protected]> | 2024-02-22 20:51:28 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-10-08 14:10:05 +0900 |
commit | 74d459fd52ef85f92f7c20819afcc4ffcf11714d (patch) | |
tree | c967d95e7b5f20bc32956087368571e831f7ded6 /ext/json/generator/generator.h | |
parent | 6e47968929f2ee77376d28a6561266d8f8e3a4f7 (diff) |
[ruby/json] Adjust to the CVTUTF code being gone
I, Luke T. Shumaker, am the sole author of the added code.
I did not reference CVTUTF when writing it. I did reference the
Unicode standard (15.0.0), the Wikipedia article on UTF-8, and the
Wikipedia article on UTF-16. When I saw some tests fail, I did
reference the old deleted code (but a JSON-specific part, inherently
not as based on CVTUTF) to determine that script_safe should also
escape U+2028 and U+2029.
I targeted simplicity and clarity when writing the code--it can likely
be optimized. In my mind, the obvious next optimization is to have it
combine contiguous non-escaped characters into just one call to
fbuffer_append(), instead of calling fbuffer_append() for each
character.
Regarding the use of the "modern" types `uint32_t`, `uint16_t`, and
`bool`:
- ruby.h is guaranteed to give us uint32_t and uint16_t.
- Since Ruby 3.0.0, ruby.h is guaranteed to give us bool... but we
support down to Ruby 2.3. But, ruby.h is guaranteed to give us
HAVE_STDBOOL_H for the C99 stdbool.h; so use that to include
stdbool.h if we can, and if not then fall back to a copy of the
same bool definition that Ruby 3.0.5 uses with C89.
https://github.com/ruby/json/commit/c96351f874
Diffstat (limited to 'ext/json/generator/generator.h')
-rw-r--r-- | ext/json/generator/generator.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/json/generator/generator.h b/ext/json/generator/generator.h index 95ce2479c6..16aae7bc62 100644 --- a/ext/json/generator/generator.h +++ b/ext/json/generator/generator.h @@ -6,6 +6,14 @@ #include "ruby.h" +#ifdef HAVE_STDBOOL_H +#include <stdbool.h> +#else +/* This is the fallback definition from Ruby 3.0.5. */ +typedef unsigned char _Bool +#define bool _Bool +#endif + #ifdef HAVE_RUBY_RE_H #include "ruby/re.h" #else @@ -22,10 +30,7 @@ #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key)) -static void unicode_escape(char *buf, UTF16 character); -static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character); -static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char script_safe); -static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char script_safe); +static void convert_UTF8_to_JSON(FBuffer *out_buffer, VALUE in_string, bool out_ascii_only, bool out_script_safe); static char *fstrndup(const char *ptr, unsigned long len); /* ruby api and some helpers */ |