json 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ 2007-05-09 (1.0.4)
2
+ * Applied a patch from Yui NARUSE <naruse@airemix.com> to make JSON compile
3
+ under Ruby 1.9. Thank you very much for mailing it to me!
4
+ * Made binary variants of JSON fail early, instead of falling back to the
5
+ pure version. This should avoid overshadowing of eventual problems while
6
+ loading of the binary.
1
7
  2007-03-24 (1.0.3)
2
8
  * Improved performance of pure variant a bit.
3
9
  * The ext variant of this release supports the mswin32 platform. Ugh!
data/Rakefile CHANGED
@@ -290,6 +290,7 @@ module JSON
290
290
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
291
291
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
292
292
  VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
293
+ VARIANT_BINARY = #{!!ON_WINDOWS}
293
294
  end
294
295
  EOT
295
296
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -22,7 +22,7 @@ def go(s, args = ARGV)
22
22
  until p == ''
23
23
  o = p.slice!(0, 1)
24
24
  if v.key?(o)
25
- v[o] = if p == '': args.shift or break 1 else p end
25
+ v[o] = if p == '' then args.shift or break 1 else p end
26
26
  break
27
27
  elsif b.key?(o)
28
28
  b[o] = true
@@ -30,7 +30,6 @@ typedef struct JSON_Generator_StateStruct {
30
30
  #define GET_STATE(self) \
31
31
  JSON_Generator_State *state; \
32
32
  Data_Get_Struct(self, JSON_Generator_State, state);
33
- #define FUL(string) RSTRING(string)->len
34
33
 
35
34
  /*
36
35
  * Document-module: JSON::Ext::Generator
@@ -55,19 +54,19 @@ static int hash_to_json_state_i(VALUE key, VALUE value, VALUE Vstate)
55
54
  if (state->flag) {
56
55
  state->flag = 0;
57
56
  rb_str_buf_cat2(buf, ",");
58
- if (FUL(state->object_nl)) rb_str_buf_append(buf, state->object_nl);
57
+ if (RSTRING_LEN(state->object_nl)) rb_str_buf_append(buf, state->object_nl);
59
58
  }
60
- if (FUL(state->object_nl)) {
59
+ if (RSTRING_LEN(state->object_nl)) {
61
60
  rb_str_buf_append(buf, rb_str_times(state->indent, Vdepth));
62
61
  }
63
62
  json = rb_funcall(rb_funcall(key, i_to_s, 0), i_to_json, 2, Vstate, Vdepth);
64
63
  rb_str_buf_append(buf, json);
65
64
  OBJ_INFECT(buf, json);
66
- if (FUL(state->space_before)) {
65
+ if (RSTRING_LEN(state->space_before)) {
67
66
  rb_str_buf_append(buf, state->space_before);
68
67
  }
69
68
  rb_str_buf_cat2(buf, ":");
70
- if (FUL(state->space)) rb_str_buf_append(buf, state->space);
69
+ if (RSTRING_LEN(state->space)) rb_str_buf_append(buf, state->space);
71
70
  json = rb_funcall(value, i_to_json, 2, Vstate, Vdepth);
72
71
  state->flag = 1;
73
72
  rb_str_buf_append(buf, json);
@@ -88,10 +87,10 @@ inline static VALUE mHash_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth)
88
87
  state->depth = LONG2FIX(depth);
89
88
  state->flag = 0;
90
89
  rb_str_buf_cat2(result, "{");
91
- if (FUL(state->object_nl)) rb_str_buf_append(result, state->object_nl);
90
+ if (RSTRING_LEN(state->object_nl)) rb_str_buf_append(result, state->object_nl);
92
91
  rb_hash_foreach(self, hash_to_json_state_i, Vstate);
93
- if (FUL(state->object_nl)) rb_str_buf_append(result, state->object_nl);
94
- if (FUL(state->object_nl)) {
92
+ if (RSTRING_LEN(state->object_nl)) rb_str_buf_append(result, state->object_nl);
93
+ if (RSTRING_LEN(state->object_nl)) {
95
94
  rb_str_buf_append(result, rb_str_times(state->indent, Vdepth));
96
95
  }
97
96
  rb_str_buf_cat2(result, "}");
@@ -103,7 +102,7 @@ static int hash_to_json_i(VALUE key, VALUE value, VALUE buf)
103
102
  VALUE tmp;
104
103
 
105
104
  if (key == Qundef) return ST_CONTINUE;
106
- if (RSTRING(buf)->len > 1) rb_str_buf_cat2(buf, ",");
105
+ if (RSTRING_LEN(buf) > 1) rb_str_buf_cat2(buf, ",");
107
106
  tmp = rb_funcall(rb_funcall(key, i_to_s, 0), i_to_json, 0);
108
107
  rb_str_buf_append(buf, tmp);
109
108
  OBJ_INFECT(buf, tmp);
@@ -157,7 +156,7 @@ static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self)
157
156
  }
158
157
 
159
158
  inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth) {
160
- long i, len = RARRAY(self)->len;
159
+ long i, len = RARRAY_LEN(self);
161
160
  VALUE shift, result;
162
161
  long depth = NIL_P(Vdepth) ? 0 : FIX2LONG(Vdepth);
163
162
  VALUE delim = rb_str_new2(",");
@@ -167,13 +166,13 @@ inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth
167
166
  VALUE self_id = rb_obj_id(self);
168
167
  rb_hash_aset(state->seen, self_id, Qtrue);
169
168
  result = rb_str_buf_new(len);
170
- if (FUL(state->array_nl)) rb_str_append(delim, state->array_nl);
169
+ if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl);
171
170
  shift = rb_str_times(state->indent, LONG2FIX(depth + 1));
172
171
 
173
172
  rb_str_buf_cat2(result, "[");
174
173
  rb_str_buf_append(result, state->array_nl);
175
174
  for (i = 0; i < len; i++) {
176
- VALUE element = RARRAY(self)->ptr[i];
175
+ VALUE element = RARRAY_PTR(self)[i];
177
176
  if (RTEST(rb_hash_aref(state->seen, rb_obj_id(element)))) {
178
177
  rb_raise(eCircularDatastructure,
179
178
  "circular data structures not supported!");
@@ -183,7 +182,7 @@ inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth
183
182
  rb_str_buf_append(result, shift);
184
183
  rb_str_buf_append(result, rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1)));
185
184
  }
186
- if (FUL(state->array_nl)) {
185
+ if (RSTRING_LEN(state->array_nl)) {
187
186
  rb_str_buf_append(result, state->array_nl);
188
187
  rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth)));
189
188
  }
@@ -191,20 +190,20 @@ inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth
191
190
  rb_hash_delete(state->seen, self_id);
192
191
  } else {
193
192
  result = rb_str_buf_new(len);
194
- if (FUL(state->array_nl)) rb_str_append(delim, state->array_nl);
193
+ if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl);
195
194
  shift = rb_str_times(state->indent, LONG2FIX(depth + 1));
196
195
 
197
196
  rb_str_buf_cat2(result, "[");
198
197
  rb_str_buf_append(result, state->array_nl);
199
198
  for (i = 0; i < len; i++) {
200
- VALUE element = RARRAY(self)->ptr[i];
199
+ VALUE element = RARRAY_PTR(self)[i];
201
200
  OBJ_INFECT(result, element);
202
201
  if (i > 0) rb_str_buf_append(result, delim);
203
202
  rb_str_buf_append(result, shift);
204
203
  rb_str_buf_append(result, rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1)));
205
204
  }
206
205
  rb_str_buf_append(result, state->array_nl);
207
- if (FUL(state->array_nl)) {
206
+ if (RSTRING_LEN(state->array_nl)) {
208
207
  rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth)));
209
208
  }
210
209
  rb_str_buf_cat2(result, "]");
@@ -226,11 +225,11 @@ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
226
225
 
227
226
  rb_scan_args(argc, argv, "02", &Vstate, &Vdepth);
228
227
  if (NIL_P(Vstate)) {
229
- long i, len = RARRAY(self)->len;
228
+ long i, len = RARRAY_LEN(self);
230
229
  result = rb_str_buf_new(2 + 2 * len);
231
230
  rb_str_buf_cat2(result, "[");
232
231
  for (i = 0; i < len; i++) {
233
- VALUE element = RARRAY(self)->ptr[i];
232
+ VALUE element = RARRAY_PTR(self)[i];
234
233
  OBJ_INFECT(result, element);
235
234
  if (i > 0) rb_str_buf_cat2(result, ",");
236
235
  rb_str_buf_append(result, rb_funcall(element, i_to_json, 0));
@@ -281,7 +280,7 @@ static VALUE mString_included_s(VALUE self, VALUE modul) {
281
280
  */
282
281
  static VALUE mString_to_json(int argc, VALUE *argv, VALUE self)
283
282
  {
284
- VALUE result = rb_str_buf_new(RSTRING(self)->len);
283
+ VALUE result = rb_str_buf_new(RSTRING_LEN(self));
285
284
  rb_str_buf_cat2(result, "\"");
286
285
  JSON_convert_UTF8_to_JSON(result, self, strictConversion);
287
286
  rb_str_buf_cat2(result, "\"");
@@ -103,8 +103,8 @@ inline static unsigned char isLegalUTF8(const UTF8 *source, int length)
103
103
  void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags)
104
104
  {
105
105
  char buf[7];
106
- const UTF8* source = (UTF8 *) RSTRING(string)->ptr;
107
- const UTF8* sourceEnd = source + RSTRING(string)->len;
106
+ const UTF8* source = (UTF8 *) RSTRING_PTR(string);
107
+ const UTF8* sourceEnd = source + RSTRING_LEN(string);
108
108
 
109
109
  while (source < sourceEnd) {
110
110
  UTF32 ch = 0;
@@ -37,4 +37,17 @@ static const UTF32 halfMask = 0x3FFUL;
37
37
 
38
38
  void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags);
39
39
 
40
+ #ifndef RARRAY_PTR
41
+ #define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
42
+ #endif
43
+ #ifndef RARRAY_LEN
44
+ #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
45
+ #endif
46
+ #ifndef RSTRING_PTR
47
+ #define RSTRING_PTR(string) RSTRING(string)->ptr
48
+ #endif
49
+ #ifndef RSTRING_LEN
50
+ #define RSTRING_LEN(string) RSTRING(string)->len
51
+ #endif
52
+
40
53
  #endif
@@ -1317,8 +1317,8 @@ static VALUE cParser_initialize(VALUE self, VALUE source)
1317
1317
  long len;
1318
1318
  GET_STRUCT;
1319
1319
  source = StringValue(source);
1320
- ptr = RSTRING(source)->ptr;
1321
- len = RSTRING(source)->len;
1320
+ ptr = RSTRING_PTR(source);
1321
+ len = RSTRING_LEN(source);
1322
1322
  if (len < 2) {
1323
1323
  rb_raise(eParserError, "A JSON text must at least contain two octets!");
1324
1324
  }
@@ -412,8 +412,8 @@ static VALUE cParser_initialize(VALUE self, VALUE source)
412
412
  long len;
413
413
  GET_STRUCT;
414
414
  source = StringValue(source);
415
- ptr = RSTRING(source)->ptr;
416
- len = RSTRING(source)->len;
415
+ ptr = RSTRING_PTR(source);
416
+ len = RSTRING_LEN(source);
417
417
  if (len < 2) {
418
418
  rb_raise(eParserError, "A JSON text must at least contain two octets!");
419
419
  }
@@ -41,4 +41,18 @@ char *JSON_convert_UTF16_to_UTF8 (
41
41
  char *source,
42
42
  char *sourceEnd,
43
43
  ConversionFlags flags);
44
+
45
+ #ifndef RARRAY_PTR
46
+ #define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
47
+ #endif
48
+ #ifndef RARRAY_LEN
49
+ #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
50
+ #endif
51
+ #ifndef RSTRING_PTR
52
+ #define RSTRING_PTR(string) RSTRING(string)->ptr
53
+ #endif
54
+ #ifndef RSTRING_LEN
55
+ #define RSTRING_LEN(string) RSTRING(string)->len
56
+ #endif
57
+
44
58
  #endif
@@ -197,9 +197,15 @@ require 'json/common'
197
197
  # javasript prototype library (http://www.prototypejs.org) works.
198
198
  #
199
199
  module JSON
200
- begin
200
+ require 'json/version'
201
+
202
+ if VARIANT_BINARY
201
203
  require 'json/ext'
202
- rescue LoadError
203
- require 'json/pure'
204
+ else
205
+ begin
206
+ require 'json/ext'
207
+ rescue LoadError
208
+ require 'json/pure'
209
+ end
204
210
  end
205
211
  end
@@ -29,11 +29,12 @@ module JSON
29
29
  # level (absolute namespace path?). If there doesn't exist a constant at
30
30
  # the given path, an ArgumentError is raised.
31
31
  def deep_const_get(path) # :nodoc:
32
+ path = path.to_s
32
33
  path.split(/::/).inject(Object) do |p, c|
33
34
  case
34
35
  when c.empty? then p
35
36
  when p.const_defined?(c) then p.const_get(c)
36
- else raise ArgumentError, "can't find #{path}"
37
+ else raise ArgumentError, "can't find const #{path}"
37
38
  end
38
39
  end
39
40
  end
@@ -1,8 +1,9 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.0.3'
3
+ VERSION = '1.0.4'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7
7
  VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
8
+ VARIANT_BINARY = false
8
9
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: json
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.3
7
- date: 2007-04-26 00:00:00 +02:00
6
+ version: 1.0.4
7
+ date: 2007-05-10 00:00:00 +02:00
8
8
  summary: A JSON implementation as a Ruby extension
9
9
  require_paths:
10
10
  - ext/json/ext
@@ -27,106 +27,105 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
27
27
  platform: ruby
28
28
  signing_key:
29
29
  cert_chain:
30
- post_install_message:
31
30
  authors:
32
31
  - Florian Frank
33
32
  files:
34
- - ext
35
- - tools
33
+ - bin
34
+ - VERSION
35
+ - TODO
36
36
  - tests
37
- - lib
37
+ - GPL
38
+ - install.rb
39
+ - ext
38
40
  - diagrams
39
- - bin
40
- - data
41
41
  - benchmarks
42
- - GPL
43
42
  - Rakefile
44
- - TODO
45
- - VERSION
46
- - CHANGES
47
- - install.rb
43
+ - data
44
+ - lib
48
45
  - README
49
- - ext/json
50
- - ext/json/ext
51
- - ext/json/ext/generator
52
- - ext/json/ext/parser
53
- - ext/json/ext/generator/generator.c
54
- - ext/json/ext/generator/unicode.c
55
- - ext/json/ext/generator/extconf.rb
56
- - ext/json/ext/generator/unicode.h
57
- - ext/json/ext/parser/unicode.c
58
- - ext/json/ext/parser/extconf.rb
59
- - ext/json/ext/parser/parser.rl
60
- - ext/json/ext/parser/unicode.h
61
- - ext/json/ext/parser/parser.c
62
- - tools/fuzz.rb
63
- - tools/server.rb
46
+ - tools
47
+ - CHANGES
48
+ - bin/edit_json.rb
49
+ - bin/prettify_json.rb
50
+ - tests/test_json_fixtures.rb
51
+ - tests/runner.rb
52
+ - tests/test_json.rb
64
53
  - tests/fixtures
65
54
  - tests/test_json_unicode.rb
66
- - tests/test_json_fixtures.rb
67
55
  - tests/test_json_generate.rb
68
56
  - tests/test_json_addition.rb
69
- - tests/test_json.rb
70
- - tests/runner.rb
71
- - tests/fixtures/fail10.json
72
- - tests/fixtures/fail20.json
73
- - tests/fixtures/fail11.json
74
- - tests/fixtures/fail21.json
75
- - tests/fixtures/fail12.json
57
+ - tests/fixtures/fail27.json
76
58
  - tests/fixtures/fail22.json
77
- - tests/fixtures/fail13.json
59
+ - tests/fixtures/fail26.json
60
+ - tests/fixtures/fail16.json
61
+ - tests/fixtures/fail28.json
62
+ - tests/fixtures/fail25.json
78
63
  - tests/fixtures/pass18.json
79
- - tests/fixtures/fail23.json
80
- - tests/fixtures/fail14.json
64
+ - tests/fixtures/fail9.json
65
+ - tests/fixtures/fail20.json
81
66
  - tests/fixtures/fail24.json
67
+ - tests/fixtures/fail14.json
68
+ - tests/fixtures/fail4.json
69
+ - tests/fixtures/fail7.json
70
+ - tests/fixtures/fail10.json
71
+ - tests/fixtures/fail13.json
72
+ - tests/fixtures/fail6.json
73
+ - tests/fixtures/fail21.json
74
+ - tests/fixtures/fail23.json
75
+ - tests/fixtures/fail3.json
76
+ - tests/fixtures/fail1.json
77
+ - tests/fixtures/fail11.json
78
+ - tests/fixtures/fail5.json
79
+ - tests/fixtures/pass1.json
80
+ - tests/fixtures/fail12.json
82
81
  - tests/fixtures/fail15.json
83
- - tests/fixtures/fail16.json
84
- - tests/fixtures/fail25.json
82
+ - tests/fixtures/pass3.json
83
+ - tests/fixtures/fail8.json
85
84
  - tests/fixtures/fail17.json
86
- - tests/fixtures/fail26.json
87
- - tests/fixtures/fail27.json
88
85
  - tests/fixtures/fail19.json
89
- - tests/fixtures/fail28.json
90
- - tests/fixtures/pass1.json
91
86
  - tests/fixtures/pass2.json
92
- - tests/fixtures/pass3.json
93
- - tests/fixtures/fail1.json
94
87
  - tests/fixtures/fail2.json
95
- - tests/fixtures/fail3.json
96
- - tests/fixtures/fail4.json
97
- - tests/fixtures/fail5.json
98
- - tests/fixtures/fail6.json
99
- - tests/fixtures/fail7.json
100
- - tests/fixtures/fail8.json
101
- - tests/fixtures/fail9.json
88
+ - ext/json
89
+ - ext/json/ext
90
+ - ext/json/ext/generator
91
+ - ext/json/ext/parser
92
+ - ext/json/ext/generator/unicode.c
93
+ - ext/json/ext/generator/unicode.h
94
+ - ext/json/ext/generator/extconf.rb
95
+ - ext/json/ext/generator/generator.c
96
+ - ext/json/ext/parser/parser.c
97
+ - ext/json/ext/parser/unicode.c
98
+ - ext/json/ext/parser/parser.rl
99
+ - ext/json/ext/parser/unicode.h
100
+ - ext/json/ext/parser/extconf.rb
101
+ - benchmarks/benchmark_generator.rb
102
+ - benchmarks/benchmark.txt
103
+ - benchmarks/benchmark_parser.rb
104
+ - benchmarks/benchmark_rails.rb
105
+ - data/example.json
106
+ - data/prototype.js
107
+ - data/index.html
102
108
  - lib/json
103
109
  - lib/json.rb
104
- - lib/json/pure
105
- - lib/json/Array.xpm
106
- - lib/json/ext.rb
107
110
  - lib/json/FalseClass.xpm
108
- - lib/json/Numeric.xpm
109
- - lib/json/Hash.xpm
110
- - lib/json/version.rb
111
111
  - lib/json/TrueClass.xpm
112
- - lib/json/editor.rb
113
- - lib/json/String.xpm
112
+ - lib/json/ext.rb
114
113
  - lib/json/common.rb
114
+ - lib/json/Hash.xpm
115
+ - lib/json/pure
115
116
  - lib/json/Key.xpm
117
+ - lib/json/Numeric.xpm
118
+ - lib/json/Array.xpm
119
+ - lib/json/editor.rb
120
+ - lib/json/String.xpm
121
+ - lib/json/pure.rb
116
122
  - lib/json/NilClass.xpm
123
+ - lib/json/version.rb
117
124
  - lib/json/json.xpm
118
- - lib/json/pure.rb
119
- - lib/json/pure/generator.rb
120
125
  - lib/json/pure/parser.rb
121
- - bin/edit_json.rb
122
- - bin/prettify_json.rb
123
- - data/prototype.js
124
- - data/example.json
125
- - data/index.html
126
- - benchmarks/benchmark_generator.rb
127
- - benchmarks/benchmark_rails.rb
128
- - benchmarks/benchmark.txt
129
- - benchmarks/benchmark_parser.rb
126
+ - lib/json/pure/generator.rb
127
+ - tools/server.rb
128
+ - tools/fuzz.rb
130
129
  test_files:
131
130
  - tests/runner.rb
132
131
  rdoc_options: