… | |
… | |
27 | #define F_SPACE_AFTER 0x00000040UL |
27 | #define F_SPACE_AFTER 0x00000040UL |
28 | #define F_ALLOW_NONREF 0x00000100UL |
28 | #define F_ALLOW_NONREF 0x00000100UL |
29 | #define F_SHRINK 0x00000200UL |
29 | #define F_SHRINK 0x00000200UL |
30 | #define F_ALLOW_BLESSED 0x00000400UL |
30 | #define F_ALLOW_BLESSED 0x00000400UL |
31 | #define F_CONV_BLESSED 0x00000800UL |
31 | #define F_CONV_BLESSED 0x00000800UL |
|
|
32 | #define F_RELAXED 0x00001000UL |
|
|
33 | |
32 | #define F_MAXDEPTH 0xf8000000UL |
34 | #define F_MAXDEPTH 0xf8000000UL |
33 | #define S_MAXDEPTH 27 |
35 | #define S_MAXDEPTH 27 |
34 | #define F_MAXSIZE 0x01f00000UL |
36 | #define F_MAXSIZE 0x01f00000UL |
35 | #define S_MAXSIZE 20 |
37 | #define S_MAXSIZE 20 |
36 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
38 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
… | |
… | |
48 | |
50 | |
49 | #define SB do { |
51 | #define SB do { |
50 | #define SE } while (0) |
52 | #define SE } while (0) |
51 | |
53 | |
52 | #if __GNUC__ >= 3 |
54 | #if __GNUC__ >= 3 |
53 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
55 | # define expect(expr,value) __builtin_expect ((expr), (value)) |
54 | # define inline inline |
56 | # define INLINE static inline |
55 | #else |
57 | #else |
56 | # define expect(expr,value) (expr) |
58 | # define expect(expr,value) (expr) |
57 | # define inline static |
59 | # define INLINE static |
58 | #endif |
60 | #endif |
59 | |
61 | |
60 | #define expect_false(expr) expect ((expr) != 0, 0) |
62 | #define expect_false(expr) expect ((expr) != 0, 0) |
61 | #define expect_true(expr) expect ((expr) != 0, 1) |
63 | #define expect_true(expr) expect ((expr) != 0, 1) |
62 | |
64 | |
|
|
65 | #define IN_RANGE_INC(type,val,beg,end) \ |
|
|
66 | ((unsigned type)((unsigned type)(val) - (unsigned type)(beg)) \ |
|
|
67 | <= (unsigned type)((unsigned type)(end) - (unsigned type)(beg))) |
|
|
68 | |
63 | #ifdef USE_ITHREADS |
69 | #ifdef USE_ITHREADS |
64 | # define JSON_SLOW 1 |
70 | # define JSON_SLOW 1 |
|
|
71 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
65 | #else |
72 | #else |
66 | # define JSON_SLOW 0 |
73 | # define JSON_SLOW 0 |
|
|
74 | # define JSON_STASH json_stash |
67 | #endif |
75 | #endif |
68 | |
76 | |
69 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
77 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
70 | static SV *json_true, *json_false; |
78 | static SV *json_true, *json_false; |
71 | |
79 | |
… | |
… | |
76 | } JSON; |
84 | } JSON; |
77 | |
85 | |
78 | ///////////////////////////////////////////////////////////////////////////// |
86 | ///////////////////////////////////////////////////////////////////////////// |
79 | // utility functions |
87 | // utility functions |
80 | |
88 | |
81 | inline void |
89 | INLINE void |
82 | shrink (SV *sv) |
90 | shrink (SV *sv) |
83 | { |
91 | { |
84 | sv_utf8_downgrade (sv, 1); |
92 | sv_utf8_downgrade (sv, 1); |
85 | if (SvLEN (sv) > SvCUR (sv) + 1) |
93 | if (SvLEN (sv) > SvCUR (sv) + 1) |
86 | { |
94 | { |
… | |
… | |
95 | // decode an utf-8 character and return it, or (UV)-1 in |
103 | // decode an utf-8 character and return it, or (UV)-1 in |
96 | // case of an error. |
104 | // case of an error. |
97 | // we special-case "safe" characters from U+80 .. U+7FF, |
105 | // we special-case "safe" characters from U+80 .. U+7FF, |
98 | // but use the very good perl function to parse anything else. |
106 | // but use the very good perl function to parse anything else. |
99 | // note that we never call this function for a ascii codepoints |
107 | // note that we never call this function for a ascii codepoints |
100 | inline UV |
108 | INLINE UV |
101 | decode_utf8 (unsigned char *s, STRLEN len, STRLEN *clen) |
109 | decode_utf8 (unsigned char *s, STRLEN len, STRLEN *clen) |
102 | { |
110 | { |
103 | if (expect_false (s[0] > 0xdf || s[0] < 0xc2)) |
111 | if (expect_true (len >= 2 |
104 | return utf8n_to_uvuni (s, len, clen, UTF8_CHECK_ONLY); |
112 | && IN_RANGE_INC (char, s[0], 0xc2, 0xdf) |
105 | else if (len > 1 && s[1] >= 0x80 && s[1] <= 0xbf) |
113 | && IN_RANGE_INC (char, s[1], 0x80, 0xbf))) |
106 | { |
114 | { |
107 | *clen = 2; |
115 | *clen = 2; |
108 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
116 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
109 | } |
117 | } |
110 | else |
118 | else |
111 | { |
119 | return utf8n_to_uvuni (s, len, clen, UTF8_CHECK_ONLY); |
112 | *clen = (STRLEN)-1; |
120 | } |
113 | return (UV)-1; |
121 | |
114 | } |
122 | // likewise for encoding, also never called for ascii codepoints |
|
|
123 | // this function takes advantage of this fact, although current gccs |
|
|
124 | // seem to optimise the check for >= 0x80 away anyways |
|
|
125 | INLINE unsigned char * |
|
|
126 | encode_utf8 (unsigned char *s, UV ch) |
|
|
127 | { |
|
|
128 | if (expect_false (ch < 0x000080)) |
|
|
129 | *s++ = ch; |
|
|
130 | else if (expect_true (ch < 0x000800)) |
|
|
131 | *s++ = 0xc0 | ( ch >> 6), |
|
|
132 | *s++ = 0x80 | ( ch & 0x3f); |
|
|
133 | else if ( ch < 0x010000) |
|
|
134 | *s++ = 0xe0 | ( ch >> 12), |
|
|
135 | *s++ = 0x80 | ((ch >> 6) & 0x3f), |
|
|
136 | *s++ = 0x80 | ( ch & 0x3f); |
|
|
137 | else if ( ch < 0x110000) |
|
|
138 | *s++ = 0xf0 | ( ch >> 18), |
|
|
139 | *s++ = 0x80 | ((ch >> 12) & 0x3f), |
|
|
140 | *s++ = 0x80 | ((ch >> 6) & 0x3f), |
|
|
141 | *s++ = 0x80 | ( ch & 0x3f); |
|
|
142 | |
|
|
143 | return s; |
115 | } |
144 | } |
116 | |
145 | |
117 | ///////////////////////////////////////////////////////////////////////////// |
146 | ///////////////////////////////////////////////////////////////////////////// |
118 | // encoder |
147 | // encoder |
119 | |
148 | |
… | |
… | |
124 | char *end; // SvEND (sv) |
153 | char *end; // SvEND (sv) |
125 | SV *sv; // result scalar |
154 | SV *sv; // result scalar |
126 | JSON json; |
155 | JSON json; |
127 | U32 indent; // indentation level |
156 | U32 indent; // indentation level |
128 | U32 maxdepth; // max. indentation/recursion level |
157 | U32 maxdepth; // max. indentation/recursion level |
|
|
158 | UV limit; // escape character values >= this value when encoding |
129 | } enc_t; |
159 | } enc_t; |
130 | |
160 | |
131 | inline void |
161 | INLINE void |
132 | need (enc_t *enc, STRLEN len) |
162 | need (enc_t *enc, STRLEN len) |
133 | { |
163 | { |
134 | if (expect_false (enc->cur + len >= enc->end)) |
164 | if (expect_false (enc->cur + len >= enc->end)) |
135 | { |
165 | { |
136 | STRLEN cur = enc->cur - SvPVX (enc->sv); |
166 | STRLEN cur = enc->cur - SvPVX (enc->sv); |
… | |
… | |
138 | enc->cur = SvPVX (enc->sv) + cur; |
168 | enc->cur = SvPVX (enc->sv) + cur; |
139 | enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; |
169 | enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; |
140 | } |
170 | } |
141 | } |
171 | } |
142 | |
172 | |
143 | inline void |
173 | INLINE void |
144 | encode_ch (enc_t *enc, char ch) |
174 | encode_ch (enc_t *enc, char ch) |
145 | { |
175 | { |
146 | need (enc, 1); |
176 | need (enc, 1); |
147 | *enc->cur++ = ch; |
177 | *enc->cur++ = ch; |
148 | } |
178 | } |
… | |
… | |
202 | { |
232 | { |
203 | uch = ch; |
233 | uch = ch; |
204 | clen = 1; |
234 | clen = 1; |
205 | } |
235 | } |
206 | |
236 | |
207 | if (uch > 0x10FFFFUL) |
237 | if (uch < 0x80/*0x20*/ || uch >= enc->limit) |
208 | croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch); |
|
|
209 | |
|
|
210 | if (uch < 0x80 || enc->json.flags & F_ASCII || (enc->json.flags & F_LATIN1 && uch > 0xFF)) |
|
|
211 | { |
238 | { |
212 | if (uch > 0xFFFFUL) |
239 | if (uch >= 0x10000UL) |
213 | { |
240 | { |
|
|
241 | if (uch >= 0x110000UL) |
|
|
242 | croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch); |
|
|
243 | |
214 | need (enc, len += 11); |
244 | need (enc, len += 11); |
215 | sprintf (enc->cur, "\\u%04x\\u%04x", |
245 | sprintf (enc->cur, "\\u%04x\\u%04x", |
216 | (int)((uch - 0x10000) / 0x400 + 0xD800), |
246 | (int)((uch - 0x10000) / 0x400 + 0xD800), |
217 | (int)((uch - 0x10000) % 0x400 + 0xDC00)); |
247 | (int)((uch - 0x10000) % 0x400 + 0xDC00)); |
218 | enc->cur += 12; |
248 | enc->cur += 12; |
… | |
… | |
246 | while (--clen); |
276 | while (--clen); |
247 | } |
277 | } |
248 | else |
278 | else |
249 | { |
279 | { |
250 | need (enc, len += UTF8_MAXBYTES - 1); // never more than 11 bytes needed |
280 | need (enc, len += UTF8_MAXBYTES - 1); // never more than 11 bytes needed |
251 | enc->cur = uvuni_to_utf8_flags (enc->cur, uch, 0); |
281 | enc->cur = encode_utf8 (enc->cur, uch); |
252 | ++str; |
282 | ++str; |
253 | } |
283 | } |
254 | } |
284 | } |
255 | } |
285 | } |
256 | } |
286 | } |
257 | |
287 | |
258 | --len; |
288 | --len; |
259 | } |
289 | } |
260 | } |
290 | } |
261 | |
291 | |
262 | inline void |
292 | INLINE void |
263 | encode_indent (enc_t *enc) |
293 | encode_indent (enc_t *enc) |
264 | { |
294 | { |
265 | if (enc->json.flags & F_INDENT) |
295 | if (enc->json.flags & F_INDENT) |
266 | { |
296 | { |
267 | int spaces = enc->indent * INDENT_STEP; |
297 | int spaces = enc->indent * INDENT_STEP; |
… | |
… | |
270 | memset (enc->cur, ' ', spaces); |
300 | memset (enc->cur, ' ', spaces); |
271 | enc->cur += spaces; |
301 | enc->cur += spaces; |
272 | } |
302 | } |
273 | } |
303 | } |
274 | |
304 | |
275 | inline void |
305 | INLINE void |
276 | encode_space (enc_t *enc) |
306 | encode_space (enc_t *enc) |
277 | { |
307 | { |
278 | need (enc, 1); |
308 | need (enc, 1); |
279 | encode_ch (enc, ' '); |
309 | encode_ch (enc, ' '); |
280 | } |
310 | } |
281 | |
311 | |
282 | inline void |
312 | INLINE void |
283 | encode_nl (enc_t *enc) |
313 | encode_nl (enc_t *enc) |
284 | { |
314 | { |
285 | if (enc->json.flags & F_INDENT) |
315 | if (enc->json.flags & F_INDENT) |
286 | { |
316 | { |
287 | need (enc, 1); |
317 | need (enc, 1); |
288 | encode_ch (enc, '\n'); |
318 | encode_ch (enc, '\n'); |
289 | } |
319 | } |
290 | } |
320 | } |
291 | |
321 | |
292 | inline void |
322 | INLINE void |
293 | encode_comma (enc_t *enc) |
323 | encode_comma (enc_t *enc) |
294 | { |
324 | { |
295 | encode_ch (enc, ','); |
325 | encode_ch (enc, ','); |
296 | |
326 | |
297 | if (enc->json.flags & F_INDENT) |
327 | if (enc->json.flags & F_INDENT) |
… | |
… | |
308 | int i, len = av_len (av); |
338 | int i, len = av_len (av); |
309 | |
339 | |
310 | if (enc->indent >= enc->maxdepth) |
340 | if (enc->indent >= enc->maxdepth) |
311 | croak ("data structure too deep (hit recursion limit)"); |
341 | croak ("data structure too deep (hit recursion limit)"); |
312 | |
342 | |
313 | encode_ch (enc, '['); encode_nl (enc); |
343 | encode_ch (enc, '['); |
314 | ++enc->indent; |
344 | |
|
|
345 | if (len >= 0) |
|
|
346 | { |
|
|
347 | encode_nl (enc); ++enc->indent; |
315 | |
348 | |
316 | for (i = 0; i <= len; ++i) |
349 | for (i = 0; i <= len; ++i) |
317 | { |
350 | { |
318 | SV **svp = av_fetch (av, i, 0); |
351 | SV **svp = av_fetch (av, i, 0); |
319 | |
352 | |
320 | encode_indent (enc); |
353 | encode_indent (enc); |
321 | |
354 | |
322 | if (svp) |
355 | if (svp) |
323 | encode_sv (enc, *svp); |
356 | encode_sv (enc, *svp); |
324 | else |
357 | else |
325 | encode_str (enc, "null", 4, 0); |
358 | encode_str (enc, "null", 4, 0); |
326 | |
359 | |
327 | if (i < len) |
360 | if (i < len) |
328 | encode_comma (enc); |
361 | encode_comma (enc); |
329 | } |
362 | } |
330 | |
363 | |
|
|
364 | encode_nl (enc); --enc->indent; encode_indent (enc); |
|
|
365 | } |
|
|
366 | |
331 | encode_nl (enc); |
367 | encode_ch (enc, ']'); |
332 | |
|
|
333 | --enc->indent; |
|
|
334 | encode_indent (enc); encode_ch (enc, ']'); |
|
|
335 | } |
368 | } |
336 | |
369 | |
337 | static void |
370 | static void |
338 | encode_he (enc_t *enc, HE *he) |
371 | encode_hk (enc_t *enc, HE *he) |
339 | { |
372 | { |
340 | encode_ch (enc, '"'); |
373 | encode_ch (enc, '"'); |
341 | |
374 | |
342 | if (HeKLEN (he) == HEf_SVKEY) |
375 | if (HeKLEN (he) == HEf_SVKEY) |
343 | { |
376 | { |
… | |
… | |
356 | encode_ch (enc, '"'); |
389 | encode_ch (enc, '"'); |
357 | |
390 | |
358 | if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc); |
391 | if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc); |
359 | encode_ch (enc, ':'); |
392 | encode_ch (enc, ':'); |
360 | if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc); |
393 | if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc); |
361 | encode_sv (enc, HeVAL (he)); |
|
|
362 | } |
394 | } |
363 | |
395 | |
364 | // compare hash entries, used when all keys are bytestrings |
396 | // compare hash entries, used when all keys are bytestrings |
365 | static int |
397 | static int |
366 | he_cmp_fast (const void *a_, const void *b_) |
398 | he_cmp_fast (const void *a_, const void *b_) |
… | |
… | |
371 | HE *b = *(HE **)b_; |
403 | HE *b = *(HE **)b_; |
372 | |
404 | |
373 | STRLEN la = HeKLEN (a); |
405 | STRLEN la = HeKLEN (a); |
374 | STRLEN lb = HeKLEN (b); |
406 | STRLEN lb = HeKLEN (b); |
375 | |
407 | |
376 | if (!(cmp = memcmp (HeKEY (a), HeKEY (b), la < lb ? la : lb))) |
408 | if (!(cmp = memcmp (HeKEY (b), HeKEY (a), lb < la ? lb : la))) |
377 | cmp = la - lb; |
409 | cmp = lb - la; |
378 | |
410 | |
379 | return cmp; |
411 | return cmp; |
380 | } |
412 | } |
381 | |
413 | |
382 | // compare hash entries, used when some keys are sv's or utf-x |
414 | // compare hash entries, used when some keys are sv's or utf-x |
383 | static int |
415 | static int |
384 | he_cmp_slow (const void *a, const void *b) |
416 | he_cmp_slow (const void *a, const void *b) |
385 | { |
417 | { |
386 | return sv_cmp (HeSVKEY_force (*(HE **)a), HeSVKEY_force (*(HE **)b)); |
418 | return sv_cmp (HeSVKEY_force (*(HE **)b), HeSVKEY_force (*(HE **)a)); |
387 | } |
419 | } |
388 | |
420 | |
389 | static void |
421 | static void |
390 | encode_hv (enc_t *enc, HV *hv) |
422 | encode_hv (enc_t *enc, HV *hv) |
391 | { |
423 | { |
|
|
424 | HE *he; |
392 | int count, i; |
425 | int count; |
393 | |
426 | |
394 | if (enc->indent >= enc->maxdepth) |
427 | if (enc->indent >= enc->maxdepth) |
395 | croak ("data structure too deep (hit recursion limit)"); |
428 | croak ("data structure too deep (hit recursion limit)"); |
396 | |
429 | |
397 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
430 | encode_ch (enc, '{'); |
398 | |
431 | |
399 | if ((count = hv_iterinit (hv))) |
|
|
400 | { |
|
|
401 | // for canonical output we have to sort by keys first |
432 | // for canonical output we have to sort by keys first |
402 | // actually, this is mostly due to the stupid so-called |
433 | // actually, this is mostly due to the stupid so-called |
403 | // security workaround added somewhere in 5.8.x. |
434 | // security workaround added somewhere in 5.8.x. |
404 | // that randomises hash orderings |
435 | // that randomises hash orderings |
405 | if (enc->json.flags & F_CANONICAL) |
436 | if (enc->json.flags & F_CANONICAL) |
|
|
437 | { |
|
|
438 | int count = hv_iterinit (hv); |
|
|
439 | |
|
|
440 | if (SvMAGICAL (hv)) |
406 | { |
441 | { |
|
|
442 | // need to count by iterating. could improve by dynamically building the vector below |
|
|
443 | // but I don't care for the speed of this special case. |
|
|
444 | // note also that we will run into undefined behaviour when the two iterations |
|
|
445 | // do not result in the same count, something I might care for in some later release. |
|
|
446 | |
|
|
447 | count = 0; |
|
|
448 | while (hv_iternext (hv)) |
|
|
449 | ++count; |
|
|
450 | |
|
|
451 | hv_iterinit (hv); |
|
|
452 | } |
|
|
453 | |
|
|
454 | if (count) |
|
|
455 | { |
407 | int fast = 1; |
456 | int i, fast = 1; |
408 | HE *he; |
|
|
409 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
457 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
410 | HE **hes = _alloca (count * sizeof (HE)); |
458 | HE **hes = _alloca (count * sizeof (HE)); |
411 | #else |
459 | #else |
412 | HE *hes [count]; // if your compiler dies here, you need to enable C99 mode |
460 | HE *hes [count]; // if your compiler dies here, you need to enable C99 mode |
413 | #endif |
461 | #endif |
… | |
… | |
440 | |
488 | |
441 | FREETMPS; |
489 | FREETMPS; |
442 | LEAVE; |
490 | LEAVE; |
443 | } |
491 | } |
444 | |
492 | |
445 | for (i = 0; i < count; ++i) |
493 | encode_nl (enc); ++enc->indent; |
|
|
494 | |
|
|
495 | while (count--) |
446 | { |
496 | { |
447 | encode_indent (enc); |
497 | encode_indent (enc); |
|
|
498 | he = hes [count]; |
448 | encode_he (enc, hes [i]); |
499 | encode_hk (enc, he); |
|
|
500 | encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he)); |
449 | |
501 | |
450 | if (i < count - 1) |
502 | if (count) |
451 | encode_comma (enc); |
503 | encode_comma (enc); |
452 | } |
504 | } |
453 | |
505 | |
454 | encode_nl (enc); |
506 | encode_nl (enc); --enc->indent; encode_indent (enc); |
455 | } |
507 | } |
|
|
508 | } |
456 | else |
509 | else |
|
|
510 | { |
|
|
511 | if (hv_iterinit (hv) || SvMAGICAL (hv)) |
|
|
512 | if ((he = hv_iternext (hv))) |
457 | { |
513 | { |
458 | HE *he = hv_iternext (hv); |
514 | encode_nl (enc); ++enc->indent; |
459 | |
515 | |
460 | for (;;) |
516 | for (;;) |
461 | { |
517 | { |
462 | encode_indent (enc); |
518 | encode_indent (enc); |
463 | encode_he (enc, he); |
519 | encode_hk (enc, he); |
|
|
520 | encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he)); |
464 | |
521 | |
465 | if (!(he = hv_iternext (hv))) |
522 | if (!(he = hv_iternext (hv))) |
466 | break; |
523 | break; |
467 | |
524 | |
468 | encode_comma (enc); |
525 | encode_comma (enc); |
469 | } |
526 | } |
470 | |
527 | |
471 | encode_nl (enc); |
528 | encode_nl (enc); --enc->indent; encode_indent (enc); |
472 | } |
529 | } |
473 | } |
530 | } |
474 | |
531 | |
475 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
532 | encode_ch (enc, '}'); |
476 | } |
533 | } |
477 | |
534 | |
478 | // encode objects, arrays and special \0=false and \1=true values. |
535 | // encode objects, arrays and special \0=false and \1=true values. |
479 | static void |
536 | static void |
480 | encode_rv (enc_t *enc, SV *sv) |
537 | encode_rv (enc_t *enc, SV *sv) |
… | |
… | |
588 | Gconvert (SvNVX (sv), NV_DIG, 0, enc->cur); |
645 | Gconvert (SvNVX (sv), NV_DIG, 0, enc->cur); |
589 | enc->cur += strlen (enc->cur); |
646 | enc->cur += strlen (enc->cur); |
590 | } |
647 | } |
591 | else if (SvIOKp (sv)) |
648 | else if (SvIOKp (sv)) |
592 | { |
649 | { |
593 | // we assume we can always read an IV as a UV |
650 | // we assume we can always read an IV as a UV and vice versa |
594 | if (SvUV (sv) & ~(UV)0x7fff) |
651 | // we assume two's complement |
|
|
652 | // we assume no aliasing issues in the union |
|
|
653 | if (SvIsUV (sv) ? SvUVX (sv) > 59000 |
|
|
654 | : SvIVX (sv) > 59000 || SvIVX (sv) < -59000) |
595 | { |
655 | { |
596 | // large integer, use the (rather slow) snprintf way. |
656 | // large integer, use the (rather slow) snprintf way. |
597 | need (enc, sizeof (UV) * 3); |
657 | need (enc, sizeof (UV) * 5 / 2 + 1); // CHAR_BIT is at least 8 |
598 | enc->cur += |
658 | enc->cur += |
599 | SvIsUV(sv) |
659 | SvIsUV(sv) |
600 | ? snprintf (enc->cur, sizeof (UV) * 3, "%"UVuf, (UV)SvUVX (sv)) |
660 | ? snprintf (enc->cur, sizeof (UV) * 3, "%"UVuf, (UV)SvUVX (sv)) |
601 | : snprintf (enc->cur, sizeof (UV) * 3, "%"IVdf, (IV)SvIVX (sv)); |
661 | : snprintf (enc->cur, sizeof (UV) * 3, "%"IVdf, (IV)SvIVX (sv)); |
602 | } |
662 | } |
603 | else |
663 | else |
604 | { |
664 | { |
605 | // optimise the "small number case" |
665 | // optimise the "small number case" |
606 | // code will likely be branchless and use only a single multiplication |
666 | // code will likely be branchless and use only a single multiplication |
|
|
667 | // works for numbers up to 59074 |
607 | I32 i = SvIV (sv); |
668 | I32 i = SvIVX (sv); |
608 | U32 u; |
669 | U32 u; |
609 | char digit, nz = 0; |
670 | char digit, nz = 0; |
610 | |
671 | |
611 | need (enc, 6); |
672 | need (enc, 6); |
612 | |
673 | |
… | |
… | |
649 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
710 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
650 | enc.cur = SvPVX (enc.sv); |
711 | enc.cur = SvPVX (enc.sv); |
651 | enc.end = SvEND (enc.sv); |
712 | enc.end = SvEND (enc.sv); |
652 | enc.indent = 0; |
713 | enc.indent = 0; |
653 | enc.maxdepth = DEC_DEPTH (enc.json.flags); |
714 | enc.maxdepth = DEC_DEPTH (enc.json.flags); |
|
|
715 | enc.limit = enc.json.flags & F_ASCII ? 0x000080UL |
|
|
716 | : enc.json.flags & F_LATIN1 ? 0x000100UL |
|
|
717 | : 0x110000UL; |
654 | |
718 | |
655 | SvPOK_only (enc.sv); |
719 | SvPOK_only (enc.sv); |
656 | encode_sv (&enc, scalar); |
720 | encode_sv (&enc, scalar); |
657 | |
721 | |
658 | SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); |
722 | SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); |
… | |
… | |
679 | JSON json; |
743 | JSON json; |
680 | U32 depth; // recursion depth |
744 | U32 depth; // recursion depth |
681 | U32 maxdepth; // recursion depth limit |
745 | U32 maxdepth; // recursion depth limit |
682 | } dec_t; |
746 | } dec_t; |
683 | |
747 | |
684 | inline void |
748 | INLINE void |
|
|
749 | decode_comment (dec_t *dec) |
|
|
750 | { |
|
|
751 | // only '#'-style comments allowed a.t.m. |
|
|
752 | |
|
|
753 | while (*dec->cur && *dec->cur != 0x0a && *dec->cur != 0x0d) |
|
|
754 | ++dec->cur; |
|
|
755 | } |
|
|
756 | |
|
|
757 | INLINE void |
685 | decode_ws (dec_t *dec) |
758 | decode_ws (dec_t *dec) |
686 | { |
759 | { |
687 | for (;;) |
760 | for (;;) |
688 | { |
761 | { |
689 | char ch = *dec->cur; |
762 | char ch = *dec->cur; |
690 | |
763 | |
691 | if (ch > 0x20 |
764 | if (ch > 0x20) |
|
|
765 | { |
|
|
766 | if (expect_false (ch == '#')) |
|
|
767 | { |
|
|
768 | if (dec->json.flags & F_RELAXED) |
|
|
769 | decode_comment (dec); |
|
|
770 | else |
|
|
771 | break; |
|
|
772 | } |
|
|
773 | else |
|
|
774 | break; |
|
|
775 | } |
692 | || (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)) |
776 | else if (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09) |
693 | break; |
777 | break; // parse error, but let higher level handle it, gives better error messages |
694 | |
778 | |
695 | ++dec->cur; |
779 | ++dec->cur; |
696 | } |
780 | } |
697 | } |
781 | } |
698 | |
782 | |
… | |
… | |
804 | |
888 | |
805 | if (hi >= 0x80) |
889 | if (hi >= 0x80) |
806 | { |
890 | { |
807 | utf8 = 1; |
891 | utf8 = 1; |
808 | |
892 | |
809 | cur = (char *)uvuni_to_utf8_flags (cur, hi, 0); |
893 | cur = encode_utf8 (cur, hi); |
810 | } |
894 | } |
811 | else |
895 | else |
812 | *cur++ = hi; |
896 | *cur++ = hi; |
813 | } |
897 | } |
814 | break; |
898 | break; |
… | |
… | |
816 | default: |
900 | default: |
817 | --dec_cur; |
901 | --dec_cur; |
818 | ERR ("illegal backslash escape sequence in string"); |
902 | ERR ("illegal backslash escape sequence in string"); |
819 | } |
903 | } |
820 | } |
904 | } |
821 | else if (expect_true (ch >= 0x20 && ch <= 0x7f)) |
905 | else if (expect_true (ch >= 0x20 && ch < 0x80)) |
822 | *cur++ = ch; |
906 | *cur++ = ch; |
823 | else if (ch >= 0x80) |
907 | else if (ch >= 0x80) |
824 | { |
908 | { |
825 | STRLEN clen; |
909 | STRLEN clen; |
826 | UV uch; |
910 | UV uch; |
… | |
… | |
949 | |
1033 | |
950 | if (!is_nv) |
1034 | if (!is_nv) |
951 | { |
1035 | { |
952 | int len = dec->cur - start; |
1036 | int len = dec->cur - start; |
953 | |
1037 | |
954 | // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so |
1038 | // special case the rather common 1..5-digit-int case |
955 | if (*start == '-') |
1039 | if (*start == '-') |
956 | switch (len) |
1040 | switch (len) |
957 | { |
1041 | { |
958 | case 2: return newSViv (-( start [1] - '0' * 1)); |
1042 | case 2: return newSViv (-( start [1] - '0' * 1)); |
959 | case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); |
1043 | case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); |
960 | case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); |
1044 | case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); |
961 | case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); |
1045 | case 5: return newSViv (-( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); |
|
|
1046 | case 6: return newSViv (-(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111)); |
962 | } |
1047 | } |
963 | else |
1048 | else |
964 | switch (len) |
1049 | switch (len) |
965 | { |
1050 | { |
966 | case 1: return newSViv ( start [0] - '0' * 1); |
1051 | case 1: return newSViv ( start [0] - '0' * 1); |
967 | case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); |
1052 | case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); |
968 | case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); |
1053 | case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); |
969 | case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); |
1054 | case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); |
|
|
1055 | case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111); |
970 | } |
1056 | } |
971 | |
1057 | |
972 | { |
1058 | { |
973 | UV uv; |
1059 | UV uv; |
974 | int numtype = grok_number (start, len, &uv); |
1060 | int numtype = grok_number (start, len, &uv); |
… | |
… | |
1035 | |
1121 | |
1036 | if (*dec->cur != ',') |
1122 | if (*dec->cur != ',') |
1037 | ERR (", or ] expected while parsing array"); |
1123 | ERR (", or ] expected while parsing array"); |
1038 | |
1124 | |
1039 | ++dec->cur; |
1125 | ++dec->cur; |
|
|
1126 | |
|
|
1127 | decode_ws (dec); |
|
|
1128 | |
|
|
1129 | if (*dec->cur == ']' && dec->json.flags & F_RELAXED) |
|
|
1130 | { |
|
|
1131 | ++dec->cur; |
|
|
1132 | break; |
|
|
1133 | } |
1040 | } |
1134 | } |
1041 | |
1135 | |
1042 | DEC_DEC_DEPTH; |
1136 | DEC_DEC_DEPTH; |
1043 | return newRV_noinc ((SV *)av); |
1137 | return newRV_noinc ((SV *)av); |
1044 | |
1138 | |
… | |
… | |
1060 | if (*dec->cur == '}') |
1154 | if (*dec->cur == '}') |
1061 | ++dec->cur; |
1155 | ++dec->cur; |
1062 | else |
1156 | else |
1063 | for (;;) |
1157 | for (;;) |
1064 | { |
1158 | { |
1065 | decode_ws (dec); EXPECT_CH ('"'); |
1159 | EXPECT_CH ('"'); |
1066 | |
1160 | |
1067 | // heuristic: assume that |
1161 | // heuristic: assume that |
1068 | // a) decode_str + hv_store_ent are abysmally slow. |
1162 | // a) decode_str + hv_store_ent are abysmally slow. |
1069 | // b) most hash keys are short, simple ascii text. |
1163 | // b) most hash keys are short, simple ascii text. |
1070 | // => try to "fast-match" such strings to avoid |
1164 | // => try to "fast-match" such strings to avoid |
… | |
… | |
1084 | if (!key) |
1178 | if (!key) |
1085 | goto fail; |
1179 | goto fail; |
1086 | |
1180 | |
1087 | decode_ws (dec); EXPECT_CH (':'); |
1181 | decode_ws (dec); EXPECT_CH (':'); |
1088 | |
1182 | |
|
|
1183 | decode_ws (dec); |
1089 | value = decode_sv (dec); |
1184 | value = decode_sv (dec); |
1090 | if (!value) |
1185 | if (!value) |
1091 | { |
1186 | { |
1092 | SvREFCNT_dec (key); |
1187 | SvREFCNT_dec (key); |
1093 | goto fail; |
1188 | goto fail; |
… | |
… | |
1105 | int len = p - key; |
1200 | int len = p - key; |
1106 | dec->cur = p + 1; |
1201 | dec->cur = p + 1; |
1107 | |
1202 | |
1108 | decode_ws (dec); EXPECT_CH (':'); |
1203 | decode_ws (dec); EXPECT_CH (':'); |
1109 | |
1204 | |
|
|
1205 | decode_ws (dec); |
1110 | value = decode_sv (dec); |
1206 | value = decode_sv (dec); |
1111 | if (!value) |
1207 | if (!value) |
1112 | goto fail; |
1208 | goto fail; |
1113 | |
1209 | |
1114 | hv_store (hv, key, len, value, 0); |
1210 | hv_store (hv, key, len, value, 0); |
… | |
… | |
1130 | |
1226 | |
1131 | if (*dec->cur != ',') |
1227 | if (*dec->cur != ',') |
1132 | ERR (", or } expected while parsing object/hash"); |
1228 | ERR (", or } expected while parsing object/hash"); |
1133 | |
1229 | |
1134 | ++dec->cur; |
1230 | ++dec->cur; |
|
|
1231 | |
|
|
1232 | decode_ws (dec); |
|
|
1233 | |
|
|
1234 | if (*dec->cur == '}' && dec->json.flags & F_RELAXED) |
|
|
1235 | { |
|
|
1236 | ++dec->cur; |
|
|
1237 | break; |
|
|
1238 | } |
1135 | } |
1239 | } |
1136 | |
1240 | |
1137 | DEC_DEC_DEPTH; |
1241 | DEC_DEC_DEPTH; |
1138 | sv = newRV_noinc ((SV *)hv); |
1242 | sv = newRV_noinc ((SV *)hv); |
1139 | |
1243 | |
… | |
… | |
1204 | } |
1308 | } |
1205 | |
1309 | |
1206 | static SV * |
1310 | static SV * |
1207 | decode_sv (dec_t *dec) |
1311 | decode_sv (dec_t *dec) |
1208 | { |
1312 | { |
1209 | decode_ws (dec); |
|
|
1210 | |
|
|
1211 | // the beauty of JSON: you need exactly one character lookahead |
1313 | // the beauty of JSON: you need exactly one character lookahead |
1212 | // to parse anything. |
1314 | // to parse everything. |
1213 | switch (*dec->cur) |
1315 | switch (*dec->cur) |
1214 | { |
1316 | { |
1215 | case '"': ++dec->cur; return decode_str (dec); |
1317 | case '"': ++dec->cur; return decode_str (dec); |
1216 | case '[': ++dec->cur; return decode_av (dec); |
1318 | case '[': ++dec->cur; return decode_av (dec); |
1217 | case '{': ++dec->cur; return decode_hv (dec); |
1319 | case '{': ++dec->cur; return decode_hv (dec); |
1218 | |
1320 | |
1219 | case '-': |
1321 | case '-': |
1220 | case '0': case '1': case '2': case '3': case '4': |
1322 | case '0': case '1': case '2': case '3': case '4': |
1221 | case '5': case '6': case '7': case '8': case '9': |
1323 | case '5': case '6': case '7': case '8': case '9': |
1222 | return decode_num (dec); |
1324 | return decode_num (dec); |
1223 | |
1325 | |
1224 | case 't': |
1326 | case 't': |
1225 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1327 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1226 | { |
1328 | { |
1227 | dec->cur += 4; |
1329 | dec->cur += 4; |
|
|
1330 | #if JSON_SLOW |
|
|
1331 | json_true = get_sv ("JSON::XS::true", 1); SvREADONLY_on (json_true); |
|
|
1332 | #endif |
1228 | return SvREFCNT_inc (json_true); |
1333 | return SvREFCNT_inc (json_true); |
1229 | } |
1334 | } |
1230 | else |
1335 | else |
1231 | ERR ("'true' expected"); |
1336 | ERR ("'true' expected"); |
1232 | |
1337 | |
… | |
… | |
1234 | |
1339 | |
1235 | case 'f': |
1340 | case 'f': |
1236 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1341 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1237 | { |
1342 | { |
1238 | dec->cur += 5; |
1343 | dec->cur += 5; |
|
|
1344 | #if JSON_SLOW |
|
|
1345 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
|
|
1346 | #endif |
1239 | return SvREFCNT_inc (json_false); |
1347 | return SvREFCNT_inc (json_false); |
1240 | } |
1348 | } |
1241 | else |
1349 | else |
1242 | ERR ("'false' expected"); |
1350 | ERR ("'false' expected"); |
1243 | |
1351 | |
… | |
… | |
1293 | |
1401 | |
1294 | if (dec.json.cb_object || dec.json.cb_sk_object) |
1402 | if (dec.json.cb_object || dec.json.cb_sk_object) |
1295 | dec.json.flags |= F_HOOK; |
1403 | dec.json.flags |= F_HOOK; |
1296 | |
1404 | |
1297 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
1405 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
|
|
1406 | |
|
|
1407 | decode_ws (&dec); |
1298 | sv = decode_sv (&dec); |
1408 | sv = decode_sv (&dec); |
1299 | |
1409 | |
1300 | if (!(offset_return || !sv)) |
1410 | if (!(offset_return || !sv)) |
1301 | { |
1411 | { |
1302 | // check for trailing garbage |
1412 | // check for trailing garbage |
… | |
… | |
1378 | json_boolean_stash = 0; |
1488 | json_boolean_stash = 0; |
1379 | |
1489 | |
1380 | void new (char *klass) |
1490 | void new (char *klass) |
1381 | PPCODE: |
1491 | PPCODE: |
1382 | { |
1492 | { |
1383 | HV *stash = !JSON_SLOW || json_stash |
|
|
1384 | ? json_stash |
|
|
1385 | : gv_stashpv ("JSON::XS", 1); |
|
|
1386 | SV *pv = NEWSV (0, sizeof (JSON)); |
1493 | SV *pv = NEWSV (0, sizeof (JSON)); |
1387 | SvPOK_only (pv); |
1494 | SvPOK_only (pv); |
1388 | Zero (SvPVX (pv), 1, JSON); |
1495 | Zero (SvPVX (pv), 1, JSON); |
1389 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1496 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1390 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), stash))); |
1497 | XPUSHs (sv_2mortal (sv_bless ( |
|
|
1498 | newRV_noinc (pv), |
|
|
1499 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |
|
|
1500 | ))); |
1391 | } |
1501 | } |
1392 | |
1502 | |
1393 | void ascii (JSON *self, int enable = 1) |
1503 | void ascii (JSON *self, int enable = 1) |
1394 | ALIAS: |
1504 | ALIAS: |
1395 | ascii = F_ASCII |
1505 | ascii = F_ASCII |
… | |
… | |
1402 | pretty = F_PRETTY |
1512 | pretty = F_PRETTY |
1403 | allow_nonref = F_ALLOW_NONREF |
1513 | allow_nonref = F_ALLOW_NONREF |
1404 | shrink = F_SHRINK |
1514 | shrink = F_SHRINK |
1405 | allow_blessed = F_ALLOW_BLESSED |
1515 | allow_blessed = F_ALLOW_BLESSED |
1406 | convert_blessed = F_CONV_BLESSED |
1516 | convert_blessed = F_CONV_BLESSED |
|
|
1517 | relaxed = F_RELAXED |
1407 | PPCODE: |
1518 | PPCODE: |
1408 | { |
1519 | { |
1409 | if (enable) |
1520 | if (enable) |
1410 | self->flags |= ix; |
1521 | self->flags |= ix; |
1411 | else |
1522 | else |
1412 | self->flags &= ~ix; |
1523 | self->flags &= ~ix; |
1413 | |
1524 | |
1414 | XPUSHs (ST (0)); |
1525 | XPUSHs (ST (0)); |
1415 | } |
1526 | } |
1416 | |
1527 | |
|
|
1528 | void get_ascii (JSON *self) |
|
|
1529 | ALIAS: |
|
|
1530 | get_ascii = F_ASCII |
|
|
1531 | get_latin1 = F_LATIN1 |
|
|
1532 | get_utf8 = F_UTF8 |
|
|
1533 | get_indent = F_INDENT |
|
|
1534 | get_canonical = F_CANONICAL |
|
|
1535 | get_space_before = F_SPACE_BEFORE |
|
|
1536 | get_space_after = F_SPACE_AFTER |
|
|
1537 | get_allow_nonref = F_ALLOW_NONREF |
|
|
1538 | get_shrink = F_SHRINK |
|
|
1539 | get_allow_blessed = F_ALLOW_BLESSED |
|
|
1540 | get_convert_blessed = F_CONV_BLESSED |
|
|
1541 | get_relaxed = F_RELAXED |
|
|
1542 | PPCODE: |
|
|
1543 | XPUSHs (boolSV (self->flags & ix)); |
|
|
1544 | |
1417 | void max_depth (JSON *self, UV max_depth = 0x80000000UL) |
1545 | void max_depth (JSON *self, UV max_depth = 0x80000000UL) |
1418 | PPCODE: |
1546 | PPCODE: |
1419 | { |
1547 | { |
1420 | UV log2 = 0; |
1548 | UV log2 = 0; |
1421 | |
1549 | |
… | |
… | |
1427 | self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
1555 | self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
1428 | |
1556 | |
1429 | XPUSHs (ST (0)); |
1557 | XPUSHs (ST (0)); |
1430 | } |
1558 | } |
1431 | |
1559 | |
|
|
1560 | U32 get_max_depth (JSON *self) |
|
|
1561 | CODE: |
|
|
1562 | RETVAL = DEC_DEPTH (self->flags); |
|
|
1563 | OUTPUT: |
|
|
1564 | RETVAL |
|
|
1565 | |
1432 | void max_size (JSON *self, UV max_size = 0) |
1566 | void max_size (JSON *self, UV max_size = 0) |
1433 | PPCODE: |
1567 | PPCODE: |
1434 | { |
1568 | { |
1435 | UV log2 = 0; |
1569 | UV log2 = 0; |
1436 | |
1570 | |
… | |
… | |
1442 | |
1576 | |
1443 | self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); |
1577 | self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); |
1444 | |
1578 | |
1445 | XPUSHs (ST (0)); |
1579 | XPUSHs (ST (0)); |
1446 | } |
1580 | } |
|
|
1581 | |
|
|
1582 | int get_max_size (JSON *self) |
|
|
1583 | CODE: |
|
|
1584 | RETVAL = DEC_SIZE (self->flags); |
|
|
1585 | OUTPUT: |
|
|
1586 | RETVAL |
1447 | |
1587 | |
1448 | void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) |
1588 | void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) |
1449 | PPCODE: |
1589 | PPCODE: |
1450 | { |
1590 | { |
1451 | SvREFCNT_dec (self->cb_object); |
1591 | SvREFCNT_dec (self->cb_object); |
… | |
… | |
1498 | SvREFCNT_dec (self->cb_sk_object); |
1638 | SvREFCNT_dec (self->cb_sk_object); |
1499 | SvREFCNT_dec (self->cb_object); |
1639 | SvREFCNT_dec (self->cb_object); |
1500 | |
1640 | |
1501 | PROTOTYPES: ENABLE |
1641 | PROTOTYPES: ENABLE |
1502 | |
1642 | |
1503 | void to_json (SV *scalar) |
1643 | void encode_json (SV *scalar) |
1504 | PPCODE: |
1644 | PPCODE: |
1505 | { |
1645 | { |
1506 | JSON json = { F_DEFAULT | F_UTF8 }; |
1646 | JSON json = { F_DEFAULT | F_UTF8 }; |
1507 | XPUSHs (encode_json (scalar, &json)); |
1647 | XPUSHs (encode_json (scalar, &json)); |
1508 | } |
1648 | } |
1509 | |
1649 | |
1510 | void from_json (SV *jsonstr) |
1650 | void decode_json (SV *jsonstr) |
1511 | PPCODE: |
1651 | PPCODE: |
1512 | { |
1652 | { |
1513 | JSON json = { F_DEFAULT | F_UTF8 }; |
1653 | JSON json = { F_DEFAULT | F_UTF8 }; |
1514 | XPUSHs (decode_json (jsonstr, &json, 0)); |
1654 | XPUSHs (decode_json (jsonstr, &json, 0)); |
1515 | } |
1655 | } |