json 2.19.3 → 2.21.1

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.
data/ext/json/ext/json.h CHANGED
@@ -11,6 +11,9 @@
11
11
 
12
12
  #if defined(RUBY_DEBUG) && RUBY_DEBUG
13
13
  # define JSON_ASSERT RUBY_ASSERT
14
+ # ifndef JSON_DEBUG
15
+ # define JSON_DEBUG 1
16
+ # endif
14
17
  #else
15
18
  # ifdef JSON_DEBUG
16
19
  # include <assert.h>
@@ -20,8 +23,22 @@
20
23
  # endif
21
24
  #endif
22
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
+
23
32
  /* shims */
24
33
 
34
+ #ifndef RUBY_TYPED_THREAD_SAFE_FREE
35
+ #define RUBY_TYPED_THREAD_SAFE_FREE RUBY_TYPED_FREE_IMMEDIATELY
36
+ #endif
37
+
38
+ #ifndef UNDEF_P
39
+ #define UNDEF_P(val) (val == Qundef)
40
+ #endif
41
+
25
42
  #if SIZEOF_UINT64_T == SIZEOF_LONG_LONG
26
43
  # define INT64T2NUM(x) LL2NUM(x)
27
44
  # define UINT64T2NUM(x) ULL2NUM(x)
@@ -49,11 +66,40 @@ typedef unsigned char _Bool;
49
66
  #endif
50
67
  #endif
51
68
 
69
+ #ifndef HAVE_RUBY_XFREE_SIZED
70
+ static inline void ruby_xfree_sized(void *ptr, size_t oldsize)
71
+ {
72
+ ruby_xfree(ptr);
73
+ }
74
+
75
+ static inline void *ruby_xrealloc2_sized(void *ptr, size_t new_elems, size_t elem_size, size_t old_elems)
76
+ {
77
+ return ruby_xrealloc2(ptr, new_elems, elem_size);
78
+ }
79
+ #endif
80
+
81
+ # define JSON_SIZED_REALLOC_N(v, T, m, n) \
82
+ ((v) = (T *)ruby_xrealloc2_sized((void *)(v), (m), sizeof(T), (n)))
83
+
84
+ # define JSON_SIZED_FREE(v) ruby_xfree_sized((void *)(v), sizeof(*(v)))
85
+ # define JSON_SIZED_FREE_N(v, n) ruby_xfree_sized((void *)(v), sizeof(*(v)) * (n))
86
+
52
87
  #ifndef HAVE_RB_EXT_RACTOR_SAFE
53
88
  # undef RUBY_TYPED_FROZEN_SHAREABLE
54
89
  # define RUBY_TYPED_FROZEN_SHAREABLE 0
55
90
  #endif
56
91
 
92
+ #ifdef RUBY_TYPED_EMBEDDABLE
93
+ # define HAVE_RUBY_TYPED_EMBEDDABLE 1
94
+ #else
95
+ # ifdef HAVE_CONST_RUBY_TYPED_EMBEDDABLE
96
+ # define RUBY_TYPED_EMBEDDABLE RUBY_TYPED_EMBEDDABLE
97
+ # define HAVE_RUBY_TYPED_EMBEDDABLE 1
98
+ # else
99
+ # define RUBY_TYPED_EMBEDDABLE 0
100
+ # endif
101
+ #endif
102
+
57
103
  #ifndef NORETURN
58
104
  #if defined(__has_attribute) && __has_attribute(noreturn)
59
105
  #define NORETURN(x) __attribute__((noreturn)) x
@@ -102,4 +148,36 @@ typedef unsigned char _Bool;
102
148
  #define JSON_CPU_LITTLE_ENDIAN_64BITS 0
103
149
  #endif
104
150
 
151
+ #ifdef JSON_TRUFFLERUBY_RB_CATCH_BUG
152
+
153
+ #undef RB_BLOCK_CALL_FUNC_ARGLIST
154
+ #define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, func_args) VALUE func_args
155
+
156
+ NORETURN(static inline) void json_rb_throw_obj(VALUE tag, VALUE obj)
157
+ {
158
+ VALUE exc = rb_exc_new_str(rb_eException, rb_utf8_str_new_cstr("throw_workaround"));
159
+ rb_ivar_set(exc, rb_intern("@throw_tag"), tag);
160
+ rb_ivar_set(exc, rb_intern("@throw_obj"), obj);
161
+ rb_exc_raise(exc);
162
+ }
163
+ #define rb_throw_obj json_rb_throw_obj
164
+
165
+ static inline VALUE json_rb_catch_obj(VALUE tag, VALUE (*func)(VALUE args), VALUE func_args)
166
+ {
167
+ int status;
168
+ VALUE result = rb_protect(func, func_args, &status);
169
+ if (status) {
170
+ VALUE exc = rb_errinfo();
171
+ if (tag == rb_ivar_get(exc, rb_intern("@throw_tag"))) {
172
+ rb_set_errinfo(Qnil);
173
+ return rb_ivar_get(exc, rb_intern("@throw_obj"));
174
+ }
175
+ rb_jump_tag(status);
176
+ }
177
+ return result;
178
+ }
179
+ #define rb_catch_obj json_rb_catch_obj
180
+
181
+ #endif // JSON_TRUFFLERUBY_RB_CATCH_BUG
182
+
105
183
  #endif // _JSON_H_
@@ -2,10 +2,31 @@
2
2
  require 'mkmf'
3
3
 
4
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
+
5
12
  have_func("rb_enc_interned_str", "ruby/encoding.h") # RUBY_VERSION >= 3.0
6
13
  have_func("rb_str_to_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
7
14
  have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
8
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
+ if have_header("x86intrin.h")
19
+ have_func("_lzcnt_u64", "x86intrin.h")
20
+ end
21
+
22
+ if have_header("intrin.h")
23
+ have_func("__lzcnt64", "intrin.h")
24
+ have_func("_BitScanReverse64", "intrin.h")
25
+ end
26
+
27
+ if RUBY_ENGINE == "ruby"
28
+ have_const("RUBY_TYPED_EMBEDDABLE", "ruby.h") # RUBY_VERSION >= 3.3
29
+ end
9
30
 
10
31
  append_cflags("-std=c99")
11
32