json 1.0.0 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +503 -0
  3. data/LICENSE +56 -0
  4. data/README.md +416 -0
  5. data/ext/json/ext/fbuffer/fbuffer.h +187 -0
  6. data/ext/json/ext/generator/depend +1 -0
  7. data/ext/json/ext/generator/extconf.rb +2 -7
  8. data/ext/json/ext/generator/generator.c +1312 -338
  9. data/ext/json/ext/generator/generator.h +177 -0
  10. data/ext/json/ext/parser/depend +1 -0
  11. data/ext/json/ext/parser/extconf.rb +28 -5
  12. data/ext/json/ext/parser/parser.c +1349 -689
  13. data/ext/json/ext/parser/parser.h +96 -0
  14. data/ext/json/ext/parser/parser.rl +644 -188
  15. data/ext/json/extconf.rb +3 -0
  16. data/json.gemspec +68 -0
  17. data/lib/json/add/bigdecimal.rb +58 -0
  18. data/lib/json/add/complex.rb +51 -0
  19. data/lib/json/add/core.rb +12 -0
  20. data/lib/json/add/date.rb +54 -0
  21. data/lib/json/add/date_time.rb +67 -0
  22. data/lib/json/add/exception.rb +49 -0
  23. data/lib/json/add/ostruct.rb +54 -0
  24. data/lib/json/add/range.rb +54 -0
  25. data/lib/json/add/rational.rb +49 -0
  26. data/lib/json/add/regexp.rb +48 -0
  27. data/lib/json/add/set.rb +48 -0
  28. data/lib/json/add/struct.rb +52 -0
  29. data/lib/json/add/symbol.rb +48 -0
  30. data/lib/json/add/time.rb +59 -0
  31. data/lib/json/common.rb +588 -74
  32. data/lib/json/ext.rb +3 -1
  33. data/lib/json/generic_object.rb +75 -0
  34. data/lib/json/pure/generator.rb +311 -119
  35. data/lib/json/pure/parser.rb +182 -55
  36. data/lib/json/pure.rb +5 -65
  37. data/lib/json/version.rb +2 -1
  38. data/lib/json.rb +583 -196
  39. metadata +78 -137
  40. data/CHANGES +0 -25
  41. data/GPL +0 -340
  42. data/README +0 -77
  43. data/Rakefile +0 -250
  44. data/TODO +0 -1
  45. data/VERSION +0 -1
  46. data/benchmarks/benchmark.txt +0 -133
  47. data/benchmarks/benchmark_generator.rb +0 -44
  48. data/benchmarks/benchmark_parser.rb +0 -22
  49. data/benchmarks/benchmark_rails.rb +0 -26
  50. data/bin/edit_json.rb +0 -11
  51. data/data/example.json +0 -1
  52. data/data/index.html +0 -37
  53. data/data/prototype.js +0 -2515
  54. data/ext/json/ext/generator/Makefile +0 -149
  55. data/ext/json/ext/generator/unicode.c +0 -184
  56. data/ext/json/ext/generator/unicode.h +0 -40
  57. data/ext/json/ext/parser/Makefile +0 -149
  58. data/ext/json/ext/parser/unicode.c +0 -156
  59. data/ext/json/ext/parser/unicode.h +0 -44
  60. data/install.rb +0 -26
  61. data/lib/json/Array.xpm +0 -21
  62. data/lib/json/FalseClass.xpm +0 -21
  63. data/lib/json/Hash.xpm +0 -21
  64. data/lib/json/Key.xpm +0 -73
  65. data/lib/json/NilClass.xpm +0 -21
  66. data/lib/json/Numeric.xpm +0 -28
  67. data/lib/json/String.xpm +0 -96
  68. data/lib/json/TrueClass.xpm +0 -21
  69. data/lib/json/editor.rb +0 -1207
  70. data/lib/json/json.xpm +0 -1499
  71. data/tests/fixtures/fail1.json +0 -1
  72. data/tests/fixtures/fail10.json +0 -1
  73. data/tests/fixtures/fail11.json +0 -1
  74. data/tests/fixtures/fail12.json +0 -1
  75. data/tests/fixtures/fail13.json +0 -1
  76. data/tests/fixtures/fail14.json +0 -1
  77. data/tests/fixtures/fail15.json +0 -1
  78. data/tests/fixtures/fail16.json +0 -1
  79. data/tests/fixtures/fail17.json +0 -1
  80. data/tests/fixtures/fail19.json +0 -1
  81. data/tests/fixtures/fail2.json +0 -1
  82. data/tests/fixtures/fail20.json +0 -1
  83. data/tests/fixtures/fail21.json +0 -1
  84. data/tests/fixtures/fail22.json +0 -1
  85. data/tests/fixtures/fail23.json +0 -1
  86. data/tests/fixtures/fail24.json +0 -1
  87. data/tests/fixtures/fail25.json +0 -1
  88. data/tests/fixtures/fail26.json +0 -1
  89. data/tests/fixtures/fail27.json +0 -2
  90. data/tests/fixtures/fail28.json +0 -2
  91. data/tests/fixtures/fail3.json +0 -1
  92. data/tests/fixtures/fail4.json +0 -1
  93. data/tests/fixtures/fail5.json +0 -1
  94. data/tests/fixtures/fail6.json +0 -1
  95. data/tests/fixtures/fail7.json +0 -1
  96. data/tests/fixtures/fail8.json +0 -1
  97. data/tests/fixtures/fail9.json +0 -1
  98. data/tests/fixtures/pass1.json +0 -56
  99. data/tests/fixtures/pass18.json +0 -1
  100. data/tests/fixtures/pass2.json +0 -1
  101. data/tests/fixtures/pass3.json +0 -6
  102. data/tests/runner.rb +0 -24
  103. data/tests/test_json.rb +0 -235
  104. data/tests/test_json_addition.rb +0 -94
  105. data/tests/test_json_fixtures.rb +0 -30
  106. data/tests/test_json_generate.rb +0 -81
  107. data/tests/test_json_unicode.rb +0 -55
  108. data/tools/fuzz.rb +0 -133
  109. data/tools/server.rb +0 -62
