json_pure 2.4.1 → 2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccaf5d00b6462faaa558a21e868626904f051a833eea93e81e2ae2e3cdc9dfd0
4
- data.tar.gz: 63d055fcb71de6f94d7c2632aba540f5450631a96813a7eee962939a0957b43d
3
+ metadata.gz: f4e1c25d9bf266db237cc4ff4b8ed5d3eef23970a2955629263bd77cde2a2d22
4
+ data.tar.gz: 17c534038df29705db934ed1142422809303e15e867b10826f2249b593b01b9c
5
5
  SHA512:
6
- metadata.gz: 7f40f310a0c21b71b936caa11fa219f24a746719d4e7f10c07a2dc7747a741943344a639ad21b404964413d00fe3f9a74c97e936d3fe82a1a36c23aae522724e
7
- data.tar.gz: 53cc02a7433b9d08cd7f6ba48bce2de608c8daac160e662fa8cf14d65173b9402527390a521aa90a1679fb0ee67f4e9a25b1e3cf4baeb7765c7adc12439f13fc
6
+ metadata.gz: 21d99e851ffb2f991fe4b1abc9aa68afe45fbce41db7bfd46a3e511b5f5436cf8074f9916287bf73b9bb9fb47c50747b49a75461c90c43300cb9dcb196c28856
7
+ data.tar.gz: b4f0783804a87d0274f757085933df8776c4faa7776d43075c9613b210ccff72988cdec0895aef6b94aaec2e02ce03b512c8d093b534bf7d4e4a5778716e51ca
data/CHANGES.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changes
2
2
 
3
+ ## 2020-12-22 (2.5.1)
4
+
5
+ * Restore the compatibility for constants of JSON class.
6
+
7
+ ## 2020-12-22 (2.5.0)
8
+
9
+ * Ready to Ractor-safe at Ruby 3.0.
10
+
3
11
  ## 2020-12-17 (2.4.1)
4
12
 
5
13
  * Restore version.rb with 2.4.1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.1
data/lib/json/common.rb CHANGED
@@ -71,22 +71,30 @@ module JSON
71
71
  end
72
72
  self.state = generator::State
73
73
  const_set :State, self.state
