| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
/* The C part is broken into three pieces, "json-common.c", |
|
2
|
|
|
|
|
|
|
"json-perl.c", and "json-entry-points.c". This file contains the |
|
3
|
|
|
|
|
|
|
"Perl" stuff, for example if we have a string, the stuff to convert |
|
4
|
|
|
|
|
|
|
it into a Perl hash key or a Perl scalar is in this file. */ |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
/* There are two routes through the code, the PERLING route and the |
|
7
|
|
|
|
|
|
|
non-PERLING route. If we go via the non-PERLING route, we never |
|
8
|
|
|
|
|
|
|
create or alter any Perl-related stuff, we just parse each byte and |
|
9
|
|
|
|
|
|
|
possibly throw an error. This makes validation faster. */ |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#ifdef PERLING |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
/* We are creating Perl structures from the JSON. */ |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#define PREFIX(x) x |
|
16
|
|
|
|
|
|
|
#define SVPTR SV * |
|
17
|
|
|
|
|
|
|
#define SETVALUE value = |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#elif defined(TOKENING) |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
/* We are just tokenizing the JSON. */ |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#define PREFIX(x) tokenize_ ## x |
|
24
|
|
|
|
|
|
|
#define SVPTR json_token_t * |
|
25
|
|
|
|
|
|
|
#define SETVALUE value = |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#else /* not def PERLING/TOKENING */ |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
/* Turn off everything to do with creating Perl things. */ |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#define PREFIX(x) valid_ ## x |
|
32
|
|
|
|
|
|
|
#define SVPTR void |
|
33
|
|
|
|
|
|
|
#define SETVALUE |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#endif /* def PERLING */ |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
/* |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This is what INT_MAX_DIGITS is, but #defining it like this causes huge |
|
40
|
|
|
|
|
|
|
amounts of unnecessary calculation, so this is commented out. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#define INT_MAX_DIGITS ((int) (log (INT_MAX) / log (10)) - 1) |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
*/ |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
/* The maximum digits we allow an integer before throwing in the towel |
|
47
|
|
|
|
|
|
|
and returning a Perl string type. */ |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#define INT_MAX_DIGITS 8 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#define USEDIGIT guess = guess * 10 + (c - '0') |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
static INLINE SVPTR |
|
54
|
493
|
|
|
|
|
|
PREFIX (number) (json_parse_t * parser) |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
|
|
|
|
|
|
/* End marker for strtod. */ |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
char * end; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
/* Start marker for strtod. */ |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
char * start; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
/* A guess for integer numbers. */ |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
int guess; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
/* The parsed character itself, the cause of our motion. */ |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
unsigned char c; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
/* If it has exp or dot in it. */ |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
double d; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
/* Negative number. */ |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
int minus; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
/* When this is called, it means that a byte indicating a number |
|
81
|
|
|
|
|
|
|
was found. We need to re-examine that byte as a number. */ |
|
82
|
|
|
|
|
|
|
|
|
83
|
493
|
|
|
|
|
|
parser->end--; |
|
84
|
493
|
|
|
|
|
|
start = (char *) parser->end; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#define FAILNUMBER(err) \ |
|
87
|
|
|
|
|
|
|
if (STRINGEND && \ |
|
88
|
|
|
|
|
|
|
parser->top_level_value && \ |
|
89
|
|
|
|
|
|
|
c == '\0') { \ |
|
90
|
|
|
|
|
|
|
goto exp_number_end; \ |
|
91
|
|
|
|
|
|
|
} \ |
|
92
|
|
|
|
|
|
|
parser->bad_byte = parser->end - 1; \ |
|
93
|
|
|
|
|
|
|
parser->error = json_error_ ## err; \ |
|
94
|
|
|
|
|
|
|
parser->bad_type = json_number; \ |
|
95
|
|
|
|
|
|
|
parser->bad_beginning = \ |
|
96
|
|
|
|
|
|
|
(unsigned char*) start; \ |
|
97
|
|
|
|
|
|
|
failbadinput (parser) |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#define NUMBEREND \ |
|
100
|
|
|
|
|
|
|
WHITESPACE: \ |
|
101
|
|
|
|
|
|
|
case ']': \ |
|
102
|
|
|
|
|
|
|
case '}': \ |
|
103
|
|
|
|
|
|
|
case ',' |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#define XNUMBEREND (XCOMMA|XWHITESPACE|parser->end_expected) |
|
106
|
|
|
|
|
|
|
|
|
107
|
493
|
|
|
|
|
|
guess = 0; |
|
108
|
493
|
|
|
|
|
|
minus = 0; |
|
109
|
|
|
|
|
|
|
|
|
110
|
493
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
111
|
|
|
|
|
|
|
case DIGIT19: |
|
112
|
198
|
|
|
|
|
|
guess = c - '0'; |
|
113
|
198
|
|
|
|
|
|
goto leading_digit19; |
|
114
|
|
|
|
|
|
|
case '0': |
|
115
|
291
|
|
|
|
|
|
goto leading_zero; |
|
116
|
|
|
|
|
|
|
case '-': |
|
117
|
4
|
|
|
|
|
|
minus = 1; |
|
118
|
4
|
|
|
|
|
|
goto leading_minus; |
|
119
|
|
|
|
|
|
|
default: |
|
120
|
0
|
|
|
|
|
|
parser->expected = XDIGIT | XMINUS; |
|
121
|
0
|
0
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
leading_digit19: |
|
125
|
|
|
|
|
|
|
|
|
126
|
431
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
127
|
|
|
|
|
|
|
case DIGIT: |
|
128
|
233
|
|
|
|
|
|
USEDIGIT; |
|
129
|
233
|
|
|
|
|
|
goto leading_digit19; |
|
130
|
|
|
|
|
|
|
case '.': |
|
131
|
25
|
|
|
|
|
|
goto dot; |
|
132
|
|
|
|
|
|
|
case 'e': |
|
133
|
|
|
|
|
|
|
case 'E': |
|
134
|
4
|
|
|
|
|
|
goto exp; |
|
135
|
37
|
|
|
|
|
|
case NUMBEREND: |
|
136
|
165
|
|
|
|
|
|
goto int_number_end; |
|
137
|
|
|
|
|
|
|
default: |
|
138
|
4
|
|
|
|
|
|
parser->expected = XDIGIT | XDOT | XEXPONENTIAL | XNUMBEREND; |
|
139
|
4
|
50
|
|
|
|
|
if (parser->top_level_value) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
parser->expected &= ~XCOMMA; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
4
|
100
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
leading_zero: |
|
146
|
291
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
147
|
|
|
|
|
|
|
case '.': |
|
148
|
|
|
|
|
|
|
/* "0." */ |
|
149
|
20
|
|
|
|
|
|
goto dot; |
|
150
|
|
|
|
|
|
|
case 'e': |
|
151
|
|
|
|
|
|
|
case 'E': |
|
152
|
|
|
|
|
|
|
/* "0e" */ |
|
153
|
4
|
|
|
|
|
|
goto exp; |
|
154
|
0
|
|
|
|
|
|
case NUMBEREND: |
|
155
|
|
|
|
|
|
|
/* "0" */ |
|
156
|
264
|
|
|
|
|
|
goto int_number_end; |
|
157
|
|
|
|
|
|
|
default: |
|
158
|
3
|
|
|
|
|
|
parser->expected = XDOT | XEXPONENTIAL | XNUMBEREND; |
|
159
|
3
|
50
|
|
|
|
|
if (parser->top_level_value) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
parser->expected &= ~XCOMMA; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
3
|
50
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
leading_minus: |
|
166
|
4
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
167
|
|
|
|
|
|
|
case DIGIT19: |
|
168
|
0
|
|
|
|
|
|
USEDIGIT; |
|
169
|
0
|
|
|
|
|
|
goto leading_digit19; |
|
170
|
|
|
|
|
|
|
case '0': |
|
171
|
0
|
|
|
|
|
|
goto leading_zero; |
|
172
|
|
|
|
|
|
|
default: |
|
173
|
4
|
|
|
|
|
|
parser->expected = XDIGIT; |
|
174
|
4
|
50
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
/* Things like "5." are not allowed so there is no NUMBEREND |
|
178
|
|
|
|
|
|
|
here. */ |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
dot: |
|
181
|
45
|
100
|
|
|
|
|
switch (NEXTBYTE) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
case DIGIT: |
|
183
|
40
|
|
|
|
|
|
goto dot_digits; |
|
184
|
|
|
|
|
|
|
default: |
|
185
|
5
|
|
|
|
|
|
parser->expected = XDIGIT; |
|
186
|
5
|
100
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
/* We have as much as 5.5 so we can stop. */ |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
dot_digits: |
|
192
|
58
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
193
|
|
|
|
|
|
|
case DIGIT: |
|
194
|
18
|
|
|
|
|
|
goto dot_digits; |
|
195
|
|
|
|
|
|
|
case 'e': |
|
196
|
|
|
|
|
|
|
case 'E': |
|
197
|
26
|
|
|
|
|
|
goto exp; |
|
198
|
2
|
|
|
|
|
|
case NUMBEREND: |
|
199
|
10
|
|
|
|
|
|
goto exp_number_end; |
|
200
|
|
|
|
|
|
|
default: |
|
201
|
4
|
|
|
|
|
|
parser->expected = XDIGIT | XNUMBEREND | XEXPONENTIAL; |
|
202
|
4
|
50
|
|
|
|
|
if (parser->top_level_value) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
203
|
4
|
|
|
|
|
|
parser->expected &= ~XCOMMA; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
4
|
50
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
/* Things like "10E" are not allowed so there is no NUMBEREND |
|
209
|
|
|
|
|
|
|
here. */ |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
exp: |
|
212
|
34
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
213
|
|
|
|
|
|
|
case '-': |
|
214
|
|
|
|
|
|
|
case '+': |
|
215
|
17
|
|
|
|
|
|
goto exp_sign; |
|
216
|
|
|
|
|
|
|
case DIGIT: |
|
217
|
17
|
|
|
|
|
|
goto exp_digits; |
|
218
|
|
|
|
|
|
|
default: |
|
219
|
0
|
|
|
|
|
|
parser->expected = XDIGIT | XMINUS | XPLUS; |
|
220
|
0
|
0
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
exp_sign: |
|
224
|
|
|
|
|
|
|
|
|
225
|
17
|
100
|
|
|
|
|
switch (NEXTBYTE) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
case DIGIT: |
|
227
|
11
|
|
|
|
|
|
goto exp_digits; |
|
228
|
|
|
|
|
|
|
default: |
|
229
|
6
|
|
|
|
|
|
parser->expected = XDIGIT; |
|
230
|
6
|
50
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
/* We have as much as "3.0e1" or similar. */ |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
exp_digits: |
|
236
|
33
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
237
|
|
|
|
|
|
|
case DIGIT: |
|
238
|
5
|
|
|
|
|
|
goto exp_digits; |
|
239
|
2
|
|
|
|
|
|
case NUMBEREND: |
|
240
|
22
|
|
|
|
|
|
goto exp_number_end; |
|
241
|
|
|
|
|
|
|
default: |
|
242
|
6
|
|
|
|
|
|
parser->expected = XDIGIT | XNUMBEREND; |
|
243
|
6
|
50
|
|
|
|
|
if (parser->top_level_value) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
parser->expected &= ~XCOMMA; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
6
|
50
|
|
|
|
|
FAILNUMBER (unexpected_character); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
exp_number_end: |
|
250
|
36
|
|
|
|
|
|
parser->end--; |
|
251
|
|
|
|
|
|
|
#ifdef PERLING |
|
252
|
19
|
|
|
|
|
|
d = strtod (start, & end); |
|
253
|
|
|
|
|
|
|
#else |
|
254
|
17
|
|
|
|
|
|
strtod (start, & end); |
|
255
|
|
|
|
|
|
|
#endif |
|
256
|
36
|
|
|
|
|
|
if ((unsigned char *) end == parser->end) { |
|
257
|
|
|
|
|
|
|
/* Success, strtod worked as planned. */ |
|
258
|
|
|
|
|
|
|
#ifdef PERLING |
|
259
|
19
|
|
|
|
|
|
return newSVnv (d); |
|
260
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
261
|
0
|
|
|
|
|
|
return json_token_new (parser, (unsigned char *) start, |
|
262
|
|
|
|
|
|
|
parser->end, |
|
263
|
|
|
|
|
|
|
json_token_number); |
|
264
|
|
|
|
|
|
|
#else |
|
265
|
17
|
|
|
|
|
|
return; |
|
266
|
|
|
|
|
|
|
#endif |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
else { |
|
269
|
|
|
|
|
|
|
/* Failure, strtod rejected the number. */ |
|
270
|
0
|
|
|
|
|
|
goto string_number_end; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
int_number_end: |
|
274
|
|
|
|
|
|
|
|
|
275
|
429
|
|
|
|
|
|
parser->end--; |
|
276
|
429
|
50
|
|
|
|
|
if (parser->end - (unsigned char *) start < INT_MAX_DIGITS + minus) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
277
|
424
|
50
|
|
|
|
|
if (minus) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
278
|
0
|
|
|
|
|
|
guess = -guess; |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
/* |
|
281
|
|
|
|
|
|
|
printf ("number debug: '%.*s': %d\n", |
|
282
|
|
|
|
|
|
|
parser->end - (unsigned char *) start, start, guess); |
|
283
|
|
|
|
|
|
|
*/ |
|
284
|
|
|
|
|
|
|
#ifdef PERLING |
|
285
|
405
|
|
|
|
|
|
return newSViv (guess); |
|
286
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
287
|
10
|
|
|
|
|
|
return json_token_new (parser, (unsigned char *) start, |
|
288
|
10
|
|
|
|
|
|
parser->end - 1, json_token_number); |
|
289
|
|
|
|
|
|
|
#else |
|
290
|
9
|
|
|
|
|
|
return; |
|
291
|
|
|
|
|
|
|
#endif |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
else { |
|
294
|
5
|
|
|
|
|
|
goto string_number_end; |
|
295
|
|
|
|
|
|
|
} |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
string_number_end: |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
/* We could not convert this number using a number conversion |
|
300
|
|
|
|
|
|
|
routine, so we are going to convert it to a string. This might |
|
301
|
|
|
|
|
|
|
happen with ridiculously long numbers or something. The JSON |
|
302
|
|
|
|
|
|
|
standard doesn't explicitly disallow integers with a million |
|
303
|
|
|
|
|
|
|
digits. */ |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
#ifdef PERLING |
|
306
|
429
|
|
|
|
|
|
return newSVpv (start, (STRLEN) ((char *) parser->end - start)); |
|
307
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
308
|
10
|
|
|
|
|
|
return json_token_new (parser, (unsigned char *) start, |
|
309
|
0
|
|
|
|
|
|
parser->end - 1, json_token_number); |
|
310
|
|
|
|
|
|
|
#else |
|
311
|
26
|
|
|
|
|
|
return; |
|
312
|
|
|
|
|
|
|
#endif |
|
313
|
|
|
|
|
|
|
} |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
#ifdef PERLING |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
/* This copies our on-stack buffer "buffer" of size "size" into the |
|
318
|
|
|
|
|
|
|
end of a Perl SV called "string". */ |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
#define COPYBUFFER { \ |
|
321
|
|
|
|
|
|
|
if (! string) { \ |
|
322
|
|
|
|
|
|
|
string = newSVpvn ((char *) buffer, size); \ |
|
323
|
|
|
|
|
|
|
} \ |
|
324
|
|
|
|
|
|
|
else { \ |
|
325
|
|
|
|
|
|
|
char * svbuf; \ |
|
326
|
|
|
|
|
|
|
STRLEN cur = SvCUR (string); \ |
|
327
|
|
|
|
|
|
|
if (SvLEN (string) <= cur + size) { \ |
|
328
|
|
|
|
|
|
|
SvGROW (string, cur + size); \ |
|
329
|
|
|
|
|
|
|
} \ |
|
330
|
|
|
|
|
|
|
svbuf = SvPVX (string); \ |
|
331
|
|
|
|
|
|
|
memcpy (svbuf + cur, buffer, size); \ |
|
332
|
|
|
|
|
|
|
SvCUR_set (string, cur + size); \ |
|
333
|
|
|
|
|
|
|
} \ |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
/* The size of the on-stack buffer. */ |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
#define BUFSIZE 0x1000 |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
/* We need a safety margin when dealing with the buffer, for example |
|
341
|
|
|
|
|
|
|
if we hit a Unicode \uabcd escape which needs to be decoded, we |
|
342
|
|
|
|
|
|
|
need to have enough bytes to write into the buffer. */ |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
#define MARGIN 0x10 |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
/* Speedup hack, a special "get_string" for Perl parsing which doesn't |
|
347
|
|
|
|
|
|
|
use parser->buffer but its own buffer on the stack. */ |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
static INLINE SV * |
|
350
|
20
|
|
|
|
|
|
perl_get_string (json_parse_t * parser, STRLEN prefixlen) |
|
351
|
|
|
|
|
|
|
{ |
|
352
|
|
|
|
|
|
|
unsigned char * b; |
|
353
|
|
|
|
|
|
|
unsigned char c; |
|
354
|
|
|
|
|
|
|
unsigned char * start; |
|
355
|
|
|
|
|
|
|
unsigned char buffer[BUFSIZE]; |
|
356
|
|
|
|
|
|
|
STRLEN size; |
|
357
|
|
|
|
|
|
|
SV * string; |
|
358
|
20
|
|
|
|
|
|
string = 0; |
|
359
|
20
|
|
|
|
|
|
start = parser->end; |
|
360
|
20
|
|
|
|
|
|
b = buffer; |
|
361
|
|
|
|
|
|
|
|
|
362
|
20
|
50
|
|
|
|
|
if (prefixlen > 0) { |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
/* The string from parser->end to parser->end + prefixlen has |
|
365
|
|
|
|
|
|
|
already been checked and found not to contain the end of |
|
366
|
|
|
|
|
|
|
the string or any escapes, so we just copy the memory |
|
367
|
|
|
|
|
|
|
straight into the buffer. This was supposed to speed things |
|
368
|
|
|
|
|
|
|
up, but it didn't seem to. However this presumably cannot |
|
369
|
|
|
|
|
|
|
hurt either. */ |
|
370
|
|
|
|
|
|
|
|
|
371
|
0
|
0
|
|
|
|
|
if (prefixlen > BUFSIZE - MARGIN) { |
|
372
|
|
|
|
|
|
|
/* This is to account for the very unlikely case that the |
|
373
|
|
|
|
|
|
|
key of the JSON object is more than BUFSIZE - MARGIN |
|
374
|
|
|
|
|
|
|
bytes long and has an escape after more than BUFSIZE - |
|
375
|
|
|
|
|
|
|
MARGIN bytes. */ |
|
376
|
0
|
|
|
|
|
|
prefixlen = BUFSIZE - MARGIN; |
|
377
|
|
|
|
|
|
|
} |
|
378
|
|
|
|
|
|
|
|
|
379
|
0
|
|
|
|
|
|
memcpy (buffer, parser->end, prefixlen); |
|
380
|
0
|
|
|
|
|
|
start += prefixlen; |
|
381
|
|
|
|
|
|
|
} |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
string_start: |
|
384
|
|
|
|
|
|
|
|
|
385
|
13494
|
|
|
|
|
|
size = b - buffer; |
|
386
|
13494
|
100
|
|
|
|
|
if (size >= BUFSIZE - MARGIN) { |
|
387
|
|
|
|
|
|
|
/* Spot-check for an overflow. */ |
|
388
|
2
|
50
|
|
|
|
|
if (STRINGEND) { |
|
389
|
0
|
|
|
|
|
|
STRINGFAIL (unexpected_end_of_input); |
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
/* "string_start" is a label for a goto which is applied until |
|
392
|
|
|
|
|
|
|
we get to the end of the string, so size keeps getting |
|
393
|
|
|
|
|
|
|
larger and larger. Now the string being parsed has proved |
|
394
|
|
|
|
|
|
|
to be too big for our puny BUFSIZE buffer, so we copy the |
|
395
|
|
|
|
|
|
|
contents of the buffer into the nice Perl scalar. */ |
|
396
|
2
|
50
|
|
|
|
|
COPYBUFFER; |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
/* Set the point of copying bytes back to the beginning of |
|
398
|
|
|
|
|
|
|
buffer. We don't reset the memory in buffer. */ |
|
399
|
2
|
|
|
|
|
|
b = buffer; |
|
400
|
2
|
|
|
|
|
|
size = b - buffer; |
|
401
|
|
|
|
|
|
|
} |
|
402
|
13494
|
|
|
|
|
|
NEXTBYTE; |
|
403
|
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
/* "if" statements seem to compile to something marginally faster |
|
405
|
|
|
|
|
|
|
than "switch" statements, for some reason. */ |
|
406
|
|
|
|
|
|
|
|
|
407
|
13494
|
50
|
|
|
|
|
if (c < 0x20) { |
|
408
|
0
|
|
|
|
|
|
ILLEGALBYTE; |
|
409
|
|
|
|
|
|
|
} |
|
410
|
13494
|
50
|
|
|
|
|
else if (c >= 0x20 && c <= 0x80) { |
|
|
|
100
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
/* For some reason or another, putting the following "if" |
|
412
|
|
|
|
|
|
|
statements after the above one results in about 4% faster |
|
413
|
|
|
|
|
|
|
code than putting them before it. */ |
|
414
|
13493
|
100
|
|
|
|
|
if (c == '"') { |
|
415
|
20
|
|
|
|
|
|
goto string_end; |
|
416
|
|
|
|
|
|
|
} |
|
417
|
13473
|
100
|
|
|
|
|
if (c == '\\') { |
|
418
|
52
|
50
|
|
|
|
|
HANDLE_ESCAPES (parser->end, start - 1); |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
419
|
52
|
|
|
|
|
|
goto string_start; |
|
420
|
|
|
|
|
|
|
} |
|
421
|
13421
|
|
|
|
|
|
* b++ = c; |
|
422
|
13421
|
|
|
|
|
|
goto string_start; |
|
423
|
|
|
|
|
|
|
} |
|
424
|
|
|
|
|
|
|
else { |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
/* Resort to switch statements for the UTF-8 stuff. This |
|
427
|
|
|
|
|
|
|
actually also contains statements to handle ASCII but they |
|
428
|
|
|
|
|
|
|
will never be executed. */ |
|
429
|
|
|
|
|
|
|
|
|
430
|
1
|
|
|
|
|
|
switch (c) { |
|
431
|
|
|
|
|
|
|
#define ADDBYTE * b = c; b++ |
|
432
|
|
|
|
|
|
|
#define startofutf8string start |
|
433
|
|
|
|
|
|
|
#include "utf8-byte-one.c" |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
default: |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
/* We have to give up, this byte is too mysterious for our |
|
438
|
|
|
|
|
|
|
weak minds. */ |
|
439
|
|
|
|
|
|
|
|
|
440
|
0
|
|
|
|
|
|
ILLEGALBYTE; |
|
441
|
|
|
|
|
|
|
} |
|
442
|
|
|
|
|
|
|
} |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
string_end: |
|
445
|
|
|
|
|
|
|
|
|
446
|
20
|
50
|
|
|
|
|
if (STRINGEND) { |
|
447
|
0
|
|
|
|
|
|
STRINGFAIL (unexpected_end_of_input); |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
|
|
450
|
20
|
100
|
|
|
|
|
COPYBUFFER; |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
451
|
20
|
|
|
|
|
|
return string; |
|
452
|
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
/* The rest of the UTF-8 stuff goes in here. */ |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
#include "utf8-next-byte.c" |
|
456
|
|
|
|
|
|
|
#undef ADDBYTE |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
goto string_end; |
|
459
|
|
|
|
|
|
|
} |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
#endif /* PERLING */ |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
static SVPTR |
|
464
|
546
|
|
|
|
|
|
PREFIX (string) (json_parse_t * parser) |
|
465
|
|
|
|
|
|
|
{ |
|
466
|
|
|
|
|
|
|
unsigned char c; |
|
467
|
|
|
|
|
|
|
#ifdef PERLING |
|
468
|
|
|
|
|
|
|
SV * string; |
|
469
|
|
|
|
|
|
|
STRLEN len; |
|
470
|
|
|
|
|
|
|
STRLEN prefixlen; |
|
471
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
472
|
|
|
|
|
|
|
json_token_t * string; |
|
473
|
|
|
|
|
|
|
int len; |
|
474
|
|
|
|
|
|
|
#else |
|
475
|
|
|
|
|
|
|
int len; |
|
476
|
|
|
|
|
|
|
#endif |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
unsigned char * start; |
|
479
|
|
|
|
|
|
|
|
|
480
|
546
|
|
|
|
|
|
start = parser->end; |
|
481
|
546
|
|
|
|
|
|
len = 0; |
|
482
|
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
/* First of all, we examine the string to work out how long it is |
|
484
|
|
|
|
|
|
|
and to look for escapes. If we find them, we go to "contains_escapes" |
|
485
|
|
|
|
|
|
|
and go back and do all the hard work of converting the escapes |
|
486
|
|
|
|
|
|
|
into the right things. If we don't find any escapes, we just |
|
487
|
|
|
|
|
|
|
use "start" and "len" and copy the string from inside |
|
488
|
|
|
|
|
|
|
"input". This is a trick to increase the speed of |
|
489
|
|
|
|
|
|
|
processing. */ |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
string_start: |
|
492
|
18450
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
493
|
|
|
|
|
|
|
case '"': |
|
494
|
488
|
|
|
|
|
|
goto string_end; |
|
495
|
|
|
|
|
|
|
case '\\': |
|
496
|
48
|
|
|
|
|
|
goto contains_escapes; |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
#define ADDBYTE len++ |
|
499
|
|
|
|
|
|
|
#include "utf8-byte-one.c" |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
/* Not a fall through. */ |
|
502
|
|
|
|
|
|
|
case BADBYTES: |
|
503
|
8
|
|
|
|
|
|
ILLEGALBYTE; |
|
504
|
|
|
|
|
|
|
} |
|
505
|
|
|
|
|
|
|
/* Parsing of the string ended due to a \0 byte flipping the |
|
506
|
|
|
|
|
|
|
"while" switch and we dropped into this section before |
|
507
|
|
|
|
|
|
|
reaching the string's end. */ |
|
508
|
2
|
|
|
|
|
|
ILLEGALBYTE; |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
#include "utf8-next-byte.c" |
|
511
|
|
|
|
|
|
|
#undef ADDBYTE |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
string_end: |
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
#ifdef PERLING |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
/* Our string didn't contain any escape sequences, so we can just |
|
518
|
|
|
|
|
|
|
make a new SV * by copying the string from "start", the old |
|
519
|
|
|
|
|
|
|
position within the thing we're parsing to start + len. */ |
|
520
|
|
|
|
|
|
|
|
|
521
|
73
|
|
|
|
|
|
string = newSVpvn ((char *) start, len); |
|
522
|
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
524
|
|
|
|
|
|
|
|
|
525
|
11
|
|
|
|
|
|
string = json_token_new (parser, start - 1, |
|
526
|
|
|
|
|
|
|
start + len, |
|
527
|
|
|
|
|
|
|
json_token_string); |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
#endif |
|
530
|
|
|
|
|
|
|
|
|
531
|
488
|
|
|
|
|
|
goto string_done; |
|
532
|
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
contains_escapes: |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
#ifdef PERLING |
|
536
|
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
/* Use "perl_get_string" which keeps the buffer on the |
|
538
|
|
|
|
|
|
|
stack. Results in a minor speed increase. */ |
|
539
|
20
|
|
|
|
|
|
parser->end = start; |
|
540
|
20
|
|
|
|
|
|
prefixlen = (STRLEN) (parser->end - start); |
|
541
|
20
|
|
|
|
|
|
string = perl_get_string (parser, prefixlen); |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
544
|
|
|
|
|
|
|
/* Don't use "len" here since it subtracts the escapes. */ |
|
545
|
1
|
|
|
|
|
|
parser->end = start; |
|
546
|
1
|
|
|
|
|
|
len = get_string (parser); |
|
547
|
1
|
|
|
|
|
|
string = json_token_new (parser, |
|
548
|
|
|
|
|
|
|
/* Location of first quote. */ |
|
549
|
|
|
|
|
|
|
start - 1, |
|
550
|
|
|
|
|
|
|
/* Location of last quote. */ |
|
551
|
1
|
|
|
|
|
|
parser->end - 1, |
|
552
|
|
|
|
|
|
|
json_token_string); |
|
553
|
|
|
|
|
|
|
#else |
|
554
|
27
|
|
|
|
|
|
parser->end = start; |
|
555
|
27
|
|
|
|
|
|
len = get_string (parser); |
|
556
|
|
|
|
|
|
|
#endif |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
string_done: |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
#ifdef PERLING |
|
561
|
93
|
100
|
|
|
|
|
if (parser->unicode || parser->force_unicode || parser->upgrade_utf8) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
562
|
60
|
|
|
|
|
|
SvUTF8_on (string); |
|
563
|
60
|
|
|
|
|
|
parser->force_unicode = 0; |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
#endif |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
#if defined (PERLING) || defined (TOKENING) |
|
568
|
105
|
|
|
|
|
|
return string; |
|
569
|
|
|
|
|
|
|
#else |
|
570
|
416
|
|
|
|
|
|
return; |
|
571
|
|
|
|
|
|
|
#endif |
|
572
|
|
|
|
|
|
|
} |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
#define FAILLITERAL(c) \ |
|
575
|
|
|
|
|
|
|
parser->expected = XIN_LITERAL; \ |
|
576
|
|
|
|
|
|
|
parser->literal_char = c; \ |
|
577
|
|
|
|
|
|
|
parser->bad_beginning = start; \ |
|
578
|
|
|
|
|
|
|
parser->error = json_error_unexpected_character; \ |
|
579
|
|
|
|
|
|
|
parser->bad_type = json_literal; \ |
|
580
|
|
|
|
|
|
|
parser->bad_byte = parser->end - 1; \ |
|
581
|
|
|
|
|
|
|
failbadinput (parser) |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
static SVPTR |
|
584
|
32
|
|
|
|
|
|
PREFIX (literal_true) (json_parse_t * parser) |
|
585
|
|
|
|
|
|
|
{ |
|
586
|
|
|
|
|
|
|
unsigned char * start; |
|
587
|
32
|
|
|
|
|
|
start = parser->end - 1; |
|
588
|
32
|
100
|
|
|
|
|
if (* parser->end++ == 'r') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
589
|
30
|
50
|
|
|
|
|
if (* parser->end++ == 'u') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
590
|
30
|
100
|
|
|
|
|
if (* parser->end++ == 'e') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
#ifdef PERLING |
|
592
|
21
|
100
|
|
|
|
|
if (parser->user_true) { |
|
593
|
3
|
|
|
|
|
|
return newSVsv (parser->user_true); |
|
594
|
|
|
|
|
|
|
} |
|
595
|
18
|
100
|
|
|
|
|
else if (parser->copy_literals) { |
|
596
|
4
|
|
|
|
|
|
return newSVsv (&PL_sv_yes); |
|
597
|
|
|
|
|
|
|
} |
|
598
|
|
|
|
|
|
|
else { |
|
599
|
14
|
|
|
|
|
|
return &PL_sv_yes; |
|
600
|
|
|
|
|
|
|
} |
|
601
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
602
|
2
|
|
|
|
|
|
return json_token_new (parser, start, parser->end - 1, |
|
603
|
|
|
|
|
|
|
json_token_literal); |
|
604
|
|
|
|
|
|
|
#else |
|
605
|
5
|
|
|
|
|
|
return; |
|
606
|
|
|
|
|
|
|
#endif |
|
607
|
|
|
|
|
|
|
} |
|
608
|
2
|
|
|
|
|
|
FAILLITERAL ('e'); |
|
609
|
|
|
|
|
|
|
} |
|
610
|
0
|
|
|
|
|
|
FAILLITERAL ('u'); |
|
611
|
|
|
|
|
|
|
} |
|
612
|
2
|
|
|
|
|
|
FAILLITERAL ('r'); |
|
613
|
|
|
|
|
|
|
} |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
static SVPTR |
|
616
|
19
|
|
|
|
|
|
PREFIX (literal_false) (json_parse_t * parser) |
|
617
|
|
|
|
|
|
|
{ |
|
618
|
|
|
|
|
|
|
unsigned char * start; |
|
619
|
19
|
|
|
|
|
|
start = parser->end - 1; |
|
620
|
19
|
50
|
|
|
|
|
if (* parser->end++ == 'a') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
621
|
19
|
50
|
|
|
|
|
if (* parser->end++ == 'l') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
622
|
19
|
50
|
|
|
|
|
if (* parser->end++ == 's') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
623
|
19
|
50
|
|
|
|
|
if (* parser->end++ == 'e') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
#ifdef PERLING |
|
625
|
17
|
100
|
|
|
|
|
if (parser->user_false) { |
|
626
|
3
|
|
|
|
|
|
return newSVsv (parser->user_false); |
|
627
|
|
|
|
|
|
|
} |
|
628
|
14
|
100
|
|
|
|
|
else if (parser->copy_literals) { |
|
629
|
4
|
|
|
|
|
|
return newSVsv (&PL_sv_no); |
|
630
|
|
|
|
|
|
|
} |
|
631
|
|
|
|
|
|
|
else { |
|
632
|
10
|
|
|
|
|
|
return &PL_sv_no; |
|
633
|
|
|
|
|
|
|
} |
|
634
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
635
|
0
|
|
|
|
|
|
return json_token_new (parser, start, parser->end - 1, |
|
636
|
|
|
|
|
|
|
json_token_literal); |
|
637
|
|
|
|
|
|
|
#else |
|
638
|
2
|
|
|
|
|
|
return; |
|
639
|
|
|
|
|
|
|
#endif |
|
640
|
|
|
|
|
|
|
} |
|
641
|
0
|
|
|
|
|
|
FAILLITERAL ('e'); |
|
642
|
|
|
|
|
|
|
} |
|
643
|
0
|
|
|
|
|
|
FAILLITERAL ('s'); |
|
644
|
|
|
|
|
|
|
} |
|
645
|
0
|
|
|
|
|
|
FAILLITERAL ('l'); |
|
646
|
|
|
|
|
|
|
} |
|
647
|
0
|
|
|
|
|
|
FAILLITERAL ('a'); |
|
648
|
|
|
|
|
|
|
} |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
static SVPTR |
|
651
|
13
|
|
|
|
|
|
PREFIX (literal_null) (json_parse_t * parser) |
|
652
|
|
|
|
|
|
|
{ |
|
653
|
|
|
|
|
|
|
unsigned char * start; |
|
654
|
13
|
|
|
|
|
|
start = parser->end - 1; |
|
655
|
13
|
50
|
|
|
|
|
if (* parser->end++ == 'u') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
656
|
13
|
50
|
|
|
|
|
if (* parser->end++ == 'l') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
657
|
13
|
50
|
|
|
|
|
if (* parser->end++ == 'l') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
#ifdef PERLING |
|
659
|
10
|
100
|
|
|
|
|
if (parser->user_null) { |
|
660
|
3
|
|
|
|
|
|
return newSVsv (parser->user_null); |
|
661
|
|
|
|
|
|
|
} |
|
662
|
7
|
100
|
|
|
|
|
else if (parser->copy_literals) { |
|
663
|
3
|
|
|
|
|
|
return newSVsv (&PL_sv_undef); |
|
664
|
|
|
|
|
|
|
} |
|
665
|
|
|
|
|
|
|
else { |
|
666
|
4
|
|
|
|
|
|
SvREFCNT_inc (json_null); |
|
667
|
4
|
|
|
|
|
|
return json_null; |
|
668
|
|
|
|
|
|
|
} |
|
669
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
670
|
0
|
|
|
|
|
|
return json_token_new (parser, start, parser-> end - 1, |
|
671
|
|
|
|
|
|
|
json_token_literal); |
|
672
|
|
|
|
|
|
|
#else |
|
673
|
3
|
|
|
|
|
|
return; |
|
674
|
|
|
|
|
|
|
#endif |
|
675
|
|
|
|
|
|
|
} |
|
676
|
0
|
|
|
|
|
|
FAILLITERAL ('l'); |
|
677
|
|
|
|
|
|
|
} |
|
678
|
0
|
|
|
|
|
|
FAILLITERAL ('l'); |
|
679
|
|
|
|
|
|
|
} |
|
680
|
0
|
|
|
|
|
|
FAILLITERAL ('u'); |
|
681
|
|
|
|
|
|
|
} |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
static SVPTR PREFIX (object) (json_parse_t * parser); |
|
684
|
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
/* Given one character, decide what to do next. This goes in the |
|
686
|
|
|
|
|
|
|
switch statement in both "object ()" and "array ()". */ |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
#define PARSE(start,expected) \ |
|
689
|
|
|
|
|
|
|
\ |
|
690
|
|
|
|
|
|
|
case WHITESPACE: \ |
|
691
|
|
|
|
|
|
|
goto start; \ |
|
692
|
|
|
|
|
|
|
\ |
|
693
|
|
|
|
|
|
|
case '"': \ |
|
694
|
|
|
|
|
|
|
SETVALUE PREFIX (string) (parser); \ |
|
695
|
|
|
|
|
|
|
break; \ |
|
696
|
|
|
|
|
|
|
\ |
|
697
|
|
|
|
|
|
|
case '-': \ |
|
698
|
|
|
|
|
|
|
case DIGIT: \ |
|
699
|
|
|
|
|
|
|
parser->end_expected = expected; \ |
|
700
|
|
|
|
|
|
|
SETVALUE PREFIX (number) (parser); \ |
|
701
|
|
|
|
|
|
|
break; \ |
|
702
|
|
|
|
|
|
|
\ |
|
703
|
|
|
|
|
|
|
case '{': \ |
|
704
|
|
|
|
|
|
|
INCDEPTH; \ |
|
705
|
|
|
|
|
|
|
SETVALUE PREFIX (object) (parser); \ |
|
706
|
|
|
|
|
|
|
break; \ |
|
707
|
|
|
|
|
|
|
\ |
|
708
|
|
|
|
|
|
|
case '[': \ |
|
709
|
|
|
|
|
|
|
INCDEPTH; \ |
|
710
|
|
|
|
|
|
|
SETVALUE PREFIX (array) (parser); \ |
|
711
|
|
|
|
|
|
|
break; \ |
|
712
|
|
|
|
|
|
|
\ |
|
713
|
|
|
|
|
|
|
case 'f': \ |
|
714
|
|
|
|
|
|
|
SETVALUE PREFIX (literal_false) (parser); \ |
|
715
|
|
|
|
|
|
|
break; \ |
|
716
|
|
|
|
|
|
|
\ |
|
717
|
|
|
|
|
|
|
case 'n': \ |
|
718
|
|
|
|
|
|
|
SETVALUE PREFIX (literal_null) (parser); \ |
|
719
|
|
|
|
|
|
|
break; \ |
|
720
|
|
|
|
|
|
|
\ |
|
721
|
|
|
|
|
|
|
case 't': \ |
|
722
|
|
|
|
|
|
|
SETVALUE PREFIX (literal_true) (parser); \ |
|
723
|
|
|
|
|
|
|
break |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
#define FAILARRAY(err) \ |
|
726
|
|
|
|
|
|
|
parser->bad_byte = parser->end - 1; \ |
|
727
|
|
|
|
|
|
|
parser->bad_type = json_array; \ |
|
728
|
|
|
|
|
|
|
parser->bad_beginning = start; \ |
|
729
|
|
|
|
|
|
|
parser->error = json_error_ ## err; \ |
|
730
|
|
|
|
|
|
|
failbadinput (parser) |
|
731
|
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
/* We have seen "[", so now deal with the contents of an array. At the |
|
733
|
|
|
|
|
|
|
end of this routine, "parser->end" is pointing one beyond the final |
|
734
|
|
|
|
|
|
|
"]" of the array. */ |
|
735
|
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
static SVPTR |
|
737
|
159
|
|
|
|
|
|
PREFIX (array) (json_parse_t * parser) |
|
738
|
|
|
|
|
|
|
{ |
|
739
|
|
|
|
|
|
|
unsigned char c; |
|
740
|
|
|
|
|
|
|
unsigned char * start; |
|
741
|
|
|
|
|
|
|
#ifdef PERLING |
|
742
|
|
|
|
|
|
|
AV * av; |
|
743
|
63
|
|
|
|
|
|
SV * value = & PL_sv_undef; |
|
744
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
745
|
|
|
|
|
|
|
json_token_t * av; |
|
746
|
|
|
|
|
|
|
json_token_t * prev; |
|
747
|
|
|
|
|
|
|
json_token_t * value; |
|
748
|
|
|
|
|
|
|
#endif |
|
749
|
|
|
|
|
|
|
|
|
750
|
94
|
|
|
|
|
|
start = parser->end - 1; |
|
751
|
|
|
|
|
|
|
#ifdef PERLING |
|
752
|
63
|
|
|
|
|
|
av = newAV (); |
|
753
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
754
|
2
|
|
|
|
|
|
av = json_token_new (parser, start, 0, json_token_array); |
|
755
|
2
|
|
|
|
|
|
prev = 0; |
|
756
|
|
|
|
|
|
|
#endif |
|
757
|
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
array_start: |
|
759
|
|
|
|
|
|
|
|
|
760
|
527
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
761
|
|
|
|
|
|
|
|
|
762
|
520
|
50
|
|
|
|
|
PARSE (array_start, XARRAY_END); |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
case ']': |
|
765
|
3
|
|
|
|
|
|
goto array_end; |
|
766
|
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
default: |
|
768
|
4
|
|
|
|
|
|
parser->expected = VALUE_START | XWHITESPACE | XARRAY_END; |
|
769
|
4
|
|
|
|
|
|
FAILARRAY (unexpected_character); |
|
770
|
|
|
|
|
|
|
} |
|
771
|
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
#ifdef PERLING |
|
773
|
59
|
|
|
|
|
|
av_push (av, value); |
|
774
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
775
|
2
|
|
|
|
|
|
prev = json_token_set_child (parser, av, value); |
|
776
|
|
|
|
|
|
|
#endif |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
/* Accept either a comma or whitespace or the end of the array. */ |
|
779
|
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
array_middle: |
|
781
|
|
|
|
|
|
|
|
|
782
|
737
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
783
|
|
|
|
|
|
|
|
|
784
|
38
|
|
|
|
|
|
case WHITESPACE: |
|
785
|
254
|
|
|
|
|
|
goto array_middle; |
|
786
|
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
case ',': |
|
788
|
|
|
|
|
|
|
#ifdef TOKENING |
|
789
|
4
|
|
|
|
|
|
value = json_token_new (parser, parser->end - 1, |
|
790
|
4
|
|
|
|
|
|
parser->end - 1, |
|
791
|
|
|
|
|
|
|
json_token_comma); |
|
792
|
4
|
|
|
|
|
|
prev = json_token_set_next (prev, value); |
|
793
|
|
|
|
|
|
|
#endif |
|
794
|
383
|
|
|
|
|
|
goto array_next; |
|
795
|
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
case ']': |
|
797
|
|
|
|
|
|
|
/* Array with at least one element. */ |
|
798
|
94
|
|
|
|
|
|
goto array_end; |
|
799
|
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
default: |
|
801
|
|
|
|
|
|
|
|
|
802
|
6
|
|
|
|
|
|
parser->expected = XWHITESPACE | XCOMMA | XARRAY_END; |
|
803
|
6
|
|
|
|
|
|
FAILARRAY (unexpected_character); |
|
804
|
|
|
|
|
|
|
} |
|
805
|
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
array_next: |
|
807
|
|
|
|
|
|
|
|
|
808
|
955
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
809
|
|
|
|
|
|
|
|
|
810
|
953
|
50
|
|
|
|
|
PARSE (array_next, XARRAY_END); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
default: |
|
813
|
2
|
|
|
|
|
|
parser->expected = VALUE_START | XWHITESPACE; |
|
814
|
2
|
|
|
|
|
|
FAILARRAY (unexpected_character); |
|
815
|
|
|
|
|
|
|
} |
|
816
|
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
#ifdef PERLING |
|
818
|
362
|
|
|
|
|
|
av_push (av, value); |
|
819
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
820
|
4
|
|
|
|
|
|
prev = json_token_set_next (prev, value); |
|
821
|
|
|
|
|
|
|
#endif |
|
822
|
|
|
|
|
|
|
|
|
823
|
379
|
|
|
|
|
|
goto array_middle; |
|
824
|
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
array_end: |
|
826
|
97
|
|
|
|
|
|
DECDEPTH; |
|
827
|
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
#ifdef PERLING |
|
829
|
60
|
|
|
|
|
|
return newRV_noinc ((SV *) av); |
|
830
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
831
|
|
|
|
|
|
|
/* We didn't know where the end was until now. */ |
|
832
|
2
|
|
|
|
|
|
json_token_set_end (parser, av, parser->end - 1); |
|
833
|
2
|
|
|
|
|
|
return av; |
|
834
|
|
|
|
|
|
|
#else |
|
835
|
35
|
|
|
|
|
|
return; |
|
836
|
|
|
|
|
|
|
#endif |
|
837
|
|
|
|
|
|
|
} |
|
838
|
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
#define FAILOBJECT(err) \ |
|
840
|
|
|
|
|
|
|
parser->bad_byte = parser->end - 1; \ |
|
841
|
|
|
|
|
|
|
parser->bad_type = json_object; \ |
|
842
|
|
|
|
|
|
|
parser->bad_beginning = start; \ |
|
843
|
|
|
|
|
|
|
parser->error = json_error_ ## err; \ |
|
844
|
|
|
|
|
|
|
failbadinput (parser) |
|
845
|
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
/* We have seen "{", so now deal with the contents of an object. At |
|
847
|
|
|
|
|
|
|
the end of this routine, "parser->end" is pointing one beyond the |
|
848
|
|
|
|
|
|
|
final "}" of the object. */ |
|
849
|
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
static SVPTR |
|
851
|
123
|
|
|
|
|
|
PREFIX (object) (json_parse_t * parser) |
|
852
|
|
|
|
|
|
|
{ |
|
853
|
|
|
|
|
|
|
char c; |
|
854
|
|
|
|
|
|
|
#ifdef PERLING |
|
855
|
|
|
|
|
|
|
HV * hv; |
|
856
|
|
|
|
|
|
|
SV * value; |
|
857
|
|
|
|
|
|
|
/* This is set to -1 if we want a Unicode key. See "perldoc |
|
858
|
|
|
|
|
|
|
perlapi" under "hv_store". */ |
|
859
|
|
|
|
|
|
|
int uniflag; |
|
860
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
861
|
|
|
|
|
|
|
json_token_t * hv; |
|
862
|
|
|
|
|
|
|
json_token_t * value; |
|
863
|
|
|
|
|
|
|
json_token_t * prev; |
|
864
|
|
|
|
|
|
|
#endif |
|
865
|
|
|
|
|
|
|
string_t key; |
|
866
|
|
|
|
|
|
|
/* Start of parsing. */ |
|
867
|
|
|
|
|
|
|
unsigned char * start; |
|
868
|
|
|
|
|
|
|
|
|
869
|
54
|
|
|
|
|
|
start = parser->end - 1; |
|
870
|
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
#ifdef PERLING |
|
872
|
61
|
100
|
|
|
|
|
if (parser->unicode || parser->upgrade_utf8) { |
|
|
|
100
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
/* Keys are unicode. */ |
|
874
|
21
|
|
|
|
|
|
uniflag = -1; |
|
875
|
|
|
|
|
|
|
} |
|
876
|
|
|
|
|
|
|
else { |
|
877
|
|
|
|
|
|
|
/* Keys are not unicode. */ |
|
878
|
40
|
|
|
|
|
|
uniflag = 1; |
|
879
|
|
|
|
|
|
|
} |
|
880
|
61
|
|
|
|
|
|
hv = newHV (); |
|
881
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
882
|
8
|
|
|
|
|
|
hv = json_token_new (parser, start, 0, json_token_object); |
|
883
|
8
|
|
|
|
|
|
prev = 0; |
|
884
|
|
|
|
|
|
|
#endif |
|
885
|
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
hash_start: |
|
887
|
|
|
|
|
|
|
|
|
888
|
379
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
889
|
32
|
|
|
|
|
|
case WHITESPACE: |
|
890
|
256
|
|
|
|
|
|
goto hash_start; |
|
891
|
|
|
|
|
|
|
case '}': |
|
892
|
3
|
|
|
|
|
|
goto hash_end; |
|
893
|
|
|
|
|
|
|
case '"': |
|
894
|
|
|
|
|
|
|
#ifdef TOKENING |
|
895
|
8
|
|
|
|
|
|
value = json_token_new (parser, parser->end - 1, 0, |
|
896
|
|
|
|
|
|
|
json_token_string); |
|
897
|
|
|
|
|
|
|
/* We only come past the label "hash_start" once, so we don't |
|
898
|
|
|
|
|
|
|
need to check that there is not already a child. */ |
|
899
|
8
|
|
|
|
|
|
json_token_set_child (parser, hv, value); |
|
900
|
8
|
|
|
|
|
|
prev = value; |
|
901
|
|
|
|
|
|
|
#endif |
|
902
|
116
|
|
|
|
|
|
get_key_string (parser, & key); |
|
903
|
|
|
|
|
|
|
#ifdef TOKENING |
|
904
|
|
|
|
|
|
|
/* We didn't know where the end of the string was until now so |
|
905
|
|
|
|
|
|
|
we wait until after "get_key_string" to set the end. */ |
|
906
|
8
|
|
|
|
|
|
json_token_set_end (parser, value, parser->end - 1); |
|
907
|
|
|
|
|
|
|
#endif |
|
908
|
114
|
|
|
|
|
|
goto hash_next; |
|
909
|
|
|
|
|
|
|
default: |
|
910
|
4
|
|
|
|
|
|
parser->expected = XWHITESPACE | XSTRING_START | XOBJECT_END; |
|
911
|
4
|
|
|
|
|
|
FAILOBJECT (unexpected_character); |
|
912
|
|
|
|
|
|
|
} |
|
913
|
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
hash_middle: |
|
915
|
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
/* We are in the middle of a hash. We have seen a key:value pair, |
|
917
|
|
|
|
|
|
|
and now we're looking for either a comma and then another |
|
918
|
|
|
|
|
|
|
key-value pair, or a closing curly brace and the end of the |
|
919
|
|
|
|
|
|
|
hash. */ |
|
920
|
|
|
|
|
|
|
|
|
921
|
763
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
922
|
30
|
|
|
|
|
|
case WHITESPACE: |
|
923
|
150
|
|
|
|
|
|
goto hash_middle; |
|
924
|
|
|
|
|
|
|
case '}': |
|
925
|
82
|
|
|
|
|
|
goto hash_end; |
|
926
|
|
|
|
|
|
|
case ',': |
|
927
|
|
|
|
|
|
|
#ifdef TOKENING |
|
928
|
16
|
|
|
|
|
|
value = json_token_new (parser, parser->end - 1, |
|
929
|
16
|
|
|
|
|
|
parser->end - 1, |
|
930
|
|
|
|
|
|
|
json_token_comma); |
|
931
|
16
|
|
|
|
|
|
prev = json_token_set_next (prev, value); |
|
932
|
|
|
|
|
|
|
#endif |
|
933
|
526
|
|
|
|
|
|
goto hash_key; |
|
934
|
|
|
|
|
|
|
default: |
|
935
|
5
|
|
|
|
|
|
parser->expected = XWHITESPACE | XCOMMA | XOBJECT_END; |
|
936
|
5
|
|
|
|
|
|
FAILOBJECT (unexpected_character); |
|
937
|
|
|
|
|
|
|
} |
|
938
|
|
|
|
|
|
|
|
|
939
|
|
|
|
|
|
|
hash_key: |
|
940
|
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
/* We're looking for a key in the hash, which is a string starting |
|
942
|
|
|
|
|
|
|
with a double quotation mark. */ |
|
943
|
|
|
|
|
|
|
|
|
944
|
1727
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
945
|
464
|
|
|
|
|
|
case WHITESPACE: |
|
946
|
1201
|
|
|
|
|
|
goto hash_key; |
|
947
|
|
|
|
|
|
|
case '"': |
|
948
|
|
|
|
|
|
|
#ifdef TOKENING |
|
949
|
16
|
|
|
|
|
|
value = json_token_new (parser, parser->end - 1, 0, |
|
950
|
|
|
|
|
|
|
json_token_string); |
|
951
|
16
|
|
|
|
|
|
prev = json_token_set_next (prev, value); |
|
952
|
|
|
|
|
|
|
#endif |
|
953
|
524
|
|
|
|
|
|
get_key_string (parser, & key); |
|
954
|
|
|
|
|
|
|
#ifdef TOKENING |
|
955
|
|
|
|
|
|
|
/* We didn't know where the end of the string was until now so |
|
956
|
|
|
|
|
|
|
we wait until after "get_key_string" to set the end. */ |
|
957
|
16
|
|
|
|
|
|
json_token_set_end (parser, value, parser->end - 1); |
|
958
|
|
|
|
|
|
|
#endif |
|
959
|
524
|
|
|
|
|
|
goto hash_next; |
|
960
|
|
|
|
|
|
|
default: |
|
961
|
2
|
|
|
|
|
|
parser->expected = XWHITESPACE | XSTRING_START; |
|
962
|
2
|
|
|
|
|
|
FAILOBJECT (unexpected_character); |
|
963
|
|
|
|
|
|
|
} |
|
964
|
|
|
|
|
|
|
|
|
965
|
|
|
|
|
|
|
hash_next: |
|
966
|
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
/* We've seen a key, now we're looking for a colon. */ |
|
968
|
|
|
|
|
|
|
|
|
969
|
724
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
970
|
2
|
|
|
|
|
|
case WHITESPACE: |
|
971
|
86
|
|
|
|
|
|
goto hash_next; |
|
972
|
|
|
|
|
|
|
case ':': |
|
973
|
|
|
|
|
|
|
#ifdef TOKENING |
|
974
|
24
|
|
|
|
|
|
value = json_token_new (parser, parser->end - 1, |
|
975
|
24
|
|
|
|
|
|
parser->end - 1, |
|
976
|
|
|
|
|
|
|
json_token_colon); |
|
977
|
24
|
|
|
|
|
|
prev = json_token_set_next (prev, value); |
|
978
|
|
|
|
|
|
|
#endif |
|
979
|
636
|
|
|
|
|
|
goto hash_value; |
|
980
|
|
|
|
|
|
|
default: |
|
981
|
2
|
|
|
|
|
|
parser->expected = XWHITESPACE | XVALUE_SEPARATOR; |
|
982
|
2
|
|
|
|
|
|
FAILOBJECT (unexpected_character); |
|
983
|
|
|
|
|
|
|
} |
|
984
|
|
|
|
|
|
|
|
|
985
|
|
|
|
|
|
|
hash_value: |
|
986
|
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
/* We've seen a colon, now we're looking for a value, which can be |
|
988
|
|
|
|
|
|
|
anything at all, including another hash. Most of the cases are |
|
989
|
|
|
|
|
|
|
dealt with in the PARSE macro. */ |
|
990
|
|
|
|
|
|
|
|
|
991
|
771
|
|
|
|
|
|
switch (NEXTBYTE) { |
|
992
|
767
|
50
|
|
|
|
|
PARSE (hash_value, XOBJECT_END); |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
default: |
|
994
|
4
|
|
|
|
|
|
parser->expected = XWHITESPACE | VALUE_START; |
|
995
|
4
|
|
|
|
|
|
FAILOBJECT (unexpected_character); |
|
996
|
|
|
|
|
|
|
} |
|
997
|
|
|
|
|
|
|
|
|
998
|
616
|
100
|
|
|
|
|
if (key.contains_escapes) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
999
|
|
|
|
|
|
|
|
|
1000
|
|
|
|
|
|
|
/* The key had something like "\n" in it, so we can't just |
|
1001
|
|
|
|
|
|
|
copy the value but have to process it to remove the |
|
1002
|
|
|
|
|
|
|
escapes. */ |
|
1003
|
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
#ifdef PERLING |
|
1005
|
|
|
|
|
|
|
int klen; |
|
1006
|
3
|
|
|
|
|
|
klen = resolve_string (parser, & key); |
|
1007
|
3
|
|
|
|
|
|
key.start = parser->buffer; |
|
1008
|
3
|
|
|
|
|
|
key.length = klen; |
|
1009
|
|
|
|
|
|
|
#else |
|
1010
|
2
|
|
|
|
|
|
resolve_string (parser, & key); |
|
1011
|
|
|
|
|
|
|
#endif |
|
1012
|
|
|
|
|
|
|
} |
|
1013
|
|
|
|
|
|
|
#ifdef PERLING |
|
1014
|
198
|
100
|
|
|
|
|
if (parser->detect_collisions) { |
|
1015
|
|
|
|
|
|
|
/* Look in hv for an existing key with our values. */ |
|
1016
|
|
|
|
|
|
|
SV ** sv_ptr; |
|
1017
|
21
|
|
|
|
|
|
sv_ptr = hv_fetch (hv, (char *) key.start, key.length * uniflag, 0); |
|
1018
|
21
|
100
|
|
|
|
|
if (sv_ptr) { |
|
1019
|
3
|
|
|
|
|
|
parser->bad_byte = key.start; |
|
1020
|
3
|
|
|
|
|
|
parser->bad_length = key.length; |
|
1021
|
3
|
|
|
|
|
|
parser->bad_type = json_object; |
|
1022
|
3
|
|
|
|
|
|
parser->bad_beginning = start; |
|
1023
|
3
|
|
|
|
|
|
parser->error = json_error_name_is_not_unique; |
|
1024
|
3
|
|
|
|
|
|
failbadinput (parser); |
|
1025
|
|
|
|
|
|
|
} |
|
1026
|
|
|
|
|
|
|
} |
|
1027
|
195
|
|
|
|
|
|
(void) hv_store (hv, (char *) key.start, key.length * uniflag, value, 0); |
|
1028
|
|
|
|
|
|
|
#endif |
|
1029
|
|
|
|
|
|
|
|
|
1030
|
|
|
|
|
|
|
#if defined(TOKENING) |
|
1031
|
24
|
|
|
|
|
|
prev = json_token_set_next (prev, value); |
|
1032
|
|
|
|
|
|
|
#endif |
|
1033
|
613
|
|
|
|
|
|
goto hash_middle; |
|
1034
|
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
hash_end: |
|
1036
|
85
|
|
|
|
|
|
DECDEPTH; |
|
1037
|
|
|
|
|
|
|
|
|
1038
|
|
|
|
|
|
|
#ifdef PERLING |
|
1039
|
56
|
|
|
|
|
|
return newRV_noinc ((SV *) hv); |
|
1040
|
|
|
|
|
|
|
#elif defined (TOKENING) |
|
1041
|
8
|
|
|
|
|
|
json_token_set_end (parser, hv, parser->end - 1); |
|
1042
|
8
|
|
|
|
|
|
return hv; |
|
1043
|
|
|
|
|
|
|
#else |
|
1044
|
21
|
|
|
|
|
|
return; |
|
1045
|
|
|
|
|
|
|
#endif |
|
1046
|
|
|
|
|
|
|
} |
|
1047
|
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
#undef PREFIX |
|
1049
|
|
|
|
|
|
|
#undef SVPTR |
|
1050
|
|
|
|
|
|
|
#undef SETVALUE |
|
1051
|
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
#ifdef PERLING |
|
1053
|
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
/* Set and delete user-defined literals. */ |
|
1055
|
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
static void |
|
1057
|
13
|
|
|
|
|
|
json_parse_delete_true (json_parse_t * parser) |
|
1058
|
|
|
|
|
|
|
{ |
|
1059
|
13
|
100
|
|
|
|
|
if (parser->user_true) { |
|
1060
|
4
|
|
|
|
|
|
SvREFCNT_dec (parser->user_true); |
|
1061
|
4
|
|
|
|
|
|
parser->user_true = 0; |
|
1062
|
|
|
|
|
|
|
} |
|
1063
|
13
|
|
|
|
|
|
} |
|
1064
|
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
static void |
|
1066
|
4
|
|
|
|
|
|
json_parse_set_true (json_parse_t * parser, SV * user_true) |
|
1067
|
|
|
|
|
|
|
{ |
|
1068
|
4
|
|
|
|
|
|
json_parse_delete_true (parser); |
|
1069
|
4
|
50
|
|
|
|
|
if (! SvTRUE (user_true) && ! parser->no_warn_literals) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1070
|
3
|
|
|
|
|
|
warn ("User-defined value for JSON true evaluates as false"); |
|
1071
|
|
|
|
|
|
|
} |
|
1072
|
4
|
50
|
|
|
|
|
if (parser->copy_literals && ! parser->no_warn_literals) { |
|
|
|
0
|
|
|
|
|
|
|
1073
|
0
|
|
|
|
|
|
warn ("User-defined value overrules copy_literals"); |
|
1074
|
|
|
|
|
|
|
} |
|
1075
|
4
|
|
|
|
|
|
parser->user_true = user_true; |
|
1076
|
4
|
|
|
|
|
|
SvREFCNT_inc (user_true); |
|
1077
|
4
|
|
|
|
|
|
} |
|
1078
|
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
static void |
|
1080
|
14
|
|
|
|
|
|
json_parse_delete_false (json_parse_t * parser) |
|
1081
|
|
|
|
|
|
|
{ |
|
1082
|
14
|
100
|
|
|
|
|
if (parser->user_false) { |
|
1083
|
5
|
|
|
|
|
|
SvREFCNT_dec (parser->user_false); |
|
1084
|
5
|
|
|
|
|
|
parser->user_false = 0; |
|
1085
|
|
|
|
|
|
|
} |
|
1086
|
14
|
|
|
|
|
|
} |
|
1087
|
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
static void |
|
1089
|
5
|
|
|
|
|
|
json_parse_set_false (json_parse_t * parser, SV * user_false) |
|
1090
|
|
|
|
|
|
|
{ |
|
1091
|
5
|
|
|
|
|
|
json_parse_delete_false (parser); |
|
1092
|
5
|
50
|
|
|
|
|
if (SvTRUE (user_false) && ! parser->no_warn_literals) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1093
|
1
|
|
|
|
|
|
warn ("User-defined value for JSON false evaluates as true"); |
|
1094
|
|
|
|
|
|
|
} |
|
1095
|
5
|
50
|
|
|
|
|
if (parser->copy_literals && ! parser->no_warn_literals) { |
|
|
|
0
|
|
|
|
|
|
|
1096
|
0
|
|
|
|
|
|
warn ("User-defined value overrules copy_literals"); |
|
1097
|
|
|
|
|
|
|
} |
|
1098
|
5
|
|
|
|
|
|
parser->user_false = user_false; |
|
1099
|
5
|
|
|
|
|
|
SvREFCNT_inc (user_false); |
|
1100
|
5
|
|
|
|
|
|
} |
|
1101
|
|
|
|
|
|
|
|
|
1102
|
|
|
|
|
|
|
static void |
|
1103
|
13
|
|
|
|
|
|
json_parse_delete_null (json_parse_t * parser) |
|
1104
|
|
|
|
|
|
|
{ |
|
1105
|
13
|
100
|
|
|
|
|
if (parser->user_null) { |
|
1106
|
4
|
|
|
|
|
|
SvREFCNT_dec (parser->user_null); |
|
1107
|
4
|
|
|
|
|
|
parser->user_null = 0; |
|
1108
|
|
|
|
|
|
|
} |
|
1109
|
13
|
|
|
|
|
|
} |
|
1110
|
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
static void |
|
1112
|
4
|
|
|
|
|
|
json_parse_set_null (json_parse_t * parser, SV * user_null) |
|
1113
|
|
|
|
|
|
|
{ |
|
1114
|
4
|
50
|
|
|
|
|
if (parser->copy_literals && ! parser->no_warn_literals) { |
|
|
|
0
|
|
|
|
|
|
|
1115
|
0
|
|
|
|
|
|
warn ("User-defined value overrules copy_literals"); |
|
1116
|
|
|
|
|
|
|
} |
|
1117
|
4
|
|
|
|
|
|
json_parse_delete_null (parser); |
|
1118
|
4
|
|
|
|
|
|
parser->user_null = user_null; |
|
1119
|
4
|
|
|
|
|
|
SvREFCNT_inc (user_null); |
|
1120
|
4
|
|
|
|
|
|
} |
|
1121
|
|
|
|
|
|
|
|
|
1122
|
|
|
|
|
|
|
static void |
|
1123
|
8
|
|
|
|
|
|
json_parse_free (json_parse_t * parser) |
|
1124
|
|
|
|
|
|
|
{ |
|
1125
|
|
|
|
|
|
|
/* We can get here with depth > 0 if the parser fails and then the |
|
1126
|
|
|
|
|
|
|
error is caught. */ |
|
1127
|
8
|
50
|
|
|
|
|
if (parser->depth < 0) { |
|
1128
|
0
|
|
|
|
|
|
warn ("Parser depth underflow %d", parser->depth); |
|
1129
|
|
|
|
|
|
|
} |
|
1130
|
8
|
|
|
|
|
|
json_parse_delete_true (parser); |
|
1131
|
8
|
|
|
|
|
|
json_parse_delete_false (parser); |
|
1132
|
8
|
|
|
|
|
|
json_parse_delete_null (parser); |
|
1133
|
8
|
|
|
|
|
|
Safefree (parser); |
|
1134
|
8
|
|
|
|
|
|
} |
|
1135
|
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
static void |
|
1137
|
4
|
|
|
|
|
|
json_parse_copy_literals (json_parse_t * parser, SV * onoff) |
|
1138
|
|
|
|
|
|
|
{ |
|
1139
|
4
|
100
|
|
|
|
|
if (! parser->no_warn_literals && |
|
|
|
50
|
|
|
|
|
|
|
1140
|
3
|
50
|
|
|
|
|
(parser->user_true || parser->user_false || parser->user_null)) { |
|
|
|
50
|
|
|
|
|
|
|
1141
|
0
|
|
|
|
|
|
warn ("User-defined value overrules copy_literals"); |
|
1142
|
|
|
|
|
|
|
} |
|
1143
|
4
|
50
|
|
|
|
|
parser->copy_literals = SvTRUE (onoff) ? 1 : 0; |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1144
|
4
|
|
|
|
|
|
} |
|
1145
|
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
#endif /* def PERLING */ |