line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "EXTERN.h" |
2
|
|
|
|
|
|
|
#include "perl.h" |
3
|
|
|
|
|
|
|
#include |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
/* TESTRANDOM should never be defined in the code released to |
7
|
|
|
|
|
|
|
CPAN. That this is not defined is tested in |
8
|
|
|
|
|
|
|
"xt/testrandom-invalid.t". */ |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
//#define TESTRANDOM |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#ifdef TESTRANDOM |
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
#endif /* def TESTRANDOM */ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
/* A structure representing the "null" in JSON. Although we're now |
17
|
|
|
|
|
|
|
using PL_sv_yes and PL_sv_no, we don't use PL_sv_undef, because |
18
|
|
|
|
|
|
|
perldoc perlguts says it's a bad idea. */ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
static SV * json_null; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
/* Code starts here. */ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#include "unicode.h" |
25
|
|
|
|
|
|
|
#include "unicode.c" |
26
|
|
|
|
|
|
|
#include "json-common.c" |
27
|
|
|
|
|
|
|
#define PERLING |
28
|
|
|
|
|
|
|
#include "json-perl.c" |
29
|
|
|
|
|
|
|
#undef PERLING |
30
|
|
|
|
|
|
|
#define TOKENING |
31
|
|
|
|
|
|
|
#include "json-perl.c" |
32
|
|
|
|
|
|
|
#undef TOKENING |
33
|
|
|
|
|
|
|
#include "json-perl.c" |
34
|
|
|
|
|
|
|
#include "json-entry-points.c" |
35
|
|
|
|
|
|
|
#ifdef TESTRANDOM |
36
|
|
|
|
|
|
|
#include "json-random-test.c" |
37
|
|
|
|
|
|
|
#endif /* def TESTRANDOM */ |
38
|
|
|
|
|
|
|
#include "json-whitespace.c" |
39
|
|
|
|
|
|
|
#ifdef NOPERL |
40
|
|
|
|
|
|
|
#error "Cannot define NOPERL error when compiling Perl version" |
41
|
|
|
|
|
|
|
#endif /* def NOPERL */ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
typedef json_parse_t * JSON__Parse; |
44
|
|
|
|
|
|
|
typedef json_token_t * JSON__Tokenize; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
MODULE=JSON::Parse PACKAGE=JSON::Parse |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
49
|
|
|
|
|
|
|
BOOT: |
50
|
|
|
|
|
|
|
{ |
51
|
24
|
|
|
|
|
|
json_null = get_sv ("JSON::Parse::null", GV_ADD); |
52
|
24
|
|
|
|
|
|
SvREADONLY_on (json_null); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
SV * parse_json (json) |
56
|
|
|
|
|
|
|
SV * json; |
57
|
|
|
|
|
|
|
CODE: |
58
|
55
|
|
|
|
|
|
RETVAL = parse (json); |
59
|
|
|
|
|
|
|
OUTPUT: |
60
|
|
|
|
|
|
|
RETVAL |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
SV * parse_json_safer (json) |
63
|
|
|
|
|
|
|
SV * json; |
64
|
|
|
|
|
|
|
CODE: |
65
|
4
|
|
|
|
|
|
RETVAL = parse_safe (json); |
66
|
|
|
|
|
|
|
OUTPUT: |
67
|
|
|
|
|
|
|
RETVAL |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
void assert_valid_json (json) |
70
|
|
|
|
|
|
|
SV * json; |
71
|
|
|
|
|
|
|
CODE: |
72
|
221
|
|
|
|
|
|
validate (json, 0); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
JSON::Parse |
75
|
|
|
|
|
|
|
new (char * class, ...) |
76
|
|
|
|
|
|
|
CODE: |
77
|
8
|
50
|
|
|
|
|
if (! class) { |
78
|
0
|
|
|
|
|
|
croak ("no class"); |
79
|
|
|
|
|
|
|
} |
80
|
8
|
|
|
|
|
|
Newxz (RETVAL, 1, json_parse_t); |
81
|
8
|
|
|
|
|
|
json_parse_init (RETVAL); |
82
|
|
|
|
|
|
|
OUTPUT: |
83
|
|
|
|
|
|
|
RETVAL |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
SV * run_internal (parser, json) |
86
|
|
|
|
|
|
|
JSON::Parse parser |
87
|
|
|
|
|
|
|
SV * json |
88
|
|
|
|
|
|
|
CODE: |
89
|
21
|
|
|
|
|
|
RETVAL = json_parse_run (parser, json); |
90
|
|
|
|
|
|
|
OUTPUT: |
91
|
|
|
|
|
|
|
RETVAL |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
void |
94
|
|
|
|
|
|
|
check (parser, json) |
95
|
|
|
|
|
|
|
JSON::Parse parser |
96
|
|
|
|
|
|
|
SV * json |
97
|
|
|
|
|
|
|
CODE: |
98
|
0
|
|
|
|
|
|
check (parser, json); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
void |
101
|
|
|
|
|
|
|
DESTROY (parser) |
102
|
|
|
|
|
|
|
JSON::Parse parser; |
103
|
|
|
|
|
|
|
CODE: |
104
|
8
|
|
|
|
|
|
json_parse_free (parser); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
void |
107
|
|
|
|
|
|
|
set_true (parser, user_true) |
108
|
|
|
|
|
|
|
JSON::Parse parser; |
109
|
|
|
|
|
|
|
SV * user_true; |
110
|
|
|
|
|
|
|
CODE: |
111
|
4
|
|
|
|
|
|
json_parse_set_true (parser, user_true); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
void |
114
|
|
|
|
|
|
|
set_false (parser, user_false) |
115
|
|
|
|
|
|
|
JSON::Parse parser; |
116
|
|
|
|
|
|
|
SV * user_false; |
117
|
|
|
|
|
|
|
CODE: |
118
|
5
|
|
|
|
|
|
json_parse_set_false (parser, user_false); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
void |
121
|
|
|
|
|
|
|
set_null (parser, user_null) |
122
|
|
|
|
|
|
|
JSON::Parse parser; |
123
|
|
|
|
|
|
|
SV * user_null; |
124
|
|
|
|
|
|
|
CODE: |
125
|
4
|
|
|
|
|
|
json_parse_set_null (parser, user_null); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
void |
128
|
|
|
|
|
|
|
delete_true (parser) |
129
|
|
|
|
|
|
|
JSON::Parse parser; |
130
|
|
|
|
|
|
|
CODE: |
131
|
1
|
|
|
|
|
|
json_parse_delete_true (parser); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
void |
134
|
|
|
|
|
|
|
delete_false (parser) |
135
|
|
|
|
|
|
|
JSON::Parse parser; |
136
|
|
|
|
|
|
|
CODE: |
137
|
1
|
|
|
|
|
|
json_parse_delete_false (parser); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
void |
140
|
|
|
|
|
|
|
copy_literals (parser, onoff) |
141
|
|
|
|
|
|
|
JSON::Parse parser; |
142
|
|
|
|
|
|
|
SV * onoff; |
143
|
|
|
|
|
|
|
CODE: |
144
|
4
|
|
|
|
|
|
json_parse_copy_literals (parser, onoff); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
void |
147
|
|
|
|
|
|
|
delete_null (parser) |
148
|
|
|
|
|
|
|
JSON::Parse parser; |
149
|
|
|
|
|
|
|
CODE: |
150
|
1
|
|
|
|
|
|
json_parse_delete_null (parser); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
void |
153
|
|
|
|
|
|
|
no_warn_literals (parser, onoff) |
154
|
|
|
|
|
|
|
JSON::Parse parser; |
155
|
|
|
|
|
|
|
SV * onoff; |
156
|
|
|
|
|
|
|
CODE: |
157
|
4
|
50
|
|
|
|
|
parser->no_warn_literals = SvTRUE (onoff) ? 1 : 0; |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
void |
160
|
|
|
|
|
|
|
detect_collisions (parser, onoff) |
161
|
|
|
|
|
|
|
JSON::Parse parser; |
162
|
|
|
|
|
|
|
SV * onoff; |
163
|
|
|
|
|
|
|
CODE: |
164
|
3
|
50
|
|
|
|
|
parser->detect_collisions = SvTRUE (onoff) ? 1 : 0; |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
void |
167
|
|
|
|
|
|
|
diagnostics_hash (parser, onoff) |
168
|
|
|
|
|
|
|
JSON::Parse parser; |
169
|
|
|
|
|
|
|
SV * onoff; |
170
|
|
|
|
|
|
|
CODE: |
171
|
|
|
|
|
|
|
#if PERL_VERSION > 12 |
172
|
0
|
0
|
|
|
|
|
parser->diagnostics_hash = SvTRUE (onoff) ? 1 : 0; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
173
|
|
|
|
|
|
|
#else |
174
|
|
|
|
|
|
|
warn ("diagnostics_hash () requires Perl 5.14 or later; this is 5.%d", |
175
|
|
|
|
|
|
|
PERL_VERSION); |
176
|
|
|
|
|
|
|
#endif |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
void |
179
|
|
|
|
|
|
|
warn_only (parser, onoff) |
180
|
|
|
|
|
|
|
JSON::Parse parser; |
181
|
|
|
|
|
|
|
SV * onoff; |
182
|
|
|
|
|
|
|
CODE: |
183
|
1
|
50
|
|
|
|
|
parser->warn_only = SvTRUE (onoff) ? 1 : 0; |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
int |
186
|
|
|
|
|
|
|
get_warn_only (parser) |
187
|
|
|
|
|
|
|
JSON::Parse parser; |
188
|
|
|
|
|
|
|
CODE: |
189
|
21
|
100
|
|
|
|
|
if (parser->warn_only) { |
190
|
2
|
|
|
|
|
|
RETVAL = 1; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
else { |
193
|
19
|
|
|
|
|
|
RETVAL = 0; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
OUTPUT: |
196
|
|
|
|
|
|
|
RETVAL |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
void |
200
|
|
|
|
|
|
|
set_max_depth (json, max_depth) |
201
|
|
|
|
|
|
|
JSON::Parse json; |
202
|
|
|
|
|
|
|
int max_depth; |
203
|
|
|
|
|
|
|
CODE: |
204
|
2
|
50
|
|
|
|
|
if (max_depth < 0) { |
205
|
0
|
|
|
|
|
|
croak ("Invalid max depth %d", max_depth); |
206
|
|
|
|
|
|
|
} |
207
|
2
|
|
|
|
|
|
json->max_depth = max_depth; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
int |
210
|
|
|
|
|
|
|
get_max_depth (json) |
211
|
|
|
|
|
|
|
JSON::Parse json; |
212
|
|
|
|
|
|
|
CODE: |
213
|
2
|
|
|
|
|
|
RETVAL = json->max_depth; |
214
|
2
|
100
|
|
|
|
|
if (json->max_depth == 0) { |
215
|
1
|
|
|
|
|
|
RETVAL = JSON_PARSE_DEFAULT_MAX_DEPTH; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
OUTPUT: |
218
|
|
|
|
|
|
|
RETVAL |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
#ifdef TESTRANDOM |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
int random_json () |
223
|
|
|
|
|
|
|
CODE: |
224
|
|
|
|
|
|
|
RETVAL = random_json (); |
225
|
|
|
|
|
|
|
OUTPUT: |
226
|
|
|
|
|
|
|
RETVAL |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
#endif /* def TESTRANDOM */ |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
void |
231
|
|
|
|
|
|
|
upgrade_utf8 (parser, onoff) |
232
|
|
|
|
|
|
|
JSON::Parse parser; |
233
|
|
|
|
|
|
|
SV * onoff; |
234
|
|
|
|
|
|
|
CODE: |
235
|
1
|
50
|
|
|
|
|
parser->upgrade_utf8 = SvTRUE (onoff) ? 1 : 0; |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
MODULE=JSON::Parse PACKAGE=JSON::Tokenize |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
JSON::Tokenize tokenize_json (json) |
240
|
|
|
|
|
|
|
SV * json; |
241
|
|
|
|
|
|
|
CODE: |
242
|
4
|
|
|
|
|
|
RETVAL = tokenize (json); |
243
|
4
|
|
|
|
|
|
RETVAL->blessed = 1; |
244
|
|
|
|
|
|
|
OUTPUT: |
245
|
|
|
|
|
|
|
RETVAL |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
JSON::Tokenize tokenize_child (token) |
248
|
|
|
|
|
|
|
JSON::Tokenize token |
249
|
|
|
|
|
|
|
CODE: |
250
|
2
|
|
|
|
|
|
RETVAL = 0; |
251
|
2
|
50
|
|
|
|
|
if (token->child) { |
252
|
2
|
|
|
|
|
|
RETVAL = token->child; |
253
|
2
|
|
|
|
|
|
RETVAL->blessed = 1; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
OUTPUT: |
256
|
|
|
|
|
|
|
RETVAL |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
JSON::Tokenize tokenize_next (token) |
259
|
|
|
|
|
|
|
JSON::Tokenize token |
260
|
|
|
|
|
|
|
CODE: |
261
|
2
|
50
|
|
|
|
|
if (token->next) { |
262
|
2
|
|
|
|
|
|
RETVAL = token->next; |
263
|
2
|
|
|
|
|
|
RETVAL->blessed = 1; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
else { |
266
|
0
|
|
|
|
|
|
RETVAL = 0; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
OUTPUT: |
269
|
|
|
|
|
|
|
RETVAL |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
int tokenize_start (token) |
272
|
|
|
|
|
|
|
JSON::Tokenize token |
273
|
|
|
|
|
|
|
CODE: |
274
|
5
|
|
|
|
|
|
RETVAL = token->start; |
275
|
|
|
|
|
|
|
OUTPUT: |
276
|
|
|
|
|
|
|
RETVAL |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
int tokenize_end (token) |
279
|
|
|
|
|
|
|
JSON::Tokenize token |
280
|
|
|
|
|
|
|
CODE: |
281
|
4
|
|
|
|
|
|
RETVAL = token->end; |
282
|
|
|
|
|
|
|
OUTPUT: |
283
|
|
|
|
|
|
|
RETVAL |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
SV * tokenize_type (token) |
286
|
|
|
|
|
|
|
JSON::Tokenize token |
287
|
|
|
|
|
|
|
CODE: |
288
|
|
|
|
|
|
|
/* Only set this to the real value if everything is OK. */ |
289
|
4
|
|
|
|
|
|
RETVAL = & PL_sv_undef; |
290
|
4
|
50
|
|
|
|
|
if (token->type > json_token_invalid && |
|
|
50
|
|
|
|
|
|
291
|
4
|
|
|
|
|
|
token->type < n_json_tokens) { |
292
|
4
|
|
|
|
|
|
RETVAL = newSVpv (token_names[token->type], 0); |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
else { |
295
|
0
|
|
|
|
|
|
warn ("Invalid JSON token type %d", token->type); |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
OUTPUT: |
298
|
|
|
|
|
|
|
RETVAL |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
void DESTROY (token) |
301
|
|
|
|
|
|
|
JSON::Tokenize token |
302
|
|
|
|
|
|
|
CODE: |
303
|
8
|
|
|
|
|
|
tokenize_free (token); |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
MODULE=JSON::Parse PACKAGE=JSON::Whitespace |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
SV * strip_whitespace (tokens, json) |
308
|
|
|
|
|
|
|
JSON::Tokenize tokens; |
309
|
|
|
|
|
|
|
SV * json; |
310
|
|
|
|
|
|
|
CODE: |
311
|
1
|
|
|
|
|
|
RETVAL = strip_whitespace (tokens, json); |
312
|
|
|
|
|
|
|
OUTPUT: |
313
|
|
|
|
|
|
|
RETVAL |