1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
5 | #include "assert.h" |
5 | #include <assert.h> |
6 | #include "string.h" |
6 | #include <string.h> |
7 | #include "stdlib.h" |
7 | #include <stdlib.h> |
8 | #include "stdio.h" |
8 | #include <stdio.h> |
|
|
9 | #include <float.h> |
9 | |
10 | |
10 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
11 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
11 | # define snprintf _snprintf // C compilers have this in stdio.h |
12 | # define snprintf _snprintf // C compilers have this in stdio.h |
12 | #endif |
13 | #endif |
13 | |
14 | |
… | |
… | |
25 | #define F_SPACE_BEFORE 0x00000020UL |
26 | #define F_SPACE_BEFORE 0x00000020UL |
26 | #define F_SPACE_AFTER 0x00000040UL |
27 | #define F_SPACE_AFTER 0x00000040UL |
27 | #define F_ALLOW_NONREF 0x00000100UL |
28 | #define F_ALLOW_NONREF 0x00000100UL |
28 | #define F_SHRINK 0x00000200UL |
29 | #define F_SHRINK 0x00000200UL |
29 | #define F_ALLOW_BLESSED 0x00000400UL |
30 | #define F_ALLOW_BLESSED 0x00000400UL |
30 | #define F_CONV_BLESSED 0x00000800UL // NYI |
31 | #define F_CONV_BLESSED 0x00000800UL |
31 | #define F_MAXDEPTH 0xf8000000UL |
32 | #define F_MAXDEPTH 0xf8000000UL |
32 | #define S_MAXDEPTH 27 |
33 | #define S_MAXDEPTH 27 |
|
|
34 | #define F_MAXSIZE 0x01f00000UL |
|
|
35 | #define S_MAXSIZE 20 |
|
|
36 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
33 | |
37 | |
34 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
38 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
|
|
39 | #define DEC_SIZE(flags) (1UL << ((flags & F_MAXSIZE ) >> S_MAXSIZE )) |
35 | |
40 | |
36 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
41 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
37 | #define F_DEFAULT (9UL << S_MAXDEPTH) |
42 | #define F_DEFAULT (9UL << S_MAXDEPTH) |
38 | |
43 | |
39 | #define INIT_SIZE 32 // initial scalar size to be allocated |
44 | #define INIT_SIZE 32 // initial scalar size to be allocated |
… | |
… | |
53 | #endif |
58 | #endif |
54 | |
59 | |
55 | #define expect_false(expr) expect ((expr) != 0, 0) |
60 | #define expect_false(expr) expect ((expr) != 0, 0) |
56 | #define expect_true(expr) expect ((expr) != 0, 1) |
61 | #define expect_true(expr) expect ((expr) != 0, 1) |
57 | |
62 | |
|
|
63 | #ifdef USE_ITHREADS |
|
|
64 | # define JSON_SLOW 1 |
|
|
65 | #else |
|
|
66 | # define JSON_SLOW 1 |
|
|
67 | #endif |
|
|
68 | |
58 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
69 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
59 | static SV *json_true, *json_false; |
70 | static SV *json_true, *json_false; |
60 | |
71 | |
|
|
72 | typedef struct { |
|
|
73 | U32 flags; |
|
|
74 | SV *cb_object; |
|
|
75 | HV *cb_sk_object; |
|
|
76 | } JSON; |
|
|
77 | |
61 | ///////////////////////////////////////////////////////////////////////////// |
78 | ///////////////////////////////////////////////////////////////////////////// |
62 | // utility functions |
79 | // utility functions |
63 | |
80 | |
64 | static UV * |
81 | inline void |
65 | SvJSON (SV *sv) |
|
|
66 | { |
|
|
67 | if (!(SvROK (sv) && SvOBJECT (SvRV (sv)) && SvSTASH (SvRV (sv)) == json_stash)) |
|
|
68 | croak ("object is not of type JSON::XS"); |
|
|
69 | |
|
|
70 | return &SvUVX (SvRV (sv)); |
|
|
71 | } |
|
|
72 | |
|
|
73 | static void |
|
|
74 | shrink (SV *sv) |
82 | shrink (SV *sv) |
75 | { |
83 | { |
76 | sv_utf8_downgrade (sv, 1); |
84 | sv_utf8_downgrade (sv, 1); |
77 | if (SvLEN (sv) > SvCUR (sv) + 1) |
85 | if (SvLEN (sv) > SvCUR (sv) + 1) |
78 | { |
86 | { |
… | |
… | |
113 | typedef struct |
121 | typedef struct |
114 | { |
122 | { |
115 | char *cur; // SvPVX (sv) + current output position |
123 | char *cur; // SvPVX (sv) + current output position |
116 | char *end; // SvEND (sv) |
124 | char *end; // SvEND (sv) |
117 | SV *sv; // result scalar |
125 | SV *sv; // result scalar |
118 | U32 flags; // F_* |
126 | JSON json; |
119 | U32 indent; // indentation level |
127 | U32 indent; // indentation level |
120 | U32 maxdepth; // max. indentation/recursion level |
128 | U32 maxdepth; // max. indentation/recursion level |
121 | } enc_t; |
129 | } enc_t; |
122 | |
130 | |
123 | inline void |
131 | inline void |
… | |
… | |
197 | } |
205 | } |
198 | |
206 | |
199 | if (uch > 0x10FFFFUL) |
207 | if (uch > 0x10FFFFUL) |
200 | croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch); |
208 | croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch); |
201 | |
209 | |
202 | if (uch < 0x80 || enc->flags & F_ASCII || (enc->flags & F_LATIN1 && uch > 0xFF)) |
210 | if (uch < 0x80 || enc->json.flags & F_ASCII || (enc->json.flags & F_LATIN1 && uch > 0xFF)) |
203 | { |
211 | { |
204 | if (uch > 0xFFFFUL) |
212 | if (uch > 0xFFFFUL) |
205 | { |
213 | { |
206 | need (enc, len += 11); |
214 | need (enc, len += 11); |
207 | sprintf (enc->cur, "\\u%04x\\u%04x", |
215 | sprintf (enc->cur, "\\u%04x\\u%04x", |
… | |
… | |
221 | *enc->cur++ = hexdigit [(uch >> 0) & 15]; |
229 | *enc->cur++ = hexdigit [(uch >> 0) & 15]; |
222 | } |
230 | } |
223 | |
231 | |
224 | str += clen; |
232 | str += clen; |
225 | } |
233 | } |
226 | else if (enc->flags & F_LATIN1) |
234 | else if (enc->json.flags & F_LATIN1) |
227 | { |
235 | { |
228 | *enc->cur++ = uch; |
236 | *enc->cur++ = uch; |
229 | str += clen; |
237 | str += clen; |
230 | } |
238 | } |
231 | else if (is_utf8) |
239 | else if (is_utf8) |
… | |
… | |
252 | } |
260 | } |
253 | |
261 | |
254 | inline void |
262 | inline void |
255 | encode_indent (enc_t *enc) |
263 | encode_indent (enc_t *enc) |
256 | { |
264 | { |
257 | if (enc->flags & F_INDENT) |
265 | if (enc->json.flags & F_INDENT) |
258 | { |
266 | { |
259 | int spaces = enc->indent * INDENT_STEP; |
267 | int spaces = enc->indent * INDENT_STEP; |
260 | |
268 | |
261 | need (enc, spaces); |
269 | need (enc, spaces); |
262 | memset (enc->cur, ' ', spaces); |
270 | memset (enc->cur, ' ', spaces); |
… | |
… | |
272 | } |
280 | } |
273 | |
281 | |
274 | inline void |
282 | inline void |
275 | encode_nl (enc_t *enc) |
283 | encode_nl (enc_t *enc) |
276 | { |
284 | { |
277 | if (enc->flags & F_INDENT) |
285 | if (enc->json.flags & F_INDENT) |
278 | { |
286 | { |
279 | need (enc, 1); |
287 | need (enc, 1); |
280 | encode_ch (enc, '\n'); |
288 | encode_ch (enc, '\n'); |
281 | } |
289 | } |
282 | } |
290 | } |
… | |
… | |
284 | inline void |
292 | inline void |
285 | encode_comma (enc_t *enc) |
293 | encode_comma (enc_t *enc) |
286 | { |
294 | { |
287 | encode_ch (enc, ','); |
295 | encode_ch (enc, ','); |
288 | |
296 | |
289 | if (enc->flags & F_INDENT) |
297 | if (enc->json.flags & F_INDENT) |
290 | encode_nl (enc); |
298 | encode_nl (enc); |
291 | else if (enc->flags & F_SPACE_AFTER) |
299 | else if (enc->json.flags & F_SPACE_AFTER) |
292 | encode_space (enc); |
300 | encode_space (enc); |
293 | } |
301 | } |
294 | |
302 | |
295 | static void encode_sv (enc_t *enc, SV *sv); |
303 | static void encode_sv (enc_t *enc, SV *sv); |
296 | |
304 | |
… | |
… | |
305 | encode_ch (enc, '['); encode_nl (enc); |
313 | encode_ch (enc, '['); encode_nl (enc); |
306 | ++enc->indent; |
314 | ++enc->indent; |
307 | |
315 | |
308 | for (i = 0; i <= len; ++i) |
316 | for (i = 0; i <= len; ++i) |
309 | { |
317 | { |
|
|
318 | SV **svp = av_fetch (av, i, 0); |
|
|
319 | |
310 | encode_indent (enc); |
320 | encode_indent (enc); |
311 | encode_sv (enc, *av_fetch (av, i, 0)); |
321 | |
|
|
322 | if (svp) |
|
|
323 | encode_sv (enc, *svp); |
|
|
324 | else |
|
|
325 | encode_str (enc, "null", 4, 0); |
312 | |
326 | |
313 | if (i < len) |
327 | if (i < len) |
314 | encode_comma (enc); |
328 | encode_comma (enc); |
315 | } |
329 | } |
316 | |
330 | |
… | |
… | |
339 | else |
353 | else |
340 | encode_str (enc, HeKEY (he), HeKLEN (he), HeKUTF8 (he)); |
354 | encode_str (enc, HeKEY (he), HeKLEN (he), HeKUTF8 (he)); |
341 | |
355 | |
342 | encode_ch (enc, '"'); |
356 | encode_ch (enc, '"'); |
343 | |
357 | |
344 | if (enc->flags & F_SPACE_BEFORE) encode_space (enc); |
358 | if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc); |
345 | encode_ch (enc, ':'); |
359 | encode_ch (enc, ':'); |
346 | if (enc->flags & F_SPACE_AFTER ) encode_space (enc); |
360 | if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc); |
347 | encode_sv (enc, HeVAL (he)); |
361 | encode_sv (enc, HeVAL (he)); |
348 | } |
362 | } |
349 | |
363 | |
350 | // compare hash entries, used when all keys are bytestrings |
364 | // compare hash entries, used when all keys are bytestrings |
351 | static int |
365 | static int |
… | |
… | |
386 | { |
400 | { |
387 | // for canonical output we have to sort by keys first |
401 | // for canonical output we have to sort by keys first |
388 | // actually, this is mostly due to the stupid so-called |
402 | // actually, this is mostly due to the stupid so-called |
389 | // security workaround added somewhere in 5.8.x. |
403 | // security workaround added somewhere in 5.8.x. |
390 | // that randomises hash orderings |
404 | // that randomises hash orderings |
391 | if (enc->flags & F_CANONICAL) |
405 | if (enc->json.flags & F_CANONICAL) |
392 | { |
406 | { |
393 | int fast = 1; |
407 | int fast = 1; |
394 | HE *he; |
408 | HE *he; |
395 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
409 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
396 | HE **hes = _alloca (count * sizeof (HE)); |
410 | HE **hes = _alloca (count * sizeof (HE)); |
… | |
… | |
470 | SvGETMAGIC (sv); |
484 | SvGETMAGIC (sv); |
471 | svt = SvTYPE (sv); |
485 | svt = SvTYPE (sv); |
472 | |
486 | |
473 | if (expect_false (SvOBJECT (sv))) |
487 | if (expect_false (SvOBJECT (sv))) |
474 | { |
488 | { |
|
|
489 | HV *stash = !JSON_SLOW || json_boolean_stash |
|
|
490 | ? json_boolean_stash |
|
|
491 | : gv_stashpv ("JSON::XS::Boolean", 1); |
|
|
492 | |
475 | if (SvSTASH (sv) == json_boolean_stash) |
493 | if (SvSTASH (sv) == stash) |
476 | { |
494 | { |
477 | if (SvIV (sv) == 0) |
495 | if (SvIV (sv)) |
|
|
496 | encode_str (enc, "true", 4, 0); |
|
|
497 | else |
478 | encode_str (enc, "false", 5, 0); |
498 | encode_str (enc, "false", 5, 0); |
479 | else |
|
|
480 | encode_str (enc, "true", 4, 0); |
|
|
481 | } |
499 | } |
482 | else |
500 | else |
483 | { |
501 | { |
484 | #if 0 |
502 | #if 0 |
485 | if (0 && sv_derived_from (rv, "JSON::Literal")) |
503 | if (0 && sv_derived_from (rv, "JSON::Literal")) |
486 | { |
504 | { |
487 | // not yet |
505 | // not yet |
488 | } |
506 | } |
489 | #endif |
507 | #endif |
490 | if (enc->flags & F_CONV_BLESSED) |
508 | if (enc->json.flags & F_CONV_BLESSED) |
491 | { |
509 | { |
492 | // we re-bless the reference to get overload and other niceties right |
510 | // we re-bless the reference to get overload and other niceties right |
493 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 1); |
511 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
494 | |
512 | |
495 | if (to_json) |
513 | if (to_json) |
496 | { |
514 | { |
|
|
515 | int count; |
497 | dSP; |
516 | dSP; |
498 | ENTER; |
517 | |
499 | SAVETMPS; |
|
|
500 | PUSHMARK (SP); |
518 | ENTER; SAVETMPS; PUSHMARK (SP); |
501 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
519 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
502 | |
520 | |
503 | // calling with G_SCALAR ensures that we always get a 1 reutrn value |
521 | // calling with G_SCALAR ensures that we always get a 1 return value |
504 | // check anyways. |
|
|
505 | PUTBACK; |
522 | PUTBACK; |
506 | assert (1 == call_sv ((SV *)GvCV (to_json), G_SCALAR)); |
523 | call_sv ((SV *)GvCV (to_json), G_SCALAR); |
507 | SPAGAIN; |
524 | SPAGAIN; |
508 | |
525 | |
|
|
526 | // catch this surprisingly common error |
|
|
527 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
|
|
528 | croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
|
|
529 | |
|
|
530 | sv = POPs; |
|
|
531 | PUTBACK; |
|
|
532 | |
509 | encode_sv (enc, POPs); |
533 | encode_sv (enc, sv); |
510 | |
534 | |
511 | FREETMPS; |
535 | FREETMPS; LEAVE; |
512 | LEAVE; |
|
|
513 | } |
536 | } |
514 | else if (enc->flags & F_ALLOW_BLESSED) |
537 | else if (enc->json.flags & F_ALLOW_BLESSED) |
515 | encode_str (enc, "null", 4, 0); |
538 | encode_str (enc, "null", 4, 0); |
516 | else |
539 | else |
517 | croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it", |
540 | croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it", |
518 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
541 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
519 | } |
542 | } |
520 | else if (enc->flags & F_ALLOW_BLESSED) |
543 | else if (enc->json.flags & F_ALLOW_BLESSED) |
521 | encode_str (enc, "null", 4, 0); |
544 | encode_str (enc, "null", 4, 0); |
522 | else |
545 | else |
523 | croak ("encountered object '%s', but neither allow_blessed nor convert_blessed settings are enabled", |
546 | croak ("encountered object '%s', but neither allow_blessed nor convert_blessed settings are enabled", |
524 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
547 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
525 | } |
548 | } |
… | |
… | |
528 | encode_hv (enc, (HV *)sv); |
551 | encode_hv (enc, (HV *)sv); |
529 | else if (svt == SVt_PVAV) |
552 | else if (svt == SVt_PVAV) |
530 | encode_av (enc, (AV *)sv); |
553 | encode_av (enc, (AV *)sv); |
531 | else if (svt < SVt_PVAV) |
554 | else if (svt < SVt_PVAV) |
532 | { |
555 | { |
533 | if (SvNIOK (sv) && SvIV (sv) == 0) |
556 | STRLEN len = 0; |
|
|
557 | char *pv = svt ? SvPV (sv, len) : 0; |
|
|
558 | |
|
|
559 | if (len == 1 && *pv == '1') |
|
|
560 | encode_str (enc, "true", 4, 0); |
|
|
561 | else if (len == 1 && *pv == '0') |
534 | encode_str (enc, "false", 5, 0); |
562 | encode_str (enc, "false", 5, 0); |
535 | else if (SvNIOK (sv) && SvIV (sv) == 1) |
|
|
536 | encode_str (enc, "true", 4, 0); |
|
|
537 | else |
563 | else |
538 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
564 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
539 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
565 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
540 | } |
566 | } |
541 | else |
567 | else |
… | |
… | |
611 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
637 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
612 | SvPV_nolen (sv), SvFLAGS (sv)); |
638 | SvPV_nolen (sv), SvFLAGS (sv)); |
613 | } |
639 | } |
614 | |
640 | |
615 | static SV * |
641 | static SV * |
616 | encode_json (SV *scalar, U32 flags) |
642 | encode_json (SV *scalar, JSON *json) |
617 | { |
643 | { |
618 | enc_t enc; |
644 | enc_t enc; |
619 | |
645 | |
620 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
646 | if (!(json->flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
621 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
647 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
622 | |
648 | |
623 | enc.flags = flags; |
649 | enc.json = *json; |
624 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
650 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
625 | enc.cur = SvPVX (enc.sv); |
651 | enc.cur = SvPVX (enc.sv); |
626 | enc.end = SvEND (enc.sv); |
652 | enc.end = SvEND (enc.sv); |
627 | enc.indent = 0; |
653 | enc.indent = 0; |
628 | enc.maxdepth = DEC_DEPTH (flags); |
654 | enc.maxdepth = DEC_DEPTH (enc.json.flags); |
629 | |
655 | |
630 | SvPOK_only (enc.sv); |
656 | SvPOK_only (enc.sv); |
631 | encode_sv (&enc, scalar); |
657 | encode_sv (&enc, scalar); |
632 | |
658 | |
633 | SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); |
659 | SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); |
634 | *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings |
660 | *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings |
635 | |
661 | |
636 | if (!(flags & (F_ASCII | F_LATIN1 | F_UTF8))) |
662 | if (!(enc.json.flags & (F_ASCII | F_LATIN1 | F_UTF8))) |
637 | SvUTF8_on (enc.sv); |
663 | SvUTF8_on (enc.sv); |
638 | |
664 | |
639 | if (enc.flags & F_SHRINK) |
665 | if (enc.json.flags & F_SHRINK) |
640 | shrink (enc.sv); |
666 | shrink (enc.sv); |
641 | |
667 | |
642 | return enc.sv; |
668 | return enc.sv; |
643 | } |
669 | } |
644 | |
670 | |
… | |
… | |
649 | typedef struct |
675 | typedef struct |
650 | { |
676 | { |
651 | char *cur; // current parser pointer |
677 | char *cur; // current parser pointer |
652 | char *end; // end of input string |
678 | char *end; // end of input string |
653 | const char *err; // parse error, if != 0 |
679 | const char *err; // parse error, if != 0 |
654 | U32 flags; // F_* |
680 | JSON json; |
655 | U32 depth; // recursion depth |
681 | U32 depth; // recursion depth |
656 | U32 maxdepth; // recursion depth limit |
682 | U32 maxdepth; // recursion depth limit |
657 | } dec_t; |
683 | } dec_t; |
658 | |
684 | |
659 | inline void |
685 | inline void |
… | |
… | |
922 | is_nv = 1; |
948 | is_nv = 1; |
923 | } |
949 | } |
924 | |
950 | |
925 | if (!is_nv) |
951 | if (!is_nv) |
926 | { |
952 | { |
|
|
953 | int len = dec->cur - start; |
|
|
954 | |
927 | // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so |
955 | // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so |
928 | if (*start == '-') |
956 | if (*start == '-') |
929 | switch (dec->cur - start) |
957 | switch (len) |
930 | { |
958 | { |
931 | case 2: return newSViv (-( start [1] - '0' * 1)); |
959 | case 2: return newSViv (-( start [1] - '0' * 1)); |
932 | case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); |
960 | case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); |
933 | case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); |
961 | case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); |
934 | case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); |
962 | case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); |
935 | } |
963 | } |
936 | else |
964 | else |
937 | switch (dec->cur - start) |
965 | switch (len) |
938 | { |
966 | { |
939 | case 1: return newSViv ( start [0] - '0' * 1); |
967 | case 1: return newSViv ( start [0] - '0' * 1); |
940 | case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); |
968 | case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); |
941 | case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); |
969 | case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); |
942 | case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); |
970 | case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); |
943 | } |
971 | } |
944 | |
972 | |
945 | { |
973 | { |
946 | UV uv; |
974 | UV uv; |
947 | int numtype = grok_number (start, dec->cur - start, &uv); |
975 | int numtype = grok_number (start, len, &uv); |
948 | if (numtype & IS_NUMBER_IN_UV) |
976 | if (numtype & IS_NUMBER_IN_UV) |
949 | if (numtype & IS_NUMBER_NEG) |
977 | if (numtype & IS_NUMBER_NEG) |
950 | { |
978 | { |
951 | if (uv < (UV)IV_MIN) |
979 | if (uv < (UV)IV_MIN) |
952 | return newSViv (-(IV)uv); |
980 | return newSViv (-(IV)uv); |
953 | } |
981 | } |
954 | else |
982 | else |
955 | return newSVuv (uv); |
983 | return newSVuv (uv); |
956 | |
|
|
957 | // here would likely be the place for bigint support |
|
|
958 | } |
984 | } |
959 | } |
|
|
960 | |
985 | |
961 | // if we ever support bigint or bigfloat, this is the place for bigfloat |
986 | len -= *start == '-' ? 1 : 0; |
|
|
987 | |
|
|
988 | // does not fit into IV or UV, try NV |
|
|
989 | if ((sizeof (NV) == sizeof (double) && DBL_DIG >= len) |
|
|
990 | #if defined (LDBL_DIG) |
|
|
991 | || (sizeof (NV) == sizeof (long double) && LDBL_DIG >= len) |
|
|
992 | #endif |
|
|
993 | ) |
|
|
994 | // fits into NV without loss of precision |
|
|
995 | return newSVnv (Atof (start)); |
|
|
996 | |
|
|
997 | // everything else fails, convert it to a string |
|
|
998 | return newSVpvn (start, dec->cur - start); |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | // loss of precision here |
962 | return newSVnv (Atof (start)); |
1002 | return newSVnv (Atof (start)); |
963 | |
1003 | |
964 | fail: |
1004 | fail: |
965 | return 0; |
1005 | return 0; |
966 | } |
1006 | } |
… | |
… | |
1010 | } |
1050 | } |
1011 | |
1051 | |
1012 | static SV * |
1052 | static SV * |
1013 | decode_hv (dec_t *dec) |
1053 | decode_hv (dec_t *dec) |
1014 | { |
1054 | { |
|
|
1055 | SV *sv; |
1015 | HV *hv = newHV (); |
1056 | HV *hv = newHV (); |
1016 | |
1057 | |
1017 | DEC_INC_DEPTH; |
1058 | DEC_INC_DEPTH; |
1018 | decode_ws (dec); |
1059 | decode_ws (dec); |
1019 | |
1060 | |
1020 | if (*dec->cur == '}') |
1061 | if (*dec->cur == '}') |
1021 | ++dec->cur; |
1062 | ++dec->cur; |
1022 | else |
1063 | else |
1023 | for (;;) |
1064 | for (;;) |
1024 | { |
1065 | { |
1025 | SV *key, *value; |
|
|
1026 | |
|
|
1027 | decode_ws (dec); EXPECT_CH ('"'); |
1066 | decode_ws (dec); EXPECT_CH ('"'); |
1028 | |
1067 | |
1029 | key = decode_str (dec); |
1068 | // heuristic: assume that |
1030 | if (!key) |
1069 | // a) decode_str + hv_store_ent are abysmally slow. |
1031 | goto fail; |
1070 | // b) most hash keys are short, simple ascii text. |
|
|
1071 | // => try to "fast-match" such strings to avoid |
|
|
1072 | // the overhead of decode_str + hv_store_ent. |
|
|
1073 | { |
|
|
1074 | SV *value; |
|
|
1075 | char *p = dec->cur; |
|
|
1076 | char *e = p + 24; // only try up to 24 bytes |
1032 | |
1077 | |
1033 | decode_ws (dec); EXPECT_CH (':'); |
1078 | for (;;) |
1034 | |
|
|
1035 | value = decode_sv (dec); |
|
|
1036 | if (!value) |
|
|
1037 | { |
1079 | { |
|
|
1080 | // the >= 0x80 is true on most architectures |
|
|
1081 | if (p == e || *p < 0x20 || *p >= 0x80 || *p == '\\') |
|
|
1082 | { |
|
|
1083 | // slow path, back up and use decode_str |
|
|
1084 | SV *key = decode_str (dec); |
|
|
1085 | if (!key) |
|
|
1086 | goto fail; |
|
|
1087 | |
|
|
1088 | decode_ws (dec); EXPECT_CH (':'); |
|
|
1089 | |
|
|
1090 | value = decode_sv (dec); |
|
|
1091 | if (!value) |
|
|
1092 | { |
|
|
1093 | SvREFCNT_dec (key); |
|
|
1094 | goto fail; |
|
|
1095 | } |
|
|
1096 | |
|
|
1097 | hv_store_ent (hv, key, value, 0); |
1038 | SvREFCNT_dec (key); |
1098 | SvREFCNT_dec (key); |
|
|
1099 | |
|
|
1100 | break; |
|
|
1101 | } |
|
|
1102 | else if (*p == '"') |
|
|
1103 | { |
|
|
1104 | // fast path, got a simple key |
|
|
1105 | char *key = dec->cur; |
|
|
1106 | int len = p - key; |
|
|
1107 | dec->cur = p + 1; |
|
|
1108 | |
|
|
1109 | decode_ws (dec); EXPECT_CH (':'); |
|
|
1110 | |
|
|
1111 | value = decode_sv (dec); |
|
|
1112 | if (!value) |
1039 | goto fail; |
1113 | goto fail; |
|
|
1114 | |
|
|
1115 | hv_store (hv, key, len, value, 0); |
|
|
1116 | |
|
|
1117 | break; |
|
|
1118 | } |
|
|
1119 | |
|
|
1120 | ++p; |
1040 | } |
1121 | } |
1041 | |
1122 | } |
1042 | hv_store_ent (hv, key, value, 0); |
|
|
1043 | SvREFCNT_dec (key); |
|
|
1044 | |
1123 | |
1045 | decode_ws (dec); |
1124 | decode_ws (dec); |
1046 | |
1125 | |
1047 | if (*dec->cur == '}') |
1126 | if (*dec->cur == '}') |
1048 | { |
1127 | { |
… | |
… | |
1055 | |
1134 | |
1056 | ++dec->cur; |
1135 | ++dec->cur; |
1057 | } |
1136 | } |
1058 | |
1137 | |
1059 | DEC_DEC_DEPTH; |
1138 | DEC_DEC_DEPTH; |
1060 | return newRV_noinc ((SV *)hv); |
1139 | sv = newRV_noinc ((SV *)hv); |
|
|
1140 | |
|
|
1141 | // check filter callbacks |
|
|
1142 | if (dec->json.flags & F_HOOK) |
|
|
1143 | { |
|
|
1144 | if (dec->json.cb_sk_object && HvKEYS (hv) == 1) |
|
|
1145 | { |
|
|
1146 | HE *cb, *he; |
|
|
1147 | |
|
|
1148 | hv_iterinit (hv); |
|
|
1149 | he = hv_iternext (hv); |
|
|
1150 | hv_iterinit (hv); |
|
|
1151 | |
|
|
1152 | // the next line creates a mortal sv each time its called. |
|
|
1153 | // might want to optimise this for common cases. |
|
|
1154 | cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0); |
|
|
1155 | |
|
|
1156 | if (cb) |
|
|
1157 | { |
|
|
1158 | dSP; |
|
|
1159 | int count; |
|
|
1160 | |
|
|
1161 | ENTER; SAVETMPS; PUSHMARK (SP); |
|
|
1162 | XPUSHs (HeVAL (he)); |
|
|
1163 | |
|
|
1164 | PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; |
|
|
1165 | |
|
|
1166 | if (count == 1) |
|
|
1167 | { |
|
|
1168 | sv = newSVsv (POPs); |
|
|
1169 | FREETMPS; LEAVE; |
|
|
1170 | return sv; |
|
|
1171 | } |
|
|
1172 | |
|
|
1173 | FREETMPS; LEAVE; |
|
|
1174 | } |
|
|
1175 | } |
|
|
1176 | |
|
|
1177 | if (dec->json.cb_object) |
|
|
1178 | { |
|
|
1179 | dSP; |
|
|
1180 | int count; |
|
|
1181 | |
|
|
1182 | ENTER; SAVETMPS; PUSHMARK (SP); |
|
|
1183 | XPUSHs (sv_2mortal (sv)); |
|
|
1184 | |
|
|
1185 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
|
|
1186 | |
|
|
1187 | if (count == 1) |
|
|
1188 | { |
|
|
1189 | sv = newSVsv (POPs); |
|
|
1190 | FREETMPS; LEAVE; |
|
|
1191 | return sv; |
|
|
1192 | } |
|
|
1193 | |
|
|
1194 | SvREFCNT_inc (sv); |
|
|
1195 | FREETMPS; LEAVE; |
|
|
1196 | } |
|
|
1197 | } |
|
|
1198 | |
|
|
1199 | return sv; |
1061 | |
1200 | |
1062 | fail: |
1201 | fail: |
1063 | SvREFCNT_dec (hv); |
1202 | SvREFCNT_dec (hv); |
1064 | DEC_DEC_DEPTH; |
1203 | DEC_DEC_DEPTH; |
1065 | return 0; |
1204 | return 0; |
… | |
… | |
1124 | fail: |
1263 | fail: |
1125 | return 0; |
1264 | return 0; |
1126 | } |
1265 | } |
1127 | |
1266 | |
1128 | static SV * |
1267 | static SV * |
1129 | decode_json (SV *string, U32 flags, UV *offset_return) |
1268 | decode_json (SV *string, JSON *json, UV *offset_return) |
1130 | { |
1269 | { |
1131 | dec_t dec; |
1270 | dec_t dec; |
1132 | UV offset; |
1271 | UV offset; |
1133 | SV *sv; |
1272 | SV *sv; |
1134 | |
1273 | |
1135 | SvGETMAGIC (string); |
1274 | SvGETMAGIC (string); |
1136 | SvUPGRADE (string, SVt_PV); |
1275 | SvUPGRADE (string, SVt_PV); |
1137 | |
1276 | |
|
|
1277 | if (json->flags & F_MAXSIZE && SvCUR (string) > DEC_SIZE (json->flags)) |
|
|
1278 | croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", |
|
|
1279 | (unsigned long)SvCUR (string), (unsigned long)DEC_SIZE (json->flags)); |
|
|
1280 | |
1138 | if (flags & F_UTF8) |
1281 | if (json->flags & F_UTF8) |
1139 | sv_utf8_downgrade (string, 0); |
1282 | sv_utf8_downgrade (string, 0); |
1140 | else |
1283 | else |
1141 | sv_utf8_upgrade (string); |
1284 | sv_utf8_upgrade (string); |
1142 | |
1285 | |
1143 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
1286 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
1144 | |
1287 | |
1145 | dec.flags = flags; |
1288 | dec.json = *json; |
1146 | dec.cur = SvPVX (string); |
1289 | dec.cur = SvPVX (string); |
1147 | dec.end = SvEND (string); |
1290 | dec.end = SvEND (string); |
1148 | dec.err = 0; |
1291 | dec.err = 0; |
1149 | dec.depth = 0; |
1292 | dec.depth = 0; |
1150 | dec.maxdepth = DEC_DEPTH (dec.flags); |
1293 | dec.maxdepth = DEC_DEPTH (dec.json.flags); |
|
|
1294 | |
|
|
1295 | if (dec.json.cb_object || dec.json.cb_sk_object) |
|
|
1296 | dec.json.flags |= F_HOOK; |
1151 | |
1297 | |
1152 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
1298 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
1153 | sv = decode_sv (&dec); |
1299 | sv = decode_sv (&dec); |
1154 | |
1300 | |
1155 | if (!(offset_return || !sv)) |
1301 | if (!(offset_return || !sv)) |
… | |
… | |
1165 | } |
1311 | } |
1166 | } |
1312 | } |
1167 | |
1313 | |
1168 | if (offset_return || !sv) |
1314 | if (offset_return || !sv) |
1169 | { |
1315 | { |
1170 | offset = dec.flags & F_UTF8 |
1316 | offset = dec.json.flags & F_UTF8 |
1171 | ? dec.cur - SvPVX (string) |
1317 | ? dec.cur - SvPVX (string) |
1172 | : utf8_distance (dec.cur, SvPVX (string)); |
1318 | : utf8_distance (dec.cur, SvPVX (string)); |
1173 | |
1319 | |
1174 | if (offset_return) |
1320 | if (offset_return) |
1175 | *offset_return = offset; |
1321 | *offset_return = offset; |
… | |
… | |
1194 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1340 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1195 | } |
1341 | } |
1196 | |
1342 | |
1197 | sv = sv_2mortal (sv); |
1343 | sv = sv_2mortal (sv); |
1198 | |
1344 | |
1199 | if (!(dec.flags & F_ALLOW_NONREF) && !SvROK (sv)) |
1345 | if (!(dec.json.flags & F_ALLOW_NONREF) && !SvROK (sv)) |
1200 | croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); |
1346 | croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); |
1201 | |
1347 | |
1202 | return sv; |
1348 | return sv; |
1203 | } |
1349 | } |
1204 | |
1350 | |
… | |
… | |
1225 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1371 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1226 | } |
1372 | } |
1227 | |
1373 | |
1228 | PROTOTYPES: DISABLE |
1374 | PROTOTYPES: DISABLE |
1229 | |
1375 | |
1230 | SV *new (char *dummy) |
1376 | void CLONE (...) |
1231 | CODE: |
1377 | CODE: |
1232 | RETVAL = sv_bless (newRV_noinc (newSVuv (F_DEFAULT)), json_stash); |
1378 | json_stash = 0; |
1233 | OUTPUT: |
1379 | json_boolean_stash = 0; |
1234 | RETVAL |
|
|
1235 | |
1380 | |
|
|
1381 | void new (char *klass) |
|
|
1382 | PPCODE: |
|
|
1383 | { |
|
|
1384 | HV *stash = !JSON_SLOW || json_stash |
|
|
1385 | ? json_stash |
|
|
1386 | : gv_stashpv ("JSON::XS", 1); |
|
|
1387 | SV *pv = NEWSV (0, sizeof (JSON)); |
|
|
1388 | SvPOK_only (pv); |
|
|
1389 | Zero (SvPVX (pv), 1, JSON); |
|
|
1390 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
|
|
1391 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), stash))); |
|
|
1392 | } |
|
|
1393 | |
1236 | SV *ascii (SV *self, int enable = 1) |
1394 | void ascii (JSON *self, int enable = 1) |
1237 | ALIAS: |
1395 | ALIAS: |
1238 | ascii = F_ASCII |
1396 | ascii = F_ASCII |
1239 | latin1 = F_LATIN1 |
1397 | latin1 = F_LATIN1 |
1240 | utf8 = F_UTF8 |
1398 | utf8 = F_UTF8 |
1241 | indent = F_INDENT |
1399 | indent = F_INDENT |
… | |
… | |
1245 | pretty = F_PRETTY |
1403 | pretty = F_PRETTY |
1246 | allow_nonref = F_ALLOW_NONREF |
1404 | allow_nonref = F_ALLOW_NONREF |
1247 | shrink = F_SHRINK |
1405 | shrink = F_SHRINK |
1248 | allow_blessed = F_ALLOW_BLESSED |
1406 | allow_blessed = F_ALLOW_BLESSED |
1249 | convert_blessed = F_CONV_BLESSED |
1407 | convert_blessed = F_CONV_BLESSED |
1250 | CODE: |
1408 | PPCODE: |
1251 | { |
1409 | { |
1252 | UV *uv = SvJSON (self); |
|
|
1253 | if (enable) |
1410 | if (enable) |
1254 | *uv |= ix; |
1411 | self->flags |= ix; |
1255 | else |
1412 | else |
1256 | *uv &= ~ix; |
1413 | self->flags &= ~ix; |
1257 | |
1414 | |
1258 | RETVAL = newSVsv (self); |
1415 | XPUSHs (ST (0)); |
1259 | } |
1416 | } |
1260 | OUTPUT: |
|
|
1261 | RETVAL |
|
|
1262 | |
1417 | |
1263 | SV *max_depth (SV *self, UV max_depth = 0x80000000UL) |
1418 | void max_depth (JSON *self, UV max_depth = 0x80000000UL) |
1264 | CODE: |
1419 | PPCODE: |
1265 | { |
1420 | { |
1266 | UV *uv = SvJSON (self); |
|
|
1267 | UV log2 = 0; |
1421 | UV log2 = 0; |
1268 | |
1422 | |
1269 | if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; |
1423 | if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; |
1270 | |
1424 | |
1271 | while ((1UL << log2) < max_depth) |
1425 | while ((1UL << log2) < max_depth) |
1272 | ++log2; |
1426 | ++log2; |
1273 | |
1427 | |
1274 | *uv = *uv & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
1428 | self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
1275 | |
1429 | |
1276 | RETVAL = newSVsv (self); |
1430 | XPUSHs (ST (0)); |
1277 | } |
1431 | } |
1278 | OUTPUT: |
|
|
1279 | RETVAL |
|
|
1280 | |
1432 | |
1281 | void encode (SV *self, SV *scalar) |
1433 | void max_size (JSON *self, UV max_size = 0) |
1282 | PPCODE: |
1434 | PPCODE: |
1283 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1435 | { |
|
|
1436 | UV log2 = 0; |
1284 | |
1437 | |
1285 | void decode (SV *self, SV *jsonstr) |
1438 | if (max_size > 0x80000000UL) max_size = 0x80000000UL; |
|
|
1439 | if (max_size == 1) max_size = 2; |
|
|
1440 | |
|
|
1441 | while ((1UL << log2) < max_size) |
|
|
1442 | ++log2; |
|
|
1443 | |
|
|
1444 | self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); |
|
|
1445 | |
|
|
1446 | XPUSHs (ST (0)); |
|
|
1447 | } |
|
|
1448 | |
|
|
1449 | void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) |
1286 | PPCODE: |
1450 | PPCODE: |
|
|
1451 | { |
|
|
1452 | SvREFCNT_dec (self->cb_object); |
|
|
1453 | self->cb_object = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1454 | |
|
|
1455 | XPUSHs (ST (0)); |
|
|
1456 | } |
|
|
1457 | |
|
|
1458 | void filter_json_single_key_object (JSON *self, SV *key, SV *cb = &PL_sv_undef) |
|
|
1459 | PPCODE: |
|
|
1460 | { |
|
|
1461 | if (!self->cb_sk_object) |
|
|
1462 | self->cb_sk_object = newHV (); |
|
|
1463 | |
|
|
1464 | if (SvOK (cb)) |
|
|
1465 | hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0); |
|
|
1466 | else |
|
|
1467 | { |
|
|
1468 | hv_delete_ent (self->cb_sk_object, key, G_DISCARD, 0); |
|
|
1469 | |
|
|
1470 | if (!HvKEYS (self->cb_sk_object)) |
|
|
1471 | { |
|
|
1472 | SvREFCNT_dec (self->cb_sk_object); |
|
|
1473 | self->cb_sk_object = 0; |
|
|
1474 | } |
|
|
1475 | } |
|
|
1476 | |
|
|
1477 | XPUSHs (ST (0)); |
|
|
1478 | } |
|
|
1479 | |
|
|
1480 | void encode (JSON *self, SV *scalar) |
|
|
1481 | PPCODE: |
|
|
1482 | XPUSHs (encode_json (scalar, self)); |
|
|
1483 | |
|
|
1484 | void decode (JSON *self, SV *jsonstr) |
|
|
1485 | PPCODE: |
1287 | XPUSHs (decode_json (jsonstr, *SvJSON (self), 0)); |
1486 | XPUSHs (decode_json (jsonstr, self, 0)); |
1288 | |
1487 | |
1289 | void decode_prefix (SV *self, SV *jsonstr) |
1488 | void decode_prefix (JSON *self, SV *jsonstr) |
1290 | PPCODE: |
1489 | PPCODE: |
1291 | { |
1490 | { |
1292 | UV offset; |
1491 | UV offset; |
1293 | EXTEND (SP, 2); |
1492 | EXTEND (SP, 2); |
1294 | PUSHs (decode_json (jsonstr, *SvJSON (self), &offset)); |
1493 | PUSHs (decode_json (jsonstr, self, &offset)); |
1295 | PUSHs (sv_2mortal (newSVuv (offset))); |
1494 | PUSHs (sv_2mortal (newSVuv (offset))); |
1296 | } |
1495 | } |
1297 | |
1496 | |
|
|
1497 | void DESTROY (JSON *self) |
|
|
1498 | CODE: |
|
|
1499 | SvREFCNT_dec (self->cb_sk_object); |
|
|
1500 | SvREFCNT_dec (self->cb_object); |
|
|
1501 | |
1298 | PROTOTYPES: ENABLE |
1502 | PROTOTYPES: ENABLE |
1299 | |
1503 | |
1300 | void to_json (SV *scalar) |
1504 | void to_json (SV *scalar) |
1301 | ALIAS: |
|
|
1302 | objToJson = 0 |
|
|
1303 | PPCODE: |
1505 | PPCODE: |
|
|
1506 | { |
|
|
1507 | JSON json = { F_DEFAULT | F_UTF8 }; |
1304 | XPUSHs (encode_json (scalar, F_DEFAULT | F_UTF8)); |
1508 | XPUSHs (encode_json (scalar, &json)); |
|
|
1509 | } |
1305 | |
1510 | |
1306 | void from_json (SV *jsonstr) |
1511 | void from_json (SV *jsonstr) |
1307 | ALIAS: |
|
|
1308 | jsonToObj = 0 |
|
|
1309 | PPCODE: |
1512 | PPCODE: |
|
|
1513 | { |
|
|
1514 | JSON json = { F_DEFAULT | F_UTF8 }; |
1310 | XPUSHs (decode_json (jsonstr, F_DEFAULT | F_UTF8, 0)); |
1515 | XPUSHs (decode_json (jsonstr, &json, 0)); |
|
|
1516 | } |
1311 | |
1517 | |