json 2.3.1 → 2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +38 -5
- data/LICENSE +56 -0
- data/README.md +3 -3
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +61 -22
- data/ext/json/ext/generator/generator.h +5 -2
- data/ext/json/ext/parser/extconf.rb +26 -0
- data/ext/json/ext/parser/parser.c +2980 -1770
- data/ext/json/ext/parser/parser.h +6 -1
- data/ext/json/ext/parser/parser.rl +127 -38
- data/ext/json/extconf.rb +1 -0
- data/json.gemspec +8 -80
- data/lib/json/add/complex.rb +0 -1
- data/lib/json/add/rational.rb +0 -1
- data/lib/json/common.rb +240 -228
- data/lib/json/pure/generator.rb +28 -8
- data/lib/json/pure/parser.rb +21 -3
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +172 -1
- metadata +8 -110
- data/.gitignore +0 -18
- data/.travis.yml +0 -26
- data/Gemfile +0 -14
- data/README-json-jruby.md +0 -33
- data/Rakefile +0 -334
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -166
- data/java/src/json/ext/Generator.java +0 -466
- data/java/src/json/ext/GeneratorMethods.java +0 -231
- data/java/src/json/ext/GeneratorService.java +0 -42
- data/java/src/json/ext/GeneratorState.java +0 -490
- data/java/src/json/ext/OptionsReader.java +0 -113
- data/java/src/json/ext/Parser.java +0 -2362
- data/java/src/json/ext/Parser.rl +0 -893
- data/java/src/json/ext/ParserService.java +0 -34
- data/java/src/json/ext/RuntimeInfo.java +0 -116
- data/java/src/json/ext/StringDecoder.java +0 -166
- data/java/src/json/ext/StringEncoder.java +0 -111
- data/java/src/json/ext/Utils.java +0 -88
- data/json-java.gemspec +0 -37
- data/json_pure.gemspec +0 -33
- data/lib/json/ext/.keep +0 -0
- data/references/rfc7159.txt +0 -899
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail18.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/obsolete_fail1.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass15.json +0 -1
- data/tests/fixtures/pass16.json +0 -1
- data/tests/fixtures/pass17.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass26.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/json_addition_test.rb +0 -203
- data/tests/json_common_interface_test.rb +0 -126
- data/tests/json_encoding_test.rb +0 -107
- data/tests/json_ext_parser_test.rb +0 -15
- data/tests/json_fixtures_test.rb +0 -37
- data/tests/json_generator_test.rb +0 -421
- data/tests/json_generic_object_test.rb +0 -82
- data/tests/json_parser_test.rb +0 -472
- data/tests/json_string_matching_test.rb +0 -38
- data/tests/test_helper.rb +0 -17
- data/tools/diff.sh +0 -18
- data/tools/fuzz.rb +0 -131
- data/tools/server.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21e09bba5bfe89e923363872b46bfb0ee800ff01e039e36b662008c85983983f
|
4
|
+
data.tar.gz: 2f319b945dd9f7510ce8dac412ab6d69f289942278cd298728af1cecb3b329c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7edf79e46c4a5e1b353f1463cad92af3198c8983247e9bb04751dd98ee714040455ebff17f03fe2b1a7928992885914d192e8b509673a26b47c8966822cb450
|
7
|
+
data.tar.gz: 5b086c18aac3d99ac1ef2ec5bdf66af841ba5dd6bc3a85e1e8e65ccb086458902b4a49fdb08a8acce978a46c13b82c23dc724450869f02898d6374d79750aca6
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
### 2021-10-24 (2.6.1)
|
4
|
+
|
5
|
+
* Restore version.rb with 2.6.1
|
6
|
+
|
7
|
+
### 2021-10-14 (2.6.0)
|
8
|
+
|
9
|
+
* Use `rb_enc_interned_str` if available to reduce allocations in `freeze: true` mode. #451.
|
10
|
+
* Bump required_ruby_version to 2.3.
|
11
|
+
* Fix compatibility with `GC.compact`.
|
12
|
+
* Fix some compilation warnings. #469
|
13
|
+
|
14
|
+
## 2020-12-22 (2.5.1)
|
15
|
+
|
16
|
+
* Restore the compatibility for constants of JSON class.
|
17
|
+
|
18
|
+
## 2020-12-22 (2.5.0)
|
19
|
+
|
20
|
+
* Ready to Ractor-safe at Ruby 3.0.
|
21
|
+
|
22
|
+
## 2020-12-17 (2.4.1)
|
23
|
+
|
24
|
+
* Restore version.rb with 2.4.1
|
25
|
+
|
26
|
+
## 2020-12-15 (2.4.0)
|
27
|
+
|
28
|
+
* Implement a freeze: parser option #447
|
29
|
+
* Fix an issue with generate_pretty and empty objects in the Ruby and Java implementations #449
|
30
|
+
* Fix JSON.load_file doc #448
|
31
|
+
* Fix pure parser with unclosed arrays / objects #425
|
32
|
+
* bundle the LICENSE file in the gem #444
|
33
|
+
* Add an option to escape forward slash character #405
|
34
|
+
* RDoc for JSON #439 #446 #442 #434 #433 #430
|
35
|
+
|
3
36
|
## 2020-06-30 (2.3.1)
|
4
37
|
|
5
38
|
* Spelling and grammar fixes for comments. Pull request #191 by Josh
|
@@ -61,7 +94,7 @@
|
|
61
94
|
|
62
95
|
## 2015-09-11 (2.0.0)
|
63
96
|
* Now complies to newest JSON RFC 7159.
|
64
|
-
* Implements
|
97
|
+
* Implements compatibility to ruby 2.4 integer unification.
|
65
98
|
* Drops support for old rubies whose life has ended, that is rubies < 2.0.
|
66
99
|
Also see https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/
|
67
100
|
* There were still some mentions of dual GPL licensing in the source, but JSON
|
@@ -102,9 +135,9 @@
|
|
102
135
|
## 2013-02-04 (1.7.7)
|
103
136
|
* Security fix for JSON create_additions default value and
|
104
137
|
`JSON::GenericObject`. It should not be possible to create additions unless
|
105
|
-
|
138
|
+
explicitly requested by setting the create_additions argument to true or
|
106
139
|
using the JSON.load/dump interface. If `JSON::GenericObject` is supposed to
|
107
|
-
be automatically deserialised, this has to be
|
140
|
+
be automatically deserialised, this has to be explicitly enabled by
|
108
141
|
setting
|
109
142
|
JSON::GenericObject.json_creatable = true
|
110
143
|
as well.
|
@@ -250,7 +283,7 @@
|
|
250
283
|
## 2010-04-23 (1.4.0)
|
251
284
|
* Major speed improvements and building with simplified
|
252
285
|
directory/file-structure.
|
253
|
-
* Extension should at least be
|
286
|
+
* Extension should at least be compatible with MRI, YARV and Rubinius.
|
254
287
|
|
255
288
|
## 2010-04-07 (1.2.4)
|
256
289
|
* Triger const_missing callback to make Rails' dynamic class loading work.
|
@@ -268,7 +301,7 @@
|
|
268
301
|
strings in object names/keys.
|
269
302
|
|
270
303
|
## 2009-10-01 (1.2.0)
|
271
|
-
* `fast_generate` now raises an
|
304
|
+
* `fast_generate` now raises an exception for nan and infinite floats.
|
272
305
|
* On Ruby 1.8 json supports parsing of UTF-8, UTF-16BE, UTF-16LE, UTF-32BE,
|
273
306
|
and UTF-32LE JSON documents now. Under Ruby 1.9 the M17n conversion
|
274
307
|
functions are used to convert from all supported encodings. ASCII-8BIT
|
data/LICENSE
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c) give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# JSON implementation for Ruby
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CI](https://github.com/flori/json/actions/workflows/ci.yml/badge.svg)](https://github.com/flori/json/actions/workflows/ci.yml)
|
4
4
|
|
5
5
|
## Description
|
6
6
|
|
@@ -267,7 +267,7 @@ the `pp` library's `pp` methods.
|
|
267
267
|
|
268
268
|
The script `tools/server.rb` contains a small example if you want to test, how
|
269
269
|
receiving a JSON object from a webrick server in your browser with the
|
270
|
-
|
270
|
+
JavaScript prototype library http://www.prototypejs.org works.
|
271
271
|
|
272
272
|
## Speed Comparisons
|
273
273
|
|
@@ -294,7 +294,7 @@ extension:
|
|
294
294
|
```
|
295
295
|
|
296
296
|
In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
|
297
|
-
|
297
|
+
compatible JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
|
298
298
|
`ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
|
299
299
|
input first to YAML and then uses the YAML-parser, the conversion seems to
|
300
300
|
slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.2
|
@@ -1,11 +1,6 @@
|
|
1
1
|
#include "../fbuffer/fbuffer.h"
|
2
2
|
#include "generator.h"
|
3
3
|
|
4
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
5
|
-
static VALUE CEncoding_UTF_8;
|
6
|
-
static ID i_encoding, i_encode;
|
7
|
-
#endif
|
8
|
-
|
9
4
|
static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
10
5
|
mHash, mArray,
|
11
6
|
#ifdef RUBY_INTEGER_UNIFICATION
|
@@ -15,14 +10,13 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
|
15
10
|
#endif
|
16
11
|
mFloat, mString, mString_Extend,
|
17
12
|
mTrueClass, mFalseClass, mNilClass, eGeneratorError,
|
18
|
-
eNestingError
|
19
|
-
i_SAFE_STATE_PROTOTYPE;
|
13
|
+
eNestingError;
|
20
14
|
|
21
15
|
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
22
16
|
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
|
23
17
|
i_pack, i_unpack, i_create_id, i_extend, i_key_p,
|
24
18
|
i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth,
|
25
|
-
i_buffer_initial_length, i_dup;
|
19
|
+
i_buffer_initial_length, i_dup, i_escape_slash;
|
26
20
|
|
27
21
|
/*
|
28
22
|
* Copyright 2001-2004 Unicode, Inc.
|
@@ -130,7 +124,7 @@ static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16
|
|
130
124
|
|
131
125
|
/* Converts string to a JSON string in FBuffer buffer, where all but the ASCII
|
132
126
|
* and control characters are JSON escaped. */
|
133
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
127
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash)
|
134
128
|
{
|
135
129
|
const UTF8 *source = (UTF8 *) RSTRING_PTR(string);
|
136
130
|
const UTF8 *sourceEnd = source + RSTRING_LEN(string);
|
@@ -180,6 +174,11 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
|
180
174
|
case '"':
|
181
175
|
fbuffer_append(buffer, "\\\"", 2);
|
182
176
|
break;
|
177
|
+
case '/':
|
178
|
+
if(escape_slash) {
|
179
|
+
fbuffer_append(buffer, "\\/", 2);
|
180
|
+
break;
|
181
|
+
}
|
183
182
|
default:
|
184
183
|
fbuffer_append_char(buffer, (char)ch);
|
185
184
|
break;
|
@@ -229,7 +228,7 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
|
229
228
|
* characters required by the JSON standard are JSON escaped. The remaining
|
230
229
|
* characters (should be UTF8) are just passed through and appended to the
|
231
230
|
* result. */
|
232
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
231
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash)
|
233
232
|
{
|
234
233
|
const char *ptr = RSTRING_PTR(string), *p;
|
235
234
|
unsigned long len = RSTRING_LEN(string), start = 0, end = 0;
|
@@ -280,6 +279,12 @@ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string)
|
|
280
279
|
escape = "\\\"";
|
281
280
|
escape_len = 2;
|
282
281
|
break;
|
282
|
+
case '/':
|
283
|
+
if(escape_slash) {
|
284
|
+
escape = "\\/";
|
285
|
+
escape_len = 2;
|
286
|
+
break;
|
287
|
+
}
|
283
288
|
default:
|
284
289
|
{
|
285
290
|
unsigned short clen = 1;
|
@@ -609,13 +614,18 @@ static size_t State_memsize(const void *ptr)
|
|
609
614
|
return size;
|
610
615
|
}
|
611
616
|
|
617
|
+
#ifndef HAVE_RB_EXT_RACTOR_SAFE
|
618
|
+
# undef RUBY_TYPED_FROZEN_SHAREABLE
|
619
|
+
# define RUBY_TYPED_FROZEN_SHAREABLE 0
|
620
|
+
#endif
|
621
|
+
|
612
622
|
#ifdef NEW_TYPEDDATA_WRAPPER
|
613
623
|
static const rb_data_type_t JSON_Generator_State_type = {
|
614
624
|
"JSON/Generator/State",
|
615
625
|
{NULL, State_free, State_memsize,},
|
616
626
|
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
617
627
|
0, 0,
|
618
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
628
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE,
|
619
629
|
#endif
|
620
630
|
};
|
621
631
|
#endif
|
@@ -716,6 +726,8 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
716
726
|
state->allow_nan = RTEST(tmp);
|
717
727
|
tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
|
718
728
|
state->ascii_only = RTEST(tmp);
|
729
|
+
tmp = rb_hash_aref(opts, ID2SYM(i_escape_slash));
|
730
|
+
state->escape_slash = RTEST(tmp);
|
719
731
|
return self;
|
720
732
|
}
|
721
733
|
|
@@ -750,6 +762,7 @@ static VALUE cState_to_h(VALUE self)
|
|
750
762
|
rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse);
|
751
763
|
rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse);
|
752
764
|
rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting));
|
765
|
+
rb_hash_aset(result, ID2SYM(i_escape_slash), state->escape_slash ? Qtrue : Qfalse);
|
753
766
|
rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth));
|
754
767
|
rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length));
|
755
768
|
return result;
|
@@ -930,13 +943,13 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
930
943
|
fbuffer_append_char(buffer, '"');
|
931
944
|
#ifdef HAVE_RUBY_ENCODING_H
|
932
945
|
if (!enc_utf8_compatible_p(rb_enc_get(obj))) {
|
933
|
-
obj =
|
946
|
+
obj = rb_str_export_to_enc(obj, rb_utf8_encoding());
|
934
947
|
}
|
935
948
|
#endif
|
936
949
|
if (state->ascii_only) {
|
937
|
-
convert_UTF8_to_JSON_ASCII(buffer, obj);
|
950
|
+
convert_UTF8_to_JSON_ASCII(buffer, obj, state->escape_slash);
|
938
951
|
} else {
|
939
|
-
convert_UTF8_to_JSON(buffer, obj);
|
952
|
+
convert_UTF8_to_JSON(buffer, obj, state->escape_slash);
|
940
953
|
}
|
941
954
|
fbuffer_append_char(buffer, '"');
|
942
955
|
}
|
@@ -1152,8 +1165,7 @@ static VALUE cState_from_state_s(VALUE self, VALUE opts)
|
|
1152
1165
|
} else if (rb_obj_is_kind_of(opts, rb_cHash)) {
|
1153
1166
|
return rb_funcall(self, i_new, 1, opts);
|
1154
1167
|
} else {
|
1155
|
-
|
1156
|
-
return rb_funcall(prototype, i_dup, 0);
|
1168
|
+
return rb_class_new_instance(0, NULL, cState);
|
1157
1169
|
}
|
1158
1170
|
}
|
1159
1171
|
|
@@ -1377,6 +1389,31 @@ static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
|
|
1377
1389
|
return state->max_nesting = FIX2LONG(depth);
|
1378
1390
|
}
|
1379
1391
|
|
1392
|
+
/*
|
1393
|
+
* call-seq: escape_slash
|
1394
|
+
*
|
1395
|
+
* If this boolean is true, the forward slashes will be escaped in
|
1396
|
+
* the json output.
|
1397
|
+
*/
|
1398
|
+
static VALUE cState_escape_slash(VALUE self)
|
1399
|
+
{
|
1400
|
+
GET_STATE(self);
|
1401
|
+
return state->escape_slash ? Qtrue : Qfalse;
|
1402
|
+
}
|
1403
|
+
|
1404
|
+
/*
|
1405
|
+
* call-seq: escape_slash=(depth)
|
1406
|
+
*
|
1407
|
+
* This sets whether or not the forward slashes will be escaped in
|
1408
|
+
* the json output.
|
1409
|
+
*/
|
1410
|
+
static VALUE cState_escape_slash_set(VALUE self, VALUE enable)
|
1411
|
+
{
|
1412
|
+
GET_STATE(self);
|
1413
|
+
state->escape_slash = RTEST(enable);
|
1414
|
+
return Qnil;
|
1415
|
+
}
|
1416
|
+
|
1380
1417
|
/*
|
1381
1418
|
* call-seq: allow_nan?
|
1382
1419
|
*
|
@@ -1460,6 +1497,10 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l
|
|
1460
1497
|
*/
|
1461
1498
|
void Init_generator(void)
|
1462
1499
|
{
|
1500
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
1501
|
+
rb_ext_ractor_safe(true);
|
1502
|
+
#endif
|
1503
|
+
|
1463
1504
|
#undef rb_intern
|
1464
1505
|
rb_require("json/common");
|
1465
1506
|
|
@@ -1489,6 +1530,9 @@ void Init_generator(void)
|
|
1489
1530
|
rb_define_method(cState, "array_nl=", cState_array_nl_set, 1);
|
1490
1531
|
rb_define_method(cState, "max_nesting", cState_max_nesting, 0);
|
1491
1532
|
rb_define_method(cState, "max_nesting=", cState_max_nesting_set, 1);
|
1533
|
+
rb_define_method(cState, "escape_slash", cState_escape_slash, 0);
|
1534
|
+
rb_define_method(cState, "escape_slash?", cState_escape_slash, 0);
|
1535
|
+
rb_define_method(cState, "escape_slash=", cState_escape_slash_set, 1);
|
1492
1536
|
rb_define_method(cState, "check_circular?", cState_check_circular_p, 0);
|
1493
1537
|
rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0);
|
1494
1538
|
rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0);
|
@@ -1545,6 +1589,7 @@ void Init_generator(void)
|
|
1545
1589
|
i_object_nl = rb_intern("object_nl");
|
1546
1590
|
i_array_nl = rb_intern("array_nl");
|
1547
1591
|
i_max_nesting = rb_intern("max_nesting");
|
1592
|
+
i_escape_slash = rb_intern("escape_slash");
|
1548
1593
|
i_allow_nan = rb_intern("allow_nan");
|
1549
1594
|
i_ascii_only = rb_intern("ascii_only");
|
1550
1595
|
i_depth = rb_intern("depth");
|
@@ -1560,10 +1605,4 @@ void Init_generator(void)
|
|
1560
1605
|
i_match = rb_intern("match");
|
1561
1606
|
i_keys = rb_intern("keys");
|
1562
1607
|
i_dup = rb_intern("dup");
|
1563
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
1564
|
-
CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
|
1565
|
-
i_encoding = rb_intern("encoding");
|
1566
|
-
i_encode = rb_intern("encode");
|
1567
|
-
#endif
|
1568
|
-
i_SAFE_STATE_PROTOTYPE = rb_intern("SAFE_STATE_PROTOTYPE");
|
1569
1608
|
}
|
@@ -49,8 +49,8 @@ static const UTF32 halfMask = 0x3FFUL;
|
|
49
49
|
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
50
50
|
static void unicode_escape(char *buf, UTF16 character);
|
51
51
|
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
52
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
|
53
|
-
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
|
52
|
+
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char escape_slash);
|
53
|
+
static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char escape_slash);
|
54
54
|
static char *fstrndup(const char *ptr, unsigned long len);
|
55
55
|
|
56
56
|
/* ruby api and some helpers */
|
@@ -72,6 +72,7 @@ typedef struct JSON_Generator_StateStruct {
|
|
72
72
|
long max_nesting;
|
73
73
|
char allow_nan;
|
74
74
|
char ascii_only;
|
75
|
+
char escape_slash;
|
75
76
|
long depth;
|
76
77
|
long buffer_initial_length;
|
77
78
|
} JSON_Generator_State;
|
@@ -150,6 +151,8 @@ static VALUE cState_allow_nan_p(VALUE self);
|
|
150
151
|
static VALUE cState_ascii_only_p(VALUE self);
|
151
152
|
static VALUE cState_depth(VALUE self);
|
152
153
|
static VALUE cState_depth_set(VALUE self, VALUE depth);
|
154
|
+
static VALUE cState_escape_slash(VALUE self);
|
155
|
+
static VALUE cState_escape_slash_set(VALUE self, VALUE depth);
|
153
156
|
static FBuffer *cState_prepare_buffer(VALUE self);
|
154
157
|
#ifndef ZALLOC
|
155
158
|
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
@@ -2,5 +2,31 @@
|
|
2
2
|
require 'mkmf'
|
3
3
|
|
4
4
|
have_func("rb_enc_raise", "ruby.h")
|
5
|
+
have_func("rb_enc_interned_str", "ruby.h")
|
6
|
+
|
7
|
+
# checking if String#-@ (str_uminus) dedupes... '
|
8
|
+
begin
|
9
|
+
a = -(%w(t e s t).join)
|
10
|
+
b = -(%w(t e s t).join)
|
11
|
+
if a.equal?(b)
|
12
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
|
13
|
+
else
|
14
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
15
|
+
end
|
16
|
+
rescue NoMethodError
|
17
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
|
18
|
+
end
|
19
|
+
|
20
|
+
# checking if String#-@ (str_uminus) directly interns frozen strings... '
|
21
|
+
begin
|
22
|
+
s = rand.to_s.freeze
|
23
|
+
if (-s).equal?(s) && (-s.dup).equal?(s)
|
24
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
|
25
|
+
else
|
26
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
27
|
+
end
|
28
|
+
rescue NoMethodError
|
29
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
30
|
+
end
|
5
31
|
|
6
32
|
create_makefile 'json/ext/parser'
|