json_pure 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
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
data/bin/prettify_json.rb CHANGED
@@ -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
data/lib/json.rb CHANGED
@@ -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
data/lib/json/common.rb CHANGED
@@ -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
data/lib/json/version.rb CHANGED
@@ -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_pure
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 in Ruby
9
9
  require_paths:
10
10
  - lib
@@ -25,106 +25,105 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
- post_install_message:
29
28
  authors:
30
29
  - Florian Frank
31
30
  files:
32
- - ext
33
- - tools
31
+ - bin
32
+ - VERSION
33
+ - TODO
34
34
  - tests
35
- - lib
35
+ - GPL
36
+ - install.rb
37
+ - ext
36
38
  - diagrams
37
- - bin
38
- - data
39
39
  - benchmarks
40
- - GPL
41
40
  - Rakefile
42
- - TODO
43
- - VERSION
44
- - CHANGES
45
- - install.rb
41
+ - data
42
+ - lib
46
43
  - README
47
- - ext/json
48
- - ext/json/ext
49
- - ext/json/ext/generator
50
- - ext/json/ext/parser
51
- - ext/json/ext/generator/generator.c
52
- - ext/json/ext/generator/unicode.c
53
- - ext/json/ext/generator/extconf.rb
54
- - ext/json/ext/generator/unicode.h
55
- - ext/json/ext/parser/unicode.c
56
- - ext/json/ext/parser/extconf.rb
57
- - ext/json/ext/parser/parser.rl
58
- - ext/json/ext/parser/unicode.h
59
- - ext/json/ext/parser/parser.c
60
- - tools/fuzz.rb
61
- - tools/server.rb
44
+ - tools
45
+ - CHANGES
46
+ - bin/edit_json.rb
47
+ - bin/prettify_json.rb
48
+ - tests/test_json_fixtures.rb
49
+ - tests/runner.rb
50
+ - tests/test_json.rb
62
51
  - tests/fixtures
63
52
  - tests/test_json_unicode.rb
64
- - tests/test_json_fixtures.rb
65
53
  - tests/test_json_generate.rb
66
54
  - tests/test_json_addition.rb
67
- - tests/test_json.rb
68
- - tests/runner.rb
69
- - tests/fixtures/fail10.json
70
- - tests/fixtures/fail20.json
71
- - tests/fixtures/fail11.json
72
- - tests/fixtures/fail21.json
73
- - tests/fixtures/fail12.json
55
+ - tests/fixtures/fail27.json
74
56
  - tests/fixtures/fail22.json
75
- - tests/fixtures/fail13.json
57
+ - tests/fixtures/fail26.json
58
+ - tests/fixtures/fail16.json
59
+ - tests/fixtures/fail28.json
60
+ - tests/fixtures/fail25.json
76
61
  - tests/fixtures/pass18.json
77
- - tests/fixtures/fail23.json
78
- - tests/fixtures/fail14.json
62
+ - tests/fixtures/fail9.json
63
+ - tests/fixtures/fail20.json
79
64
  - tests/fixtures/fail24.json
65
+ - tests/fixtures/fail14.json
66
+ - tests/fixtures/fail4.json
67
+ - tests/fixtures/fail7.json
68
+ - tests/fixtures/fail10.json
69
+ - tests/fixtures/fail13.json
70
+ - tests/fixtures/fail6.json
71
+ - tests/fixtures/fail21.json
72
+ - tests/fixtures/fail23.json
73
+ - tests/fixtures/fail3.json
74
+ - tests/fixtures/fail1.json
75
+ - tests/fixtures/fail11.json
76
+ - tests/fixtures/fail5.json
77
+ - tests/fixtures/pass1.json
78
+ - tests/fixtures/fail12.json
80
79
  - tests/fixtures/fail15.json
81
- - tests/fixtures/fail16.json
82
- - tests/fixtures/fail25.json
80
+ - tests/fixtures/pass3.json
81
+ - tests/fixtures/fail8.json
83
82
  - tests/fixtures/fail17.json
84
- - tests/fixtures/fail26.json
85
- - tests/fixtures/fail27.json
86
83
  - tests/fixtures/fail19.json
87
- - tests/fixtures/fail28.json
88
- - tests/fixtures/pass1.json
89
84
  - tests/fixtures/pass2.json
90
- - tests/fixtures/pass3.json
91
- - tests/fixtures/fail1.json
92
85
  - tests/fixtures/fail2.json
93
- - tests/fixtures/fail3.json
94
- - tests/fixtures/fail4.json
95
- - tests/fixtures/fail5.json
96
- - tests/fixtures/fail6.json
97
- - tests/fixtures/fail7.json
98
- - tests/fixtures/fail8.json
99
- - tests/fixtures/fail9.json
86
+ - ext/json
87
+ - ext/json/ext
88
+ - ext/json/ext/generator
89
+ - ext/json/ext/parser
90
+ - ext/json/ext/generator/unicode.c
91
+ - ext/json/ext/generator/unicode.h
92
+ - ext/json/ext/generator/extconf.rb
93
+ - ext/json/ext/generator/generator.c
94
+ - ext/json/ext/parser/parser.c
95
+ - ext/json/ext/parser/unicode.c
96
+ - ext/json/ext/parser/parser.rl
97
+ - ext/json/ext/parser/unicode.h
98
+ - ext/json/ext/parser/extconf.rb
99
+ - benchmarks/benchmark_generator.rb
100
+ - benchmarks/benchmark.txt
101
+ - benchmarks/benchmark_parser.rb
102
+ - benchmarks/benchmark_rails.rb
103
+ - data/example.json
104
+ - data/prototype.js
105
+ - data/index.html
100
106
  - lib/json
101
107
  - lib/json.rb
102
- - lib/json/pure
103
- - lib/json/Array.xpm
104
- - lib/json/ext.rb
105
108
  - lib/json/FalseClass.xpm
106
- - lib/json/Numeric.xpm
107
- - lib/json/Hash.xpm
108
- - lib/json/version.rb
109
109
  - lib/json/TrueClass.xpm
110
- - lib/json/editor.rb
111
- - lib/json/String.xpm
110
+ - lib/json/ext.rb
112
111
  - lib/json/common.rb
112
+ - lib/json/Hash.xpm
113
+ - lib/json/pure
113
114
  - lib/json/Key.xpm
115
+ - lib/json/Numeric.xpm
116
+ - lib/json/Array.xpm
117
+ - lib/json/editor.rb
118
+ - lib/json/String.xpm
119
+ - lib/json/pure.rb
114
120
  - lib/json/NilClass.xpm
121
+ - lib/json/version.rb
115
122
  - lib/json/json.xpm
116
- - lib/json/pure.rb
117
- - lib/json/pure/generator.rb
118
123
  - lib/json/pure/parser.rb
119
- - bin/edit_json.rb
120
- - bin/prettify_json.rb
121
- - data/prototype.js
122
- - data/example.json
123
- - data/index.html
124
- - benchmarks/benchmark_generator.rb
125
- - benchmarks/benchmark_rails.rb
126
- - benchmarks/benchmark.txt
127
- - benchmarks/benchmark_parser.rb
124
+ - lib/json/pure/generator.rb
125
+ - tools/server.rb
126
+ - tools/fuzz.rb
128
127
  test_files:
129
128
  - tests/runner.rb
130
129
  rdoc_options: