… | |
… | |
31 | #define F_ALLOW_NONREF 0x00000100UL |
31 | #define F_ALLOW_NONREF 0x00000100UL |
32 | #define F_SHRINK 0x00000200UL |
32 | #define F_SHRINK 0x00000200UL |
33 | #define F_ALLOW_BLESSED 0x00000400UL |
33 | #define F_ALLOW_BLESSED 0x00000400UL |
34 | #define F_CONV_BLESSED 0x00000800UL |
34 | #define F_CONV_BLESSED 0x00000800UL |
35 | #define F_RELAXED 0x00001000UL |
35 | #define F_RELAXED 0x00001000UL |
36 | |
36 | #define F_ALLOW_UNKNOWN 0x00002000UL |
37 | #define F_MAXDEPTH 0xf8000000UL |
|
|
38 | #define S_MAXDEPTH 27 |
|
|
39 | #define F_MAXSIZE 0x01f00000UL |
|
|
40 | #define S_MAXSIZE 20 |
|
|
41 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
37 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
42 | |
38 | |
43 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
|
|
44 | #define DEC_SIZE(flags) (1UL << ((flags & F_MAXSIZE ) >> S_MAXSIZE )) |
|
|
45 | |
|
|
46 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
39 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
47 | #define F_DEFAULT (9UL << S_MAXDEPTH) |
|
|
48 | |
40 | |
49 | #define INIT_SIZE 32 // initial scalar size to be allocated |
41 | #define INIT_SIZE 32 // initial scalar size to be allocated |
50 | #define INDENT_STEP 3 // spaces per indentation level |
42 | #define INDENT_STEP 3 // spaces per indentation level |
51 | |
43 | |
52 | #define SHORT_STRING_LEN 16384 // special-case strings of up to this size |
44 | #define SHORT_STRING_LEN 16384 // special-case strings of up to this size |
… | |
… | |
67 | |
59 | |
68 | #define IN_RANGE_INC(type,val,beg,end) \ |
60 | #define IN_RANGE_INC(type,val,beg,end) \ |
69 | ((unsigned type)((unsigned type)(val) - (unsigned type)(beg)) \ |
61 | ((unsigned type)((unsigned type)(val) - (unsigned type)(beg)) \ |
70 | <= (unsigned type)((unsigned type)(end) - (unsigned type)(beg))) |
62 | <= (unsigned type)((unsigned type)(end) - (unsigned type)(beg))) |
71 | |
63 | |
|
|
64 | #define ERR_NESTING_EXCEEDED "json text or perl structure exceeds maximum nesting level (max_depth set too low?)" |
|
|
65 | |
72 | #ifdef USE_ITHREADS |
66 | #ifdef USE_ITHREADS |
73 | # define JSON_SLOW 1 |
67 | # define JSON_SLOW 1 |
74 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
68 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
75 | #else |
69 | #else |
76 | # define JSON_SLOW 0 |
70 | # define JSON_SLOW 0 |
… | |
… | |
85 | INCR_M_STR, // inside string |
79 | INCR_M_STR, // inside string |
86 | INCR_M_BS, // inside backslash |
80 | INCR_M_BS, // inside backslash |
87 | INCR_M_JSON // outside anything, count nesting |
81 | INCR_M_JSON // outside anything, count nesting |
88 | }; |
82 | }; |
89 | |
83 | |
90 | #define INCR_DONE(json) (!(json)->incr_nest && (json)->incr_mode == INCR_M_JSON) |
84 | #define INCR_DONE(json) ((json)->incr_nest <= 0 && (json)->incr_mode == INCR_M_JSON) |
91 | |
85 | |
92 | typedef struct { |
86 | typedef struct { |
93 | U32 flags; |
87 | U32 flags; |
|
|
88 | U32 max_depth; |
|
|
89 | STRLEN max_size; |
|
|
90 | |
94 | SV *cb_object; |
91 | SV *cb_object; |
95 | HV *cb_sk_object; |
92 | HV *cb_sk_object; |
96 | |
93 | |
97 | // for the incremental parser |
94 | // for the incremental parser |
98 | SV *incr_text; // the source text so far |
95 | SV *incr_text; // the source text so far |
99 | STRLEN incr_pos; // the current offset into the text |
96 | STRLEN incr_pos; // the current offset into the text |
100 | int incr_nest; // {[]}-nesting level |
97 | int incr_nest; // {[]}-nesting level |
101 | int incr_mode; |
98 | unsigned char incr_mode; |
102 | } JSON; |
99 | } JSON; |
|
|
100 | |
|
|
101 | INLINE void |
|
|
102 | json_init (JSON *json) |
|
|
103 | { |
|
|
104 | Zero (json, 1, JSON); |
|
|
105 | json->max_depth = 512; |
|
|
106 | } |
103 | |
107 | |
104 | ///////////////////////////////////////////////////////////////////////////// |
108 | ///////////////////////////////////////////////////////////////////////////// |
105 | // utility functions |
109 | // utility functions |
106 | |
110 | |
107 | INLINE SV * |
111 | INLINE SV * |
… | |
… | |
117 | |
121 | |
118 | INLINE void |
122 | INLINE void |
119 | shrink (SV *sv) |
123 | shrink (SV *sv) |
120 | { |
124 | { |
121 | sv_utf8_downgrade (sv, 1); |
125 | sv_utf8_downgrade (sv, 1); |
|
|
126 | |
122 | if (SvLEN (sv) > SvCUR (sv) + 1) |
127 | if (SvLEN (sv) > SvCUR (sv) + 1) |
123 | { |
128 | { |
124 | #ifdef SvPV_shrink_to_cur |
129 | #ifdef SvPV_shrink_to_cur |
125 | SvPV_shrink_to_cur (sv); |
130 | SvPV_shrink_to_cur (sv); |
126 | #elif defined (SvPV_renew) |
131 | #elif defined (SvPV_renew) |
… | |
… | |
181 | char *cur; // SvPVX (sv) + current output position |
186 | char *cur; // SvPVX (sv) + current output position |
182 | char *end; // SvEND (sv) |
187 | char *end; // SvEND (sv) |
183 | SV *sv; // result scalar |
188 | SV *sv; // result scalar |
184 | JSON json; |
189 | JSON json; |
185 | U32 indent; // indentation level |
190 | U32 indent; // indentation level |
186 | U32 maxdepth; // max. indentation/recursion level |
|
|
187 | UV limit; // escape character values >= this value when encoding |
191 | UV limit; // escape character values >= this value when encoding |
188 | } enc_t; |
192 | } enc_t; |
189 | |
193 | |
190 | INLINE void |
194 | INLINE void |
191 | need (enc_t *enc, STRLEN len) |
195 | need (enc_t *enc, STRLEN len) |
… | |
… | |
364 | static void |
368 | static void |
365 | encode_av (enc_t *enc, AV *av) |
369 | encode_av (enc_t *enc, AV *av) |
366 | { |
370 | { |
367 | int i, len = av_len (av); |
371 | int i, len = av_len (av); |
368 | |
372 | |
369 | if (enc->indent >= enc->maxdepth) |
373 | if (enc->indent >= enc->json.max_depth) |
370 | croak ("data structure too deep (hit recursion limit)"); |
374 | croak (ERR_NESTING_EXCEEDED); |
371 | |
375 | |
372 | encode_ch (enc, '['); |
376 | encode_ch (enc, '['); |
373 | |
377 | |
374 | if (len >= 0) |
378 | if (len >= 0) |
375 | { |
379 | { |
… | |
… | |
450 | static void |
454 | static void |
451 | encode_hv (enc_t *enc, HV *hv) |
455 | encode_hv (enc_t *enc, HV *hv) |
452 | { |
456 | { |
453 | HE *he; |
457 | HE *he; |
454 | |
458 | |
455 | if (enc->indent >= enc->maxdepth) |
459 | if (enc->indent >= enc->json.max_depth) |
456 | croak ("data structure too deep (hit recursion limit)"); |
460 | croak (ERR_NESTING_EXCEEDED); |
457 | |
461 | |
458 | encode_ch (enc, '{'); |
462 | encode_ch (enc, '{'); |
459 | |
463 | |
460 | // for canonical output we have to sort by keys first |
464 | // for canonical output we have to sort by keys first |
461 | // actually, this is mostly due to the stupid so-called |
465 | // actually, this is mostly due to the stupid so-called |
… | |
… | |
642 | |
646 | |
643 | if (len == 1 && *pv == '1') |
647 | if (len == 1 && *pv == '1') |
644 | encode_str (enc, "true", 4, 0); |
648 | encode_str (enc, "true", 4, 0); |
645 | else if (len == 1 && *pv == '0') |
649 | else if (len == 1 && *pv == '0') |
646 | encode_str (enc, "false", 5, 0); |
650 | encode_str (enc, "false", 5, 0); |
|
|
651 | else if (enc->json.flags & F_ALLOW_UNKNOWN) |
|
|
652 | encode_str (enc, "null", 4, 0); |
647 | else |
653 | else |
648 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
654 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
649 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
655 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
650 | } |
656 | } |
|
|
657 | else if (enc->json.flags & F_ALLOW_UNKNOWN) |
|
|
658 | encode_str (enc, "null", 4, 0); |
651 | else |
659 | else |
652 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
660 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
653 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
661 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
654 | } |
662 | } |
655 | |
663 | |
… | |
… | |
717 | : snprintf (enc->cur, IVUV_MAXCHARS, "%"IVdf, (IV)SvIVX (sv)); |
725 | : snprintf (enc->cur, IVUV_MAXCHARS, "%"IVdf, (IV)SvIVX (sv)); |
718 | } |
726 | } |
719 | } |
727 | } |
720 | else if (SvROK (sv)) |
728 | else if (SvROK (sv)) |
721 | encode_rv (enc, SvRV (sv)); |
729 | encode_rv (enc, SvRV (sv)); |
722 | else if (!SvOK (sv)) |
730 | else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) |
723 | encode_str (enc, "null", 4, 0); |
731 | encode_str (enc, "null", 4, 0); |
724 | else |
732 | else |
725 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
733 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
726 | SvPV_nolen (sv), SvFLAGS (sv)); |
734 | SvPV_nolen (sv), SvFLAGS (sv)); |
727 | } |
735 | } |
… | |
… | |
737 | enc.json = *json; |
745 | enc.json = *json; |
738 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
746 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
739 | enc.cur = SvPVX (enc.sv); |
747 | enc.cur = SvPVX (enc.sv); |
740 | enc.end = SvEND (enc.sv); |
748 | enc.end = SvEND (enc.sv); |
741 | enc.indent = 0; |
749 | enc.indent = 0; |
742 | enc.maxdepth = DEC_DEPTH (enc.json.flags); |
|
|
743 | enc.limit = enc.json.flags & F_ASCII ? 0x000080UL |
750 | enc.limit = enc.json.flags & F_ASCII ? 0x000080UL |
744 | : enc.json.flags & F_LATIN1 ? 0x000100UL |
751 | : enc.json.flags & F_LATIN1 ? 0x000100UL |
745 | : 0x110000UL; |
752 | : 0x110000UL; |
746 | |
753 | |
747 | SvPOK_only (enc.sv); |
754 | SvPOK_only (enc.sv); |
… | |
… | |
814 | if (*dec->cur != ch) \ |
821 | if (*dec->cur != ch) \ |
815 | ERR (# ch " expected"); \ |
822 | ERR (# ch " expected"); \ |
816 | ++dec->cur; \ |
823 | ++dec->cur; \ |
817 | SE |
824 | SE |
818 | |
825 | |
819 | #define DEC_INC_DEPTH if (++dec->depth > dec->maxdepth) ERR ("json datastructure exceeds maximum nesting level (set a higher max_depth)") |
826 | #define DEC_INC_DEPTH if (++dec->depth > dec->json.max_depth) ERR (ERR_NESTING_EXCEEDED) |
820 | #define DEC_DEC_DEPTH --dec->depth |
827 | #define DEC_DEC_DEPTH --dec->depth |
821 | |
828 | |
822 | static SV *decode_sv (dec_t *dec); |
829 | static SV *decode_sv (dec_t *dec); |
823 | |
830 | |
824 | static signed char decode_hexdigit[256]; |
831 | static signed char decode_hexdigit[256]; |
… | |
… | |
1407 | SV *sv; |
1414 | SV *sv; |
1408 | |
1415 | |
1409 | SvGETMAGIC (string); |
1416 | SvGETMAGIC (string); |
1410 | SvUPGRADE (string, SVt_PV); |
1417 | SvUPGRADE (string, SVt_PV); |
1411 | |
1418 | |
1412 | if (json->flags & F_MAXSIZE && SvCUR (string) > DEC_SIZE (json->flags)) |
1419 | /* work around a bug in perl 5.10, which causes SvCUR to fail an |
|
|
1420 | * assertion with -DDEBUGGING, although SvCUR is documented to |
|
|
1421 | * return the xpv_cur field which certainly exists after upgrading. |
|
|
1422 | * according to nicholas clark, calling SvPOK fixes this. |
|
|
1423 | * But it doesn't fix it, so try another workaround, call SvPV_nolen |
|
|
1424 | * and hope for the best. |
|
|
1425 | */ |
|
|
1426 | #ifdef DEBUGGING |
|
|
1427 | SvPV_nolen (string); |
|
|
1428 | #endif |
|
|
1429 | |
|
|
1430 | if (SvCUR (string) > json->max_size && json->max_size) |
1413 | croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", |
1431 | croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", |
1414 | (unsigned long)SvCUR (string), (unsigned long)DEC_SIZE (json->flags)); |
1432 | (unsigned long)SvCUR (string), (unsigned long)json->max_size); |
1415 | |
1433 | |
1416 | if (json->flags & F_UTF8) |
1434 | if (json->flags & F_UTF8) |
1417 | sv_utf8_downgrade (string, 0); |
1435 | sv_utf8_downgrade (string, 0); |
1418 | else |
1436 | else |
1419 | sv_utf8_upgrade (string); |
1437 | sv_utf8_upgrade (string); |
1420 | |
1438 | |
1421 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
1439 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
1422 | |
1440 | |
1423 | dec.json = *json; |
1441 | dec.json = *json; |
1424 | dec.cur = SvPVX (string); |
1442 | dec.cur = SvPVX (string); |
1425 | dec.end = SvEND (string); |
1443 | dec.end = SvEND (string); |
1426 | dec.err = 0; |
1444 | dec.err = 0; |
1427 | dec.depth = 0; |
1445 | dec.depth = 0; |
1428 | dec.maxdepth = DEC_DEPTH (dec.json.flags); |
|
|
1429 | |
1446 | |
1430 | if (dec.json.cb_object || dec.json.cb_sk_object) |
1447 | if (dec.json.cb_object || dec.json.cb_sk_object) |
1431 | dec.json.flags |= F_HOOK; |
1448 | dec.json.flags |= F_HOOK; |
1432 | |
1449 | |
1433 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
1450 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
… | |
… | |
1579 | self->incr_mode = INCR_M_STR; |
1596 | self->incr_mode = INCR_M_STR; |
1580 | goto incr_m_str; |
1597 | goto incr_m_str; |
1581 | |
1598 | |
1582 | case '[': |
1599 | case '[': |
1583 | case '{': |
1600 | case '{': |
1584 | ++self->incr_nest; |
1601 | if (++self->incr_nest > self->max_depth) |
|
|
1602 | croak (ERR_NESTING_EXCEEDED); |
1585 | break; |
1603 | break; |
1586 | |
1604 | |
1587 | case ']': |
1605 | case ']': |
1588 | case '}': |
1606 | case '}': |
1589 | if (!--self->incr_nest) |
1607 | if (--self->incr_nest <= 0) |
1590 | goto interrupt; |
1608 | goto interrupt; |
1591 | } |
1609 | } |
1592 | } |
1610 | } |
1593 | } |
1611 | } |
1594 | |
1612 | |
… | |
… | |
1634 | void new (char *klass) |
1652 | void new (char *klass) |
1635 | PPCODE: |
1653 | PPCODE: |
1636 | { |
1654 | { |
1637 | SV *pv = NEWSV (0, sizeof (JSON)); |
1655 | SV *pv = NEWSV (0, sizeof (JSON)); |
1638 | SvPOK_only (pv); |
1656 | SvPOK_only (pv); |
1639 | Zero (SvPVX (pv), 1, JSON); |
1657 | json_init ((JSON *)SvPVX (pv)); |
1640 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
|
|
1641 | XPUSHs (sv_2mortal (sv_bless ( |
1658 | XPUSHs (sv_2mortal (sv_bless ( |
1642 | newRV_noinc (pv), |
1659 | newRV_noinc (pv), |
1643 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |
1660 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |
1644 | ))); |
1661 | ))); |
1645 | } |
1662 | } |
… | |
… | |
1657 | allow_nonref = F_ALLOW_NONREF |
1674 | allow_nonref = F_ALLOW_NONREF |
1658 | shrink = F_SHRINK |
1675 | shrink = F_SHRINK |
1659 | allow_blessed = F_ALLOW_BLESSED |
1676 | allow_blessed = F_ALLOW_BLESSED |
1660 | convert_blessed = F_CONV_BLESSED |
1677 | convert_blessed = F_CONV_BLESSED |
1661 | relaxed = F_RELAXED |
1678 | relaxed = F_RELAXED |
|
|
1679 | allow_unknown = F_ALLOW_UNKNOWN |
1662 | PPCODE: |
1680 | PPCODE: |
1663 | { |
1681 | { |
1664 | if (enable) |
1682 | if (enable) |
1665 | self->flags |= ix; |
1683 | self->flags |= ix; |
1666 | else |
1684 | else |
… | |
… | |
1681 | get_allow_nonref = F_ALLOW_NONREF |
1699 | get_allow_nonref = F_ALLOW_NONREF |
1682 | get_shrink = F_SHRINK |
1700 | get_shrink = F_SHRINK |
1683 | get_allow_blessed = F_ALLOW_BLESSED |
1701 | get_allow_blessed = F_ALLOW_BLESSED |
1684 | get_convert_blessed = F_CONV_BLESSED |
1702 | get_convert_blessed = F_CONV_BLESSED |
1685 | get_relaxed = F_RELAXED |
1703 | get_relaxed = F_RELAXED |
|
|
1704 | get_allow_unknown = F_ALLOW_UNKNOWN |
1686 | PPCODE: |
1705 | PPCODE: |
1687 | XPUSHs (boolSV (self->flags & ix)); |
1706 | XPUSHs (boolSV (self->flags & ix)); |
1688 | |
1707 | |
1689 | void max_depth (JSON *self, UV max_depth = 0x80000000UL) |
1708 | void max_depth (JSON *self, U32 max_depth = 0x80000000UL) |
1690 | PPCODE: |
1709 | PPCODE: |
1691 | { |
1710 | self->max_depth = max_depth; |
1692 | UV log2 = 0; |
|
|
1693 | |
|
|
1694 | if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; |
|
|
1695 | |
|
|
1696 | while ((1UL << log2) < max_depth) |
|
|
1697 | ++log2; |
|
|
1698 | |
|
|
1699 | self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
|
|
1700 | |
|
|
1701 | XPUSHs (ST (0)); |
1711 | XPUSHs (ST (0)); |
1702 | } |
|
|
1703 | |
1712 | |
1704 | U32 get_max_depth (JSON *self) |
1713 | U32 get_max_depth (JSON *self) |
1705 | CODE: |
1714 | CODE: |
1706 | RETVAL = DEC_DEPTH (self->flags); |
1715 | RETVAL = self->max_depth; |
1707 | OUTPUT: |
1716 | OUTPUT: |
1708 | RETVAL |
1717 | RETVAL |
1709 | |
1718 | |
1710 | void max_size (JSON *self, UV max_size = 0) |
1719 | void max_size (JSON *self, U32 max_size = 0) |
1711 | PPCODE: |
1720 | PPCODE: |
1712 | { |
1721 | self->max_size = max_size; |
1713 | UV log2 = 0; |
|
|
1714 | |
|
|
1715 | if (max_size > 0x80000000UL) max_size = 0x80000000UL; |
|
|
1716 | if (max_size == 1) max_size = 2; |
|
|
1717 | |
|
|
1718 | while ((1UL << log2) < max_size) |
|
|
1719 | ++log2; |
|
|
1720 | |
|
|
1721 | self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); |
|
|
1722 | |
|
|
1723 | XPUSHs (ST (0)); |
1722 | XPUSHs (ST (0)); |
1724 | } |
|
|
1725 | |
1723 | |
1726 | int get_max_size (JSON *self) |
1724 | int get_max_size (JSON *self) |
1727 | CODE: |
1725 | CODE: |
1728 | RETVAL = DEC_SIZE (self->flags); |
1726 | RETVAL = self->max_size; |
1729 | OUTPUT: |
1727 | OUTPUT: |
1730 | RETVAL |
1728 | RETVAL |
1731 | |
1729 | |
1732 | void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) |
1730 | void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) |
1733 | PPCODE: |
1731 | PPCODE: |
… | |
… | |
1812 | STRLEN offset; |
1810 | STRLEN offset; |
1813 | |
1811 | |
1814 | if (!INCR_DONE (self)) |
1812 | if (!INCR_DONE (self)) |
1815 | { |
1813 | { |
1816 | incr_parse (self); |
1814 | incr_parse (self); |
|
|
1815 | |
|
|
1816 | if (self->incr_pos > self->max_size && self->max_size) |
|
|
1817 | croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", |
|
|
1818 | (unsigned long)self->incr_pos, (unsigned long)self->max_size); |
|
|
1819 | |
1817 | if (!INCR_DONE (self)) |
1820 | if (!INCR_DONE (self)) |
1818 | break; |
1821 | break; |
1819 | } |
1822 | } |
1820 | |
1823 | |
1821 | XPUSHs (decode_json (self->incr_text, self, &offset)); |
1824 | XPUSHs (decode_json (self->incr_text, self, &offset)); |
… | |
… | |
1850 | self->incr_nest = 0; |
1853 | self->incr_nest = 0; |
1851 | self->incr_mode = 0; |
1854 | self->incr_mode = 0; |
1852 | } |
1855 | } |
1853 | } |
1856 | } |
1854 | |
1857 | |
|
|
1858 | void incr_reset (JSON *self) |
|
|
1859 | CODE: |
|
|
1860 | { |
|
|
1861 | SvREFCNT_dec (self->incr_text); |
|
|
1862 | self->incr_text = 0; |
|
|
1863 | self->incr_pos = 0; |
|
|
1864 | self->incr_nest = 0; |
|
|
1865 | self->incr_mode = 0; |
|
|
1866 | } |
|
|
1867 | |
1855 | void DESTROY (JSON *self) |
1868 | void DESTROY (JSON *self) |
1856 | CODE: |
1869 | CODE: |
1857 | SvREFCNT_dec (self->cb_sk_object); |
1870 | SvREFCNT_dec (self->cb_sk_object); |
1858 | SvREFCNT_dec (self->cb_object); |
1871 | SvREFCNT_dec (self->cb_object); |
1859 | SvREFCNT_dec (self->incr_text); |
1872 | SvREFCNT_dec (self->incr_text); |
… | |
… | |
1864 | ALIAS: |
1877 | ALIAS: |
1865 | to_json_ = 0 |
1878 | to_json_ = 0 |
1866 | encode_json = F_UTF8 |
1879 | encode_json = F_UTF8 |
1867 | PPCODE: |
1880 | PPCODE: |
1868 | { |
1881 | { |
1869 | JSON json = { F_DEFAULT | ix }; |
1882 | JSON json; |
|
|
1883 | json_init (&json); |
|
|
1884 | json.flags |= ix; |
1870 | XPUSHs (encode_json (scalar, &json)); |
1885 | XPUSHs (encode_json (scalar, &json)); |
1871 | } |
1886 | } |
1872 | |
1887 | |
1873 | void decode_json (SV *jsonstr) |
1888 | void decode_json (SV *jsonstr) |
1874 | ALIAS: |
1889 | ALIAS: |
1875 | from_json_ = 0 |
1890 | from_json_ = 0 |
1876 | decode_json = F_UTF8 |
1891 | decode_json = F_UTF8 |
1877 | PPCODE: |
1892 | PPCODE: |
1878 | { |
1893 | { |
1879 | JSON json = { F_DEFAULT | ix }; |
1894 | JSON json; |
|
|
1895 | json_init (&json); |
|
|
1896 | json.flags |= ix; |
1880 | XPUSHs (decode_json (jsonstr, &json, 0)); |
1897 | XPUSHs (decode_json (jsonstr, &json, 0)); |
1881 | } |
1898 | } |
1882 | |
1899 | |
1883 | |
1900 | |