@@ -0,0 +1,177 @@
1
+ #ifndef _GENERATOR_H_
2
+ #define _GENERATOR_H_
3
+
4
+ #include <math.h>
5
+ #include <ctype.h>
6
+
7
+ #include "ruby.h"
8
+
9
+ #ifdef HAVE_RUBY_RE_H
10
+ #include "ruby/re.h"
11
+ #else
12
+ #include "re.h"
13
+ #endif
14
+
15
+ #ifndef rb_intern_str
16
+ #define rb_intern_str(string) SYM2ID(rb_str_intern(string))
17
+ #endif
18
+
19
+ #ifndef rb_obj_instance_variables
20
+ #define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
21
+ #endif
22
+
23
+ #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
24
+
25
+ /* unicode definitions */
26
+
27
+ #define UNI_STRICT_CONVERSION 1
28
+
29
+ typedef unsigned long UTF32; /* at least 32 bits */
30
+ typedef unsigned short UTF16; /* at least 16 bits */
31
+ typedef unsigned char UTF8; /* typically 8 bits */
32
+
33
+ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
34
+ #define UNI_MAX_BMP (UTF32)0x0000FFFF
35
+ #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
36
+ #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
37
+ #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
38
+
39
+ #define UNI_SUR_HIGH_START (UTF32)0xD800
40
+ #define UNI_SUR_HIGH_END (UTF32)0xDBFF
41
+ #define UNI_SUR_LOW_START (UTF32)0xDC00
42
+ #define UNI_SUR_LOW_END (UTF32)0xDFFF
43
+
44
+ static const int halfShift = 10; /* used for shifting by 10 bits */
45
+
46
+ static const UTF32 halfBase = 0x0010000UL;
47
+ static const UTF32 halfMask = 0x3FFUL;
48
+
49
+ static unsigned char isLegalUTF8(const UTF8 *source, unsigned long length);
50
+ static void unicode_escape(char *buf, UTF16 character);
51
+ static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
52
+ static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string, char script_safe);
53
+ static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string, char script_safe);
54
+ static char *fstrndup(const char *ptr, unsigned long len);
55
+
56
+ /* ruby api and some helpers */
57
+
58
+ typedef struct JSON_Generator_StateStruct {
59
+ char *indent;
60
+ long indent_len;
61
+ char *space;
62
+ long space_len;
63
+ char *space_before;
64
+ long space_before_len;
65
+ char *object_nl;
66
+ long object_nl_len;
67
+ char *array_nl;
68
+ long array_nl_len;
69
+ FBuffer *array_delim;
70
+ FBuffer *object_delim;
71
+ FBuffer *object_delim2;
72
+ long max_nesting;
73
+ char allow_nan;
74
+ char ascii_only;
75
+ char script_safe;
76
+ char strict;
77
+ long depth;
78
+ long buffer_initial_length;
79
+ } JSON_Generator_State;
80
+
81
+ #define GET_STATE_TO(self, state) \
82
+ TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
83
+
84
+ #define GET_STATE(self) \
85
+ JSON_Generator_State *state; \
86
+ GET_STATE_TO(self, state)
87
+
88
+ #define GENERATE_JSON(type) \
89
+ FBuffer *buffer; \
90
+ VALUE Vstate; \
91
+ JSON_Generator_State *state; \
92
+ \
93
+ rb_scan_args(argc, argv, "01", &Vstate); \
94
+ Vstate = cState_from_state_s(cState, Vstate); \
95
+ TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
96
+ buffer = cState_prepare_buffer(Vstate); \
97
+ generate_json_##type(buffer, Vstate, state, self); \
98
+ return fbuffer_to_s(buffer)
99
+
100
+ static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
101
+ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
102
+ #ifdef RUBY_INTEGER_UNIFICATION
103
+ static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
104
+ #else
105
+ static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
106
+ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
107
+ #endif
108
+ static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
109
+ static VALUE mString_included_s(VALUE self, VALUE modul);
110
+ static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
111
+ static VALUE mString_to_json_raw_object(VALUE self);
112
+ static VALUE mString_to_json_raw(int argc, VALUE *argv, VALUE self);
113
+ static VALUE mString_Extend_json_create(VALUE self, VALUE o);
114
+ static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
115
+ static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
116
+ static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
117
+ static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
118
+ static void State_free(void *state);
119
+ static VALUE cState_s_allocate(VALUE klass);
120
+ static VALUE cState_configure(VALUE self, VALUE opts);
121
+ static VALUE cState_to_h(VALUE self);
122
+ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
123
+ static void generate_json_object(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
124
+ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
125
+ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
126
+ static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
127
+ static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
128
+ static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
129
+ #ifdef RUBY_INTEGER_UNIFICATION
130
+ static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
131
+ #endif
132
+ static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
133
+ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
134
+ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
135
+ static VALUE cState_partial_generate(VALUE self, VALUE obj);
136
+ static VALUE cState_generate(VALUE self, VALUE obj);
137
+ static VALUE cState_initialize(int argc, VALUE *argv, VALUE self);
138
+ static VALUE cState_from_state_s(VALUE self, VALUE opts);
139
+ static VALUE cState_indent(VALUE self);
140
+ static VALUE cState_indent_set(VALUE self, VALUE indent);
141
+ static VALUE cState_space(VALUE self);
142
+ static VALUE cState_space_set(VALUE self, VALUE space);
143
+ static VALUE cState_space_before(VALUE self);
144
+ static VALUE cState_space_before_set(VALUE self, VALUE space_before);
145
+ static VALUE cState_object_nl(VALUE self);
146
+ static VALUE cState_object_nl_set(VALUE self, VALUE object_nl);
147
+ static VALUE cState_array_nl(VALUE self);
148
+ static VALUE cState_array_nl_set(VALUE self, VALUE array_nl);
149
+ static VALUE cState_max_nesting(VALUE self);
150
+ static VALUE cState_max_nesting_set(VALUE self, VALUE depth);
151
+ static VALUE cState_allow_nan_p(VALUE self);
152
+ static VALUE cState_ascii_only_p(VALUE self);
153
+ static VALUE cState_depth(VALUE self);
154
+ static VALUE cState_depth_set(VALUE self, VALUE depth);
155
+ static VALUE cState_script_safe(VALUE self);
156
+ static VALUE cState_script_safe_set(VALUE self, VALUE depth);
157
+ static VALUE cState_strict(VALUE self);
158
+ static VALUE cState_strict_set(VALUE self, VALUE strict);
159
+ static FBuffer *cState_prepare_buffer(VALUE self);
160
+ #ifndef ZALLOC
161
+ #define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
162
+ static inline void *ruby_zalloc(size_t n)
163
+ {
164
+ void *p = ruby_xmalloc(n);
165
+ memset(p, 0, n);
166
+ return p;
167
+ }
168
+ #endif
169
+ #ifdef TypedData_Make_Struct
170
+ static const rb_data_type_t JSON_Generator_State_type;
171
+ #define NEW_TYPEDDATA_WRAPPER 1
172
+ #else
173
+ #define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
174
+ #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
175
+ #endif
176
+
177
+ #endif
@@ -0,0 +1 @@
1
+ parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
@@ -1,9 +1,32 @@
1
+ # frozen_string_literal: false
1
2
  require 'mkmf'
2
- require 'rbconfig'
3
3
 
4
- if CONFIG['CC'] =~ /gcc/
5
- #CONFIG['CC'] += ' -Wall -ggdb'
6
- CONFIG['CC'] += ' -Wall'
4
+ have_func("rb_enc_raise", "ruby.h")
5
+ have_func("rb_enc_interned_str", "ruby.h")
6
+
7
+ # checking if String#-@ (str_uminus) dedupes... '
8
+ begin
9
+ a = -(%w(t e s t).join)
10
+ b = -(%w(t e s t).join)
11
+ if a.equal?(b)
12
+ $CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
13
+ else
14
+ $CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
15
+ end
16
+ rescue NoMethodError
17
+ $CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
18
+ end
19
+
20
+ # checking if String#-@ (str_uminus) directly interns frozen strings... '
21
+ begin
22
+ s = rand.to_s.freeze
23
+ if (-s).equal?(s) && (-s.dup).equal?(s)
24
+ $CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
25
+ else
26
+ $CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
27
+ end
28
+ rescue NoMethodError
29
+ $CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
7
30
  end
8
31
 
9
- create_makefile 'parser'
32
+ create_makefile 'json/ext/parser'