oj 2.18.3 → 3.13.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1324 -0
  3. data/README.md +51 -204
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +49 -72
  6. data/ext/oj/cache.c +326 -0
  7. data/ext/oj/cache.h +21 -0
  8. data/ext/oj/cache8.c +61 -64
  9. data/ext/oj/cache8.h +12 -39
  10. data/ext/oj/circarray.c +37 -68
  11. data/ext/oj/circarray.h +16 -42
  12. data/ext/oj/code.c +221 -0
  13. data/ext/oj/code.h +40 -0
  14. data/ext/oj/compat.c +231 -107
  15. data/ext/oj/custom.c +1125 -0
  16. data/ext/oj/debug.c +132 -0
  17. data/ext/oj/dump.c +935 -2513
  18. data/ext/oj/dump.h +108 -0
  19. data/ext/oj/dump_compat.c +936 -0
  20. data/ext/oj/dump_leaf.c +164 -0
  21. data/ext/oj/dump_object.c +761 -0
  22. data/ext/oj/dump_strict.c +410 -0
  23. data/ext/oj/encode.h +7 -42
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +40 -54
  26. data/ext/oj/err.h +52 -46
  27. data/ext/oj/extconf.rb +21 -30
  28. data/ext/oj/fast.c +1097 -1080
  29. data/ext/oj/intern.c +301 -0
  30. data/ext/oj/intern.h +26 -0
  31. data/ext/oj/mimic_json.c +893 -0
  32. data/ext/oj/object.c +549 -620
  33. data/ext/oj/odd.c +155 -167
  34. data/ext/oj/odd.h +37 -63
  35. data/ext/oj/oj.c +1661 -2063
  36. data/ext/oj/oj.h +341 -270
  37. data/ext/oj/parse.c +974 -737
  38. data/ext/oj/parse.h +105 -97
  39. data/ext/oj/parser.c +1526 -0
  40. data/ext/oj/parser.h +90 -0
  41. data/ext/oj/rails.c +1504 -0
  42. data/ext/oj/rails.h +18 -0
  43. data/ext/oj/reader.c +141 -163
  44. data/ext/oj/reader.h +75 -113
  45. data/ext/oj/resolve.c +45 -93
  46. data/ext/oj/resolve.h +7 -34
  47. data/ext/oj/rxclass.c +143 -0
  48. data/ext/oj/rxclass.h +26 -0
  49. data/ext/oj/saj.c +447 -511
  50. data/ext/oj/saj2.c +348 -0
  51. data/ext/oj/scp.c +91 -138
  52. data/ext/oj/sparse.c +793 -644
  53. data/ext/oj/stream_writer.c +331 -0
  54. data/ext/oj/strict.c +145 -109
  55. data/ext/oj/string_writer.c +493 -0
  56. data/ext/oj/trace.c +72 -0
  57. data/ext/oj/trace.h +28 -0
  58. data/ext/oj/usual.c +1254 -0
  59. data/ext/oj/util.c +136 -0
  60. data/ext/oj/util.h +20 -0
  61. data/ext/oj/val_stack.c +62 -70
  62. data/ext/oj/val_stack.h +95 -129
  63. data/ext/oj/validate.c +51 -0
  64. data/ext/oj/wab.c +622 -0
  65. data/lib/oj/bag.rb +1 -0
  66. data/lib/oj/easy_hash.rb +17 -8
  67. data/lib/oj/error.rb +10 -11
  68. data/lib/oj/json.rb +176 -0
  69. data/lib/oj/mimic.rb +158 -19
  70. data/lib/oj/state.rb +132 -0
  71. data/lib/oj/version.rb +2 -2
  72. data/lib/oj.rb +1 -31
  73. data/pages/Advanced.md +22 -0
  74. data/pages/Compatibility.md +25 -0
  75. data/pages/Custom.md +23 -0
  76. data/pages/Encoding.md +65 -0
  77. data/pages/JsonGem.md +94 -0
  78. data/pages/Modes.md +161 -0
  79. data/pages/Options.md +327 -0
  80. data/pages/Parser.md +309 -0
  81. data/pages/Rails.md +167 -0
  82. data/pages/Security.md +20 -0
  83. data/pages/WAB.md +13 -0
  84. data/test/activerecord/result_test.rb +32 -0
  85. data/test/activesupport4/decoding_test.rb +108 -0
  86. data/test/activesupport4/encoding_test.rb +531 -0
  87. data/test/activesupport4/test_helper.rb +41 -0
  88. data/test/activesupport5/abstract_unit.rb +45 -0
  89. data/test/activesupport5/decoding_test.rb +133 -0
  90. data/test/activesupport5/encoding_test.rb +500 -0
  91. data/test/activesupport5/encoding_test_cases.rb +98 -0
  92. data/test/activesupport5/test_helper.rb +72 -0
  93. data/test/activesupport5/time_zone_test_helpers.rb +39 -0
  94. data/test/activesupport6/abstract_unit.rb +44 -0
  95. data/test/activesupport6/decoding_test.rb +133 -0
  96. data/test/activesupport6/encoding_test.rb +507 -0
  97. data/test/activesupport6/encoding_test_cases.rb +98 -0
  98. data/test/activesupport6/test_common.rb +17 -0
  99. data/test/activesupport6/test_helper.rb +163 -0
  100. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  101. data/test/activesupport7/abstract_unit.rb +49 -0
  102. data/test/activesupport7/decoding_test.rb +125 -0
  103. data/test/activesupport7/encoding_test.rb +486 -0
  104. data/test/activesupport7/encoding_test_cases.rb +104 -0
  105. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  106. data/test/bar.rb +9 -0
  107. data/test/baz.rb +16 -0
  108. data/test/bug.rb +11 -46
  109. data/test/foo.rb +69 -16
  110. data/test/helper.rb +10 -1
  111. data/test/isolated/shared.rb +12 -8
  112. data/test/isolated/test_mimic_rails_after.rb +3 -3
  113. data/test/isolated/test_mimic_rails_before.rb +3 -3
  114. data/test/json_gem/json_addition_test.rb +216 -0
  115. data/test/json_gem/json_common_interface_test.rb +153 -0
  116. data/test/json_gem/json_encoding_test.rb +107 -0
  117. data/test/json_gem/json_ext_parser_test.rb +20 -0
  118. data/test/json_gem/json_fixtures_test.rb +35 -0
  119. data/test/json_gem/json_generator_test.rb +397 -0
  120. data/test/json_gem/json_generic_object_test.rb +90 -0
  121. data/test/json_gem/json_parser_test.rb +470 -0
  122. data/test/json_gem/json_string_matching_test.rb +42 -0
  123. data/test/json_gem/test_helper.rb +26 -0
  124. data/test/mem.rb +33 -0
  125. data/test/perf.rb +1 -1
  126. data/test/perf_compat.rb +30 -28
  127. data/test/perf_dump.rb +50 -0
  128. data/test/perf_object.rb +1 -1
  129. data/test/perf_once.rb +58 -0
  130. data/test/perf_parser.rb +189 -0
  131. data/test/perf_scp.rb +11 -10
  132. data/test/perf_strict.rb +30 -19
  133. data/test/perf_wab.rb +131 -0
  134. data/test/prec.rb +23 -0
  135. data/test/sample.rb +0 -1
  136. data/test/sample_json.rb +1 -1
  137. data/test/test_compat.rb +219 -102
  138. data/test/test_custom.rb +533 -0
  139. data/test/test_fast.rb +107 -35
  140. data/test/test_file.rb +19 -25
  141. data/test/test_generate.rb +21 -0
  142. data/test/test_hash.rb +11 -1
  143. data/test/test_integer_range.rb +72 -0
  144. data/test/test_null.rb +376 -0
  145. data/test/test_object.rb +357 -70
  146. data/test/test_parser.rb +27 -0
  147. data/test/test_parser_saj.rb +245 -0
  148. data/test/test_parser_usual.rb +217 -0
  149. data/test/test_rails.rb +35 -0
  150. data/test/test_saj.rb +1 -1
  151. data/test/test_scp.rb +39 -2
  152. data/test/test_strict.rb +186 -7
  153. data/test/test_various.rb +160 -774
  154. data/test/test_wab.rb +307 -0
  155. data/test/test_writer.rb +90 -2
  156. data/test/tests.rb +24 -0
  157. data/test/tests_mimic.rb +14 -0
  158. data/test/tests_mimic_addition.rb +7 -0
  159. data/test/zoo.rb +13 -0
  160. metadata +194 -56
  161. data/ext/oj/hash.c +0 -163
  162. data/ext/oj/hash.h +0 -46
  163. data/ext/oj/hash_test.c +0 -512
  164. data/test/activesupport_datetime_test.rb +0 -23
  165. data/test/bug2.rb +0 -10
  166. data/test/bug3.rb +0 -46
  167. data/test/bug_fast.rb +0 -32
  168. data/test/bug_load.rb +0 -24
  169. data/test/crash.rb +0 -111
  170. data/test/curl/curl_oj.rb +0 -46
  171. data/test/curl/get_oj.rb +0 -24
  172. data/test/curl/just_curl.rb +0 -31
  173. data/test/curl/just_oj.rb +0 -51
  174. data/test/example.rb +0 -11
  175. data/test/io.rb +0 -48
  176. data/test/isolated/test_mimic_rails_datetime.rb +0 -27
  177. data/test/mod.rb +0 -16
  178. data/test/rails.rb +0 -50
  179. data/test/russian.rb +0 -18
  180. data/test/struct.rb +0 -29
  181. data/test/test_serializer.rb +0 -59
  182. data/test/write_timebars.rb +0 -31
