oj 3.7.4 → 3.13.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1352 -0
  3. data/README.md +29 -8
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +53 -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 -43
  11. data/ext/oj/circarray.h +16 -17
  12. data/ext/oj/code.c +165 -179
  13. data/ext/oj/code.h +27 -29
  14. data/ext/oj/compat.c +174 -194
  15. data/ext/oj/custom.c +809 -866
  16. data/ext/oj/debug.c +132 -0
  17. data/ext/oj/dump.c +848 -863
  18. data/ext/oj/dump.h +81 -67
  19. data/ext/oj/dump_compat.c +85 -123
  20. data/ext/oj/dump_leaf.c +100 -188
  21. data/ext/oj/dump_object.c +527 -656
  22. data/ext/oj/dump_strict.c +315 -338
  23. data/ext/oj/encode.h +7 -34
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +40 -29
  26. data/ext/oj/err.h +48 -48
  27. data/ext/oj/extconf.rb +17 -4
  28. data/ext/oj/fast.c +1070 -1087
  29. data/ext/oj/intern.c +301 -0
  30. data/ext/oj/intern.h +26 -0
  31. data/ext/oj/mimic_json.c +469 -436
  32. data/ext/oj/object.c +525 -593
  33. data/ext/oj/odd.c +154 -138
  34. data/ext/oj/odd.h +37 -38
  35. data/ext/oj/oj.c +1325 -986
  36. data/ext/oj/oj.h +333 -316
  37. data/ext/oj/parse.c +1002 -846
  38. data/ext/oj/parse.h +92 -87
  39. data/ext/oj/parser.c +1557 -0
  40. data/ext/oj/parser.h +91 -0
  41. data/ext/oj/rails.c +888 -878
  42. data/ext/oj/rails.h +11 -14
  43. data/ext/oj/reader.c +141 -147
  44. data/ext/oj/reader.h +73 -89
  45. data/ext/oj/resolve.c +41 -62
  46. data/ext/oj/resolve.h +7 -9
  47. data/ext/oj/rxclass.c +71 -75
  48. data/ext/oj/rxclass.h +18 -19
  49. data/ext/oj/saj.c +443 -486
  50. data/ext/oj/saj2.c +602 -0
  51. data/ext/oj/scp.c +88 -113
  52. data/ext/oj/sparse.c +787 -709
  53. data/ext/oj/stream_writer.c +133 -159
  54. data/ext/oj/strict.c +127 -118
  55. data/ext/oj/string_writer.c +230 -249
  56. data/ext/oj/trace.c +34 -41
  57. data/ext/oj/trace.h +19 -19
  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 +59 -67
  62. data/ext/oj/val_stack.h +91 -129
  63. data/ext/oj/validate.c +46 -0
  64. data/ext/oj/wab.c +342 -353
  65. data/lib/oj/bag.rb +1 -0
  66. data/lib/oj/easy_hash.rb +5 -4
  67. data/lib/oj/error.rb +1 -1
  68. data/lib/oj/json.rb +1 -1
  69. data/lib/oj/mimic.rb +48 -14
  70. data/lib/oj/saj.rb +20 -6
  71. data/lib/oj/state.rb +8 -7
  72. data/lib/oj/version.rb +2 -2
  73. data/lib/oj.rb +0 -8
  74. data/pages/Compatibility.md +1 -1
  75. data/pages/JsonGem.md +15 -0
  76. data/pages/Modes.md +53 -46
  77. data/pages/Options.md +72 -11
  78. data/pages/Parser.md +309 -0
  79. data/pages/Rails.md +73 -22
  80. data/pages/Security.md +1 -1
  81. data/test/activerecord/result_test.rb +7 -2
  82. data/test/activesupport5/abstract_unit.rb +45 -0
  83. data/test/activesupport5/decoding_test.rb +68 -60
  84. data/test/activesupport5/encoding_test.rb +111 -96
  85. data/test/activesupport5/encoding_test_cases.rb +33 -25
  86. data/test/activesupport5/test_helper.rb +43 -21
  87. data/test/activesupport5/time_zone_test_helpers.rb +18 -3
  88. data/test/activesupport6/abstract_unit.rb +44 -0
  89. data/test/activesupport6/decoding_test.rb +133 -0
  90. data/test/activesupport6/encoding_test.rb +507 -0
  91. data/test/activesupport6/encoding_test_cases.rb +98 -0
  92. data/test/activesupport6/test_common.rb +17 -0
  93. data/test/activesupport6/test_helper.rb +163 -0
  94. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  95. data/test/activesupport7/abstract_unit.rb +49 -0
  96. data/test/activesupport7/decoding_test.rb +125 -0
  97. data/test/activesupport7/encoding_test.rb +486 -0
  98. data/test/activesupport7/encoding_test_cases.rb +104 -0
  99. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  100. data/test/bar.rb +6 -12
  101. data/test/baz.rb +16 -0
  102. data/test/bug.rb +16 -0
  103. data/test/foo.rb +69 -75
  104. data/test/helper.rb +16 -0
  105. data/test/json_gem/json_common_interface_test.rb +8 -3
  106. data/test/json_gem/json_generator_test.rb +18 -4
  107. data/test/json_gem/json_parser_test.rb +9 -0
  108. data/test/json_gem/test_helper.rb +12 -0
  109. data/test/mem.rb +33 -0
  110. data/test/perf.rb +1 -1
  111. data/test/perf_dump.rb +50 -0
  112. data/test/perf_once.rb +58 -0
  113. data/test/perf_parser.rb +189 -0
  114. data/test/perf_scp.rb +11 -10
  115. data/test/perf_strict.rb +17 -23
  116. data/test/prec.rb +23 -0
  117. data/test/sample_json.rb +1 -1
  118. data/test/test_compat.rb +46 -10
  119. data/test/test_custom.rb +147 -8
  120. data/test/test_fast.rb +62 -2
  121. data/test/test_file.rb +25 -2
  122. data/test/test_gc.rb +13 -0
  123. data/test/test_generate.rb +21 -0
  124. data/test/test_hash.rb +11 -1
  125. data/test/test_integer_range.rb +7 -2
  126. data/test/test_object.rb +85 -9
  127. data/test/test_parser.rb +27 -0
  128. data/test/test_parser_saj.rb +335 -0
  129. data/test/test_parser_usual.rb +217 -0
  130. data/test/test_rails.rb +35 -0
  131. data/test/test_saj.rb +1 -1
  132. data/test/test_scp.rb +5 -5
  133. data/test/test_strict.rb +26 -1
  134. data/test/test_various.rb +87 -65
  135. data/test/test_wab.rb +2 -0
  136. data/test/test_writer.rb +19 -2
  137. data/test/tests.rb +1 -1
  138. data/test/zoo.rb +13 -0
  139. metadata +60 -110
  140. data/ext/oj/hash.c +0 -163
  141. data/ext/oj/hash.h +0 -46
  142. data/ext/oj/hash_test.c +0 -512
