… | |
… | |
15 | |
15 | |
16 | // some old perls do not have this, try to make it work, no |
16 | // some old perls do not have this, try to make it work, no |
17 | // guarantees, though. if it breaks, you get to keep the pieces. |
17 | // guarantees, though. if it breaks, you get to keep the pieces. |
18 | #ifndef UTF8_MAXBYTES |
18 | #ifndef UTF8_MAXBYTES |
19 | # define UTF8_MAXBYTES 13 |
19 | # define UTF8_MAXBYTES 13 |
|
|
20 | #endif |
|
|
21 | |
|
|
22 | // compatibility with perl <5.18 |
|
|
23 | #ifndef HvNAMELEN_get |
|
|
24 | # define HvNAMELEN_get(hv) strlen (HvNAME (hv)) |
|
|
25 | #endif |
|
|
26 | #ifndef HvNAMELEN |
|
|
27 | # define HvNAMELEN(hv) HvNAMELEN_get (hv) |
|
|
28 | #endif |
|
|
29 | #ifndef HvNAMEUTF8 |
|
|
30 | # define HvNAMEUTF8(hv) 0 |
20 | #endif |
31 | #endif |
21 | |
32 | |
22 | // three extra for rounding, sign, and end of string |
33 | // three extra for rounding, sign, and end of string |
23 | #define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3) |
34 | #define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3) |
24 | |
35 | |
… | |
… | |
33 | #define F_SHRINK 0x00000200UL |
44 | #define F_SHRINK 0x00000200UL |
34 | #define F_ALLOW_BLESSED 0x00000400UL |
45 | #define F_ALLOW_BLESSED 0x00000400UL |
35 | #define F_CONV_BLESSED 0x00000800UL |
46 | #define F_CONV_BLESSED 0x00000800UL |
36 | #define F_RELAXED 0x00001000UL |
47 | #define F_RELAXED 0x00001000UL |
37 | #define F_ALLOW_UNKNOWN 0x00002000UL |
48 | #define F_ALLOW_UNKNOWN 0x00002000UL |
|
|
49 | #define F_ALLOW_TAGS 0x00004000UL |
38 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
50 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
39 | |
51 | |
40 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
52 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
41 | |
53 | |
42 | #define INIT_SIZE 32 // initial scalar size to be allocated |
54 | #define INIT_SIZE 32 // initial scalar size to be allocated |
… | |
… | |
67 | #define ERR_NESTING_EXCEEDED "json text or perl structure exceeds maximum nesting level (max_depth set too low?)" |
79 | #define ERR_NESTING_EXCEEDED "json text or perl structure exceeds maximum nesting level (max_depth set too low?)" |
68 | |
80 | |
69 | #ifdef USE_ITHREADS |
81 | #ifdef USE_ITHREADS |
70 | # define JSON_SLOW 1 |
82 | # define JSON_SLOW 1 |
71 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
83 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
|
|
84 | # define BOOL_STASH (bool_stash ? bool_stash : gv_stashpv ("Types::Serialiser::Boolean", 1)) |
72 | #else |
85 | #else |
73 | # define JSON_SLOW 0 |
86 | # define JSON_SLOW 0 |
74 | # define JSON_STASH json_stash |
87 | # define JSON_STASH json_stash |
|
|
88 | # define BOOL_STASH bool_stash |
75 | #endif |
89 | #endif |
76 | |
90 | |
77 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
91 | // the amount of HEs to allocate on the stack, when sorting keys |
78 | static SV *json_true, *json_false; |
92 | #define STACK_HES 64 |
|
|
93 | |
|
|
94 | static HV *json_stash, *bool_stash; // JSON::XS::, Types::Serialiser::Boolean:: |
|
|
95 | static SV *bool_true, *bool_false, *sv_json; |
79 | |
96 | |
80 | enum { |
97 | enum { |
81 | INCR_M_WS = 0, // initial whitespace skipping, must be 0 |
98 | INCR_M_WS = 0, // initial whitespace skipping, must be 0 |
82 | INCR_M_STR, // inside string |
99 | INCR_M_STR, // inside string |
83 | INCR_M_BS, // inside backslash |
100 | INCR_M_BS, // inside backslash |
… | |
… | |
284 | // a recursion depth of ten gives us >>500 bits |
301 | // a recursion depth of ten gives us >>500 bits |
285 | json_atof_scan1 (s, &accum, &expo, 0, 10); |
302 | json_atof_scan1 (s, &accum, &expo, 0, 10); |
286 | |
303 | |
287 | return neg ? -accum : accum; |
304 | return neg ? -accum : accum; |
288 | } |
305 | } |
|
|
306 | |
|
|
307 | // target of scalar reference is bool? -1 == nope, 0 == false, 1 == true |
|
|
308 | static int |
|
|
309 | ref_bool_type (SV *sv) |
|
|
310 | { |
|
|
311 | svtype svt = SvTYPE (sv); |
|
|
312 | |
|
|
313 | if (svt < SVt_PVAV) |
|
|
314 | { |
|
|
315 | STRLEN len = 0; |
|
|
316 | char *pv = svt ? SvPV (sv, len) : 0; |
|
|
317 | |
|
|
318 | if (len == 1) |
|
|
319 | if (*pv == '1') |
|
|
320 | return 1; |
|
|
321 | else if (*pv == '0') |
|
|
322 | return 0; |
|
|
323 | |
|
|
324 | } |
|
|
325 | |
|
|
326 | return -1; |
|
|
327 | } |
|
|
328 | |
|
|
329 | // returns whether scalar is not a reference in the sense of allow_nonref |
|
|
330 | static int |
|
|
331 | json_nonref (SV *scalar) |
|
|
332 | { |
|
|
333 | if (!SvROK (scalar)) |
|
|
334 | return 1; |
|
|
335 | |
|
|
336 | scalar = SvRV (scalar); |
|
|
337 | |
|
|
338 | if (SvSTASH (scalar) == bool_stash) |
|
|
339 | return 1; |
|
|
340 | |
|
|
341 | if (!SvOBJECT (scalar) && ref_bool_type (scalar) >= 0) |
|
|
342 | return 1; |
|
|
343 | |
|
|
344 | return 0; |
|
|
345 | } |
|
|
346 | |
289 | ///////////////////////////////////////////////////////////////////////////// |
347 | ///////////////////////////////////////////////////////////////////////////// |
290 | // encoder |
348 | // encoder |
291 | |
349 | |
292 | // structure used for encoding JSON |
350 | // structure used for encoding JSON |
293 | typedef struct |
351 | typedef struct |
… | |
… | |
480 | |
538 | |
481 | if (enc->indent >= enc->json.max_depth) |
539 | if (enc->indent >= enc->json.max_depth) |
482 | croak (ERR_NESTING_EXCEEDED); |
540 | croak (ERR_NESTING_EXCEEDED); |
483 | |
541 | |
484 | encode_ch (enc, '['); |
542 | encode_ch (enc, '['); |
485 | |
543 | |
486 | if (len >= 0) |
544 | if (len >= 0) |
487 | { |
545 | { |
488 | encode_nl (enc); ++enc->indent; |
546 | encode_nl (enc); ++enc->indent; |
489 | |
547 | |
490 | for (i = 0; i <= len; ++i) |
548 | for (i = 0; i <= len; ++i) |
… | |
… | |
502 | encode_comma (enc); |
560 | encode_comma (enc); |
503 | } |
561 | } |
504 | |
562 | |
505 | encode_nl (enc); --enc->indent; encode_indent (enc); |
563 | encode_nl (enc); --enc->indent; encode_indent (enc); |
506 | } |
564 | } |
507 | |
565 | |
508 | encode_ch (enc, ']'); |
566 | encode_ch (enc, ']'); |
509 | } |
567 | } |
510 | |
568 | |
511 | static void |
569 | static void |
512 | encode_hk (enc_t *enc, HE *he) |
570 | encode_hk (enc_t *enc, HE *he) |
… | |
… | |
516 | if (HeKLEN (he) == HEf_SVKEY) |
574 | if (HeKLEN (he) == HEf_SVKEY) |
517 | { |
575 | { |
518 | SV *sv = HeSVKEY (he); |
576 | SV *sv = HeSVKEY (he); |
519 | STRLEN len; |
577 | STRLEN len; |
520 | char *str; |
578 | char *str; |
521 | |
579 | |
522 | SvGETMAGIC (sv); |
580 | SvGETMAGIC (sv); |
523 | str = SvPV (sv, len); |
581 | str = SvPV (sv, len); |
524 | |
582 | |
525 | encode_str (enc, str, len, SvUTF8 (sv)); |
583 | encode_str (enc, str, len, SvUTF8 (sv)); |
526 | } |
584 | } |
… | |
… | |
592 | } |
650 | } |
593 | |
651 | |
594 | if (count) |
652 | if (count) |
595 | { |
653 | { |
596 | int i, fast = 1; |
654 | int i, fast = 1; |
597 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
655 | HE *hes_stack [STACK_HES]; |
598 | HE **hes = _alloca (count * sizeof (HE)); |
656 | HE **hes = hes_stack; |
599 | #else |
657 | |
600 | HE *hes [count]; // if your compiler dies here, you need to enable C99 mode |
658 | // allocate larger arrays on the heap |
601 | #endif |
659 | if (count > STACK_HES) |
|
|
660 | { |
|
|
661 | SV *sv = sv_2mortal (NEWSV (0, count * sizeof (*hes))); |
|
|
662 | hes = (HE **)SvPVX (sv); |
|
|
663 | } |
602 | |
664 | |
603 | i = 0; |
665 | i = 0; |
604 | while ((he = hv_iternext (hv))) |
666 | while ((he = hv_iternext (hv))) |
605 | { |
667 | { |
606 | hes [i++] = he; |
668 | hes [i++] = he; |
… | |
… | |
675 | // encode objects, arrays and special \0=false and \1=true values. |
737 | // encode objects, arrays and special \0=false and \1=true values. |
676 | static void |
738 | static void |
677 | encode_rv (enc_t *enc, SV *sv) |
739 | encode_rv (enc_t *enc, SV *sv) |
678 | { |
740 | { |
679 | svtype svt; |
741 | svtype svt; |
|
|
742 | GV *method; |
680 | |
743 | |
681 | SvGETMAGIC (sv); |
744 | SvGETMAGIC (sv); |
682 | svt = SvTYPE (sv); |
745 | svt = SvTYPE (sv); |
683 | |
746 | |
684 | if (expect_false (SvOBJECT (sv))) |
747 | if (expect_false (SvOBJECT (sv))) |
685 | { |
748 | { |
686 | HV *stash = !JSON_SLOW || json_boolean_stash |
749 | HV *stash = SvSTASH (sv); |
687 | ? json_boolean_stash |
|
|
688 | : gv_stashpv ("JSON::XS::Boolean", 1); |
|
|
689 | |
750 | |
690 | if (SvSTASH (sv) == stash) |
751 | if (stash == bool_stash) |
691 | { |
752 | { |
692 | if (SvIV (sv)) |
753 | if (SvIV (sv)) |
693 | encode_str (enc, "true", 4, 0); |
754 | encode_str (enc, "true", 4, 0); |
694 | else |
755 | else |
695 | encode_str (enc, "false", 5, 0); |
756 | encode_str (enc, "false", 5, 0); |
696 | } |
757 | } |
|
|
758 | else if ((enc->json.flags & F_ALLOW_TAGS) && (method = gv_fetchmethod_autoload (stash, "FREEZE", 0))) |
|
|
759 | { |
|
|
760 | int count; |
|
|
761 | dSP; |
|
|
762 | |
|
|
763 | ENTER; SAVETMPS; |
|
|
764 | SAVESTACK_POS (); |
|
|
765 | PUSHMARK (SP); |
|
|
766 | EXTEND (SP, 2); |
|
|
767 | // we re-bless the reference to get overload and other niceties right |
|
|
768 | PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); |
|
|
769 | PUSHs (sv_json); |
|
|
770 | |
|
|
771 | PUTBACK; |
|
|
772 | count = call_sv ((SV *)GvCV (method), G_ARRAY); |
|
|
773 | SPAGAIN; |
|
|
774 | |
|
|
775 | // catch this surprisingly common error |
|
|
776 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
|
|
777 | croak ("%s::FREEZE method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
|
|
778 | |
|
|
779 | encode_ch (enc, '('); |
|
|
780 | encode_ch (enc, '"'); |
|
|
781 | encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash)); |
|
|
782 | encode_ch (enc, '"'); |
|
|
783 | encode_ch (enc, ')'); |
|
|
784 | encode_ch (enc, '['); |
|
|
785 | |
|
|
786 | while (count) |
|
|
787 | { |
|
|
788 | encode_sv (enc, SP[1 - count--]); |
|
|
789 | |
|
|
790 | if (count) |
|
|
791 | encode_ch (enc, ','); |
|
|
792 | } |
|
|
793 | |
|
|
794 | encode_ch (enc, ']'); |
|
|
795 | |
|
|
796 | FREETMPS; LEAVE; |
|
|
797 | } |
|
|
798 | else if ((enc->json.flags & F_CONV_BLESSED) && (method = gv_fetchmethod_autoload (stash, "TO_JSON", 0))) |
|
|
799 | { |
|
|
800 | dSP; |
|
|
801 | |
|
|
802 | ENTER; SAVETMPS; |
|
|
803 | PUSHMARK (SP); |
|
|
804 | // we re-bless the reference to get overload and other niceties right |
|
|
805 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); |
|
|
806 | |
|
|
807 | // calling with G_SCALAR ensures that we always get a 1 return value |
|
|
808 | PUTBACK; |
|
|
809 | call_sv ((SV *)GvCV (method), G_SCALAR); |
|
|
810 | SPAGAIN; |
|
|
811 | |
|
|
812 | // catch this surprisingly common error |
|
|
813 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
|
|
814 | croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
|
|
815 | |
|
|
816 | sv = POPs; |
|
|
817 | PUTBACK; |
|
|
818 | |
|
|
819 | encode_sv (enc, sv); |
|
|
820 | |
|
|
821 | FREETMPS; LEAVE; |
|
|
822 | } |
|
|
823 | else if (enc->json.flags & F_ALLOW_BLESSED) |
|
|
824 | encode_str (enc, "null", 4, 0); |
697 | else |
825 | else |
698 | { |
|
|
699 | #if 0 |
|
|
700 | if (0 && sv_derived_from (rv, "JSON::Literal")) |
|
|
701 | { |
|
|
702 | // not yet |
|
|
703 | } |
|
|
704 | #endif |
|
|
705 | if (enc->json.flags & F_CONV_BLESSED) |
|
|
706 | { |
|
|
707 | // we re-bless the reference to get overload and other niceties right |
|
|
708 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
|
|
709 | |
|
|
710 | if (to_json) |
|
|
711 | { |
|
|
712 | dSP; |
|
|
713 | |
|
|
714 | ENTER; SAVETMPS; PUSHMARK (SP); |
|
|
715 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
|
|
716 | |
|
|
717 | // calling with G_SCALAR ensures that we always get a 1 return value |
|
|
718 | PUTBACK; |
|
|
719 | call_sv ((SV *)GvCV (to_json), G_SCALAR); |
|
|
720 | SPAGAIN; |
|
|
721 | |
|
|
722 | // catch this surprisingly common error |
|
|
723 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
|
|
724 | croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
|
|
725 | |
|
|
726 | sv = POPs; |
|
|
727 | PUTBACK; |
|
|
728 | |
|
|
729 | encode_sv (enc, sv); |
|
|
730 | |
|
|
731 | FREETMPS; LEAVE; |
|
|
732 | } |
|
|
733 | else if (enc->json.flags & F_ALLOW_BLESSED) |
|
|
734 | encode_str (enc, "null", 4, 0); |
|
|
735 | else |
|
|
736 | croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it", |
|
|
737 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
738 | } |
|
|
739 | else if (enc->json.flags & F_ALLOW_BLESSED) |
|
|
740 | encode_str (enc, "null", 4, 0); |
|
|
741 | else |
|
|
742 | croak ("encountered object '%s', but neither allow_blessed nor convert_blessed settings are enabled", |
826 | croak ("encountered object '%s', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing)", |
743 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
827 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
744 | } |
|
|
745 | } |
828 | } |
746 | else if (svt == SVt_PVHV) |
829 | else if (svt == SVt_PVHV) |
747 | encode_hv (enc, (HV *)sv); |
830 | encode_hv (enc, (HV *)sv); |
748 | else if (svt == SVt_PVAV) |
831 | else if (svt == SVt_PVAV) |
749 | encode_av (enc, (AV *)sv); |
832 | encode_av (enc, (AV *)sv); |
750 | else if (svt < SVt_PVAV) |
833 | else if (svt < SVt_PVAV) |
751 | { |
834 | { |
752 | STRLEN len = 0; |
835 | int bool_type = ref_bool_type (sv); |
753 | char *pv = svt ? SvPV (sv, len) : 0; |
|
|
754 | |
836 | |
755 | if (len == 1 && *pv == '1') |
837 | if (bool_type == 1) |
756 | encode_str (enc, "true", 4, 0); |
838 | encode_str (enc, "true", 4, 0); |
757 | else if (len == 1 && *pv == '0') |
839 | else if (bool_type == 0) |
758 | encode_str (enc, "false", 5, 0); |
840 | encode_str (enc, "false", 5, 0); |
759 | else if (enc->json.flags & F_ALLOW_UNKNOWN) |
841 | else if (enc->json.flags & F_ALLOW_UNKNOWN) |
760 | encode_str (enc, "null", 4, 0); |
842 | encode_str (enc, "null", 4, 0); |
761 | else |
843 | else |
762 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
844 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
… | |
… | |
825 | } |
907 | } |
826 | else |
908 | else |
827 | { |
909 | { |
828 | // large integer, use the (rather slow) snprintf way. |
910 | // large integer, use the (rather slow) snprintf way. |
829 | need (enc, IVUV_MAXCHARS); |
911 | need (enc, IVUV_MAXCHARS); |
830 | enc->cur += |
912 | enc->cur += |
831 | SvIsUV(sv) |
913 | SvIsUV(sv) |
832 | ? snprintf (enc->cur, IVUV_MAXCHARS, "%"UVuf, (UV)SvUVX (sv)) |
914 | ? snprintf (enc->cur, IVUV_MAXCHARS, "%"UVuf, (UV)SvUVX (sv)) |
833 | : snprintf (enc->cur, IVUV_MAXCHARS, "%"IVdf, (IV)SvIVX (sv)); |
915 | : snprintf (enc->cur, IVUV_MAXCHARS, "%"IVdf, (IV)SvIVX (sv)); |
834 | } |
916 | } |
835 | } |
917 | } |
836 | else if (SvROK (sv)) |
918 | else if (SvROK (sv)) |
837 | encode_rv (enc, SvRV (sv)); |
919 | encode_rv (enc, SvRV (sv)); |
838 | else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) |
920 | else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) |
839 | encode_str (enc, "null", 4, 0); |
921 | encode_str (enc, "null", 4, 0); |
840 | else |
922 | else |
841 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
923 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, check your input data", |
842 | SvPV_nolen (sv), SvFLAGS (sv)); |
924 | SvPV_nolen (sv), (unsigned int)SvFLAGS (sv)); |
843 | } |
925 | } |
844 | |
926 | |
845 | static SV * |
927 | static SV * |
846 | encode_json (SV *scalar, JSON *json) |
928 | encode_json (SV *scalar, JSON *json) |
847 | { |
929 | { |
848 | enc_t enc; |
930 | enc_t enc; |
849 | |
931 | |
850 | if (!(json->flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
932 | if (!(json->flags & F_ALLOW_NONREF) && json_nonref (scalar)) |
851 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
933 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
852 | |
934 | |
853 | enc.json = *json; |
935 | enc.json = *json; |
854 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
936 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
855 | enc.cur = SvPVX (enc.sv); |
937 | enc.cur = SvPVX (enc.sv); |
… | |
… | |
1062 | *cur++ = *dec_cur++; |
1144 | *cur++ = *dec_cur++; |
1063 | while (--clen); |
1145 | while (--clen); |
1064 | |
1146 | |
1065 | utf8 = 1; |
1147 | utf8 = 1; |
1066 | } |
1148 | } |
|
|
1149 | else if (ch == '\t' && dec->json.flags & F_RELAXED) |
|
|
1150 | *cur++ = ch; |
1067 | else |
1151 | else |
1068 | { |
1152 | { |
1069 | --dec_cur; |
1153 | --dec_cur; |
1070 | |
1154 | |
1071 | if (!ch) |
1155 | if (!ch) |
… | |
… | |
1259 | if (*dec->cur == ']') |
1343 | if (*dec->cur == ']') |
1260 | { |
1344 | { |
1261 | ++dec->cur; |
1345 | ++dec->cur; |
1262 | break; |
1346 | break; |
1263 | } |
1347 | } |
1264 | |
1348 | |
1265 | if (*dec->cur != ',') |
1349 | if (*dec->cur != ',') |
1266 | ERR (", or ] expected while parsing array"); |
1350 | ERR (", or ] expected while parsing array"); |
1267 | |
1351 | |
1268 | ++dec->cur; |
1352 | ++dec->cur; |
1269 | |
1353 | |
… | |
… | |
1393 | |
1477 | |
1394 | hv_iterinit (hv); |
1478 | hv_iterinit (hv); |
1395 | he = hv_iternext (hv); |
1479 | he = hv_iternext (hv); |
1396 | hv_iterinit (hv); |
1480 | hv_iterinit (hv); |
1397 | |
1481 | |
1398 | // the next line creates a mortal sv each time its called. |
1482 | // the next line creates a mortal sv each time it's called. |
1399 | // might want to optimise this for common cases. |
1483 | // might want to optimise this for common cases. |
1400 | cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0); |
1484 | cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0); |
1401 | |
1485 | |
1402 | if (cb) |
1486 | if (cb) |
1403 | { |
1487 | { |
1404 | dSP; |
1488 | dSP; |
1405 | int count; |
1489 | int count; |
1406 | |
1490 | |
1407 | ENTER; SAVETMPS; PUSHMARK (SP); |
1491 | ENTER; SAVETMPS; |
|
|
1492 | SAVESTACK_POS (); |
|
|
1493 | PUSHMARK (SP); |
1408 | XPUSHs (HeVAL (he)); |
1494 | XPUSHs (HeVAL (he)); |
1409 | sv_2mortal (sv); |
1495 | sv_2mortal (sv); |
1410 | |
1496 | |
1411 | PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; |
1497 | PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; |
1412 | |
1498 | |
… | |
… | |
1425 | if (dec->json.cb_object) |
1511 | if (dec->json.cb_object) |
1426 | { |
1512 | { |
1427 | dSP; |
1513 | dSP; |
1428 | int count; |
1514 | int count; |
1429 | |
1515 | |
1430 | ENTER; SAVETMPS; PUSHMARK (SP); |
1516 | ENTER; SAVETMPS; |
|
|
1517 | SAVESTACK_POS (); |
|
|
1518 | PUSHMARK (SP); |
1431 | XPUSHs (sv_2mortal (sv)); |
1519 | XPUSHs (sv_2mortal (sv)); |
1432 | |
1520 | |
1433 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
1521 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
1434 | |
1522 | |
1435 | if (count == 1) |
1523 | if (count == 1) |
… | |
… | |
1451 | DEC_DEC_DEPTH; |
1539 | DEC_DEC_DEPTH; |
1452 | return 0; |
1540 | return 0; |
1453 | } |
1541 | } |
1454 | |
1542 | |
1455 | static SV * |
1543 | static SV * |
|
|
1544 | decode_tag (dec_t *dec) |
|
|
1545 | { |
|
|
1546 | SV *tag = 0; |
|
|
1547 | SV *val = 0; |
|
|
1548 | |
|
|
1549 | if (!(dec->json.flags & F_ALLOW_TAGS)) |
|
|
1550 | ERR ("malformed JSON string, neither array, object, number, string or atom"); |
|
|
1551 | |
|
|
1552 | ++dec->cur; |
|
|
1553 | |
|
|
1554 | decode_ws (dec); |
|
|
1555 | |
|
|
1556 | tag = decode_sv (dec); |
|
|
1557 | if (!tag) |
|
|
1558 | goto fail; |
|
|
1559 | |
|
|
1560 | if (!SvPOK (tag)) |
|
|
1561 | ERR ("malformed JSON string, (tag) must be a string"); |
|
|
1562 | |
|
|
1563 | decode_ws (dec); |
|
|
1564 | |
|
|
1565 | if (*dec->cur != ')') |
|
|
1566 | ERR (") expected after tag"); |
|
|
1567 | |
|
|
1568 | ++dec->cur; |
|
|
1569 | |
|
|
1570 | decode_ws (dec); |
|
|
1571 | |
|
|
1572 | val = decode_sv (dec); |
|
|
1573 | if (!val) |
|
|
1574 | goto fail; |
|
|
1575 | |
|
|
1576 | if (!SvROK (val) || SvTYPE (SvRV (val)) != SVt_PVAV) |
|
|
1577 | ERR ("malformed JSON string, tag value must be an array"); |
|
|
1578 | |
|
|
1579 | { |
|
|
1580 | AV *av = (AV *)SvRV (val); |
|
|
1581 | int i, len = av_len (av) + 1; |
|
|
1582 | HV *stash = gv_stashsv (tag, 0); |
|
|
1583 | SV *sv; |
|
|
1584 | |
|
|
1585 | if (!stash) |
|
|
1586 | ERR ("cannot decode perl-object (package does not exist)"); |
|
|
1587 | |
|
|
1588 | GV *method = gv_fetchmethod_autoload (stash, "THAW", 0); |
|
|
1589 | |
|
|
1590 | if (!method) |
|
|
1591 | ERR ("cannot decode perl-object (package does not have a THAW method)"); |
|
|
1592 | |
|
|
1593 | dSP; |
|
|
1594 | |
|
|
1595 | ENTER; SAVETMPS; |
|
|
1596 | PUSHMARK (SP); |
|
|
1597 | EXTEND (SP, len + 2); |
|
|
1598 | // we re-bless the reference to get overload and other niceties right |
|
|
1599 | PUSHs (tag); |
|
|
1600 | PUSHs (sv_json); |
|
|
1601 | |
|
|
1602 | for (i = 0; i < len; ++i) |
|
|
1603 | PUSHs (*av_fetch (av, i, 1)); |
|
|
1604 | |
|
|
1605 | PUTBACK; |
|
|
1606 | call_sv ((SV *)GvCV (method), G_SCALAR); |
|
|
1607 | SPAGAIN; |
|
|
1608 | |
|
|
1609 | SvREFCNT_dec (tag); |
|
|
1610 | SvREFCNT_dec (val); |
|
|
1611 | sv = SvREFCNT_inc (POPs); |
|
|
1612 | |
|
|
1613 | PUTBACK; |
|
|
1614 | |
|
|
1615 | FREETMPS; LEAVE; |
|
|
1616 | |
|
|
1617 | return sv; |
|
|
1618 | } |
|
|
1619 | |
|
|
1620 | fail: |
|
|
1621 | SvREFCNT_dec (tag); |
|
|
1622 | SvREFCNT_dec (val); |
|
|
1623 | return 0; |
|
|
1624 | } |
|
|
1625 | |
|
|
1626 | static SV * |
1456 | decode_sv (dec_t *dec) |
1627 | decode_sv (dec_t *dec) |
1457 | { |
1628 | { |
1458 | // the beauty of JSON: you need exactly one character lookahead |
1629 | // the beauty of JSON: you need exactly one character lookahead |
1459 | // to parse everything. |
1630 | // to parse everything. |
1460 | switch (*dec->cur) |
1631 | switch (*dec->cur) |
1461 | { |
1632 | { |
1462 | case '"': ++dec->cur; return decode_str (dec); |
1633 | case '"': ++dec->cur; return decode_str (dec); |
1463 | case '[': ++dec->cur; return decode_av (dec); |
1634 | case '[': ++dec->cur; return decode_av (dec); |
1464 | case '{': ++dec->cur; return decode_hv (dec); |
1635 | case '{': ++dec->cur; return decode_hv (dec); |
|
|
1636 | case '(': return decode_tag (dec); |
1465 | |
1637 | |
1466 | case '-': |
1638 | case '-': |
1467 | case '0': case '1': case '2': case '3': case '4': |
1639 | case '0': case '1': case '2': case '3': case '4': |
1468 | case '5': case '6': case '7': case '8': case '9': |
1640 | case '5': case '6': case '7': case '8': case '9': |
1469 | return decode_num (dec); |
1641 | return decode_num (dec); |
… | |
… | |
1471 | case 't': |
1643 | case 't': |
1472 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1644 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1473 | { |
1645 | { |
1474 | dec->cur += 4; |
1646 | dec->cur += 4; |
1475 | #if JSON_SLOW |
1647 | #if JSON_SLOW |
1476 | json_true = get_bool ("JSON::XS::true"); |
1648 | bool_true = get_bool ("Types::Serialiser::true"); |
1477 | #endif |
1649 | #endif |
1478 | return newSVsv (json_true); |
1650 | return newSVsv (bool_true); |
1479 | } |
1651 | } |
1480 | else |
1652 | else |
1481 | ERR ("'true' expected"); |
1653 | ERR ("'true' expected"); |
1482 | |
1654 | |
1483 | break; |
1655 | break; |
… | |
… | |
1485 | case 'f': |
1657 | case 'f': |
1486 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1658 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1487 | { |
1659 | { |
1488 | dec->cur += 5; |
1660 | dec->cur += 5; |
1489 | #if JSON_SLOW |
1661 | #if JSON_SLOW |
1490 | json_false = get_bool ("JSON::XS::false"); |
1662 | bool_false = get_bool ("Types::Serialiser::false"); |
1491 | #endif |
1663 | #endif |
1492 | return newSVsv (json_false); |
1664 | return newSVsv (bool_false); |
1493 | } |
1665 | } |
1494 | else |
1666 | else |
1495 | ERR ("'false' expected"); |
1667 | ERR ("'false' expected"); |
1496 | |
1668 | |
1497 | break; |
1669 | break; |
… | |
… | |
1506 | ERR ("'null' expected"); |
1678 | ERR ("'null' expected"); |
1507 | |
1679 | |
1508 | break; |
1680 | break; |
1509 | |
1681 | |
1510 | default: |
1682 | default: |
1511 | ERR ("malformed JSON string, neither array, object, number, string or atom"); |
1683 | ERR ("malformed JSON string, neither tag, array, object, number, string or atom"); |
1512 | break; |
1684 | break; |
1513 | } |
1685 | } |
1514 | |
1686 | |
1515 | fail: |
1687 | fail: |
1516 | return 0; |
1688 | return 0; |
… | |
… | |
1521 | { |
1693 | { |
1522 | dec_t dec; |
1694 | dec_t dec; |
1523 | SV *sv; |
1695 | SV *sv; |
1524 | |
1696 | |
1525 | /* work around bugs in 5.10 where manipulating magic values |
1697 | /* work around bugs in 5.10 where manipulating magic values |
1526 | * will perl ignore the magic in subsequent accesses. |
1698 | * makes perl ignore the magic in subsequent accesses. |
1527 | * also make a copy of non-PV values, to get them into a clean |
1699 | * also make a copy of non-PV values, to get them into a clean |
1528 | * state (SvPV should do that, but it's buggy, see below). |
1700 | * state (SvPV should do that, but it's buggy, see below). |
1529 | */ |
1701 | */ |
1530 | /*SvGETMAGIC (string);*/ |
1702 | /*SvGETMAGIC (string);*/ |
1531 | if (SvMAGICAL (string) || !SvPOK (string)) |
1703 | if (SvMAGICAL (string) || !SvPOK (string)) |
… | |
… | |
1605 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
1777 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
1606 | LEAVE; |
1778 | LEAVE; |
1607 | |
1779 | |
1608 | croak ("%s, at character offset %d (before \"%s\")", |
1780 | croak ("%s, at character offset %d (before \"%s\")", |
1609 | dec.err, |
1781 | dec.err, |
1610 | ptr_to_index (string, dec.cur), |
1782 | (int)ptr_to_index (string, dec.cur), |
1611 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1783 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1612 | } |
1784 | } |
1613 | |
1785 | |
1614 | sv = sv_2mortal (sv); |
1786 | sv = sv_2mortal (sv); |
1615 | |
1787 | |
1616 | if (!(dec.json.flags & F_ALLOW_NONREF) && !SvROK (sv)) |
1788 | if (!(dec.json.flags & F_ALLOW_NONREF) && json_nonref (sv)) |
1617 | croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); |
1789 | croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); |
1618 | |
1790 | |
1619 | return sv; |
1791 | return sv; |
1620 | } |
1792 | } |
1621 | |
1793 | |
… | |
… | |
1743 | self->incr_mode = INCR_M_STR; |
1915 | self->incr_mode = INCR_M_STR; |
1744 | goto incr_m_str; |
1916 | goto incr_m_str; |
1745 | |
1917 | |
1746 | case '[': |
1918 | case '[': |
1747 | case '{': |
1919 | case '{': |
|
|
1920 | case '(': |
1748 | if (++self->incr_nest > self->max_depth) |
1921 | if (++self->incr_nest > self->max_depth) |
1749 | croak (ERR_NESTING_EXCEEDED); |
1922 | croak (ERR_NESTING_EXCEEDED); |
1750 | break; |
1923 | break; |
1751 | |
1924 | |
1752 | case ']': |
1925 | case ']': |
1753 | case '}': |
1926 | case '}': |
1754 | if (--self->incr_nest <= 0) |
1927 | if (--self->incr_nest <= 0) |
1755 | goto interrupt; |
1928 | goto interrupt; |
|
|
1929 | break; |
|
|
1930 | |
|
|
1931 | case ')': |
|
|
1932 | --self->incr_nest; |
1756 | break; |
1933 | break; |
1757 | |
1934 | |
1758 | case '#': |
1935 | case '#': |
1759 | self->incr_mode = INCR_M_C1; |
1936 | self->incr_mode = INCR_M_C1; |
1760 | goto incr_m_c; |
1937 | goto incr_m_c; |
… | |
… | |
1786 | i >= '0' && i <= '9' ? i - '0' |
1963 | i >= '0' && i <= '9' ? i - '0' |
1787 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
1964 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
1788 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
1965 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
1789 | : -1; |
1966 | : -1; |
1790 | |
1967 | |
1791 | json_stash = gv_stashpv ("JSON::XS" , 1); |
1968 | json_stash = gv_stashpv ("JSON::XS" , 1); |
1792 | json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1); |
1969 | bool_stash = gv_stashpv ("Types::Serialiser::Boolean", 1); |
1793 | |
|
|
1794 | json_true = get_bool ("JSON::XS::true"); |
1970 | bool_true = get_bool ("Types::Serialiser::true"); |
1795 | json_false = get_bool ("JSON::XS::false"); |
1971 | bool_false = get_bool ("Types::Serialiser::false"); |
|
|
1972 | |
|
|
1973 | sv_json = newSVpv ("JSON", 0); |
|
|
1974 | SvREADONLY_on (sv_json); |
1796 | |
1975 | |
1797 | CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */ |
1976 | CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */ |
1798 | } |
1977 | } |
1799 | |
1978 | |
1800 | PROTOTYPES: DISABLE |
1979 | PROTOTYPES: DISABLE |
1801 | |
1980 | |
1802 | void CLONE (...) |
1981 | void CLONE (...) |
1803 | CODE: |
1982 | CODE: |
1804 | json_stash = 0; |
1983 | json_stash = 0; |
1805 | json_boolean_stash = 0; |
1984 | bool_stash = 0; |
1806 | |
1985 | |
1807 | void new (char *klass) |
1986 | void new (char *klass) |
1808 | PPCODE: |
1987 | PPCODE: |
1809 | { |
1988 | { |
1810 | SV *pv = NEWSV (0, sizeof (JSON)); |
1989 | SV *pv = NEWSV (0, sizeof (JSON)); |
1811 | SvPOK_only (pv); |
1990 | SvPOK_only (pv); |
1812 | json_init ((JSON *)SvPVX (pv)); |
1991 | json_init ((JSON *)SvPVX (pv)); |
1813 | XPUSHs (sv_2mortal (sv_bless ( |
1992 | XPUSHs (sv_2mortal (sv_bless ( |
1814 | newRV_noinc (pv), |
1993 | newRV_noinc (pv), |
1815 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |
1994 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |
… | |
… | |
1830 | shrink = F_SHRINK |
2009 | shrink = F_SHRINK |
1831 | allow_blessed = F_ALLOW_BLESSED |
2010 | allow_blessed = F_ALLOW_BLESSED |
1832 | convert_blessed = F_CONV_BLESSED |
2011 | convert_blessed = F_CONV_BLESSED |
1833 | relaxed = F_RELAXED |
2012 | relaxed = F_RELAXED |
1834 | allow_unknown = F_ALLOW_UNKNOWN |
2013 | allow_unknown = F_ALLOW_UNKNOWN |
|
|
2014 | allow_tags = F_ALLOW_TAGS |
1835 | PPCODE: |
2015 | PPCODE: |
1836 | { |
2016 | { |
1837 | if (enable) |
2017 | if (enable) |
1838 | self->flags |= ix; |
2018 | self->flags |= ix; |
1839 | else |
2019 | else |
… | |
… | |
1855 | get_shrink = F_SHRINK |
2035 | get_shrink = F_SHRINK |
1856 | get_allow_blessed = F_ALLOW_BLESSED |
2036 | get_allow_blessed = F_ALLOW_BLESSED |
1857 | get_convert_blessed = F_CONV_BLESSED |
2037 | get_convert_blessed = F_CONV_BLESSED |
1858 | get_relaxed = F_RELAXED |
2038 | get_relaxed = F_RELAXED |
1859 | get_allow_unknown = F_ALLOW_UNKNOWN |
2039 | get_allow_unknown = F_ALLOW_UNKNOWN |
|
|
2040 | get_allow_tags = F_ALLOW_TAGS |
1860 | PPCODE: |
2041 | PPCODE: |
1861 | XPUSHs (boolSV (self->flags & ix)); |
2042 | XPUSHs (boolSV (self->flags & ix)); |
1862 | |
2043 | |
1863 | void max_depth (JSON *self, U32 max_depth = 0x80000000UL) |
2044 | void max_depth (JSON *self, U32 max_depth = 0x80000000UL) |
1864 | PPCODE: |
2045 | PPCODE: |
… | |
… | |
1892 | } |
2073 | } |
1893 | |
2074 | |
1894 | void filter_json_single_key_object (JSON *self, SV *key, SV *cb = &PL_sv_undef) |
2075 | void filter_json_single_key_object (JSON *self, SV *key, SV *cb = &PL_sv_undef) |
1895 | PPCODE: |
2076 | PPCODE: |
1896 | { |
2077 | { |
1897 | if (!self->cb_sk_object) |
2078 | if (!self->cb_sk_object) |
1898 | self->cb_sk_object = newHV (); |
2079 | self->cb_sk_object = newHV (); |
1899 | |
2080 | |
1900 | if (SvOK (cb)) |
2081 | if (SvOK (cb)) |
1901 | hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0); |
2082 | hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0); |
1902 | else |
2083 | else |
… | |
… | |
1913 | XPUSHs (ST (0)); |
2094 | XPUSHs (ST (0)); |
1914 | } |
2095 | } |
1915 | |
2096 | |
1916 | void encode (JSON *self, SV *scalar) |
2097 | void encode (JSON *self, SV *scalar) |
1917 | PPCODE: |
2098 | PPCODE: |
1918 | XPUSHs (encode_json (scalar, self)); |
2099 | PUTBACK; scalar = encode_json (scalar, self); SPAGAIN; |
|
|
2100 | XPUSHs (scalar); |
1919 | |
2101 | |
1920 | void decode (JSON *self, SV *jsonstr) |
2102 | void decode (JSON *self, SV *jsonstr) |
1921 | PPCODE: |
2103 | PPCODE: |
1922 | XPUSHs (decode_json (jsonstr, self, 0)); |
2104 | PUTBACK; jsonstr = decode_json (jsonstr, self, 0); SPAGAIN; |
|
|
2105 | XPUSHs (jsonstr); |
1923 | |
2106 | |
1924 | void decode_prefix (JSON *self, SV *jsonstr) |
2107 | void decode_prefix (JSON *self, SV *jsonstr) |
1925 | PPCODE: |
2108 | PPCODE: |
1926 | { |
2109 | { |
|
|
2110 | SV *sv; |
1927 | char *offset; |
2111 | char *offset; |
|
|
2112 | PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN; |
1928 | EXTEND (SP, 2); |
2113 | EXTEND (SP, 2); |
1929 | PUSHs (decode_json (jsonstr, self, &offset)); |
2114 | PUSHs (sv); |
1930 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset)))); |
2115 | PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset)))); |
1931 | } |
2116 | } |
1932 | |
2117 | |
1933 | void incr_parse (JSON *self, SV *jsonstr = 0) |
2118 | void incr_parse (JSON *self, SV *jsonstr = 0) |
1934 | PPCODE: |
2119 | PPCODE: |
… | |
… | |
1981 | } |
2166 | } |
1982 | |
2167 | |
1983 | if (GIMME_V != G_VOID) |
2168 | if (GIMME_V != G_VOID) |
1984 | do |
2169 | do |
1985 | { |
2170 | { |
|
|
2171 | SV *sv; |
1986 | char *offset; |
2172 | char *offset; |
1987 | |
2173 | |
1988 | if (!INCR_DONE (self)) |
2174 | if (!INCR_DONE (self)) |
1989 | { |
2175 | { |
1990 | incr_parse (self); |
2176 | incr_parse (self); |
… | |
… | |
2004 | |
2190 | |
2005 | break; |
2191 | break; |
2006 | } |
2192 | } |
2007 | } |
2193 | } |
2008 | |
2194 | |
2009 | XPUSHs (decode_json (self->incr_text, self, &offset)); |
2195 | PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN; |
|
|
2196 | XPUSHs (sv); |
2010 | |
2197 | |
2011 | self->incr_pos -= offset - SvPVX (self->incr_text); |
2198 | self->incr_pos -= offset - SvPVX (self->incr_text); |
2012 | self->incr_nest = 0; |
2199 | self->incr_nest = 0; |
2013 | self->incr_mode = 0; |
2200 | self->incr_mode = 0; |
2014 | |
2201 | |
… | |
… | |
2058 | SvREFCNT_dec (self->incr_text); |
2245 | SvREFCNT_dec (self->incr_text); |
2059 | |
2246 | |
2060 | PROTOTYPES: ENABLE |
2247 | PROTOTYPES: ENABLE |
2061 | |
2248 | |
2062 | void encode_json (SV *scalar) |
2249 | void encode_json (SV *scalar) |
2063 | ALIAS: |
|
|
2064 | to_json_ = 0 |
|
|
2065 | encode_json = F_UTF8 |
|
|
2066 | PPCODE: |
2250 | PPCODE: |
2067 | { |
2251 | { |
2068 | JSON json; |
2252 | JSON json; |
2069 | json_init (&json); |
2253 | json_init (&json); |
2070 | json.flags |= ix; |
2254 | json.flags |= F_UTF8; |
2071 | XPUSHs (encode_json (scalar, &json)); |
2255 | PUTBACK; scalar = encode_json (scalar, &json); SPAGAIN; |
|
|
2256 | XPUSHs (scalar); |
2072 | } |
2257 | } |
2073 | |
2258 | |
2074 | void decode_json (SV *jsonstr) |
2259 | void decode_json (SV *jsonstr) |
2075 | ALIAS: |
|
|
2076 | from_json_ = 0 |
|
|
2077 | decode_json = F_UTF8 |
|
|
2078 | PPCODE: |
2260 | PPCODE: |
2079 | { |
2261 | { |
2080 | JSON json; |
2262 | JSON json; |
2081 | json_init (&json); |
2263 | json_init (&json); |
2082 | json.flags |= ix; |
2264 | json.flags |= F_UTF8; |
2083 | XPUSHs (decode_json (jsonstr, &json, 0)); |
2265 | PUTBACK; jsonstr = decode_json (jsonstr, &json, 0); SPAGAIN; |
|
|
2266 | XPUSHs (jsonstr); |
2084 | } |
2267 | } |
2085 | |
2268 | |