data/ext/oj/oj.h CHANGED
@@ -1,37 +1,10 @@
1
- /* oj.h
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- *
5
- * Redistribution and use in source and binary forms, with or without
6
- * modification, are permitted provided that the following conditions are met:
7
- *
8
- * - Redistributions of source code must retain the above copyright notice, this
9
- * list of conditions and the following disclaimer.
10
- *
11
- * - Redistributions in binary form must reproduce the above copyright notice,
12
- * this list of conditions and the following disclaimer in the documentation
13
- * and/or other materials provided with the distribution.
14
- *
15
- * - Neither the name of Peter Ohler nor the names of its contributors may be
16
- * used to endorse or promote products derived from this software without
17
- * specific prior written permission.
18
- *
19
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */
30
-
31
- #ifndef __OJ_H__
32
- #define __OJ_H__
33
-
34
- #if defined(__cplusplus)
1
+ // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
3
+
4
+ #ifndef OJ_H
5
+ #define OJ_H
6
+
7
+ #if defined(cplusplus)
35
8
  extern "C" {
36
9
  #if 0
37
10
  } /* satisfy cc-mode */
@@ -40,15 +13,13 @@ extern "C" {
40
13
 
41
14
  #define RSTRING_NOT_MODIFIED
42
15
 
16
+ #include <stdbool.h>
17
+ #include <stdint.h>
18
+
43
19
  #include "ruby.h"
44
- #if HAS_ENCODING_SUPPORT
45
20
  #include "ruby/encoding.h"
46
- #endif
47
21
 
48
- #include "stdint.h"
49
- #include "stdbool.h"
50
-
51
- #if USE_PTHREAD_MUTEX
22
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
52
23
  #include <pthread.h>
53
24
  #endif
54
25
  #include "cache8.h"
@@ -56,271 +27,371 @@ extern "C" {
56
27
  #ifdef RUBINIUS_RUBY
57
28
  #undef T_RATIONAL
58
29
  #undef T_COMPLEX
59
- enum st_retval {ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK};
60
- #else
61
- #if HAS_TOP_LEVEL_ST_H
62
- // Only on travis, local is where it is for all others. Seems to vary depending on the travis machine picked up.
63
- #include "st.h"
30
+ enum st_retval { ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK };
64
31
  #else
65
32
  #include "ruby/st.h"
66
33
  #endif
67
- #endif
68
34
 
69
35
  #include "err.h"
36
+ #include "rxclass.h"
70
37
 
71
- #define INF_VAL "3.0e14159265358979323846"
72
- #define NINF_VAL "-3.0e14159265358979323846"
73
- #define NAN_VAL "3.3e14159265358979323846"
38
+ #define INF_VAL "3.0e14159265358979323846"
39
+ #define NINF_VAL "-3.0e14159265358979323846"
40
+ #define NAN_VAL "3.3e14159265358979323846"
74
41
 
75
- typedef enum {
76
- Yes = 'y',
77
- No = 'n',
78
- NotSet = 0
79
- } YesNo;
42
+ #if __STDC_VERSION__ >= 199901L
43
+ // To avoid using ruby_snprintf with C99.
44
+ #undef snprintf
45
+ #include <stdio.h>
46
+ #endif
47
+
48
+ // To avoid using ruby_nonempty_memcpy().
49
+ #undef memcpy
50
+ #include <string.h>
51
+
52
+ typedef enum { Yes = 'y', No = 'n', NotSet = 0 } YesNo;
80
53
 
81
54
  typedef enum {
82
- StrictMode = 's',
83
- ObjectMode = 'o',
84
- NullMode = 'n',
85
- CompatMode = 'c'
55
+ StrictMode = 's',
56
+ ObjectMode = 'o',
57
+ NullMode = 'n',
58
+ CompatMode = 'c',
59
+ RailsMode = 'r',
60
+ CustomMode = 'C',
61
+ WabMode = 'w',
86
62
  } Mode;
87
63
 
88
- typedef enum {
89
- UnixTime = 'u',
90
- UnixZTime = 'z',
91
- XmlTime = 'x',
92
- RubyTime = 'r'
93
- } TimeFormat;
64
+ typedef enum { UnixTime = 'u', UnixZTime = 'z', XmlTime = 'x', RubyTime = 'r' } TimeFormat;
94
65
 
95
66
  typedef enum {
96
- NLEsc = 'n',
97
- JSONEsc = 'j',
98
- XSSEsc = 'x',
99
- ASCIIEsc = 'a'
67
+ NLEsc = 'n',
68
+ JSONEsc = 'j',
69
+ XSSEsc = 'x',
70
+ ASCIIEsc = 'a',
71
+ JXEsc = 'g', // json gem
72
+ RailsXEsc = 'r', // rails xss mode
73
+ RailsEsc = 'R', // rails non escape
100
74
  } Encoding;
101
75
 
102
76
  typedef enum {
103
- BigDec = 'b',
104
- FloatDec = 'f',
105
- AutoDec = 'a'
77
+ BigDec = 'b',
78
+ FloatDec = 'f',
79
+ AutoDec = 'a',
80
+ FastDec = 'F',
81
+ RubyDec = 'r',
106
82
  } BigLoad;
107
83
 
108
84
  typedef enum {
109
- ArrayNew = 'A',
110
- ArrayType = 'a',
111
- ObjectNew = 'O',
112
- ObjectType = 'o',
85
+ ArrayNew = 'A',
86
+ ArrayType = 'a',
87
+ ObjectNew = 'O',
88
+ ObjectType = 'o',
113
89
  } DumpType;
114
90
 
115
91
  typedef enum {
116
- AutoNan = 'a',
117
- NullNan = 'n',
118
- HugeNan = 'h',
119
- WordNan = 'w',
120
- RaiseNan = 'r',
92
+ AutoNan = 'a',
93
+ NullNan = 'n',
94
+ HugeNan = 'h',
95
+ WordNan = 'w',
96
+ RaiseNan = 'r',
121
97
  } NanDump;
122
98
 
123
99
  typedef enum {
124
- STRING_IO = 'c',
125
- STREAM_IO = 's',
126
- FILE_IO = 'f',
100
+ STRING_IO = 'c',
101
+ STREAM_IO = 's',
102
+ FILE_IO = 'f',
127
103
  } StreamWriterType;
128
104
 
129
- typedef struct _DumpOpts {
130
- bool use;
131
- char indent_str[16];
132
- char before_sep[16];
133
- char after_sep[16];
134
- char hash_nl[16];
135
- char array_nl[16];
136
- uint8_t indent_size;
137
- uint8_t before_size;
138
- uint8_t after_size;
139
- uint8_t hash_size;
140
- uint8_t array_size;
141
- char nan_dump; // NanDump
142
- bool omit_nil;
143
- } *DumpOpts;
144
-
145
- typedef struct _Options {
146
- int indent; // indention for dump, default 2
147
- char circular; // YesNo
148
- char auto_define; // YesNo
149
- char sym_key; // YesNo
150
- char escape_mode; // Escape_Mode
151
- char mode; // Mode
152
- char class_cache; // YesNo
153
- char time_format; // TimeFormat
154
- char bigdec_as_num; // YesNo
155
- char bigdec_load; // BigLoad
156
- char to_json; // YesNo
157
- char as_json; // YesNo
158
- char nilnil; // YesNo
159
- char allow_gc; // allow GC during parse
160
- char quirks_mode; // allow single JSON values instead of documents
161
- char allow_invalid; // YesNo - allow invalid unicode
162
- const char *create_id; // 0 or string
163
- size_t create_id_len; // length of create_id
164
- int sec_prec; // second precision when dumping time
165
- char float_prec; // float precision, linked to float_fmt
166
- char float_fmt[7]; // float format for dumping, if empty use Ruby
167
- VALUE hash_class; // class to use in place of Hash on load
168
- struct _DumpOpts dump_opts;
169
- } *Options;
170
-
171
- typedef struct _Out {
172
- char *buf;
173
- char *end;
174
- char *cur;
175
- Cache8 circ_cache;
176
- slot_t circ_cnt;
177
- int indent;
178
- int depth; // used by dump_hash
179
- Options opts;
180
- uint32_t hash_cnt;
181
- int allocated;
182
- bool omit_nil;
183
- } *Out;
184
-
185
- typedef struct _StrWriter {
186
- struct _Out out;
187
- struct _Options opts;
188
- int depth;
189
- char *types; // DumpType
190
- char *types_end;
191
- int keyWritten;
192
- } *StrWriter;
193
-
194
- typedef struct _StreamWriter {
195
- struct _StrWriter sw;
196
- StreamWriterType type;
197
- VALUE stream;
198
- int fd;
199
- } *StreamWriter;
200
-
201
- enum {
202
- NO_VAL = 0x00,
203
- STR_VAL = 0x01,
204
- COL_VAL = 0x02,
205
- RUBY_VAL = 0x03
206
- };
207
-
208
- typedef struct _Leaf {
209
- struct _Leaf *next;
105
+ typedef enum {
106
+ CALLER_DUMP = 'd',
107
+ CALLER_TO_JSON = 't',
108
+ CALLER_GENERATE = 'g',
109
+ // Add the fast versions if necessary. Maybe unparse as well if needed.
110
+ } DumpCaller;
111
+
112
+ typedef struct _dumpOpts {
113
+ bool use;
114
+ char indent_str[16];
115
+ char before_sep[16];
116
+ char after_sep[16];
117
+ char hash_nl[16];
118
+ char array_nl[16];
119
+ uint8_t indent_size;
120
+ uint8_t before_size;
121
+ uint8_t after_size;
122
+ uint8_t hash_size;
123
+ uint8_t array_size;
124
+ char nan_dump; // NanDump
125
+ bool omit_nil;
126
+ int max_depth;
127
+ } * DumpOpts;
128
+
129
+ typedef struct _options {
130
+ int indent; // indention for dump, default 2
131
+ char circular; // YesNo
132
+ char auto_define; // YesNo
133
+ char sym_key; // YesNo
134
+ char escape_mode; // Escape_Mode
135
+ char mode; // Mode
136
+ char class_cache; // YesNo
137
+ char time_format; // TimeFormat
138
+ char bigdec_as_num; // YesNo
139
+ char bigdec_load; // BigLoad
140
+ char compat_bigdec; // boolean (0 or 1)
141
+ char to_hash; // YesNo
142
+ char to_json; // YesNo
143
+ char as_json; // YesNo
144
+ char raw_json; // YesNo
145
+ char nilnil; // YesNo
146
+ char empty_string; // YesNo
147
+ char allow_gc; // allow GC during parse
148
+ char quirks_mode; // allow single JSON values instead of documents
149
+ char allow_invalid; // YesNo - allow invalid unicode
150
+ char create_ok; // YesNo allow create_id
151
+ char allow_nan; // YEsyNo for parsing only
152
+ char trace; // YesNo
153
+ char safe; // YesNo
154
+ char sec_prec_set; // boolean (0 or 1)
155
+ char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
156
+ char cache_keys; // YesNo
157
+ char cache_str; // string short than or equal to this are cache
158
+ int64_t int_range_min; // dump numbers below as string
159
+ int64_t int_range_max; // dump numbers above as string
160
+ const char * create_id; // 0 or string
161
+ size_t create_id_len; // length of create_id
162
+ int sec_prec; // second precision when dumping time
163
+ char float_prec; // float precision, linked to float_fmt
164
+ char float_fmt[7]; // float format for dumping, if empty use Ruby
165
+ VALUE hash_class; // class to use in place of Hash on load
166
+ VALUE array_class; // class to use in place of Array on load
167
+ struct _dumpOpts dump_opts;
168
+ struct _rxClass str_rx;
169
+ VALUE * ignore; // Qnil terminated array of classes or NULL
170
+ } * Options;
171
+
172
+ struct _out;
173
+ typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
174
+
175
+ // rails optimize
176
+ typedef struct _rOpt {
177
+ VALUE clas;
178
+ bool on;
179
+ DumpFunc dump;
180
+ } * ROpt;
181
+
182
+ typedef struct _rOptTable {
183
+ int len;
184
+ int alen;
185
+ ROpt table;
186
+ } * ROptTable;
187
+
188
+ typedef struct _out {
189
+ char stack_buffer[4096];
190
+ char * buf;
191
+ char * end;
192
+ char * cur;
193
+ Cache8 circ_cache;
194
+ slot_t circ_cnt;
195
+ int indent;
196
+ int depth; // used by dump_hash
197
+ Options opts;
198
+ uint32_t hash_cnt;
199
+ bool allocated;
200
+ bool omit_nil;
201
+ int argc;
202
+ VALUE * argv;
203
+ DumpCaller caller; // used for the mimic json only
204
+ ROptTable ropts;
205
+ } * Out;
206
+
207
+ typedef struct _strWriter {
208
+ struct _out out;
209
+ struct _options opts;
210
+ int depth;
211
+ char * types; // DumpType
212
+ char * types_end;
213
+ int keyWritten;
214
+
215
+ } * StrWriter;
216
+
217
+ typedef struct _streamWriter {
218
+ struct _strWriter sw;
219
+ StreamWriterType type;
220
+ VALUE stream;
221
+ int fd;
222
+ int flush_limit; // indicator of when to flush
223
+ } * StreamWriter;
224
+
225
+ enum { NO_VAL = 0x00, STR_VAL = 0x01, COL_VAL = 0x02, RUBY_VAL = 0x03 };
226
+
227
+ typedef struct _leaf {
228
+ struct _leaf *next;
210
229
  union {
211
- const char *key; // hash key
212
- size_t index; // array index, 0 is not set
230
+ const char *key; // hash key
231
+ size_t index; // array index, 0 is not set
213
232
  };
214
233
  union {
215
- char *str; // pointer to location in json string or allocated
216
- struct _Leaf *elements; // array and hash elements
217
- VALUE value;
234
+ char * str; // pointer to location in json string or allocated
235
+ struct _leaf *elements; // array and hash elements
236
+ VALUE value;
218
237
  };
219
- uint8_t rtype;
220
- uint8_t parent_type;
221
- uint8_t value_type;
222
- } *Leaf;
223
-
224
- extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
225
- extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
226
-
227
- extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
228
- extern VALUE oj_strict_sparse(int argc, VALUE *argv, VALUE self);
229
- extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
230
- extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
231
-
232
- extern VALUE oj_strict_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
233
- extern VALUE oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
234
- extern VALUE oj_object_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
235
-
236
- extern void oj_parse_options(VALUE ropts, Options copts);
237
-
238
- extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
239
- extern void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
240
- extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
241
- extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
242
- extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
243
- extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
244
-
245
- extern void oj_str_writer_push_key(StrWriter sw, const char *key);
246
- extern void oj_str_writer_push_object(StrWriter sw, const char *key);
247
- extern void oj_str_writer_push_array(StrWriter sw, const char *key);
248
- extern void oj_str_writer_push_value(StrWriter sw, VALUE val, const char *key);
249
- extern void oj_str_writer_push_json(StrWriter sw, const char *json, const char *key);
250
- extern void oj_str_writer_pop(StrWriter sw);
251
- extern void oj_str_writer_pop_all(StrWriter sw);
252
-
253
- extern void oj_init_doc(void);
254
-
255
- extern VALUE Oj;
256
- extern struct _Options oj_default_options;
257
- #if HAS_ENCODING_SUPPORT
258
- extern rb_encoding *oj_utf8_encoding;
238
+ uint8_t rtype;
239
+ uint8_t parent_type;
240
+ uint8_t value_type;
241
+ } * Leaf;
242
+
243
+ extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
244
+ extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
245
+
246
+ extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
247
+ extern VALUE oj_strict_sparse(int argc, VALUE *argv, VALUE self);
248
+ extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
249
+ extern VALUE oj_compat_load(int argc, VALUE *argv, VALUE self);
250
+ extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
251
+ extern VALUE oj_custom_parse(int argc, VALUE *argv, VALUE self);
252
+ extern VALUE oj_wab_parse(int argc, VALUE *argv, VALUE self);
253
+
254
+ extern VALUE oj_strict_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
255
+ extern VALUE oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
256
+ extern VALUE oj_object_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
257
+ extern VALUE oj_custom_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
258
+
259
+ extern bool oj_hash_has_key(VALUE hash, VALUE key);
260
+ extern void oj_parse_options(VALUE ropts, Options copts);
261
+
262
+ extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
263
+ extern void
264
+ oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
265
+ extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
266
+ extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
267
+ extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
268
+ extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
269
+
270
+ extern void oj_str_writer_push_key(StrWriter sw, const char *key);
271
+ extern void oj_str_writer_push_object(StrWriter sw, const char *key);
272
+ extern void oj_str_writer_push_array(StrWriter sw, const char *key);
273
+ extern void oj_str_writer_push_value(StrWriter sw, VALUE val, const char *key);
274
+ extern void oj_str_writer_push_json(StrWriter sw, const char *json, const char *key);
275
+ extern void oj_str_writer_pop(StrWriter sw);
276
+ extern void oj_str_writer_pop_all(StrWriter sw);
277
+
278
+ extern void oj_init_doc(void);
279
+ extern void oj_string_writer_init(void);
280
+ extern void oj_stream_writer_init(void);
281
+ extern void oj_str_writer_init(StrWriter sw, int buf_size);
282
+ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
283
+ extern VALUE oj_mimic_generate(int argc, VALUE *argv, VALUE self);
284
+ extern VALUE oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self);
285
+ extern void oj_parse_mimic_dump_options(VALUE ropts, Options copts);
286
+
287
+ extern VALUE oj_mimic_parse(int argc, VALUE *argv, VALUE self);
288
+ extern VALUE oj_get_json_err_class(const char *err_classname);
289
+ extern void oj_parse_opt_match_string(RxClass rc, VALUE ropts);
290
+
291
+ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
292
+
293
+ extern VALUE Oj;
294
+ extern struct _options oj_default_options;
295
+ extern rb_encoding * oj_utf8_encoding;
296
+ extern int oj_utf8_encoding_index;
297
+
298
+ extern VALUE oj_bag_class;
299
+ extern VALUE oj_bigdecimal_class;
300
+ extern VALUE oj_cstack_class;
301
+ extern VALUE oj_date_class;
302
+ extern VALUE oj_datetime_class;
303
+ extern VALUE oj_doc_class;
304
+ extern VALUE oj_enumerable_class;
305
+ extern VALUE oj_json_generator_error_class;
306
+ extern VALUE oj_json_parser_error_class;
307
+ extern VALUE oj_stream_writer_class;
308
+ extern VALUE oj_string_writer_class;
309
+ extern VALUE oj_stringio_class;
310
+ extern VALUE oj_struct_class;
311
+
312
+ extern VALUE oj_allow_nan_sym;
313
+ extern VALUE oj_array_class_sym;
314
+ extern VALUE oj_array_nl_sym;
315
+ extern VALUE oj_ascii_only_sym;
316
+ extern VALUE oj_create_additions_sym;
317
+ extern VALUE oj_decimal_class_sym;
318
+ extern VALUE oj_hash_class_sym;
319
+ extern VALUE oj_indent_sym;
320
+ extern VALUE oj_max_nesting_sym;
321
+ extern VALUE oj_object_class_sym;
322
+ extern VALUE oj_object_nl_sym;
323
+ extern VALUE oj_quirks_mode_sym;
324
+ extern VALUE oj_space_before_sym;
325
+ extern VALUE oj_space_sym;
326
+ extern VALUE oj_symbolize_names_sym;
327
+ extern VALUE oj_trace_sym;
328
+
329
+ extern VALUE oj_slash_string;
330
+
331
+ extern ID oj_add_value_id;
332
+ extern ID oj_array_append_id;
333
+ extern ID oj_array_end_id;
334
+ extern ID oj_array_start_id;
335
+ extern ID oj_as_json_id;
336
+ extern ID oj_begin_id;
337
+ extern ID oj_bigdecimal_id;
338
+ extern ID oj_end_id;
339
+ extern ID oj_error_id;
340
+ extern ID oj_exclude_end_id;
341
+ extern ID oj_file_id;
342
+ extern ID oj_fileno_id;
343
+ extern ID oj_ftype_id;
344
+ extern ID oj_hash_end_id;
345
+ extern ID oj_hash_key_id;
346
+ extern ID oj_hash_set_id;
347
+ extern ID oj_hash_start_id;
348
+ extern ID oj_iconv_id;
349
+ extern ID oj_instance_variables_id;
350
+ extern ID oj_json_create_id;
351
+ extern ID oj_length_id;
352
+ extern ID oj_new_id;
353
+ extern ID oj_parse_id;
354
+ extern ID oj_pos_id;
355
+ extern ID oj_read_id;
356
+ extern ID oj_readpartial_id;
357
+ extern ID oj_replace_id;
358
+ extern ID oj_stat_id;
359
+ extern ID oj_string_id;
360
+ extern ID oj_raw_json_id;
361
+ extern ID oj_to_h_id;
362
+ extern ID oj_to_hash_id;
363
+ extern ID oj_to_json_id;
364
+ extern ID oj_to_s_id;
365
+ extern ID oj_to_sym_id;
366
+ extern ID oj_to_time_id;
367
+ extern ID oj_tv_nsec_id;
368
+ extern ID oj_tv_sec_id;
369
+ extern ID oj_tv_usec_id;
370
+ extern ID oj_utc_id;
371
+ extern ID oj_utc_offset_id;
372
+ extern ID oj_utcq_id;
373
+ extern ID oj_write_id;
374
+
375
+ extern bool oj_use_hash_alt;
376
+ extern bool oj_use_array_alt;
377
+ extern bool string_writer_optimized;
378
+
379
+ #define APPEND_CHARS(buffer, chars, size) \
380
+ { \
381
+ memcpy(buffer, chars, size); \
382
+ buffer += size; \
383
+ }
384
+
385
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
386
+ extern pthread_mutex_t oj_cache_mutex;
259
387
  #else
260
- extern VALUE oj_utf8_encoding;
261
- #endif
262
-
263
- extern VALUE oj_bag_class;
264
- extern VALUE oj_bigdecimal_class;
265
- extern VALUE oj_cstack_class;
266
- extern VALUE oj_date_class;
267
- extern VALUE oj_datetime_class;
268
- extern VALUE oj_doc_class;
269
- extern VALUE oj_stream_writer_class;
270
- extern VALUE oj_string_writer_class;
271
- extern VALUE oj_stringio_class;
272
- extern VALUE oj_struct_class;
273
-
274
- extern VALUE oj_slash_string;
275
-
276
- extern ID oj_add_value_id;
277
- extern ID oj_array_append_id;
278
- extern ID oj_array_end_id;
279
- extern ID oj_array_start_id;
280
- extern ID oj_as_json_id;
281
- extern ID oj_error_id;
282
- extern ID oj_file_id;
283
- extern ID oj_fileno_id;
284
- extern ID oj_ftype_id;
285
- extern ID oj_hash_end_id;
286
- extern ID oj_hash_key_id;
287
- extern ID oj_hash_set_id;
288
- extern ID oj_hash_start_id;
289
- extern ID oj_iconv_id;
290
- extern ID oj_instance_variables_id;
291
- extern ID oj_json_create_id;
292
- extern ID oj_length_id;
293
- extern ID oj_new_id;
294
- extern ID oj_parse_id;
295
- extern ID oj_pos_id;
296
- extern ID oj_read_id;
297
- extern ID oj_readpartial_id;
298
- extern ID oj_replace_id;
299
- extern ID oj_stat_id;
300
- extern ID oj_string_id;
301
- extern ID oj_to_hash_id;
302
- extern ID oj_to_json_id;
303
- extern ID oj_to_s_id;
304
- extern ID oj_to_sym_id;
305
- extern ID oj_to_time_id;
306
- extern ID oj_tv_nsec_id;
307
- extern ID oj_tv_sec_id;
308
- extern ID oj_tv_usec_id;
309
- extern ID oj_utc_id;
310
- extern ID oj_utc_offset_id;
311
- extern ID oj_utcq_id;
312
- extern ID oj_write_id;
313
-
314
- #if USE_PTHREAD_MUTEX
315
- extern pthread_mutex_t oj_cache_mutex;
316
- #elif USE_RB_MUTEX
317
- extern VALUE oj_cache_mutex;
388
+ extern VALUE oj_cache_mutex;
318
389
  #endif
319
390
 
320
- #if defined(__cplusplus)
391
+ #if defined(cplusplus)
321
392
  #if 0
322
393
  { /* satisfy cc-mode */
323
394
  #endif
324
- } /* extern "C" { */
395
+ } /* extern "C" { */
325
396
  #endif
326
- #endif /* __OJ_H__ */
397
+ #endif /* OJ_H */