json 1.8.0 → 2.6.2
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 +5 -5
- data/{CHANGES → CHANGES.md} +262 -87
- data/{COPYING-json-jruby → LICENSE} +5 -6
- data/README.md +425 -0
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +10 -4
- data/ext/json/ext/generator/extconf.rb +0 -10
- data/ext/json/ext/generator/generator.c +308 -135
- data/ext/json/ext/generator/generator.h +35 -9
- data/ext/json/ext/parser/extconf.rb +25 -6
- data/ext/json/ext/parser/parser.c +3044 -1901
- data/ext/json/ext/parser/parser.h +29 -10
- data/ext/json/ext/parser/parser.rl +270 -211
- data/ext/json/extconf.rb +3 -0
- data/json.gemspec +57 -27
- data/lib/json/add/bigdecimal.rb +3 -2
- data/lib/json/add/complex.rb +9 -3
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +1 -1
- data/lib/json/add/date_time.rb +1 -1
- data/lib/json/add/exception.rb +1 -1
- data/lib/json/add/ostruct.rb +3 -3
- data/lib/json/add/range.rb +1 -1
- data/lib/json/add/rational.rb +8 -3
- data/lib/json/add/regexp.rb +3 -3
- data/lib/json/add/set.rb +29 -0
- data/lib/json/add/struct.rb +1 -1
- data/lib/json/add/symbol.rb +1 -1
- data/lib/json/add/time.rb +2 -2
- data/lib/json/common.rb +383 -167
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure/generator.rb +83 -126
- data/lib/json/pure/parser.rb +63 -85
- data/lib/json/pure.rb +2 -8
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +550 -29
- metadata +29 -136
- data/.gitignore +0 -12
- data/.travis.yml +0 -20
- data/COPYING +0 -58
- data/GPL +0 -340
- data/Gemfile +0 -11
- data/README-json-jruby.markdown +0 -33
- data/README.rdoc +0 -358
- data/Rakefile +0 -412
- data/TODO +0 -1
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -167
- data/java/src/json/ext/Generator.java +0 -444
- data/java/src/json/ext/GeneratorMethods.java +0 -232
- data/java/src/json/ext/GeneratorService.java +0 -43
- data/java/src/json/ext/GeneratorState.java +0 -543
- data/java/src/json/ext/OptionsReader.java +0 -114
- data/java/src/json/ext/Parser.java +0 -2644
- data/java/src/json/ext/Parser.rl +0 -968
- data/java/src/json/ext/ParserService.java +0 -35
- data/java/src/json/ext/RuntimeInfo.java +0 -121
- data/java/src/json/ext/StringDecoder.java +0 -167
- data/java/src/json/ext/StringEncoder.java +0 -106
- data/java/src/json/ext/Utils.java +0 -89
- data/json-java.gemspec +0 -23
- data/json_pure.gemspec +0 -39
- data/lib/json/ext/.keep +0 -0
- data/tests/fixtures/fail1.json +0 -1
- 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/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/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -545
- data/tests/test_json_addition.rb +0 -196
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_fixtures.rb +0 -35
- data/tests/test_json_generate.rb +0 -322
- data/tests/test_json_generic_object.rb +0 -75
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
- data/tools/fuzz.rb +0 -139
- data/tools/server.rb +0 -62
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#ifndef _GENERATOR_H_
|
|
2
2
|
#define _GENERATOR_H_
|
|
3
3
|
|
|
4
|
-
#include <string.h>
|
|
5
4
|
#include <math.h>
|
|
6
5
|
#include <ctype.h>
|
|
7
6
|
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
|
|
24
23
|
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
|
|
25
24
|
|
|
26
|
-
/* unicode
|
|
25
|
+
/* unicode definitions */
|
|
27
26
|
|
|
28
27
|
#define UNI_STRICT_CONVERSION 1
|
|
29
28
|
|
|
@@ -50,8 +49,8 @@ static const UTF32 halfMask = 0x3FFUL;
|
|
|
50
49
|
static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
|
|
51
50
|
static void unicode_escape(char *buf, UTF16 character);
|
|
52
51
|
static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
|
|
53
|
-
static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
|
|
54
|
-
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);
|
|
55
54
|
static char *fstrndup(const char *ptr, unsigned long len);
|
|
56
55
|
|
|
57
56
|
/* ruby api and some helpers */
|
|
@@ -73,14 +72,17 @@ typedef struct JSON_Generator_StateStruct {
|
|
|
73
72
|
long max_nesting;
|
|
74
73
|
char allow_nan;
|
|
75
74
|
char ascii_only;
|
|
76
|
-
char
|
|
75
|
+
char escape_slash;
|
|
77
76
|
long depth;
|
|
78
77
|
long buffer_initial_length;
|
|
79
78
|
} JSON_Generator_State;
|
|
80
79
|
|
|
80
|
+
#define GET_STATE_TO(self, state) \
|
|
81
|
+
TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
|
|
82
|
+
|
|
81
83
|
#define GET_STATE(self) \
|
|
82
84
|
JSON_Generator_State *state; \
|
|
83
|
-
|
|
85
|
+
GET_STATE_TO(self, state)
|
|
84
86
|
|
|
85
87
|
#define GENERATE_JSON(type) \
|
|
86
88
|
FBuffer *buffer; \
|
|
@@ -89,15 +91,19 @@ typedef struct JSON_Generator_StateStruct {
|
|
|
89
91
|
\
|
|
90
92
|
rb_scan_args(argc, argv, "01", &Vstate); \
|
|
91
93
|
Vstate = cState_from_state_s(cState, Vstate); \
|
|
92
|
-
|
|
94
|
+
TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
|
|
93
95
|
buffer = cState_prepare_buffer(Vstate); \
|
|
94
96
|
generate_json_##type(buffer, Vstate, state, self); \
|
|
95
97
|
return fbuffer_to_s(buffer)
|
|
96
98
|
|
|
97
99
|
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
|
98
100
|
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
|
101
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
|
102
|
+
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
|
|
103
|
+
#else
|
|
99
104
|
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
|
|
100
105
|
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
|
|
106
|
+
#endif
|
|
101
107
|
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
|
|
102
108
|
static VALUE mString_included_s(VALUE self, VALUE modul);
|
|
103
109
|
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
|
|
@@ -108,8 +114,7 @@ static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
|
108
114
|
static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
109
115
|
static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
|
|
110
116
|
static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
|
|
111
|
-
static void State_free(
|
|
112
|
-
static JSON_Generator_State *State_allocate();
|
|
117
|
+
static void State_free(void *state);
|
|
113
118
|
static VALUE cState_s_allocate(VALUE klass);
|
|
114
119
|
static VALUE cState_configure(VALUE self, VALUE opts);
|
|
115
120
|
static VALUE cState_to_h(VALUE self);
|
|
@@ -120,6 +125,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
|
120
125
|
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
121
126
|
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
122
127
|
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
128
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
|
129
|
+
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
130
|
+
#endif
|
|
123
131
|
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
124
132
|
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
125
133
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
|
@@ -143,6 +151,24 @@ static VALUE cState_allow_nan_p(VALUE self);
|
|
|
143
151
|
static VALUE cState_ascii_only_p(VALUE self);
|
|
144
152
|
static VALUE cState_depth(VALUE self);
|
|
145
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);
|
|
146
156
|
static FBuffer *cState_prepare_buffer(VALUE self);
|
|
157
|
+
#ifndef ZALLOC
|
|
158
|
+
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
|
|
159
|
+
static inline void *ruby_zalloc(size_t n)
|
|
160
|
+
{
|
|
161
|
+
void *p = ruby_xmalloc(n);
|
|
162
|
+
memset(p, 0, n);
|
|
163
|
+
return p;
|
|
164
|
+
}
|
|
165
|
+
#endif
|
|
166
|
+
#ifdef TypedData_Make_Struct
|
|
167
|
+
static const rb_data_type_t JSON_Generator_State_type;
|
|
168
|
+
#define NEW_TYPEDDATA_WRAPPER 1
|
|
169
|
+
#else
|
|
170
|
+
#define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
|
|
171
|
+
#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
|
|
172
|
+
#endif
|
|
147
173
|
|
|
148
174
|
#endif
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: false
|
|
1
2
|
require 'mkmf'
|
|
2
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 '
|
|
5
18
|
end
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 '
|
|
10
27
|
end
|
|
28
|
+
rescue NoMethodError
|
|
29
|
+
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
|
|
11
30
|
end
|
|
12
31
|
|
|
13
32
|
create_makefile 'json/ext/parser'
|