oj 2.18.3 → 3.13.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1324 -0
- data/README.md +51 -204
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +49 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -68
- data/ext/oj/circarray.h +16 -42
- data/ext/oj/code.c +221 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +231 -107
- data/ext/oj/custom.c +1125 -0
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +935 -2513
- data/ext/oj/dump.h +108 -0
- data/ext/oj/dump_compat.c +936 -0
- data/ext/oj/dump_leaf.c +164 -0
- data/ext/oj/dump_object.c +761 -0
- data/ext/oj/dump_strict.c +410 -0
- data/ext/oj/encode.h +7 -42
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -54
- data/ext/oj/err.h +52 -46
- data/ext/oj/extconf.rb +21 -30
- data/ext/oj/fast.c +1097 -1080
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +893 -0
- data/ext/oj/object.c +549 -620
- data/ext/oj/odd.c +155 -167
- data/ext/oj/odd.h +37 -63
- data/ext/oj/oj.c +1661 -2063
- data/ext/oj/oj.h +341 -270
- data/ext/oj/parse.c +974 -737
- data/ext/oj/parse.h +105 -97
- data/ext/oj/parser.c +1526 -0
- data/ext/oj/parser.h +90 -0
- data/ext/oj/rails.c +1504 -0
- data/ext/oj/rails.h +18 -0
- data/ext/oj/reader.c +141 -163
- data/ext/oj/reader.h +75 -113
- data/ext/oj/resolve.c +45 -93
- data/ext/oj/resolve.h +7 -34
- data/ext/oj/rxclass.c +143 -0
- data/ext/oj/rxclass.h +26 -0
- data/ext/oj/saj.c +447 -511
- data/ext/oj/saj2.c +348 -0
- data/ext/oj/scp.c +91 -138
- data/ext/oj/sparse.c +793 -644
- data/ext/oj/stream_writer.c +331 -0
- data/ext/oj/strict.c +145 -109
- data/ext/oj/string_writer.c +493 -0
- data/ext/oj/trace.c +72 -0
- data/ext/oj/trace.h +28 -0
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +62 -70
- data/ext/oj/val_stack.h +95 -129
- data/ext/oj/validate.c +51 -0
- data/ext/oj/wab.c +622 -0
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +17 -8
- data/lib/oj/error.rb +10 -11
- data/lib/oj/json.rb +176 -0
- data/lib/oj/mimic.rb +158 -19
- data/lib/oj/state.rb +132 -0
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +1 -31
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/JsonGem.md +94 -0
- data/pages/Modes.md +161 -0
- data/pages/Options.md +327 -0
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +167 -0
- data/pages/Security.md +20 -0
- data/pages/WAB.md +13 -0
- data/test/activerecord/result_test.rb +32 -0
- data/test/activesupport4/decoding_test.rb +108 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +133 -0
- data/test/activesupport5/encoding_test.rb +500 -0
- data/test/activesupport5/encoding_test_cases.rb +98 -0
- data/test/activesupport5/test_helper.rb +72 -0
- data/test/activesupport5/time_zone_test_helpers.rb +39 -0
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +9 -0
- data/test/baz.rb +16 -0
- data/test/bug.rb +11 -46
- data/test/foo.rb +69 -16
- data/test/helper.rb +10 -1
- data/test/isolated/shared.rb +12 -8
- data/test/isolated/test_mimic_rails_after.rb +3 -3
- data/test/isolated/test_mimic_rails_before.rb +3 -3
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +153 -0
- data/test/json_gem/json_encoding_test.rb +107 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +397 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +26 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_compat.rb +30 -28
- data/test/perf_dump.rb +50 -0
- data/test/perf_object.rb +1 -1
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +30 -19
- data/test/perf_wab.rb +131 -0
- data/test/prec.rb +23 -0
- data/test/sample.rb +0 -1
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +219 -102
- data/test/test_custom.rb +533 -0
- data/test/test_fast.rb +107 -35
- data/test/test_file.rb +19 -25
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +72 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +357 -70
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +245 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +39 -2
- data/test/test_strict.rb +186 -7
- data/test/test_various.rb +160 -774
- data/test/test_wab.rb +307 -0
- data/test/test_writer.rb +90 -2
- data/test/tests.rb +24 -0
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- data/test/zoo.rb +13 -0
- metadata +194 -56
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
- data/test/activesupport_datetime_test.rb +0 -23
- data/test/bug2.rb +0 -10
- data/test/bug3.rb +0 -46
- data/test/bug_fast.rb +0 -32
- data/test/bug_load.rb +0 -24
- data/test/crash.rb +0 -111
- data/test/curl/curl_oj.rb +0 -46
- data/test/curl/get_oj.rb +0 -24
- data/test/curl/just_curl.rb +0 -31
- data/test/curl/just_oj.rb +0 -51
- data/test/example.rb +0 -11
- data/test/io.rb +0 -48
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/mod.rb +0 -16
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/struct.rb +0 -29
- data/test/test_serializer.rb +0 -59
- data/test/write_timebars.rb +0 -31
data/ext/oj/oj.h
CHANGED
@@ -1,37 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
#
|
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
|
72
|
-
#define NINF_VAL
|
73
|
-
#define NAN_VAL
|
38
|
+
#define INF_VAL "3.0e14159265358979323846"
|
39
|
+
#define NINF_VAL "-3.0e14159265358979323846"
|
40
|
+
#define NAN_VAL "3.3e14159265358979323846"
|
74
41
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
83
|
-
ObjectMode
|
84
|
-
NullMode
|
85
|
-
CompatMode
|
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
|
97
|
-
JSONEsc
|
98
|
-
XSSEsc
|
99
|
-
ASCIIEsc
|
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
|
104
|
-
FloatDec
|
105
|
-
AutoDec
|
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
|
110
|
-
ArrayType
|
111
|
-
ObjectNew
|
112
|
-
ObjectType
|
85
|
+
ArrayNew = 'A',
|
86
|
+
ArrayType = 'a',
|
87
|
+
ObjectNew = 'O',
|
88
|
+
ObjectType = 'o',
|
113
89
|
} DumpType;
|
114
90
|
|
115
91
|
typedef enum {
|
116
|
-
AutoNan
|
117
|
-
NullNan
|
118
|
-
HugeNan
|
119
|
-
WordNan
|
120
|
-
RaiseNan
|
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
|
125
|
-
STREAM_IO
|
126
|
-
FILE_IO
|
100
|
+
STRING_IO = 'c',
|
101
|
+
STREAM_IO = 's',
|
102
|
+
FILE_IO = 'f',
|
127
103
|
} StreamWriterType;
|
128
104
|
|
129
|
-
typedef
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
char
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
char
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
char
|
156
|
-
char
|
157
|
-
char
|
158
|
-
char
|
159
|
-
char
|
160
|
-
char
|
161
|
-
char
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
char
|
166
|
-
char
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
char
|
173
|
-
char
|
174
|
-
char
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
212
|
-
|
230
|
+
const char *key; // hash key
|
231
|
+
size_t index; // array index, 0 is not set
|
213
232
|
};
|
214
233
|
union {
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
220
|
-
uint8_t
|
221
|
-
uint8_t
|
222
|
-
} *Leaf;
|
223
|
-
|
224
|
-
extern VALUE
|
225
|
-
extern VALUE
|
226
|
-
|
227
|
-
extern VALUE
|
228
|
-
extern VALUE
|
229
|
-
extern VALUE
|
230
|
-
extern VALUE
|
231
|
-
|
232
|
-
extern VALUE
|
233
|
-
extern VALUE
|
234
|
-
|
235
|
-
|
236
|
-
extern
|
237
|
-
|
238
|
-
extern
|
239
|
-
|
240
|
-
extern
|
241
|
-
extern void
|
242
|
-
|
243
|
-
extern void
|
244
|
-
|
245
|
-
|
246
|
-
extern void
|
247
|
-
extern void
|
248
|
-
extern void
|
249
|
-
extern void
|
250
|
-
|
251
|
-
extern void
|
252
|
-
|
253
|
-
extern void
|
254
|
-
|
255
|
-
extern
|
256
|
-
extern
|
257
|
-
|
258
|
-
|
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
|
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(
|
391
|
+
#if defined(cplusplus)
|
321
392
|
#if 0
|
322
393
|
{ /* satisfy cc-mode */
|
323
394
|
#endif
|
324
|
-
}
|
395
|
+
} /* extern "C" { */
|
325
396
|
#endif
|
326
|
-
#endif /*
|
397
|
+
#endif /* OJ_H */
|