data/ext/oj/oj.h CHANGED
@@ -1,12 +1,10 @@
1
- /* oj.h
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- */
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.
5
3
 
6
- #ifndef __OJ_H__
7
- #define __OJ_H__
4
+ #ifndef OJ_H
5
+ #define OJ_H
8
6
 
9
- #if defined(__cplusplus)
7
+ #if defined(cplusplus)
10
8
  extern "C" {
11
9
  #if 0
12
10
  } /* satisfy cc-mode */
@@ -15,13 +13,13 @@ extern "C" {
15
13
 
16
14
  #define RSTRING_NOT_MODIFIED
17
15
 
16
+ #include <stdbool.h>
17
+ #include <stdint.h>
18
+
18
19
  #include "ruby.h"
19
20
  #include "ruby/encoding.h"
20
21
 
21
- #include <stdint.h>
22
- #include <stdbool.h>
23
-
24
- #if HAVE_LIBPTHREAD
22
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
25
23
  #include <pthread.h>
26
24
  #endif
27
25
  #include "cache8.h"
@@ -29,352 +27,371 @@ extern "C" {
29
27
  #ifdef RUBINIUS_RUBY
30
28
  #undef T_RATIONAL
31
29
  #undef T_COMPLEX
32
- enum st_retval {ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK};
30
+ enum st_retval { ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK };
33
31
  #else
34
32
  #include "ruby/st.h"
35
33
  #endif
36
34
 
37
- #include "rxclass.h"
38
35
  #include "err.h"
36
+ #include "rxclass.h"
39
37
 
40
- #define INF_VAL "3.0e14159265358979323846"
41
- #define NINF_VAL "-3.0e14159265358979323846"
42
- #define NAN_VAL "3.3e14159265358979323846"
38
+ #define INF_VAL "3.0e14159265358979323846"
39
+ #define NINF_VAL "-3.0e14159265358979323846"
40
+ #define NAN_VAL "3.3e14159265358979323846"
43
41
 
44
- typedef enum {
45
- Yes = 'y',
46
- No = 'n',
47
- NotSet = 0
48
- } 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;
49
53
 
50
54
  typedef enum {
51
- StrictMode = 's',
52
- ObjectMode = 'o',
53
- NullMode = 'n',
54
- CompatMode = 'c',
55
- RailsMode = 'r',
56
- CustomMode = 'C',
57
- WabMode = 'w',
55
+ StrictMode = 's',
56
+ ObjectMode = 'o',
57
+ NullMode = 'n',
58
+ CompatMode = 'c',
59
+ RailsMode = 'r',
60
+ CustomMode = 'C',
61
+ WabMode = 'w',
58
62
  } Mode;
59
63
 
60
- typedef enum {
61
- UnixTime = 'u',
62
- UnixZTime = 'z',
63
- XmlTime = 'x',
64
- RubyTime = 'r'
65
- } TimeFormat;
64
+ typedef enum { UnixTime = 'u', UnixZTime = 'z', XmlTime = 'x', RubyTime = 'r' } TimeFormat;
66
65
 
67
66
  typedef enum {
68
- NLEsc = 'n',
69
- JSONEsc = 'j',
70
- XSSEsc = 'x',
71
- ASCIIEsc = 'a',
72
- JXEsc = 'r', // json
73
- RailsEsc = 'R', // rails non escape
67
+ NLEsc = 'n',
68
+ JSONEsc = 'j',
69
+ SlashEsc = 's',
70
+ XSSEsc = 'x',
71
+ ASCIIEsc = 'a',
72
+ JXEsc = 'g', // json gem
73
+ RailsXEsc = 'r', // rails xss mode
74
+ RailsEsc = 'R', // rails non escape
74
75
  } Encoding;
75
76
 
76
77
  typedef enum {
77
- BigDec = 'b',
78
- FloatDec = 'f',
79
- AutoDec = 'a'
78
+ BigDec = 'b',
79
+ FloatDec = 'f',
80
+ AutoDec = 'a',
81
+ FastDec = 'F',
82
+ RubyDec = 'r',
80
83
  } BigLoad;
81
84
 
82
85
  typedef enum {
83
- ArrayNew = 'A',
84
- ArrayType = 'a',
85
- ObjectNew = 'O',
86
- ObjectType = 'o',
86
+ ArrayNew = 'A',
87
+ ArrayType = 'a',
88
+ ObjectNew = 'O',
89
+ ObjectType = 'o',
87
90
  } DumpType;
88
91
 
89
92
  typedef enum {
90
- AutoNan = 'a',
91
- NullNan = 'n',
92
- HugeNan = 'h',
93
- WordNan = 'w',
94
- RaiseNan = 'r',
93
+ AutoNan = 'a',
94
+ NullNan = 'n',
95
+ HugeNan = 'h',
96
+ WordNan = 'w',
97
+ RaiseNan = 'r',
95
98
  } NanDump;
96
99
 
97
100
  typedef enum {
98
- STRING_IO = 'c',
99
- STREAM_IO = 's',
100
- FILE_IO = 'f',
101
+ STRING_IO = 'c',
102
+ STREAM_IO = 's',
103
+ FILE_IO = 'f',
101
104
  } StreamWriterType;
102
105
 
103
106
  typedef enum {
104
- CALLER_DUMP = 'd',
105
- CALLER_TO_JSON = 't',
106
- CALLER_GENERATE = 'g',
107
+ CALLER_DUMP = 'd',
108
+ CALLER_TO_JSON = 't',
109
+ CALLER_GENERATE = 'g',
107
110
  // Add the fast versions if necessary. Maybe unparse as well if needed.
108
111
  } DumpCaller;
109
112
 
110
- typedef struct _DumpOpts {
111
- bool use;
112
- char indent_str[16];
113
- char before_sep[16];
114
- char after_sep[16];
115
- char hash_nl[16];
116
- char array_nl[16];
117
- uint8_t indent_size;
118
- uint8_t before_size;
119
- uint8_t after_size;
120
- uint8_t hash_size;
121
- uint8_t array_size;
122
- char nan_dump; // NanDump
123
- bool omit_nil;
124
- int max_depth;
125
- } *DumpOpts;
126
-
127
- typedef struct _Options {
128
- int indent; // indention for dump, default 2
129
- char circular; // YesNo
130
- char auto_define; // YesNo
131
- char sym_key; // YesNo
132
- char escape_mode; // Escape_Mode
133
- char mode; // Mode
134
- char class_cache; // YesNo
135
- char time_format; // TimeFormat
136
- char bigdec_as_num; // YesNo
137
- char bigdec_load; // BigLoad
138
- char to_hash; // YesNo
139
- char to_json; // YesNo
140
- char as_json; // YesNo
141
- char nilnil; // YesNo
142
- char empty_string; // YesNo
143
- char allow_gc; // allow GC during parse
144
- char quirks_mode; // allow single JSON values instead of documents
145
- char allow_invalid; // YesNo - allow invalid unicode
146
- char create_ok; // YesNo allow create_id
147
- char allow_nan; // YEsyNo for parsing only
148
- char trace; // YesNo
149
- int64_t integer_range_min; // dump numbers outside range as string
150
- int64_t integer_range_max;
151
- const char *create_id; // 0 or string
152
- size_t create_id_len; // length of create_id
153
- int sec_prec; // second precision when dumping time
154
- char float_prec; // float precision, linked to float_fmt
155
- char float_fmt[7]; // float format for dumping, if empty use Ruby
156
- VALUE hash_class; // class to use in place of Hash on load
157
- VALUE array_class; // class to use in place of Array on load
158
- struct _DumpOpts dump_opts;
159
- struct _RxClass str_rx;
160
- VALUE *ignore; // Qnil terminated array of classes or NULL
161
- } *Options;
162
-
163
- struct _Out;
164
- typedef void (*DumpFunc)(VALUE obj, int depth, struct _Out *out, bool as_ok);
113
+ typedef struct _dumpOpts {
114
+ bool use;
115
+ char indent_str[16];
116
+ char before_sep[16];
117
+ char after_sep[16];
118
+ char hash_nl[16];
119
+ char array_nl[16];
120
+ uint8_t indent_size;
121
+ uint8_t before_size;
122
+ uint8_t after_size;
123
+ uint8_t hash_size;
124
+ uint8_t array_size;
125
+ char nan_dump; // NanDump
126
+ bool omit_nil;
127
+ int max_depth;
128
+ } * DumpOpts;
129
+
130
+ typedef struct _options {
131
+ int indent; // indention for dump, default 2
132
+ char circular; // YesNo
133
+ char auto_define; // YesNo
134
+ char sym_key; // YesNo
135
+ char escape_mode; // Escape_Mode
136
+ char mode; // Mode
137
+ char class_cache; // YesNo
138
+ char time_format; // TimeFormat
139
+ char bigdec_as_num; // YesNo
140
+ char bigdec_load; // BigLoad
141
+ char compat_bigdec; // boolean (0 or 1)
142
+ char to_hash; // YesNo
143
+ char to_json; // YesNo
144
+ char as_json; // YesNo
145
+ char raw_json; // YesNo
146
+ char nilnil; // YesNo
147
+ char empty_string; // YesNo
148
+ char allow_gc; // allow GC during parse
149
+ char quirks_mode; // allow single JSON values instead of documents
150
+ char allow_invalid; // YesNo - allow invalid unicode
151
+ char create_ok; // YesNo allow create_id
152
+ char allow_nan; // YEsyNo for parsing only
153
+ char trace; // YesNo
154
+ char safe; // YesNo
155
+ char sec_prec_set; // boolean (0 or 1)
156
+ char ignore_under; // YesNo - ignore attrs starting with _ if true in object and custom modes
157
+ char cache_keys; // YesNo
158
+ char cache_str; // string short than or equal to this are cache
159
+ int64_t int_range_min; // dump numbers below as string
160
+ int64_t int_range_max; // dump numbers above as string
161
+ const char * create_id; // 0 or string
162
+ size_t create_id_len; // length of create_id
163
+ int sec_prec; // second precision when dumping time
164
+ char float_prec; // float precision, linked to float_fmt
165
+ char float_fmt[7]; // float format for dumping, if empty use Ruby
166
+ VALUE hash_class; // class to use in place of Hash on load
167
+ VALUE array_class; // class to use in place of Array on load
168
+ struct _dumpOpts dump_opts;
169
+ struct _rxClass str_rx;
170
+ VALUE * ignore; // Qnil terminated array of classes or NULL
171
+ } * Options;
172
+
173
+ struct _out;
174
+ typedef void (*DumpFunc)(VALUE obj, int depth, struct _out *out, bool as_ok);
165
175
 
166
176
  // rails optimize
167
- typedef struct _ROpt {
168
- VALUE clas;
169
- bool on;
170
- DumpFunc dump;
171
- } *ROpt;
172
-
173
- typedef struct _ROptTable {
174
- int len;
175
- int alen;
176
- ROpt table;
177
- } *ROptTable;
178
-
179
- typedef struct _Out {
180
- char *buf;
181
- char *end;
182
- char *cur;
183
- Cache8 circ_cache;
184
- slot_t circ_cnt;
185
- int indent;
186
- int depth; // used by dump_hash
187
- Options opts;
188
- uint32_t hash_cnt;
189
- bool allocated;
190
- bool omit_nil;
191
- int argc;
192
- VALUE *argv;
193
- DumpCaller caller; // used for the mimic json only
194
- ROptTable ropts;
195
- } *Out;
196
-
197
- typedef struct _StrWriter {
198
- struct _Out out;
199
- struct _Options opts;
200
- int depth;
201
- char *types; // DumpType
202
- char *types_end;
203
- int keyWritten;
204
-
205
- } *StrWriter;
206
-
207
- typedef struct _StreamWriter {
208
- struct _StrWriter sw;
209
- StreamWriterType type;
210
- VALUE stream;
211
- int fd;
212
- int flush_limit; // indicator of when to flush
213
- } *StreamWriter;
214
-
215
- enum {
216
- NO_VAL = 0x00,
217
- STR_VAL = 0x01,
218
- COL_VAL = 0x02,
219
- RUBY_VAL = 0x03
220
- };
221
-
222
- typedef struct _Leaf {
223
- struct _Leaf *next;
177
+ typedef struct _rOpt {
178
+ VALUE clas;
179
+ bool on;
180
+ DumpFunc dump;
181
+ } * ROpt;
182
+
183
+ typedef struct _rOptTable {
184
+ int len;
185
+ int alen;
186
+ ROpt table;
187
+ } * ROptTable;
188
+
189
+ typedef struct _out {
190
+ char stack_buffer[4096];
191
+ char * buf;
192
+ char * end;
193
+ char * cur;
194
+ Cache8 circ_cache;
195
+ slot_t circ_cnt;
196
+ int indent;
197
+ int depth; // used by dump_hash
198
+ Options opts;
199
+ uint32_t hash_cnt;
200
+ bool allocated;
201
+ bool omit_nil;
202
+ int argc;
203
+ VALUE * argv;
204
+ DumpCaller caller; // used for the mimic json only
205
+ ROptTable ropts;
206
+ } * Out;
207
+
208
+ typedef struct _strWriter {
209
+ struct _out out;
210
+ struct _options opts;
211
+ int depth;
212
+ char * types; // DumpType
213
+ char * types_end;
214
+ int keyWritten;
215
+
216
+ } * StrWriter;
217
+
218
+ typedef struct _streamWriter {
219
+ struct _strWriter sw;
220
+ StreamWriterType type;
221
+ VALUE stream;
222
+ int fd;
223
+ int flush_limit; // indicator of when to flush
224
+ } * StreamWriter;
225
+
226
+ enum { NO_VAL = 0x00, STR_VAL = 0x01, COL_VAL = 0x02, RUBY_VAL = 0x03 };
227
+
228
+ typedef struct _leaf {
229
+ struct _leaf *next;
224
230
  union {
225
- const char *key; // hash key
226
- size_t index; // array index, 0 is not set
231
+ const char *key; // hash key
232
+ size_t index; // array index, 0 is not set
227
233
  };
228
234
  union {
229
- char *str; // pointer to location in json string or allocated
230
- struct _Leaf *elements; // array and hash elements
231
- VALUE value;
235
+ char * str; // pointer to location in json string or allocated
236
+ struct _leaf *elements; // array and hash elements
237
+ VALUE value;
232
238
  };
233
- uint8_t rtype;
234
- uint8_t parent_type;
235
- uint8_t value_type;
236
- } *Leaf;
237
-
238
- extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
239
- extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
240
-
241
- extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
242
- extern VALUE oj_strict_sparse(int argc, VALUE *argv, VALUE self);
243
- extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
244
- extern VALUE oj_compat_load(int argc, VALUE *argv, VALUE self);
245
- extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
246
- extern VALUE oj_custom_parse(int argc, VALUE *argv, VALUE self);
247
- extern VALUE oj_wab_parse(int argc, VALUE *argv, VALUE self);
248
-
249
- extern VALUE oj_strict_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
250
- extern VALUE oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
251
- extern VALUE oj_object_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
252
- extern VALUE oj_custom_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
253
-
254
- extern void oj_parse_options(VALUE ropts, Options copts);
255
-
256
- extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
257
- extern void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
258
- extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
259
- extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
260
- extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
261
- extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
262
-
263
- extern void oj_str_writer_push_key(StrWriter sw, const char *key);
264
- extern void oj_str_writer_push_object(StrWriter sw, const char *key);
265
- extern void oj_str_writer_push_array(StrWriter sw, const char *key);
266
- extern void oj_str_writer_push_value(StrWriter sw, VALUE val, const char *key);
267
- extern void oj_str_writer_push_json(StrWriter sw, const char *json, const char *key);
268
- extern void oj_str_writer_pop(StrWriter sw);
269
- extern void oj_str_writer_pop_all(StrWriter sw);
270
-
271
- extern void oj_init_doc(void);
272
- extern void oj_string_writer_init();
273
- extern void oj_stream_writer_init();
274
- extern void oj_str_writer_init(StrWriter sw, int buf_size);
275
- extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
276
- extern VALUE oj_mimic_generate(int argc, VALUE *argv, VALUE self);
277
- extern VALUE oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self);
278
- extern void oj_parse_mimic_dump_options(VALUE ropts, Options copts);
279
-
280
- extern VALUE oj_mimic_parse(int argc, VALUE *argv, VALUE self);
281
- extern VALUE oj_get_json_err_class(const char *err_classname);
282
- extern void oj_parse_opt_match_string(RxClass rc, VALUE ropts);
283
-
284
- extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
285
-
286
- extern VALUE Oj;
287
- extern struct _Options oj_default_options;
288
- extern rb_encoding *oj_utf8_encoding;
289
-
290
- extern VALUE oj_bag_class;
291
- extern VALUE oj_bigdecimal_class;
292
- extern VALUE oj_cstack_class;
293
- extern VALUE oj_date_class;
294
- extern VALUE oj_datetime_class;
295
- extern VALUE oj_doc_class;
296
- extern VALUE oj_enumerable_class;
297
- extern VALUE oj_json_generator_error_class;
298
- extern VALUE oj_json_parser_error_class;
299
- extern VALUE oj_stream_writer_class;
300
- extern VALUE oj_string_writer_class;
301
- extern VALUE oj_stringio_class;
302
- extern VALUE oj_struct_class;
303
-
304
- extern VALUE oj_allow_nan_sym;
305
- extern VALUE oj_array_class_sym;
306
- extern VALUE oj_array_nl_sym;
307
- extern VALUE oj_ascii_only_sym;
308
- extern VALUE oj_create_additions_sym;
309
- extern VALUE oj_hash_class_sym;
310
- extern VALUE oj_indent_sym;
311
- extern VALUE oj_max_nesting_sym;
312
- extern VALUE oj_object_class_sym;
313
- extern VALUE oj_object_nl_sym;
314
- extern VALUE oj_quirks_mode_sym;
315
- extern VALUE oj_space_before_sym;
316
- extern VALUE oj_space_sym;
317
- extern VALUE oj_trace_sym;
318
-
319
- extern VALUE oj_slash_string;
320
-
321
- extern ID oj_add_value_id;
322
- extern ID oj_array_append_id;
323
- extern ID oj_array_end_id;
324
- extern ID oj_array_start_id;
325
- extern ID oj_as_json_id;
326
- extern ID oj_begin_id;
327
- extern ID oj_bigdecimal_id;
328
- extern ID oj_end_id;
329
- extern ID oj_error_id;
330
- extern ID oj_exclude_end_id;
331
- extern ID oj_file_id;
332
- extern ID oj_fileno_id;
333
- extern ID oj_ftype_id;
334
- extern ID oj_has_key_id;
335
- extern ID oj_hash_end_id;
336
- extern ID oj_hash_key_id;
337
- extern ID oj_hash_set_id;
338
- extern ID oj_hash_start_id;
339
- extern ID oj_iconv_id;
340
- extern ID oj_instance_variables_id;
341
- extern ID oj_json_create_id;
342
- extern ID oj_length_id;
343
- extern ID oj_new_id;
344
- extern ID oj_parse_id;
345
- extern ID oj_pos_id;
346
- extern ID oj_read_id;
347
- extern ID oj_readpartial_id;
348
- extern ID oj_replace_id;
349
- extern ID oj_stat_id;
350
- extern ID oj_string_id;
351
- extern ID oj_to_h_id;
352
- extern ID oj_to_hash_id;
353
- extern ID oj_to_json_id;
354
- extern ID oj_to_s_id;
355
- extern ID oj_to_sym_id;
356
- extern ID oj_to_time_id;
357
- extern ID oj_tv_nsec_id;
358
- extern ID oj_tv_sec_id;
359
- extern ID oj_tv_usec_id;
360
- extern ID oj_utc_id;
361
- extern ID oj_utc_offset_id;
362
- extern ID oj_utcq_id;
363
- extern ID oj_write_id;
364
-
365
- extern bool oj_use_hash_alt;
366
- extern bool oj_use_array_alt;
367
-
368
- #if HAVE_LIBPTHREAD
369
- extern pthread_mutex_t oj_cache_mutex;
239
+ uint8_t rtype;
240
+ uint8_t parent_type;
241
+ uint8_t value_type;
242
+ } * Leaf;
243
+
244
+ extern VALUE oj_saj_parse(int argc, VALUE *argv, VALUE self);
245
+ extern VALUE oj_sc_parse(int argc, VALUE *argv, VALUE self);
246
+
247
+ extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
248
+ extern VALUE oj_strict_sparse(int argc, VALUE *argv, VALUE self);
249
+ extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
250
+ extern VALUE oj_compat_load(int argc, VALUE *argv, VALUE self);
251
+ extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
252
+ extern VALUE oj_custom_parse(int argc, VALUE *argv, VALUE self);
253
+ extern VALUE oj_wab_parse(int argc, VALUE *argv, VALUE self);
254
+
255
+ extern VALUE oj_strict_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
256
+ extern VALUE oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
257
+ extern VALUE oj_object_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
258
+ extern VALUE oj_custom_parse_cstr(int argc, VALUE *argv, char *json, size_t len);
259
+
260
+ extern bool oj_hash_has_key(VALUE hash, VALUE key);
261
+ extern void oj_parse_options(VALUE ropts, Options copts);
262
+
263
+ extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out);
264
+ extern void
265
+ oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv);
266
+ extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts);
267
+ extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts);
268
+ extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);
269
+ extern void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts);
270
+
271
+ extern void oj_str_writer_push_key(StrWriter sw, const char *key);
272
+ extern void oj_str_writer_push_object(StrWriter sw, const char *key);
273
+ extern void oj_str_writer_push_array(StrWriter sw, const char *key);
274
+ extern void oj_str_writer_push_value(StrWriter sw, VALUE val, const char *key);
275
+ extern void oj_str_writer_push_json(StrWriter sw, const char *json, const char *key);
276
+ extern void oj_str_writer_pop(StrWriter sw);
277
+ extern void oj_str_writer_pop_all(StrWriter sw);
278
+
279
+ extern void oj_init_doc(void);
280
+ extern void oj_string_writer_init(void);
281
+ extern void oj_stream_writer_init(void);
282
+ extern void oj_str_writer_init(StrWriter sw, int buf_size);
283
+ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
284
+ extern VALUE oj_mimic_generate(int argc, VALUE *argv, VALUE self);
285
+ extern VALUE oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self);
286
+ extern void oj_parse_mimic_dump_options(VALUE ropts, Options copts);
287
+
288
+ extern VALUE oj_mimic_parse(int argc, VALUE *argv, VALUE self);
289
+ extern VALUE oj_get_json_err_class(const char *err_classname);
290
+ extern void oj_parse_opt_match_string(RxClass rc, VALUE ropts);
291
+
292
+ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
293
+
294
+ extern VALUE Oj;
295
+ extern struct _options oj_default_options;
296
+ extern rb_encoding * oj_utf8_encoding;
297
+ extern int oj_utf8_encoding_index;
298
+
299
+ extern VALUE oj_bag_class;
300
+ extern VALUE oj_bigdecimal_class;
301
+ extern VALUE oj_cstack_class;
302
+ extern VALUE oj_date_class;
303
+ extern VALUE oj_datetime_class;
304
+ extern VALUE oj_doc_class;
305
+ extern VALUE oj_enumerable_class;
306
+ extern VALUE oj_json_generator_error_class;
307
+ extern VALUE oj_json_parser_error_class;
308
+ extern VALUE oj_stream_writer_class;
309
+ extern VALUE oj_string_writer_class;
310
+ extern VALUE oj_stringio_class;
311
+ extern VALUE oj_struct_class;
312
+
313
+ extern VALUE oj_allow_nan_sym;
314
+ extern VALUE oj_array_class_sym;
315
+ extern VALUE oj_array_nl_sym;
316
+ extern VALUE oj_ascii_only_sym;
317
+ extern VALUE oj_create_additions_sym;
318
+ extern VALUE oj_decimal_class_sym;
319
+ extern VALUE oj_hash_class_sym;
320
+ extern VALUE oj_indent_sym;
321
+ extern VALUE oj_max_nesting_sym;
322
+ extern VALUE oj_object_class_sym;
323
+ extern VALUE oj_object_nl_sym;
324
+ extern VALUE oj_quirks_mode_sym;
325
+ extern VALUE oj_space_before_sym;
326
+ extern VALUE oj_space_sym;
327
+ extern VALUE oj_symbolize_names_sym;
328
+ extern VALUE oj_trace_sym;
329
+
330
+ extern VALUE oj_slash_string;
331
+
332
+ extern ID oj_add_value_id;
333
+ extern ID oj_array_append_id;
334
+ extern ID oj_array_end_id;
335
+ extern ID oj_array_start_id;
336
+ extern ID oj_as_json_id;
337
+ extern ID oj_begin_id;
338
+ extern ID oj_bigdecimal_id;
339
+ extern ID oj_end_id;
340
+ extern ID oj_error_id;
341
+ extern ID oj_exclude_end_id;
342
+ extern ID oj_file_id;
343
+ extern ID oj_fileno_id;
344
+ extern ID oj_ftype_id;
345
+ extern ID oj_hash_end_id;
346
+ extern ID oj_hash_key_id;
347
+ extern ID oj_hash_set_id;
348
+ extern ID oj_hash_start_id;
349
+ extern ID oj_iconv_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;
370
387
  #else
371
- extern VALUE oj_cache_mutex;
388
+ extern VALUE oj_cache_mutex;
372
389
  #endif
373
390
 
374
- #if defined(__cplusplus)
391
+ #if defined(cplusplus)
375
392
  #if 0
376
393
  { /* satisfy cc-mode */
377
394
  #endif
378
- } /* extern "C" { */
395
+ } /* extern "C" { */
379
396
  #endif
380
- #endif /* __OJ_H__ */
397
+ #endif /* OJ_H */