json-extended 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/BSDL +22 -0
- data/CHANGES.md +798 -0
- data/COPYING +56 -0
- data/LEGAL +20 -0
- data/README.md +308 -0
- data/ext/json/ext/fbuffer/fbuffer.h +259 -0
- data/ext/json/ext/generator/extconf.rb +19 -0
- data/ext/json/ext/generator/generator.c +1997 -0
- data/ext/json/ext/json.h +179 -0
- data/ext/json/ext/parser/extconf.rb +53 -0
- data/ext/json/ext/parser/parser.c +2827 -0
- data/ext/json/ext/simd/conf.rb +24 -0
- data/ext/json/ext/simd/simd.h +208 -0
- data/ext/json/ext/vendor/fast_float_parser.h +814 -0
- data/ext/json/ext/vendor/fpconv.c +480 -0
- data/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
- data/json.gemspec +62 -0
- data/lib/json/add/bigdecimal.rb +58 -0
- data/lib/json/add/complex.rb +51 -0
- data/lib/json/add/core.rb +13 -0
- data/lib/json/add/date.rb +54 -0
- data/lib/json/add/date_time.rb +67 -0
- data/lib/json/add/exception.rb +49 -0
- data/lib/json/add/ostruct.rb +54 -0
- data/lib/json/add/range.rb +54 -0
- data/lib/json/add/rational.rb +49 -0
- data/lib/json/add/regexp.rb +48 -0
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/string.rb +35 -0
- data/lib/json/add/struct.rb +52 -0
- data/lib/json/add/symbol.rb +52 -0
- data/lib/json/add/time.rb +52 -0
- data/lib/json/common.rb +1173 -0
- data/lib/json/ext/generator/state.rb +103 -0
- data/lib/json/ext.rb +45 -0
- data/lib/json/generic_object.rb +67 -0
- data/lib/json/truffle_ruby/generator.rb +755 -0
- data/lib/json/version.rb +5 -0
- data/lib/json.rb +689 -0
- metadata +90 -0
data/ext/json/ext/json.h
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#ifndef _JSON_H_
|
|
2
|
+
#define _JSON_H_
|
|
3
|
+
|
|
4
|
+
#include "ruby.h"
|
|
5
|
+
#include "ruby/encoding.h"
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
|
|
8
|
+
#ifndef RBIMPL_ASSERT_OR_ASSUME
|
|
9
|
+
# define RBIMPL_ASSERT_OR_ASSUME(x)
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#if defined(RUBY_DEBUG) && RUBY_DEBUG
|
|
13
|
+
# define JSON_ASSERT RUBY_ASSERT
|
|
14
|
+
# ifndef JSON_DEBUG
|
|
15
|
+
# define JSON_DEBUG 1
|
|
16
|
+
# endif
|
|
17
|
+
#else
|
|
18
|
+
# ifdef JSON_DEBUG
|
|
19
|
+
# include <assert.h>
|
|
20
|
+
# define JSON_ASSERT(x) assert(x)
|
|
21
|
+
# else
|
|
22
|
+
# define JSON_ASSERT(x)
|
|
23
|
+
# endif
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#ifdef JSON_DEBUG
|
|
27
|
+
# define JSON_UNREACHABLE_RETURN(val) rb_bug("Unreachable")
|
|
28
|
+
#else
|
|
29
|
+
# define JSON_UNREACHABLE_RETURN UNREACHABLE_RETURN
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
/* shims */
|
|
33
|
+
|
|
34
|
+
#ifndef UNDEF_P
|
|
35
|
+
#define UNDEF_P(val) (val == Qundef)
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#if SIZEOF_UINT64_T == SIZEOF_LONG_LONG
|
|
39
|
+
# define INT64T2NUM(x) LL2NUM(x)
|
|
40
|
+
# define UINT64T2NUM(x) ULL2NUM(x)
|
|
41
|
+
#elif SIZEOF_UINT64_T == SIZEOF_LONG
|
|
42
|
+
# define INT64T2NUM(x) LONG2NUM(x)
|
|
43
|
+
# define UINT64T2NUM(x) ULONG2NUM(x)
|
|
44
|
+
#else
|
|
45
|
+
# error No uint64_t conversion
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
/* This is the fallback definition from Ruby 3.4 */
|
|
49
|
+
#ifndef RBIMPL_STDBOOL_H
|
|
50
|
+
#if defined(__cplusplus)
|
|
51
|
+
# if defined(HAVE_STDBOOL_H) && (__cplusplus >= 201103L)
|
|
52
|
+
# include <cstdbool>
|
|
53
|
+
# endif
|
|
54
|
+
#elif defined(HAVE_STDBOOL_H)
|
|
55
|
+
# include <stdbool.h>
|
|
56
|
+
#elif !defined(HAVE__BOOL)
|
|
57
|
+
typedef unsigned char _Bool;
|
|
58
|
+
# define bool _Bool
|
|
59
|
+
# define true ((_Bool)+1)
|
|
60
|
+
# define false ((_Bool)+0)
|
|
61
|
+
# define __bool_true_false_are_defined
|
|
62
|
+
#endif
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
#ifndef HAVE_RUBY_XFREE_SIZED
|
|
66
|
+
static inline void ruby_xfree_sized(void *ptr, size_t oldsize)
|
|
67
|
+
{
|
|
68
|
+
ruby_xfree(ptr);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static inline void *ruby_xrealloc2_sized(void *ptr, size_t new_elems, size_t elem_size, size_t old_elems)
|
|
72
|
+
{
|
|
73
|
+
return ruby_xrealloc2(ptr, new_elems, elem_size);
|
|
74
|
+
}
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
# define JSON_SIZED_REALLOC_N(v, T, m, n) \
|
|
78
|
+
((v) = (T *)ruby_xrealloc2_sized((void *)(v), (m), sizeof(T), (n)))
|
|
79
|
+
|
|
80
|
+
# define JSON_SIZED_FREE(v) ruby_xfree_sized((void *)(v), sizeof(*(v)))
|
|
81
|
+
# define JSON_SIZED_FREE_N(v, n) ruby_xfree_sized((void *)(v), sizeof(*(v)) * (n))
|
|
82
|
+
|
|
83
|
+
#ifndef HAVE_RB_EXT_RACTOR_SAFE
|
|
84
|
+
# undef RUBY_TYPED_FROZEN_SHAREABLE
|
|
85
|
+
# define RUBY_TYPED_FROZEN_SHAREABLE 0
|
|
86
|
+
#endif
|
|
87
|
+
|
|
88
|
+
#ifdef RUBY_TYPED_EMBEDDABLE
|
|
89
|
+
# define HAVE_RUBY_TYPED_EMBEDDABLE 1
|
|
90
|
+
#else
|
|
91
|
+
# ifdef HAVE_CONST_RUBY_TYPED_EMBEDDABLE
|
|
92
|
+
# define RUBY_TYPED_EMBEDDABLE RUBY_TYPED_EMBEDDABLE
|
|
93
|
+
# define HAVE_RUBY_TYPED_EMBEDDABLE 1
|
|
94
|
+
# else
|
|
95
|
+
# define RUBY_TYPED_EMBEDDABLE 0
|
|
96
|
+
# endif
|
|
97
|
+
#endif
|
|
98
|
+
|
|
99
|
+
#ifndef NORETURN
|
|
100
|
+
#if defined(__has_attribute) && __has_attribute(noreturn)
|
|
101
|
+
#define NORETURN(x) __attribute__((noreturn)) x
|
|
102
|
+
#else
|
|
103
|
+
#define NORETURN(x) x
|
|
104
|
+
#endif
|
|
105
|
+
#endif
|
|
106
|
+
|
|
107
|
+
#ifndef NOINLINE
|
|
108
|
+
#if defined(__has_attribute) && __has_attribute(noinline)
|
|
109
|
+
#define NOINLINE(x) __attribute__((noinline)) x
|
|
110
|
+
#else
|
|
111
|
+
#define NOINLINE(x) x
|
|
112
|
+
#endif
|
|
113
|
+
#endif
|
|
114
|
+
|
|
115
|
+
#ifndef ALWAYS_INLINE
|
|
116
|
+
#if defined(__has_attribute) && __has_attribute(always_inline)
|
|
117
|
+
#define ALWAYS_INLINE(x) inline __attribute__((always_inline)) x
|
|
118
|
+
#else
|
|
119
|
+
#define ALWAYS_INLINE(x) inline x
|
|
120
|
+
#endif
|
|
121
|
+
#endif
|
|
122
|
+
|
|
123
|
+
#ifndef RB_UNLIKELY
|
|
124
|
+
#define RB_UNLIKELY(expr) expr
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
#ifndef RB_LIKELY
|
|
128
|
+
#define RB_LIKELY(expr) expr
|
|
129
|
+
#endif
|
|
130
|
+
|
|
131
|
+
#ifndef MAYBE_UNUSED
|
|
132
|
+
# define MAYBE_UNUSED(x) x
|
|
133
|
+
#endif
|
|
134
|
+
|
|
135
|
+
#ifdef RUBY_DEBUG
|
|
136
|
+
#ifndef JSON_DEBUG
|
|
137
|
+
#define JSON_DEBUG RUBY_DEBUG
|
|
138
|
+
#endif
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && INTPTR_MAX == INT64_MAX
|
|
142
|
+
#define JSON_CPU_LITTLE_ENDIAN_64BITS 1
|
|
143
|
+
#else
|
|
144
|
+
#define JSON_CPU_LITTLE_ENDIAN_64BITS 0
|
|
145
|
+
#endif
|
|
146
|
+
|
|
147
|
+
#ifdef JSON_TRUFFLERUBY_RB_CATCH_BUG
|
|
148
|
+
|
|
149
|
+
#undef RB_BLOCK_CALL_FUNC_ARGLIST
|
|
150
|
+
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, func_args) VALUE func_args
|
|
151
|
+
|
|
152
|
+
NORETURN(static inline) void json_rb_throw_obj(VALUE tag, VALUE obj)
|
|
153
|
+
{
|
|
154
|
+
VALUE exc = rb_exc_new_str(rb_eException, rb_utf8_str_new_cstr("throw_workaround"));
|
|
155
|
+
rb_ivar_set(exc, rb_intern("@throw_tag"), tag);
|
|
156
|
+
rb_ivar_set(exc, rb_intern("@throw_obj"), obj);
|
|
157
|
+
rb_exc_raise(exc);
|
|
158
|
+
}
|
|
159
|
+
#define rb_throw_obj json_rb_throw_obj
|
|
160
|
+
|
|
161
|
+
static inline VALUE json_rb_catch_obj(VALUE tag, VALUE (*func)(VALUE args), VALUE func_args)
|
|
162
|
+
{
|
|
163
|
+
int status;
|
|
164
|
+
VALUE result = rb_protect(func, func_args, &status);
|
|
165
|
+
if (status) {
|
|
166
|
+
VALUE exc = rb_errinfo();
|
|
167
|
+
if (tag == rb_ivar_get(exc, rb_intern("@throw_tag"))) {
|
|
168
|
+
rb_set_errinfo(Qnil);
|
|
169
|
+
return rb_ivar_get(exc, rb_intern("@throw_obj"));
|
|
170
|
+
}
|
|
171
|
+
rb_jump_tag(status);
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
#define rb_catch_obj json_rb_catch_obj
|
|
176
|
+
|
|
177
|
+
#endif // JSON_TRUFFLERUBY_RB_CATCH_BUG
|
|
178
|
+
|
|
179
|
+
#endif // _JSON_H_
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'mkmf'
|
|
3
|
+
|
|
4
|
+
$defs << "-DJSON_DEBUG" if ENV.fetch("JSON_DEBUG", "0") != "0"
|
|
5
|
+
|
|
6
|
+
if RUBY_ENGINE == 'truffleruby' && RUBY_ENGINE_VERSION < '40.0'
|
|
7
|
+
# Ref: https://github.com/truffleruby/truffleruby/issues/4329
|
|
8
|
+
# Ref: https://github.com/truffleruby/truffleruby/pull/4333
|
|
9
|
+
$defs << "-DJSON_TRUFFLERUBY_RB_CATCH_BUG"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
have_func("rb_enc_interned_str", "ruby/encoding.h") # RUBY_VERSION >= 3.0
|
|
13
|
+
have_func("rb_str_to_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
|
|
14
|
+
have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
|
|
15
|
+
have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
|
|
16
|
+
have_func("ruby_xfree_sized", "ruby.h") # RUBY_VERSION >= 4.1
|
|
17
|
+
|
|
18
|
+
def have_builtin_func(name, check_expr, opt = "", &b)
|
|
19
|
+
checking_for checking_message(name.funcall_style, nil, opt) do
|
|
20
|
+
if try_compile(<<SRC, opt, &b)
|
|
21
|
+
int foo;
|
|
22
|
+
int main() { #{check_expr}; return 0; }
|
|
23
|
+
SRC
|
|
24
|
+
$defs.push(format("-DHAVE_BUILTIN_%s", name.tr_cpp))
|
|
25
|
+
true
|
|
26
|
+
else
|
|
27
|
+
false
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
|
|
33
|
+
|
|
34
|
+
if have_header("x86intrin.h")
|
|
35
|
+
have_func("_lzcnt_u64", "x86intrin.h")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if have_header("intrin.h")
|
|
39
|
+
have_func("__lzcnt64", "intrin.h")
|
|
40
|
+
have_func("_BitScanReverse64", "intrin.h")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if RUBY_ENGINE == "ruby"
|
|
44
|
+
have_const("RUBY_TYPED_EMBEDDABLE", "ruby.h") # RUBY_VERSION >= 3.3
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
append_cflags("-std=c99")
|
|
48
|
+
|
|
49
|
+
if enable_config('parser-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
|
|
50
|
+
load __dir__ + "/../simd/conf.rb"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
create_makefile 'json/ext/parser'
|