… | |
… | |
50 | #define F_ALLOW_TAGS 0x00004000UL |
50 | #define F_ALLOW_TAGS 0x00004000UL |
51 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
51 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
52 | |
52 | |
53 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
53 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
54 | |
54 | |
55 | #define INIT_SIZE 32 // initial scalar size to be allocated |
55 | #define INIT_SIZE 64 // initial scalar size to be allocated |
56 | #define INDENT_STEP 3 // spaces per indentation level |
56 | #define INDENT_STEP 3 // spaces per indentation level |
57 | |
57 | |
58 | #define SHORT_STRING_LEN 16384 // special-case strings of up to this size |
58 | #define SHORT_STRING_LEN 16384 // special-case strings of up to this size |
59 | |
59 | |
60 | #define DECODE_WANTS_OCTETS(json) ((json)->flags & F_UTF8) |
60 | #define DECODE_WANTS_OCTETS(json) ((json)->flags & F_UTF8) |
… | |
… | |
788 | { |
788 | { |
789 | int count; |
789 | int count; |
790 | dSP; |
790 | dSP; |
791 | |
791 | |
792 | ENTER; SAVETMPS; |
792 | ENTER; SAVETMPS; |
793 | SAVESTACK_POS (); |
|
|
794 | PUSHMARK (SP); |
793 | PUSHMARK (SP); |
795 | EXTEND (SP, 2); |
794 | EXTEND (SP, 2); |
796 | // we re-bless the reference to get overload and other niceties right |
795 | // we re-bless the reference to get overload and other niceties right |
797 | PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); |
796 | PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); |
798 | PUSHs (sv_json); |
797 | PUSHs (sv_json); |
… | |
… | |
810 | encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash)); |
809 | encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash)); |
811 | encode_ch (enc, '"'); |
810 | encode_ch (enc, '"'); |
812 | encode_ch (enc, ')'); |
811 | encode_ch (enc, ')'); |
813 | encode_ch (enc, '['); |
812 | encode_ch (enc, '['); |
814 | |
813 | |
815 | while (count) |
814 | if (count) |
816 | { |
815 | { |
|
|
816 | int i; |
|
|
817 | |
|
|
818 | for (i = 0; i < count - 1; ++i) |
|
|
819 | { |
817 | encode_sv (enc, SP[1 - count--]); |
820 | encode_sv (enc, SP[i + 1 - count]); |
818 | |
|
|
819 | if (count) |
|
|
820 | encode_ch (enc, ','); |
821 | encode_ch (enc, ','); |
|
|
822 | } |
|
|
823 | |
|
|
824 | encode_sv (enc, TOPs); |
|
|
825 | SP -= count; |
821 | } |
826 | } |
822 | |
827 | |
823 | encode_ch (enc, ']'); |
828 | encode_ch (enc, ']'); |
824 | |
829 | |
825 | FREETMPS; LEAVE; |
830 | FREETMPS; LEAVE; |
… | |
… | |
1516 | { |
1521 | { |
1517 | dSP; |
1522 | dSP; |
1518 | int count; |
1523 | int count; |
1519 | |
1524 | |
1520 | ENTER; SAVETMPS; |
1525 | ENTER; SAVETMPS; |
1521 | SAVESTACK_POS (); |
|
|
1522 | PUSHMARK (SP); |
1526 | PUSHMARK (SP); |
1523 | XPUSHs (HeVAL (he)); |
1527 | XPUSHs (HeVAL (he)); |
1524 | sv_2mortal (sv); |
1528 | sv_2mortal (sv); |
1525 | |
1529 | |
1526 | PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; |
1530 | PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; |
… | |
… | |
1529 | { |
1533 | { |
1530 | sv = newSVsv (POPs); |
1534 | sv = newSVsv (POPs); |
1531 | FREETMPS; LEAVE; |
1535 | FREETMPS; LEAVE; |
1532 | return sv; |
1536 | return sv; |
1533 | } |
1537 | } |
|
|
1538 | else if (count) |
|
|
1539 | croak ("filter_json_single_key_object callbacks must not return more than one scalar"); |
1534 | |
1540 | |
1535 | SvREFCNT_inc (sv); |
1541 | SvREFCNT_inc (sv); |
1536 | FREETMPS; LEAVE; |
1542 | FREETMPS; LEAVE; |
1537 | } |
1543 | } |
1538 | } |
1544 | } |
… | |
… | |
1541 | { |
1547 | { |
1542 | dSP; |
1548 | dSP; |
1543 | int count; |
1549 | int count; |
1544 | |
1550 | |
1545 | ENTER; SAVETMPS; |
1551 | ENTER; SAVETMPS; |
1546 | SAVESTACK_POS (); |
|
|
1547 | PUSHMARK (SP); |
1552 | PUSHMARK (SP); |
1548 | XPUSHs (sv_2mortal (sv)); |
1553 | XPUSHs (sv_2mortal (sv)); |
1549 | |
1554 | |
1550 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
1555 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
1551 | |
1556 | |
… | |
… | |
1553 | { |
1558 | { |
1554 | sv = newSVsv (POPs); |
1559 | sv = newSVsv (POPs); |
1555 | FREETMPS; LEAVE; |
1560 | FREETMPS; LEAVE; |
1556 | return sv; |
1561 | return sv; |
1557 | } |
1562 | } |
|
|
1563 | else if (count) |
|
|
1564 | croak ("filter_json_object callbacks must not return more than one scalar"); |
1558 | |
1565 | |
1559 | SvREFCNT_inc (sv); |
1566 | SvREFCNT_inc (sv); |
1560 | FREETMPS; LEAVE; |
1567 | FREETMPS; LEAVE; |
1561 | } |
1568 | } |
1562 | } |
1569 | } |