74
- const_set :SAFE_STATE_PROTOTYPE, State.new
75
- const_set :FAST_STATE_PROTOTYPE, State.new(
74
+ const_set :SAFE_STATE_PROTOTYPE, State.new # for JRuby
75
+ const_set :FAST_STATE_PROTOTYPE, create_fast_state
76
+ const_set :PRETTY_STATE_PROTOTYPE, create_pretty_state
77
+ ensure
78
+ $VERBOSE = old
79
+ end
80
+
81
+ def create_fast_state
82
+ State.new(
76
83
  :indent => '',
77
84
  :space => '',
78
85
  :object_nl => "",
79
86
  :array_nl => "",
80
87
  :max_nesting => false
81
88
  )
82
- const_set :PRETTY_STATE_PROTOTYPE, State.new(
89
+ end
90
+
91
+ def create_pretty_state
92
+ State.new(
83
93
  :indent => ' ',
84
94
  :space => ' ',
85
95
  :object_nl => "\n",
86
96
  :array_nl => "\n"
87
97
  )
88
- ensure
89
- $VERBOSE = old
90
98
  end
91
99
 
92
100
  # Returns the JSON generator module that is used by JSON. This is
@@ -98,13 +106,26 @@ module JSON
98
106
  # either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
99
107
  # JSON.state # => JSON::Ext::Generator::State
100
108
  attr_accessor :state
109
+ end
110
+
111
+ DEFAULT_CREATE_ID = 'json_class'.freeze
112
+ private_constant :DEFAULT_CREATE_ID
113
+
114
+ CREATE_ID_TLS_KEY = "JSON.create_id".freeze
115
+ private_constant :CREATE_ID_TLS_KEY
116
+
117
+ # Sets create identifier, which is used to decide if the _json_create_
118
+ # hook of a class should be called; initial value is +json_class+:
119
+ # JSON.create_id # => 'json_class'
120
+ def self.create_id=(new_value)
121
+ Thread.current[CREATE_ID_TLS_KEY] = new_value.dup.freeze
122
+ end
101
123
 
102
- # Sets or returns create identifier, which is used to decide if the _json_create_
103
- # hook of a class should be called; initial value is +json_class+:
104
- # JSON.create_id # => 'json_class'
105
- attr_accessor :create_id
124
+ # Returns the current create identifier.
125
+ # See also JSON.create_id=.
126
+ def self.create_id
127
+ Thread.current[CREATE_ID_TLS_KEY] || DEFAULT_CREATE_ID
106
128
  end
107
- self.create_id = 'json_class'
108
129
 
109
130
  NaN = 0.0/0
110
131
 
@@ -276,7 +297,7 @@ module JSON
276
297
  if State === opts
277
298
  state, opts = opts, nil
278
299
  else
279
- state = SAFE_STATE_PROTOTYPE.dup
300
+ state = State.new
280
301
  end
281
302
  if opts
282
303
  if opts.respond_to? :to_hash
@@ -315,7 +336,7 @@ module JSON
315
336
  if State === opts
316
337
  state, opts = opts, nil
317
338
  else
318
- state = FAST_STATE_PROTOTYPE.dup
339
+ state = JSON.create_fast_state
319
340
  end
320
341
  if opts
321
342
  if opts.respond_to? :to_hash
@@ -370,7 +391,7 @@ module JSON
370
391
  if State === opts
371
392
  state, opts = opts, nil
372
393
  else
373
- state = PRETTY_STATE_PROTOTYPE.dup
394
+ state = JSON.create_pretty_state
374
395
  end
375
396
  if opts
376
397
  if opts.respond_to? :to_hash
data/lib/json/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  module JSON
3
3
  # JSON version
4
- VERSION = '2.4.1'
4
+ VERSION = '2.5.1'
5
5
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
6
6
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
7
7
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -48,35 +48,6 @@ EOT
48
48
  $VERBOSE = v
49
49
  end
50
50
 
51
- def test_remove_const_segv
52
- stress = GC.stress
53
- const = JSON::SAFE_STATE_PROTOTYPE.dup
54
-
55
- bignum_too_long_to_embed_as_string = 1234567890123456789012345
56
- expect = bignum_too_long_to_embed_as_string.to_s
57
- GC.stress = true
58
-
59
- 10.times do |i|
60
- tmp = bignum_too_long_to_embed_as_string.to_json
61
- raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect
62
- end
63
-
64
- silence do
65
- JSON.const_set :SAFE_STATE_PROTOTYPE, nil
66
- end
67
-
68
- 10.times do |i|
69
- assert_raise TypeError do
70
- bignum_too_long_to_embed_as_string.to_json
71
- end
72
- end
73
- ensure
74
- GC.stress = stress
75
- silence do
76
- JSON.const_set :SAFE_STATE_PROTOTYPE, const
77
- end
78
- end if JSON.const_defined?("Ext") && RUBY_ENGINE != 'jruby'
79
-
80
51
  def test_generate
81
52
  json = generate(@hash)
82
53
  assert_equal(parse(@json2), parse(json))
@@ -171,7 +142,7 @@ EOT
171
142
  end
172
143
 
173
144
  def test_pretty_state
174
- state = PRETTY_STATE_PROTOTYPE.dup
145
+ state = JSON.create_pretty_state
175
146
  assert_equal({
176
147
  :allow_nan => false,
177
148
  :array_nl => "\n",
@@ -188,7 +159,7 @@ EOT
188
159
  end
189
160
 
190
161
  def test_safe_state
191
- state = SAFE_STATE_PROTOTYPE.dup
162
+ state = JSON::State.new
192
163
  assert_equal({
193
164
  :allow_nan => false,
194
165
  :array_nl => "",
@@ -205,7 +176,7 @@ EOT
205
176
  end
206
177
 
207
178
  def test_fast_state
208
- state = FAST_STATE_PROTOTYPE.dup
179
+ state = JSON.create_fast_state
209
180
  assert_equal({
210
181
  :allow_nan => false,
211
182
  :array_nl => "",
@@ -241,12 +212,8 @@ EOT
241
212
 
242
213
  def test_depth
243
214
  ary = []; ary << ary
244
- assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
245
215
  assert_raise(JSON::NestingError) { generate(ary) }
246
- assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
247
- assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
248
216
  assert_raise(JSON::NestingError) { JSON.pretty_generate(ary) }
249
- assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
250
217
  s = JSON.state.new
251
218
  assert_equal 0, s.depth
252
219
  assert_raise(JSON::NestingError) { ary.to_json(s) }
@@ -265,7 +232,7 @@ EOT
265
232
  end
266
233
 
267
234
  def test_gc
268
- if respond_to?(:assert_in_out_err)
235
+ if respond_to?(:assert_in_out_err) && !(RUBY_PLATFORM =~ /java/)
269
236
  assert_in_out_err(%w[-rjson --disable-gems], <<-EOS, [], [])
270
237
  bignum_too_long_to_embed_as_string = 1234567890123456789012345
271
238
  expect = bignum_too_long_to_embed_as_string.to_s