json 1.2.0 → 2.19.8

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.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/BSDL +22 -0
  3. data/CHANGES.md +783 -0
  4. data/COPYING +14 -16
  5. data/LEGAL +20 -0
  6. data/README.md +310 -0
  7. data/ext/json/ext/fbuffer/fbuffer.h +260 -0
  8. data/ext/json/ext/generator/extconf.rb +15 -8
  9. data/ext/json/ext/generator/generator.c +1675 -613
  10. data/ext/json/ext/json.h +116 -0
  11. data/ext/json/ext/parser/extconf.rb +16 -7
  12. data/ext/json/ext/parser/parser.c +1649 -1772
  13. data/ext/json/ext/simd/conf.rb +24 -0
  14. data/ext/json/ext/simd/simd.h +208 -0
  15. data/ext/json/ext/vendor/fpconv.c +480 -0
  16. data/ext/json/ext/vendor/jeaiii-ltoa.h +267 -0
  17. data/ext/json/ext/vendor/ryu.h +819 -0
  18. data/json.gemspec +62 -0
  19. data/lib/json/add/bigdecimal.rb +58 -0
  20. data/lib/json/add/complex.rb +51 -0
  21. data/lib/json/add/core.rb +11 -133
  22. data/lib/json/add/date.rb +54 -0
  23. data/lib/json/add/date_time.rb +67 -0
  24. data/lib/json/add/exception.rb +49 -0
  25. data/lib/json/add/ostruct.rb +54 -0
  26. data/lib/json/add/range.rb +54 -0
  27. data/lib/json/add/rational.rb +49 -0
  28. data/lib/json/add/regexp.rb +48 -0
  29. data/lib/json/add/set.rb +48 -0
  30. data/lib/json/add/string.rb +35 -0
  31. data/lib/json/add/struct.rb +52 -0
  32. data/lib/json/add/symbol.rb +52 -0
  33. data/lib/json/add/time.rb +52 -0
  34. data/lib/json/common.rb +1056 -254
  35. data/lib/json/ext/generator/state.rb +103 -0
  36. data/lib/json/ext.rb +35 -5
  37. data/lib/json/generic_object.rb +67 -0
  38. data/lib/json/truffle_ruby/generator.rb +755 -0
  39. data/lib/json/version.rb +3 -6
  40. data/lib/json.rb +671 -6
  41. metadata +68 -159
  42. data/CHANGES +0 -136
  43. data/GPL +0 -340
  44. data/README +0 -360
  45. data/Rakefile +0 -287
  46. data/TODO +0 -1
  47. data/VERSION +0 -1
  48. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
  49. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
  50. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
  51. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
  52. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
  53. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
  54. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
  55. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
  56. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
  57. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
  58. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
  59. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
  60. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
  61. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
  62. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
  63. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
  64. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
  65. data/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
  66. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
  67. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
  68. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
  69. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
  70. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
  71. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
  72. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
  73. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
  74. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
  75. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
  76. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
  77. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
  78. data/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
  79. data/benchmarks/generator_benchmark.rb +0 -165
  80. data/benchmarks/parser_benchmark.rb +0 -197
  81. data/bin/edit_json.rb +0 -9
  82. data/bin/prettify_json.rb +0 -75
  83. data/data/example.json +0 -1
  84. data/data/index.html +0 -38
  85. data/data/prototype.js +0 -4184
  86. data/ext/json/ext/generator/unicode.c +0 -180
  87. data/ext/json/ext/generator/unicode.h +0 -53
  88. data/ext/json/ext/parser/parser.rl +0 -737
  89. data/ext/json/ext/parser/unicode.c +0 -154
  90. data/ext/json/ext/parser/unicode.h +0 -58
  91. data/install.rb +0 -26
  92. data/lib/json/Array.xpm +0 -21
  93. data/lib/json/FalseClass.xpm +0 -21
  94. data/lib/json/Hash.xpm +0 -21
  95. data/lib/json/Key.xpm +0 -73
  96. data/lib/json/NilClass.xpm +0 -21
  97. data/lib/json/Numeric.xpm +0 -28
  98. data/lib/json/String.xpm +0 -96
  99. data/lib/json/TrueClass.xpm +0 -21
  100. data/lib/json/add/rails.rb +0 -58
  101. data/lib/json/editor.rb +0 -1371
  102. data/lib/json/json.xpm +0 -1499
  103. data/lib/json/pure/generator.rb +0 -443
  104. data/lib/json/pure/parser.rb +0 -303
  105. data/lib/json/pure.rb +0 -77
  106. data/tests/fixtures/fail1.json +0 -1
  107. data/tests/fixtures/fail10.json +0 -1
  108. data/tests/fixtures/fail11.json +0 -1
  109. data/tests/fixtures/fail12.json +0 -1
  110. data/tests/fixtures/fail13.json +0 -1
  111. data/tests/fixtures/fail14.json +0 -1
  112. data/tests/fixtures/fail18.json +0 -1
  113. data/tests/fixtures/fail19.json +0 -1
  114. data/tests/fixtures/fail2.json +0 -1
  115. data/tests/fixtures/fail20.json +0 -1
  116. data/tests/fixtures/fail21.json +0 -1
  117. data/tests/fixtures/fail22.json +0 -1
  118. data/tests/fixtures/fail23.json +0 -1
  119. data/tests/fixtures/fail24.json +0 -1
  120. data/tests/fixtures/fail25.json +0 -1
  121. data/tests/fixtures/fail27.json +0 -2
  122. data/tests/fixtures/fail28.json +0 -2
  123. data/tests/fixtures/fail3.json +0 -1
  124. data/tests/fixtures/fail4.json +0 -1
  125. data/tests/fixtures/fail5.json +0 -1
  126. data/tests/fixtures/fail6.json +0 -1
  127. data/tests/fixtures/fail7.json +0 -1
  128. data/tests/fixtures/fail8.json +0 -1
  129. data/tests/fixtures/fail9.json +0 -1
  130. data/tests/fixtures/pass1.json +0 -56
  131. data/tests/fixtures/pass15.json +0 -1
  132. data/tests/fixtures/pass16.json +0 -1
  133. data/tests/fixtures/pass17.json +0 -1
  134. data/tests/fixtures/pass2.json +0 -1
  135. data/tests/fixtures/pass26.json +0 -1
  136. data/tests/fixtures/pass3.json +0 -6
  137. data/tests/test_json.rb +0 -320
  138. data/tests/test_json_addition.rb +0 -164
  139. data/tests/test_json_encoding.rb +0 -67
  140. data/tests/test_json_fixtures.rb +0 -34
  141. data/tests/test_json_generate.rb +0 -120
  142. data/tests/test_json_rails.rb +0 -146
  143. data/tests/test_json_unicode.rb +0 -62
  144. data/tools/fuzz.rb +0 -139
  145. data/tools/server.rb +0 -61
