json 1.8.3 → 2.2.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.
Potentially problematic release.
This version of json might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +7 -10
- data/{CHANGES → CHANGES.md} +186 -90
- data/Gemfile +10 -6
- data/{README-json-jruby.markdown → README-json-jruby.md} +0 -0
- data/{README.rdoc → README.md} +184 -133
- data/Rakefile +33 -37
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +47 -61
- data/ext/json/ext/generator/generator.h +7 -2
- data/ext/json/ext/parser/extconf.rb +3 -0
- data/ext/json/ext/parser/parser.c +374 -459
- data/ext/json/ext/parser/parser.h +4 -5
- data/ext/json/ext/parser/parser.rl +133 -181
- data/ext/json/extconf.rb +0 -1
- data/java/src/json/ext/ByteListTranscoder.java +1 -2
- data/java/src/json/ext/Generator.java +11 -12
- data/java/src/json/ext/GeneratorMethods.java +1 -2
- data/java/src/json/ext/GeneratorService.java +1 -2
- data/java/src/json/ext/GeneratorState.java +3 -56
- data/java/src/json/ext/OptionsReader.java +2 -3
- data/java/src/json/ext/Parser.java +132 -415
- data/java/src/json/ext/Parser.rl +48 -124
- data/java/src/json/ext/ParserService.java +1 -2
- data/java/src/json/ext/RuntimeInfo.java +1 -6
- data/java/src/json/ext/StringDecoder.java +1 -2
- data/java/src/json/ext/StringEncoder.java +5 -0
- data/java/src/json/ext/Utils.java +1 -2
- data/json-java.gemspec +15 -0
- data/json.gemspec +0 -0
- data/json_pure.gemspec +24 -26
- data/lib/json/add/bigdecimal.rb +1 -0
- data/lib/json/add/complex.rb +2 -1
- 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 +1 -0
- data/lib/json/add/regexp.rb +1 -1
- 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 +1 -1
- data/lib/json/common.rb +24 -52
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +5 -4
- data/lib/json/pure/generator.rb +61 -125
- data/lib/json/pure/parser.rb +33 -81
- data/lib/json/pure.rb +2 -8
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +1 -0
- data/references/rfc7159.txt +899 -0
- data/tests/fixtures/obsolete_fail1.json +1 -0
- data/tests/{test_json_addition.rb → json_addition_test.rb} +32 -25
- data/tests/json_common_interface_test.rb +126 -0
- data/tests/json_encoding_test.rb +107 -0
- data/tests/json_ext_parser_test.rb +15 -0
- data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +5 -8
- data/tests/{test_json_generate.rb → json_generator_test.rb} +79 -39
- data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
- data/tests/json_parser_test.rb +472 -0
- data/tests/json_string_matching_test.rb +38 -0
- data/tests/{setup_variant.rb → test_helper.rb} +6 -0
- data/tools/diff.sh +18 -0
- data/tools/fuzz.rb +1 -9
- metadata +29 -47
- data/COPYING +0 -58
- data/COPYING-json-jruby +0 -57
- data/GPL +0 -340
- data/TODO +0 -1
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
- data/tests/fixtures/fail1.json +0 -1
- data/tests/test_json.rb +0 -553
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
data/Rakefile
CHANGED
@@ -23,10 +23,6 @@ class UndocumentedTestTask < Rake::TestTask
|
|
23
23
|
def desc(*) end
|
24
24
|
end
|
25
25
|
|
26
|
-
def skip_sdoc(src)
|
27
|
-
src.gsub(/^.*sdoc.*/) { |s| s + ' if RUBY_VERSION > "1.8.6"' }
|
28
|
-
end
|
29
|
-
|
30
26
|
MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') }
|
31
27
|
BUNDLE = ENV['BUNDLE'] || %w[bundle].find { |c| system(c, '-v') }
|
32
28
|
PKG_NAME = 'json'
|
@@ -87,25 +83,25 @@ if defined?(Gem) and defined?(Gem::PackageTask)
|
|
87
83
|
s.files = PKG_FILES
|
88
84
|
|
89
85
|
s.require_path = 'lib'
|
90
|
-
s.add_development_dependency '
|
91
|
-
s.add_development_dependency '
|
92
|
-
s.add_development_dependency 'rake', '~>0.9.2'
|
86
|
+
s.add_development_dependency 'rake'
|
87
|
+
s.add_development_dependency 'test-unit', '~> 2.0'
|
93
88
|
|
94
|
-
s.extra_rdoc_files << 'README.
|
89
|
+
s.extra_rdoc_files << 'README.md'
|
95
90
|
s.rdoc_options <<
|
96
|
-
'--title' << 'JSON implemention for ruby' << '--main' << 'README.
|
91
|
+
'--title' << 'JSON implemention for ruby' << '--main' << 'README.md'
|
97
92
|
s.test_files.concat Dir['./tests/test_*.rb']
|
98
93
|
|
99
94
|
s.author = "Florian Frank"
|
100
95
|
s.email = "flori@ping.de"
|
101
96
|
s.homepage = "http://flori.github.com/#{PKG_NAME}"
|
102
97
|
s.license = 'Ruby'
|
98
|
+
s.required_ruby_version = '>= 1.9'
|
103
99
|
end
|
104
100
|
|
105
101
|
desc 'Creates a json_pure.gemspec file'
|
106
102
|
task :gemspec_pure => :version do
|
107
103
|
File.open('json_pure.gemspec', 'w') do |gemspec|
|
108
|
-
gemspec.write
|
104
|
+
gemspec.write spec_pure.to_ruby
|
109
105
|
end
|
110
106
|
end
|
111
107
|
|
@@ -125,24 +121,25 @@ if defined?(Gem) and defined?(Gem::PackageTask)
|
|
125
121
|
s.extensions = FileList['ext/**/extconf.rb']
|
126
122
|
|
127
123
|
s.require_path = 'lib'
|
128
|
-
s.add_development_dependency '
|
129
|
-
s.add_development_dependency '
|
124
|
+
s.add_development_dependency 'rake'
|
125
|
+
s.add_development_dependency 'test-unit', '~> 2.0'
|
130
126
|
|
131
|
-
s.extra_rdoc_files << 'README.
|
127
|
+
s.extra_rdoc_files << 'README.md'
|
132
128
|
s.rdoc_options <<
|
133
|
-
'--title' << 'JSON implemention for Ruby' << '--main' << 'README.
|
129
|
+
'--title' << 'JSON implemention for Ruby' << '--main' << 'README.md'
|
134
130
|
s.test_files.concat Dir['./tests/test_*.rb']
|
135
131
|
|
136
132
|
s.author = "Florian Frank"
|
137
133
|
s.email = "flori@ping.de"
|
138
134
|
s.homepage = "http://flori.github.com/#{PKG_NAME}"
|
139
135
|
s.license = 'Ruby'
|
136
|
+
s.required_ruby_version = '>= 1.9'
|
140
137
|
end
|
141
138
|
|
142
139
|
desc 'Creates a json.gemspec file'
|
143
140
|
task :gemspec_ext => :version do
|
144
141
|
File.open('json.gemspec', 'w') do |gemspec|
|
145
|
-
gemspec.write
|
142
|
+
gemspec.write spec_ext.to_ruby
|
146
143
|
end
|
147
144
|
end
|
148
145
|
|
@@ -161,6 +158,7 @@ task :version do
|
|
161
158
|
puts m
|
162
159
|
File.open(File.join('lib', 'json', 'version.rb'), 'w') do |v|
|
163
160
|
v.puts <<EOT
|
161
|
+
# frozen_string_literal: false
|
164
162
|
module JSON
|
165
163
|
# JSON version
|
166
164
|
VERSION = '#{PKG_VERSION}'
|
@@ -173,13 +171,17 @@ EOT
|
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
174
|
+
task :check_env do
|
175
|
+
ENV.key?('JSON') or fail "JSON env var is required"
|
176
|
+
end
|
177
|
+
|
176
178
|
desc "Testing library (pure ruby)"
|
177
|
-
task :test_pure => [ :clean, :do_test_pure ]
|
179
|
+
task :test_pure => [ :clean, :check_env, :do_test_pure ]
|
178
180
|
|
179
181
|
UndocumentedTestTask.new do |t|
|
180
182
|
t.name = 'do_test_pure'
|
181
|
-
t.libs << 'lib'
|
182
|
-
t.test_files = FileList['tests
|
183
|
+
t.libs << 'lib' << 'tests'
|
184
|
+
t.test_files = FileList['tests/*_test.rb']
|
183
185
|
t.verbose = true
|
184
186
|
t.options = '-v'
|
185
187
|
end
|
@@ -198,13 +200,11 @@ namespace :gems do
|
|
198
200
|
end
|
199
201
|
|
200
202
|
if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
ENV['JAVA_HOME'] = local_java
|
207
|
-
end
|
203
|
+
ENV['JAVA_HOME'] ||= [
|
204
|
+
'/usr/local/java/jdk',
|
205
|
+
'/usr/lib/jvm/java-6-openjdk',
|
206
|
+
'/Library/Java/Home',
|
207
|
+
].find { |c| File.directory?(c) }
|
208
208
|
if ENV['JAVA_HOME']
|
209
209
|
warn " *** JAVA_HOME is set to #{ENV['JAVA_HOME'].inspect}"
|
210
210
|
ENV['PATH'] = ENV['PATH'].split(/:/).unshift(java_path = "#{ENV['JAVA_HOME']}/bin") * ':'
|
@@ -238,7 +238,7 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
|
238
238
|
classpath = (Dir['java/lib/*.jar'] << 'java/src' << JRUBY_JAR) * ':'
|
239
239
|
obj = src.sub(/\.java\Z/, '.class')
|
240
240
|
file obj => src do
|
241
|
-
sh 'javac', '-classpath', classpath, '-source', '1.
|
241
|
+
sh 'javac', '-classpath', classpath, '-source', '1.6', '-target', '1.6', src
|
242
242
|
end
|
243
243
|
JAVA_CLASSES << obj
|
244
244
|
end
|
@@ -257,12 +257,12 @@ if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
|
|
257
257
|
end
|
258
258
|
|
259
259
|
desc "Testing library (jruby)"
|
260
|
-
task :test_ext => [ :create_jar, :do_test_ext ]
|
260
|
+
task :test_ext => [ :check_env, :create_jar, :do_test_ext ]
|
261
261
|
|
262
262
|
UndocumentedTestTask.new do |t|
|
263
263
|
t.name = 'do_test_ext'
|
264
|
-
t.libs << 'lib'
|
265
|
-
t.test_files = FileList['tests
|
264
|
+
t.libs << 'lib' << 'tests'
|
265
|
+
t.test_files = FileList['tests/*_test.rb']
|
266
266
|
t.verbose = true
|
267
267
|
t.options = '-v'
|
268
268
|
end
|
@@ -331,21 +331,16 @@ else
|
|
331
331
|
end
|
332
332
|
|
333
333
|
desc "Testing library (extension)"
|
334
|
-
task :test_ext => [ :compile, :do_test_ext ]
|
334
|
+
task :test_ext => [ :check_env, :compile, :do_test_ext ]
|
335
335
|
|
336
336
|
UndocumentedTestTask.new do |t|
|
337
337
|
t.name = 'do_test_ext'
|
338
|
-
t.libs << 'ext' << 'lib'
|
339
|
-
t.test_files = FileList['tests
|
338
|
+
t.libs << 'ext' << 'lib' << 'tests'
|
339
|
+
t.test_files = FileList['tests/*_test.rb']
|
340
340
|
t.verbose = true
|
341
341
|
t.options = '-v'
|
342
342
|
end
|
343
343
|
|
344
|
-
desc "Create RDOC documentation"
|
345
|
-
task :doc => [ :version, EXT_PARSER_SRC ] do
|
346
|
-
sh "sdoc -o doc -t '#{PKG_TITLE}' -m README.rdoc README.rdoc lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
|
347
|
-
end
|
348
|
-
|
349
344
|
desc "Generate parser with ragel"
|
350
345
|
task :ragel => EXT_PARSER_SRC
|
351
346
|
|
@@ -367,6 +362,7 @@ else
|
|
367
362
|
sh "ragel -x parser.rl | #{RAGEL_CODEGEN} -G2"
|
368
363
|
end
|
369
364
|
src = File.read("parser.c").gsub(/[ \t]+$/, '')
|
365
|
+
src.gsub!(/^static const int (JSON_.*=.*);$/, 'enum {\1};')
|
370
366
|
File.open("parser.c", "w") {|f| f.print src}
|
371
367
|
end
|
372
368
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.2.0
|
@@ -7,14 +7,20 @@ static ID i_encoding, i_encode;
|
|
7
7
|
#endif
|
8
8
|
|
9
9
|
static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
10
|
-
mHash, mArray,
|
10
|
+
mHash, mArray,
|
11
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
12
|
+
mInteger,
|
13
|
+
#else
|
14
|
+
mFixnum, mBignum,
|
15
|
+
#endif
|
16
|
+
mFloat, mString, mString_Extend,
|
11
17
|
mTrueClass, mFalseClass, mNilClass, eGeneratorError,
|
12
18
|
eNestingError, CRegexp_MULTILINE, CJSON_SAFE_STATE_PROTOTYPE,
|
13
19
|
i_SAFE_STATE_PROTOTYPE;
|
14
20
|
|
15
21
|
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
|
16
22
|
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
|
17
|
-
|
23
|
+
i_pack, i_unpack, i_create_id, i_extend, i_key_p,
|
18
24
|
i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth,
|
19
25
|
i_buffer_initial_length, i_dup;
|
20
26
|
|
@@ -216,6 +222,7 @@ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string)
|
|
216
222
|
unicode_escape_to_buffer(buffer, buf, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START));
|
217
223
|
}
|
218
224
|
}
|
225
|
+
RB_GC_GUARD(string);
|
219
226
|
}
|
220
227
|
|
221
228
|
/* Converts string to a JSON string in FBuffer buffer, where only the
|
@@ -301,7 +308,7 @@ static char *fstrndup(const char *ptr, unsigned long len) {
|
|
301
308
|
char *result;
|
302
309
|
if (len <= 0) return NULL;
|
303
310
|
result = ALLOC_N(char, len);
|
304
|
-
|
311
|
+
memcpy(result, ptr, len);
|
305
312
|
return result;
|
306
313
|
}
|
307
314
|
|
@@ -342,6 +349,18 @@ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
|
|
342
349
|
GENERATE_JSON(array);
|
343
350
|
}
|
344
351
|
|
352
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
353
|
+
/*
|
354
|
+
* call-seq: to_json(*)
|
355
|
+
*
|
356
|
+
* Returns a JSON string representation for this Integer number.
|
357
|
+
*/
|
358
|
+
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self)
|
359
|
+
{
|
360
|
+
GENERATE_JSON(integer);
|
361
|
+
}
|
362
|
+
|
363
|
+
#else
|
345
364
|
/*
|
346
365
|
* call-seq: to_json(*)
|
347
366
|
*
|
@@ -361,6 +380,7 @@ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self)
|
|
361
380
|
{
|
362
381
|
GENERATE_JSON(bignum);
|
363
382
|
}
|
383
|
+
#endif
|
364
384
|
|
365
385
|
/*
|
366
386
|
* call-seq: to_json(*)
|
@@ -622,8 +642,6 @@ static VALUE cState_configure(VALUE self, VALUE opts)
|
|
622
642
|
state->allow_nan = RTEST(tmp);
|
623
643
|
tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
|
624
644
|
state->ascii_only = RTEST(tmp);
|
625
|
-
tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode));
|
626
|
-
state->quirks_mode = RTEST(tmp);
|
627
645
|
return self;
|
628
646
|
}
|
629
647
|
|
@@ -657,7 +675,6 @@ static VALUE cState_to_h(VALUE self)
|
|
657
675
|
rb_hash_aset(result, ID2SYM(i_array_nl), rb_str_new(state->array_nl, state->array_nl_len));
|
658
676
|
rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse);
|
659
677
|
rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse);
|
660
|
-
rb_hash_aset(result, ID2SYM(i_quirks_mode), state->quirks_mode ? Qtrue : Qfalse);
|
661
678
|
rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting));
|
662
679
|
rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth));
|
663
680
|
rb_hash_aset(result, ID2SYM(i_buffer_initial_length), LONG2FIX(state->buffer_initial_length));
|
@@ -825,6 +842,15 @@ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
825
842
|
fbuffer_append_str(buffer, tmp);
|
826
843
|
}
|
827
844
|
|
845
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
846
|
+
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
847
|
+
{
|
848
|
+
if (FIXNUM_P(obj))
|
849
|
+
generate_json_fixnum(buffer, Vstate, state, obj);
|
850
|
+
else
|
851
|
+
generate_json_bignum(buffer, Vstate, state, obj);
|
852
|
+
}
|
853
|
+
#endif
|
828
854
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
829
855
|
{
|
830
856
|
double value = RFLOAT_VALUE(obj);
|
@@ -858,9 +884,9 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
|
|
858
884
|
generate_json_false(buffer, Vstate, state, obj);
|
859
885
|
} else if (obj == Qtrue) {
|
860
886
|
generate_json_true(buffer, Vstate, state, obj);
|
861
|
-
} else if (
|
887
|
+
} else if (FIXNUM_P(obj)) {
|
862
888
|
generate_json_fixnum(buffer, Vstate, state, obj);
|
863
|
-
} else if (
|
889
|
+
} else if (RB_TYPE_P(obj, T_BIGNUM)) {
|
864
890
|
generate_json_bignum(buffer, Vstate, state, obj);
|
865
891
|
} else if (klass == rb_cFloat) {
|
866
892
|
generate_json_float(buffer, Vstate, state, obj);
|
@@ -871,7 +897,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
|
|
871
897
|
} else {
|
872
898
|
tmp = rb_funcall(obj, i_to_s, 0);
|
873
899
|
Check_Type(tmp, T_STRING);
|
874
|
-
|
900
|
+
generate_json_string(buffer, Vstate, state, tmp);
|
875
901
|
}
|
876
902
|
}
|
877
903
|
|
@@ -914,21 +940,6 @@ static VALUE cState_partial_generate(VALUE self, VALUE obj)
|
|
914
940
|
return fbuffer_to_s(buffer);
|
915
941
|
}
|
916
942
|
|
917
|
-
/*
|
918
|
-
* This function returns true if string is either a JSON array or JSON object.
|
919
|
-
* It might suffer from false positives, e. g. syntactically incorrect JSON in
|
920
|
-
* the string or certain UTF-8 characters on the right hand side.
|
921
|
-
*/
|
922
|
-
static int isArrayOrObject(VALUE string)
|
923
|
-
{
|
924
|
-
long string_len = RSTRING_LEN(string);
|
925
|
-
char *p = RSTRING_PTR(string), *q = p + string_len - 1;
|
926
|
-
if (string_len < 2) return 0;
|
927
|
-
for (; p < q && isspace((unsigned char)*p); p++);
|
928
|
-
for (; q > p && isspace((unsigned char)*q); q--);
|
929
|
-
return (*p == '[' && *q == ']') || (*p == '{' && *q == '}');
|
930
|
-
}
|
931
|
-
|
932
943
|
/*
|
933
944
|
* call-seq: generate(obj)
|
934
945
|
*
|
@@ -940,9 +951,7 @@ static VALUE cState_generate(VALUE self, VALUE obj)
|
|
940
951
|
{
|
941
952
|
VALUE result = cState_partial_generate(self, obj);
|
942
953
|
GET_STATE(self);
|
943
|
-
|
944
|
-
rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed");
|
945
|
-
}
|
954
|
+
(void)state;
|
946
955
|
return result;
|
947
956
|
}
|
948
957
|
|
@@ -961,8 +970,6 @@ static VALUE cState_generate(VALUE self, VALUE obj)
|
|
961
970
|
* * *allow_nan*: true if NaN, Infinity, and -Infinity should be
|
962
971
|
* generated, otherwise an exception is thrown, if these values are
|
963
972
|
* encountered. This options defaults to false.
|
964
|
-
* * *quirks_mode*: Enables quirks_mode for parser, that is for example
|
965
|
-
* generating single JSON values instead of documents is possible.
|
966
973
|
* * *buffer_initial_length*: sets the initial length of the generator's
|
967
974
|
* internal buffer.
|
968
975
|
*/
|
@@ -1055,7 +1062,7 @@ static VALUE cState_indent_set(VALUE self, VALUE indent)
|
|
1055
1062
|
}
|
1056
1063
|
} else {
|
1057
1064
|
if (state->indent) ruby_xfree(state->indent);
|
1058
|
-
state->indent =
|
1065
|
+
state->indent = fstrndup(RSTRING_PTR(indent), len);
|
1059
1066
|
state->indent_len = len;
|
1060
1067
|
}
|
1061
1068
|
return Qnil;
|
@@ -1093,7 +1100,7 @@ static VALUE cState_space_set(VALUE self, VALUE space)
|
|
1093
1100
|
}
|
1094
1101
|
} else {
|
1095
1102
|
if (state->space) ruby_xfree(state->space);
|
1096
|
-
state->space =
|
1103
|
+
state->space = fstrndup(RSTRING_PTR(space), len);
|
1097
1104
|
state->space_len = len;
|
1098
1105
|
}
|
1099
1106
|
return Qnil;
|
@@ -1129,7 +1136,7 @@ static VALUE cState_space_before_set(VALUE self, VALUE space_before)
|
|
1129
1136
|
}
|
1130
1137
|
} else {
|
1131
1138
|
if (state->space_before) ruby_xfree(state->space_before);
|
1132
|
-
state->space_before =
|
1139
|
+
state->space_before = fstrndup(RSTRING_PTR(space_before), len);
|
1133
1140
|
state->space_before_len = len;
|
1134
1141
|
}
|
1135
1142
|
return Qnil;
|
@@ -1166,7 +1173,7 @@ static VALUE cState_object_nl_set(VALUE self, VALUE object_nl)
|
|
1166
1173
|
}
|
1167
1174
|
} else {
|
1168
1175
|
if (state->object_nl) ruby_xfree(state->object_nl);
|
1169
|
-
state->object_nl =
|
1176
|
+
state->object_nl = fstrndup(RSTRING_PTR(object_nl), len);
|
1170
1177
|
state->object_nl_len = len;
|
1171
1178
|
}
|
1172
1179
|
return Qnil;
|
@@ -1201,7 +1208,7 @@ static VALUE cState_array_nl_set(VALUE self, VALUE array_nl)
|
|
1201
1208
|
}
|
1202
1209
|
} else {
|
1203
1210
|
if (state->array_nl) ruby_xfree(state->array_nl);
|
1204
|
-
state->array_nl =
|
1211
|
+
state->array_nl = fstrndup(RSTRING_PTR(array_nl), len);
|
1205
1212
|
state->array_nl_len = len;
|
1206
1213
|
}
|
1207
1214
|
return Qnil;
|
@@ -1269,29 +1276,6 @@ static VALUE cState_ascii_only_p(VALUE self)
|
|
1269
1276
|
return state->ascii_only ? Qtrue : Qfalse;
|
1270
1277
|
}
|
1271
1278
|
|
1272
|
-
/*
|
1273
|
-
* call-seq: quirks_mode?
|
1274
|
-
*
|
1275
|
-
* Returns true, if quirks mode is enabled. Otherwise returns false.
|
1276
|
-
*/
|
1277
|
-
static VALUE cState_quirks_mode_p(VALUE self)
|
1278
|
-
{
|
1279
|
-
GET_STATE(self);
|
1280
|
-
return state->quirks_mode ? Qtrue : Qfalse;
|
1281
|
-
}
|
1282
|
-
|
1283
|
-
/*
|
1284
|
-
* call-seq: quirks_mode=(enable)
|
1285
|
-
*
|
1286
|
-
* If set to true, enables the quirks_mode mode.
|
1287
|
-
*/
|
1288
|
-
static VALUE cState_quirks_mode_set(VALUE self, VALUE enable)
|
1289
|
-
{
|
1290
|
-
GET_STATE(self);
|
1291
|
-
state->quirks_mode = RTEST(enable);
|
1292
|
-
return Qnil;
|
1293
|
-
}
|
1294
|
-
|
1295
1279
|
/*
|
1296
1280
|
* call-seq: depth
|
1297
1281
|
*
|
@@ -1351,6 +1335,7 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l
|
|
1351
1335
|
*/
|
1352
1336
|
void Init_generator(void)
|
1353
1337
|
{
|
1338
|
+
#undef rb_intern
|
1354
1339
|
rb_require("json/common");
|
1355
1340
|
|
1356
1341
|
mJSON = rb_define_module("JSON");
|
@@ -1380,9 +1365,6 @@ void Init_generator(void)
|
|
1380
1365
|
rb_define_method(cState, "check_circular?", cState_check_circular_p, 0);
|
1381
1366
|
rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0);
|
1382
1367
|
rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0);
|
1383
|
-
rb_define_method(cState, "quirks_mode?", cState_quirks_mode_p, 0);
|
1384
|
-
rb_define_method(cState, "quirks_mode", cState_quirks_mode_p, 0);
|
1385
|
-
rb_define_method(cState, "quirks_mode=", cState_quirks_mode_set, 1);
|
1386
1368
|
rb_define_method(cState, "depth", cState_depth, 0);
|
1387
1369
|
rb_define_method(cState, "depth=", cState_depth_set, 1);
|
1388
1370
|
rb_define_method(cState, "buffer_initial_length", cState_buffer_initial_length, 0);
|
@@ -1402,10 +1384,15 @@ void Init_generator(void)
|
|
1402
1384
|
rb_define_method(mHash, "to_json", mHash_to_json, -1);
|
1403
1385
|
mArray = rb_define_module_under(mGeneratorMethods, "Array");
|
1404
1386
|
rb_define_method(mArray, "to_json", mArray_to_json, -1);
|
1387
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
1388
|
+
mInteger = rb_define_module_under(mGeneratorMethods, "Integer");
|
1389
|
+
rb_define_method(mInteger, "to_json", mInteger_to_json, -1);
|
1390
|
+
#else
|
1405
1391
|
mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
|
1406
1392
|
rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
|
1407
1393
|
mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
|
1408
1394
|
rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
|
1395
|
+
#endif
|
1409
1396
|
mFloat = rb_define_module_under(mGeneratorMethods, "Float");
|
1410
1397
|
rb_define_method(mFloat, "to_json", mFloat_to_json, -1);
|
1411
1398
|
mString = rb_define_module_under(mGeneratorMethods, "String");
|
@@ -1434,7 +1421,6 @@ void Init_generator(void)
|
|
1434
1421
|
i_max_nesting = rb_intern("max_nesting");
|
1435
1422
|
i_allow_nan = rb_intern("allow_nan");
|
1436
1423
|
i_ascii_only = rb_intern("ascii_only");
|
1437
|
-
i_quirks_mode = rb_intern("quirks_mode");
|
1438
1424
|
i_depth = rb_intern("depth");
|
1439
1425
|
i_buffer_initial_length = rb_intern("buffer_initial_length");
|
1440
1426
|
i_pack = rb_intern("pack");
|
@@ -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
|
|
@@ -73,7 +72,6 @@ typedef struct JSON_Generator_StateStruct {
|
|
73
72
|
long max_nesting;
|
74
73
|
char allow_nan;
|
75
74
|
char ascii_only;
|
76
|
-
char quirks_mode;
|
77
75
|
long depth;
|
78
76
|
long buffer_initial_length;
|
79
77
|
} JSON_Generator_State;
|
@@ -99,8 +97,12 @@ typedef struct JSON_Generator_StateStruct {
|
|
99
97
|
|
100
98
|
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
101
99
|
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
100
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
101
|
+
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
|
102
|
+
#else
|
102
103
|
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
|
103
104
|
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
|
105
|
+
#endif
|
104
106
|
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
|
105
107
|
static VALUE mString_included_s(VALUE self, VALUE modul);
|
106
108
|
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
|
@@ -122,6 +124,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|
122
124
|
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
123
125
|
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
124
126
|
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
127
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
128
|
+
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
129
|
+
#endif
|
125
130
|
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
126
131
|
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
127
132
|
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|