data/README DELETED
@@ -1,360 +0,0 @@
1
- == json - JSON Implementation for Ruby
2
-
3
- === Description
4
-
5
- This is a implementation of the JSON specification according to RFC 4627
6
- (http://www.ietf.org/rfc/rfc4627.txt). Starting from version 1.0.0 on there
7
- will be two variants available:
8
-
9
- * A pure ruby variant, that relies on the iconv and the stringscan
10
- extensions, which are both part of the ruby standard library.
11
- * The quite a bit faster C extension variant, which is in parts implemented
12
- in C and comes with its own unicode conversion functions and a parser
13
- generated by the ragel state machine compiler
14
- (http://www.cs.queensu.ca/~thurston/ragel).
15
-
16
- Both variants of the JSON generator escape all non-ASCII and control characters
17
- with \uXXXX escape sequences, and support UTF-16 surrogate pairs in order to be
18
- able to generate the whole range of unicode code points. This means that
19
- generated JSON document is encoded as UTF-8 (because ASCII is a subset of
20
- UTF-8) and at the same time avoids decoding problems for receiving endpoints,
21
- that don't expect UTF-8 encoded texts. On the negative side this may lead to a
22
- bit longer strings than necessarry.
23
-
24
- All strings, that are to be encoded as JSON strings, should be UTF-8 byte
25
- sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
26
- encoded, please use the to_json_raw_object method of String (which produces
27
- an object, that contains a byte array) and decode the result on the receiving
28
- endpoint.
29
-
30
- The JSON parsers can parse UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, and UTF-32LE
31
- JSON documents under Ruby 1.8. Under Ruby 1.9 they take advantage of Ruby's
32
- M17n features and can parse all documents which have the correct
33
- String#encoding set. If a document string has ASCII-8BIT as an encoding the
34
- parser attempts to figure out which of the UTF encodings from above it is and
35
- trys to parse it.
36
-
37
- === Installation
38
-
39
- It's recommended to use the extension variant of JSON, because it's faster than
40
- the pure ruby variant. If you cannot build it on your system, you can settle
41
- for the latter.
42
-
43
- Just type into the command line as root:
44
-
45
- # rake install
46
-
47
- The above command will build the extensions and install them on your system.
48
-
49
- # rake install_pure
50
-
51
- or
52
-
53
- # ruby install.rb
54
-
55
- will just install the pure ruby implementation of JSON.
56
-
57
- If you use Rubygems you can type
58
-
59
- # gem install json
60
-
61
- instead, to install the newest JSON version.
62
-
63
- There is also a pure ruby json only variant of the gem, that can be installed
64
- with:
65
-
66
- # gem install json_pure
67
-
68
- === Compiling the extensions yourself
69
-
70
- If you want to build the extensions yourself you need rake:
71
-
72
- You can get it from rubyforge:
73
- http://rubyforge.org/projects/rake
74
-
75
- or just type
76
-
77
- # gem install rake
78
-
79
- for the installation via rubygems.
80
-
81
- If you want to create the parser.c file from its parser.rl file or draw nice
82
- graphviz images of the state machines, you need ragel from: http://www.cs.queensu.ca/~thurston/ragel
83
-
84
-
85
- === Usage
86
-
87
- To use JSON you can
88
- require 'json'
89
- to load the installed variant (either the extension 'json' or the pure
90
- variant 'json_pure'). If you have installed the extension variant, you can
91
- pick either the extension variant or the pure variant by typing
92
- require 'json/ext'
93
- or
94
- require 'json/pure'
95
-
96
- Now you can parse a JSON document into a ruby data structure by calling
97
-
98
- JSON.parse(document)
99
-
100
- If you want to generate a JSON document from a ruby data structure call
101
- JSON.generate(data)
102
-
103
- You can also use the pretty_generate method (which formats the output more
104
- verbosely and nicely) or fast_generate (which doesn't do any of the security
105
- checks generate performs, e. g. nesting deepness checks).
106
-
107
- To create a valid JSON document you have to make sure, that the output is
108
- embedded in either a JSON array [] or a JSON object {}. The easiest way to do
109
- this, is by putting your values in a Ruby Array or Hash instance.
110
-
111
- There are also the JSON and JSON[] methods which use parse on a String or
112
- generate a JSON document from an array or hash:
113
-
114
- document = JSON 'test' => 23 # => "{\"test\":23}"
115
- document = JSON['test'] => 23 # => "{\"test\":23}"
116
-
117
- and
118
-
119
- data = JSON '{"test":23}' # => {"test"=>23}
120
- data = JSON['{"test":23}'] # => {"test"=>23}
121
-
122
- You can choose to load a set of common additions to ruby core's objects if
123
- you
124
- require 'json/add/core'
125
-
126
- After requiring this you can, e. g., serialise/deserialise Ruby ranges:
127
-
128
- JSON JSON(1..10) # => 1..10
129
-
130
- To find out how to add JSON support to other or your own classes, read the
131
- section "More Examples" below.
132
-
133
- To get the best compatibility to rails' JSON implementation, you can
134
- require 'json/add/rails'
135
-
136
- Both of the additions attempt to require 'json' (like above) first, if it has
137
- not been required yet.
138
-
139
- === More Examples
140
-
141
- To create a JSON document from a ruby data structure, you can call
142
- JSON.generate like that:
143
-
144
- json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
145
- # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
146
-
147
- To get back a ruby data structure from a JSON document, you have to call
148
- JSON.parse on it:
149
-
150
- JSON.parse json
151
- # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
152
-
153
- Note, that the range from the original data structure is a simple
154
- string now. The reason for this is, that JSON doesn't support ranges
155
- or arbitrary classes. In this case the json library falls back to call
156
- Object#to_json, which is the same as #to_s.to_json.
157
-
158
- It's possible to add JSON support serialization to arbitrary classes by
159
- simply implementing a more specialized version of the #to_json method, that
160
- should return a JSON object (a hash converted to JSON with #to_json) like
161
- this (don't forget the *a for all the arguments):
162
-
163
- class Range
164
- def to_json(*a)
165
- {
166
- 'json_class' => self.class.name, # = 'Range'
167
- 'data' => [ first, last, exclude_end? ]
168
- }.to_json(*a)
169
- end
170
- end
171
-
172
- The hash key 'json_class' is the class, that will be asked to deserialise the
173
- JSON representation later. In this case it's 'Range', but any namespace of
174
- the form 'A::B' or '::A::B' will do. All other keys are arbitrary and can be
175
- used to store the necessary data to configure the object to be deserialised.
176
-
177
- If a the key 'json_class' is found in a JSON object, the JSON parser checks
178
- if the given class responds to the json_create class method. If so, it is
179
- called with the JSON object converted to a Ruby hash. So a range can
180
- be deserialised by implementing Range.json_create like this:
181
-
182
- class Range
183
- def self.json_create(o)
184
- new(*o['data'])
185
- end
186
- end
187
-
188
- Now it possible to serialise/deserialise ranges as well:
189
-
190
- json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
191
- # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
192
- JSON.parse json
193
- # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
194
-
195
- JSON.generate always creates the shortest possible string representation of a
196
- ruby data structure in one line. This is good for data storage or network
197
- protocols, but not so good for humans to read. Fortunately there's also
198
- JSON.pretty_generate (or JSON.pretty_generate) that creates a more readable
199
- output:
200
-
201
- puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
202
- [
203
- 1,
204
- 2,
205
- {
206
- "a": 3.141
207
- },
208
- false,
209
- true,
210
- null,
211
- {
212
- "json_class": "Range",
213
- "data": [
214
- 4,
215
- 10,
216
- false
217
- ]
218
- }
219
- ]
220
-
221
- There are also the methods Kernel#j for generate, and Kernel#jj for
222
- pretty_generate output to the console, that work analogous to Core Ruby's p and
223
- the pp library's pp methods.
224
-
225
- The script tools/server.rb contains a small example if you want to test, how
226
- receiving a JSON object from a webrick server in your browser with the
227
- javasript prototype library (http://www.prototypejs.org) works.
228
-
229
- === Speed Comparisons
230
-
231
- I have created some benchmark results (see the benchmarks/data-p4-3Ghz
232
- subdir of the package) for the JSON-parser to estimate the speed up in the C
233
- extension:
234
-
235
- Comparing times (call_time_mean):
236
- 1 ParserBenchmarkExt#parser 900 repeats:
237
- 553.922304770 ( real) -> 21.500x
238
- 0.001805307
239
- 2 ParserBenchmarkYAML#parser 1000 repeats:
240
- 224.513358139 ( real) -> 8.714x
241
- 0.004454078
242
- 3 ParserBenchmarkPure#parser 1000 repeats:
243
- 26.755020642 ( real) -> 1.038x
244
- 0.037376163
245
- 4 ParserBenchmarkRails#parser 1000 repeats:
246
- 25.763381731 ( real) -> 1.000x
247
- 0.038814780
248
- calls/sec ( time) -> speed covers
249
- secs/call
250
-
251
- In the table above 1 is JSON::Ext::Parser, 2 is YAML.load with YAML
252
- compatbile JSON document, 3 is is JSON::Pure::Parser, and 4 is
253
- ActiveSupport::JSON.decode. The ActiveSupport JSON-decoder converts the
254
- input first to YAML and then uses the YAML-parser, the conversion seems to
255
- slow it down so much that it is only as fast as the JSON::Pure::Parser!
256
-
257
- If you look at the benchmark data you can see that this is mostly caused by
258
- the frequent high outliers - the median of the Rails-parser runs is still
259
- overall smaller than the median of the JSON::Pure::Parser runs:
260
-
261
- Comparing times (call_time_median):
262
- 1 ParserBenchmarkExt#parser 900 repeats:
263
- 800.592479481 ( real) -> 26.936x
264
- 0.001249075
265
- 2 ParserBenchmarkYAML#parser 1000 repeats:
266
- 271.002390644 ( real) -> 9.118x
267
- 0.003690004
268
- 3 ParserBenchmarkRails#parser 1000 repeats:
269
- 30.227910865 ( real) -> 1.017x
270
- 0.033082008
271
- 4 ParserBenchmarkPure#parser 1000 repeats:
272
- 29.722384421 ( real) -> 1.000x
273
- 0.033644676
274
- calls/sec ( time) -> speed covers
275
- secs/call
276
-
277
- I have benchmarked the JSON-Generator as well. This generated a few more
278
- values, because there are different modes that also influence the achieved
279
- speed:
280
-
281
- Comparing times (call_time_mean):
282
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
283
- 547.354332608 ( real) -> 15.090x
284
- 0.001826970
285
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
286
- 443.968212317 ( real) -> 12.240x
287
- 0.002252414
288
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
289
- 375.104545883 ( real) -> 10.341x
290
- 0.002665923
291
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
292
- 49.978706968 ( real) -> 1.378x
293
- 0.020008521
294
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
295
- 38.531868759 ( real) -> 1.062x
296
- 0.025952543
297
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
298
- 36.927649925 ( real) -> 1.018x 7 (>=3859)
299
- 0.027079979
300
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
301
- 36.272134441 ( real) -> 1.000x 6 (>=3859)
302
- 0.027569373
303
- calls/sec ( time) -> speed covers
304
- secs/call
305
-
306
- In the table above 1-3 are JSON::Ext::Generator methods. 4, 6, and 7 are
307
- JSON::Pure::Generator methods and 5 is the Rails JSON generator. It is now a
308
- bit faster than the generator_safe and generator_pretty methods of the pure
309
- variant but slower than the others.
310
-
311
- To achieve the fastest JSON document output, you can use the fast_generate
312
- method. Beware, that this will disable the checking for circular Ruby data
313
- structures, which may cause JSON to go into an infinite loop.
314
-
315
- Here are the median comparisons for completeness' sake:
316
-
317
- Comparing times (call_time_median):
318
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
319
- 708.258020939 ( real) -> 16.547x
320
- 0.001411915
321
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
322
- 569.105020353 ( real) -> 13.296x
323
- 0.001757145
324
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
325
- 482.825371244 ( real) -> 11.280x
326
- 0.002071142
327
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
328
- 62.717626652 ( real) -> 1.465x
329
- 0.015944481
330
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
331
- 43.965681162 ( real) -> 1.027x
332
- 0.022745013
333
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
334
- 43.929073409 ( real) -> 1.026x 7 (>=3859)
335
- 0.022763968
336
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
337
- 42.802514491 ( real) -> 1.000x 6 (>=3859)
338
- 0.023363113
339
- calls/sec ( time) -> speed covers
340
- secs/call
341
-
342
- === Author
343
-
344
- Florian Frank <mailto:flori@ping.de>
345
-
346
- === License
347
-
348
- Ruby License, see the COPYING file included in the source distribution. The
349
- Ruby License includes the GNU General Public License (GPL), Version 2, so see
350
- the file GPL as well.
351
-
352
- === Download
353
-
354
- The latest version of this library can be downloaded at
355
-
356
- * http://rubyforge.org/frs?group_id=953
357
-
358
- Online Documentation should be located at
359
-
360
- * http://json.rubyforge.org
data/Rakefile DELETED
@@ -1,287 +0,0 @@
1
- begin
2
- require 'rake/gempackagetask'
3
- rescue LoadError
4
- end
5
-
6
- begin
7
- require 'rake/extensiontask'
8
- rescue LoadError
9
- puts "WARNING: rake-compiler is not installed. You will not be able to build the json gem until you install it."
10
- end
11
-
12
- require 'rake/clean'
13
- CLOBBER.include Dir['benchmarks/data/*.{dat,log}']
14
-
15
- require 'rbconfig'
16
- include Config
17
-
18
- MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') }
19
- PKG_NAME = 'json'
20
- PKG_VERSION = File.read('VERSION').chomp
21
- PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile|\.nfs\./).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
22
- EXT_ROOT_DIR = 'ext/json/ext'
23
- EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser"
24
- EXT_PARSER_DL = "#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}"
25
- EXT_PARSER_SRC = "#{EXT_PARSER_DIR}/parser.c"
26
- PKG_FILES << EXT_PARSER_SRC
27
- EXT_GENERATOR_DIR = "#{EXT_ROOT_DIR}/generator"
28
- EXT_GENERATOR_DL = "#{EXT_ROOT_DIR}/generator.#{CONFIG['DLEXT']}"
29
- EXT_GENERATOR_SRC = "#{EXT_GENERATOR_DIR}/generator.c"
30
- RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find { |c| system(c, '-v') }
31
- RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find { |c| system(c, '-v') }
32
- RAGEL_PATH = "#{EXT_PARSER_DIR}/parser.rl"
33
- CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp',
34
- FileList["ext/**/{Makefile,mkmf.log}"],
35
- FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"]
36
-
37
- def myruby(*args, &block)
38
- @myruby ||= File.join(CONFIG['bindir'], CONFIG['ruby_install_name'])
39
- options = (Hash === args.last) ? args.pop : {}
40
- if args.length > 1 then
41
- sh(*([@myruby] + args + [options]), &block)
42
- else
43
- sh("#{@myruby} #{args.first}", options, &block)
44
- end
45
- end
46
-
47
- desc "Installing library (pure)"
48
- task :install_pure => :version do
49
- myruby 'install.rb'
50
- end
51
-
52
- task :install_ext_really do
53
- sitearchdir = CONFIG["sitearchdir"]
54
- cd 'ext' do
55
- for file in Dir["json/ext/*.#{CONFIG['DLEXT']}"]
56
- d = File.join(sitearchdir, file)
57
- mkdir_p File.dirname(d)
58
- install(file, d)
59
- end
60
- end
61
- end
62
-
63
- desc "Installing library (extension)"
64
- task :install_ext => [ :compile_ext, :install_pure, :install_ext_really ]
65
-
66
- desc "Installing library (extension)"
67
- if RUBY_PLATFORM =~ /java/
68
- task :install => :install_pure
69
- else
70
- task :install => :install_ext
71
- end
72
-
73
- desc "Compiling extension"
74
- task :compile_ext => [ EXT_PARSER_DL, EXT_GENERATOR_DL ]
75
-
76
- file EXT_PARSER_DL => EXT_PARSER_SRC do
77
- cd EXT_PARSER_DIR do
78
- myruby 'extconf.rb'
79
- sh MAKE
80
- end
81
- cp "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
82
- end
83
-
84
- file EXT_GENERATOR_DL => EXT_GENERATOR_SRC do
85
- cd EXT_GENERATOR_DIR do
86
- myruby 'extconf.rb'
87
- sh MAKE
88
- end
89
- cp "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
90
- end
91
-
92
- desc "Generate parser with ragel"
93
- task :ragel => EXT_PARSER_SRC
94
-
95
- task :ragel_clean do
96
- rm_rf EXT_PARSER_SRC
97
- end
98
-
99
- file EXT_PARSER_SRC => RAGEL_PATH do
100
- cd EXT_PARSER_DIR do
101
- if RAGEL_CODEGEN == 'ragel'
102
- sh "ragel parser.rl -G2 -o parser.c"
103
- else
104
- sh "ragel -x parser.rl | #{RAGEL_CODEGEN} -G2"
105
- end
106
- end
107
- end
108
-
109
- desc "Generate diagrams of ragel parser (ps)"
110
- task :ragel_dot_ps do
111
- root = 'diagrams'
112
- specs = []
113
- File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
114
- for s in specs
115
- if RAGEL_DOTGEN == 'ragel'
116
- sh "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tps -o#{root}/#{s}.ps"
117
- else
118
- sh "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tps -o#{root}/#{s}.ps"
119
- end
120
- end
121
- end
122
-
123
- desc "Generate diagrams of ragel parser (png)"
124
- task :ragel_dot_png do
125
- root = 'diagrams'
126
- specs = []
127
- File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
128
- for s in specs
129
- if RAGEL_DOTGEN == 'ragel'
130
- sh "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tpng -o#{root}/#{s}.png"
131
- else
132
- sh "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tpng -o#{root}/#{s}.png"
133
- end
134
- end
135
- end
136
-
137
- desc "Generate diagrams of ragel parser"
138
- task :ragel_dot => [ :ragel_dot_png, :ragel_dot_ps ]
139
-
140
- desc "Testing library (pure ruby)"
141
- task :test_pure => :clean do
142
- ENV['JSON'] = 'pure'
143
- ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}"
144
- myruby "-S testrb #{Dir['./tests/*.rb'] * ' '}"
145
- end
146
-
147
- desc "Testing library (extension)"
148
- task :test_ext => :compile_ext do
149
- ENV['JSON'] = 'ext'
150
- ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}"
151
- myruby "-S testrb #{Dir['./tests/*.rb'] * ' '}"
152
- end
153
-
154
- desc "Testing library (pure ruby and extension)"
155
- task :test => [ :test_pure, :test_ext ]
156
-
157
- desc "Benchmarking parser"
158
- task :benchmark_parser do
159
- ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}"
160
- myruby 'benchmarks/parser_benchmark.rb'
161
- end
162
-
163
- desc "Benchmarking generator"
164
- task :benchmark_generator do
165
- ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}"
166
- myruby 'benchmarks/generator_benchmark.rb'
167
- end
168
-
169
- desc "Benchmarking library"
170
- task :benchmark => [ :benchmark_parser, :benchmark_generator ]
171
-
172
- desc "Create RDOC documentation"
173
- task :doc => [ :version, EXT_PARSER_SRC ] do
174
- sh "rdoc -o doc -m README README lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
175
- end
176
-
177
- if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::ExtensionTask)
178
- spec_pure = Gem::Specification.new do |s|
179
- s.name = 'json_pure'
180
- s.version = PKG_VERSION
181
- s.summary = "A JSON implementation in Ruby"
182
- s.description = "This is a JSON implementation in pure Ruby."
183
-
184
- s.files = PKG_FILES
185
-
186
- s.require_path = 'lib'
187
-
188
- s.bindir = "bin"
189
- s.executables = [ "edit_json.rb", "prettify_json.rb" ]
190
- s.default_executable = "edit_json.rb"
191
-
192
- s.has_rdoc = true
193
- s.extra_rdoc_files << 'README'
194
- s.rdoc_options <<
195
- '--title' << 'JSON -- A JSON implemention' << '--main' << 'README'
196
- s.test_files.concat Dir['tests/*.rb']
197
-
198
- s.author = "Florian Frank"
199
- s.email = "flori@ping.de"
200
- s.homepage = "http://json.rubyforge.org"
201
- s.rubyforge_project = "json"
202
- end
203
-
204
- Rake::GemPackageTask.new(spec_pure) do |pkg|
205
- pkg.need_tar = true
206
- pkg.package_files = PKG_FILES
207
- end
208
-
209
- spec_ext = Gem::Specification.new do |s|
210
- s.name = 'json'
211
- s.version = PKG_VERSION
212
- s.summary = "A JSON implementation as a Ruby extension"
213
- s.description = "This is a JSON implementation as a Ruby extension in C."
214
-
215
- s.files = PKG_FILES
216
-
217
- s.extensions = FileList['ext/**/extconf.rb']
218
-
219
- s.require_path = EXT_ROOT_DIR
220
- s.require_paths << 'ext'
221
- s.require_paths << 'lib'
222
-
223
- s.bindir = "bin"
224
- s.executables = [ "edit_json.rb", "prettify_json.rb" ]
225
- s.default_executable = "edit_json.rb"
226
-
227
- s.has_rdoc = true
228
- s.extra_rdoc_files << 'README'
229
- s.rdoc_options <<
230
- '--title' << 'JSON -- A JSON implemention' << '--main' << 'README'
231
- s.test_files.concat Dir['tests/*.rb']
232
-
233
- s.author = "Florian Frank"
234
- s.email = "flori@ping.de"
235
- s.homepage = "http://json.rubyforge.org"
236
- s.rubyforge_project = "json"
237
- end
238
-
239
- Rake::GemPackageTask.new(spec_ext) do |pkg|
240
- pkg.need_tar = true
241
- pkg.package_files = PKG_FILES
242
- end
243
-
244
- Rake::ExtensionTask.new do |ext|
245
- ext.name = 'parser'
246
- ext.gem_spec = spec_ext
247
- ext.cross_compile = true
248
- ext.cross_platform = 'i386-mswin32'
249
- ext.ext_dir = 'ext/json/ext/parser'
250
- ext.lib_dir = 'lib/json/ext'
251
- end
252
-
253
- Rake::ExtensionTask.new do |ext|
254
- ext.name = 'generator'
255
- ext.gem_spec = spec_ext
256
- ext.cross_compile = true
257
- ext.cross_platform = 'i386-mswin32'
258
- ext.ext_dir = 'ext/json/ext/generator'
259
- ext.lib_dir = 'lib/json/ext'
260
- end
261
- end
262
-
263
- desc m = "Writing version information for #{PKG_VERSION}"
264
- task :version do
265
- puts m
266
- File.open(File.join('lib', 'json', 'version.rb'), 'w') do |v|
267
- v.puts <<EOT
268
- module JSON
269
- # JSON version
270
- VERSION = '#{PKG_VERSION}'
271
- VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
272
- VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
273
- VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
274
- VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
275
- end
276
- EOT
277
- end
278
- end
279
-
280
- desc "Build all gems and archives for a new release."
281
- task :release => [ :clean, :version, :cross, :native, :gem ] do
282
- sh "#$0 clean native gem"
283
- sh "#$0 clean package"
284
- end
285
-
286
- desc "Compile in the the source directory"
287
- task :default => [ :version, :compile_ext ]
data/TODO DELETED
@@ -1 +0,0 @@
1
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.0
@@ -1,52 +0,0 @@
1
- ========================== 2009-04-01T16:54:14 CEST ===========================
2
-
3
- Comparing times (call_time_mean):
4
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
5
- 547.354332608 ( real) -> 15.090x
6
- 0.001826970
7
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
8
- 443.968212317 ( real) -> 12.240x
9
- 0.002252414
10
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
11
- 375.104545883 ( real) -> 10.341x
12
- 0.002665923
13
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
14
- 49.978706968 ( real) -> 1.378x
15
- 0.020008521
16
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
17
- 38.531868759 ( real) -> 1.062x
18
- 0.025952543
19
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
20
- 36.927649925 ( real) -> 1.018x 7 (>=3859)
21
- 0.027079979
22
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
23
- 36.272134441 ( real) -> 1.000x 6 (>=3859)
24
- 0.027569373
25
- calls/sec ( time) -> speed covers
26
- secs/call
27
-
28
- Comparing times (call_time_median):
29
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
30
- 708.258020939 ( real) -> 16.547x
31
- 0.001411915
32
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
33
- 569.105020353 ( real) -> 13.296x
34
- 0.001757145
35
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
36
- 482.825371244 ( real) -> 11.280x
37
- 0.002071142
38
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
39
- 62.717626652 ( real) -> 1.465x
40
- 0.015944481
41
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
42
- 43.965681162 ( real) -> 1.027x
43
- 0.022745013
44
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
45
- 43.929073409 ( real) -> 1.026x 7 (>=3859)
46
- 0.022763968
47
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
48
- 42.802514491 ( real) -> 1.000x 6 (>=3859)
49
- 0.023363113
50
- calls/sec ( time) -> speed covers
51
- secs/call
52
- ===============================================================================