ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.xs
(Generate patch)

Comparing JSON-XS/XS.xs (file contents):
Revision 1.114 by root, Wed Aug 1 19:04:41 2012 UTC vs.
Revision 1.120 by root, Mon Oct 28 23:23:10 2013 UTC

33#define F_SHRINK 0x00000200UL 33#define F_SHRINK 0x00000200UL
34#define F_ALLOW_BLESSED 0x00000400UL 34#define F_ALLOW_BLESSED 0x00000400UL
35#define F_CONV_BLESSED 0x00000800UL 35#define F_CONV_BLESSED 0x00000800UL
36#define F_RELAXED 0x00001000UL 36#define F_RELAXED 0x00001000UL
37#define F_ALLOW_UNKNOWN 0x00002000UL 37#define F_ALLOW_UNKNOWN 0x00002000UL
38#define F_ALLOW_TAGS 0x00004000UL
38#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing 39#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing
39 40
40#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER 41#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER
41 42
42#define INIT_SIZE 32 // initial scalar size to be allocated 43#define INIT_SIZE 32 // initial scalar size to be allocated
72#else 73#else
73# define JSON_SLOW 0 74# define JSON_SLOW 0
74# define JSON_STASH json_stash 75# define JSON_STASH json_stash
75#endif 76#endif
76 77
78// the amount of HEs to allocate on the stack, when sorting keys
79#define STACK_HES 64
80
77static HV *json_stash, *json_boolean_stash; // JSON::XS:: 81static HV *json_stash, *types_boolean_stash; // JSON::XS::
78static SV *json_true, *json_false; 82static SV *types_true, *types_false, *sv_json;
79 83
80enum { 84enum {
81 INCR_M_WS = 0, // initial whitespace skipping, must be 0 85 INCR_M_WS = 0, // initial whitespace skipping, must be 0
82 INCR_M_STR, // inside string 86 INCR_M_STR, // inside string
83 INCR_M_BS, // inside backslash 87 INCR_M_BS, // inside backslash
480 484
481 if (enc->indent >= enc->json.max_depth) 485 if (enc->indent >= enc->json.max_depth)
482 croak (ERR_NESTING_EXCEEDED); 486 croak (ERR_NESTING_EXCEEDED);
483 487
484 encode_ch (enc, '['); 488 encode_ch (enc, '[');
485 489
486 if (len >= 0) 490 if (len >= 0)
487 { 491 {
488 encode_nl (enc); ++enc->indent; 492 encode_nl (enc); ++enc->indent;
489 493
490 for (i = 0; i <= len; ++i) 494 for (i = 0; i <= len; ++i)
502 encode_comma (enc); 506 encode_comma (enc);
503 } 507 }
504 508
505 encode_nl (enc); --enc->indent; encode_indent (enc); 509 encode_nl (enc); --enc->indent; encode_indent (enc);
506 } 510 }
507 511
508 encode_ch (enc, ']'); 512 encode_ch (enc, ']');
509} 513}
510 514
511static void 515static void
512encode_hk (enc_t *enc, HE *he) 516encode_hk (enc_t *enc, HE *he)
516 if (HeKLEN (he) == HEf_SVKEY) 520 if (HeKLEN (he) == HEf_SVKEY)
517 { 521 {
518 SV *sv = HeSVKEY (he); 522 SV *sv = HeSVKEY (he);
519 STRLEN len; 523 STRLEN len;
520 char *str; 524 char *str;
521 525
522 SvGETMAGIC (sv); 526 SvGETMAGIC (sv);
523 str = SvPV (sv, len); 527 str = SvPV (sv, len);
524 528
525 encode_str (enc, str, len, SvUTF8 (sv)); 529 encode_str (enc, str, len, SvUTF8 (sv));
526 } 530 }
592 } 596 }
593 597
594 if (count) 598 if (count)
595 { 599 {
596 int i, fast = 1; 600 int i, fast = 1;
597#if defined(__BORLANDC__) || defined(_MSC_VER) 601 HE *hes_stack [STACK_HES];
598 HE **hes = _alloca (count * sizeof (HE)); 602 HE **hes = hes_stack;
599#else 603
600 HE *hes [count]; // if your compiler dies here, you need to enable C99 mode 604 // allocate larger arrays on the heap
601#endif 605 if (count > STACK_HES)
606 {
607 SV *sv = sv_2mortal (NEWSV (0, count * sizeof (*hes)));
608 hes = (HE **)SvPVX (sv);
609 }
602 610
603 i = 0; 611 i = 0;
604 while ((he = hv_iternext (hv))) 612 while ((he = hv_iternext (hv)))
605 { 613 {
606 hes [i++] = he; 614 hes [i++] = he;
675// encode objects, arrays and special \0=false and \1=true values. 683// encode objects, arrays and special \0=false and \1=true values.
676static void 684static void
677encode_rv (enc_t *enc, SV *sv) 685encode_rv (enc_t *enc, SV *sv)
678{ 686{
679 svtype svt; 687 svtype svt;
688 GV *method;
680 689
681 SvGETMAGIC (sv); 690 SvGETMAGIC (sv);
682 svt = SvTYPE (sv); 691 svt = SvTYPE (sv);
683 692
684 if (expect_false (SvOBJECT (sv))) 693 if (expect_false (SvOBJECT (sv)))
685 { 694 {
686 HV *stash = !JSON_SLOW || json_boolean_stash 695 HV *boolean_stash = !JSON_SLOW || types_boolean_stash
687 ? json_boolean_stash 696 ? types_boolean_stash
688 : gv_stashpv ("JSON::XS::Boolean", 1); 697 : gv_stashpv ("Types::Serialiser::Boolean", 1);
698 HV *stash = SvSTASH (sv);
689 699
690 if (SvSTASH (sv) == stash) 700 if (stash == boolean_stash)
691 { 701 {
692 if (SvIV (sv)) 702 if (SvIV (sv))
693 encode_str (enc, "true", 4, 0); 703 encode_str (enc, "true", 4, 0);
694 else 704 else
695 encode_str (enc, "false", 5, 0); 705 encode_str (enc, "false", 5, 0);
696 } 706 }
707 else if ((enc->json.flags & F_ALLOW_TAGS) && (method = gv_fetchmethod_autoload (stash, "FREEZE", 0)))
708 {
709 int count;
710 dSP;
711
712 ENTER; SAVETMPS; PUSHMARK (SP);
713 EXTEND (SP, 2);
714 // we re-bless the reference to get overload and other niceties right
715 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
716 PUSHs (sv_json);
717
718 PUTBACK;
719 count = call_sv ((SV *)GvCV (method), G_ARRAY);
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 encode_ch (enc, '(');
727 encode_ch (enc, '"');
728 encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash));
729 encode_ch (enc, '"');
730 encode_ch (enc, ')');
731 encode_ch (enc, '[');
732
733 while (count)
734 {
735 encode_sv (enc, SP[1 - count--]);
736
737 if (count)
738 encode_ch (enc, ',');
739 }
740
741 encode_ch (enc, ']');
742
743 PUTBACK;
744
745 FREETMPS; LEAVE;
746 }
747 else if ((enc->json.flags & F_CONV_BLESSED) && (method = gv_fetchmethod_autoload (stash, "TO_JSON", 0)))
748 {
749 dSP;
750
751 ENTER; SAVETMPS; PUSHMARK (SP);
752 // we re-bless the reference to get overload and other niceties right
753 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
754
755 // calling with G_SCALAR ensures that we always get a 1 return value
756 PUTBACK;
757 call_sv ((SV *)GvCV (method), G_SCALAR);
758 SPAGAIN;
759
760 // catch this surprisingly common error
761 if (SvROK (TOPs) && SvRV (TOPs) == sv)
762 croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv)));
763
764 sv = POPs;
765 PUTBACK;
766
767 encode_sv (enc, sv);
768
769 FREETMPS; LEAVE;
770 }
771 else if (enc->json.flags & F_ALLOW_BLESSED)
772 encode_str (enc, "null", 4, 0);
697 else 773 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", 774 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)))); 775 SvPV_nolen (sv_2mortal (newRV_inc (sv))));
744 }
745 } 776 }
746 else if (svt == SVt_PVHV) 777 else if (svt == SVt_PVHV)
747 encode_hv (enc, (HV *)sv); 778 encode_hv (enc, (HV *)sv);
748 else if (svt == SVt_PVAV) 779 else if (svt == SVt_PVAV)
749 encode_av (enc, (AV *)sv); 780 encode_av (enc, (AV *)sv);
836 else if (SvROK (sv)) 867 else if (SvROK (sv))
837 encode_rv (enc, SvRV (sv)); 868 encode_rv (enc, SvRV (sv));
838 else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) 869 else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN)
839 encode_str (enc, "null", 4, 0); 870 encode_str (enc, "null", 4, 0);
840 else 871 else
841 croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", 872 croak ("encountered perl type (%s,0x%x) that JSON cannot handle, check your input data",
842 SvPV_nolen (sv), (unsigned int)SvFLAGS (sv)); 873 SvPV_nolen (sv), (unsigned int)SvFLAGS (sv));
843} 874}
844 875
845static SV * 876static SV *
846encode_json (SV *scalar, JSON *json) 877encode_json (SV *scalar, JSON *json)
1259 if (*dec->cur == ']') 1290 if (*dec->cur == ']')
1260 { 1291 {
1261 ++dec->cur; 1292 ++dec->cur;
1262 break; 1293 break;
1263 } 1294 }
1264 1295
1265 if (*dec->cur != ',') 1296 if (*dec->cur != ',')
1266 ERR (", or ] expected while parsing array"); 1297 ERR (", or ] expected while parsing array");
1267 1298
1268 ++dec->cur; 1299 ++dec->cur;
1269 1300
1451 DEC_DEC_DEPTH; 1482 DEC_DEC_DEPTH;
1452 return 0; 1483 return 0;
1453} 1484}
1454 1485
1455static SV * 1486static SV *
1487decode_tag (dec_t *dec)
1488{
1489 SV *tag = 0;
1490 SV *val = 0;
1491
1492 if (!(dec->json.flags & F_ALLOW_TAGS))
1493 ERR ("malformed JSON string, neither array, object, number, string or atom");
1494
1495 ++dec->cur;
1496
1497 tag = decode_sv (dec);
1498 if (!tag)
1499 goto fail;
1500
1501 if (!SvPOK (tag))
1502 ERR ("malformed JSON string, (tag) must be a string");
1503
1504 if (*dec->cur != ')')
1505 ERR (") expected after tag");
1506
1507 ++dec->cur;
1508
1509 val = decode_sv (dec);
1510 if (!val)
1511 goto fail;
1512
1513 if (!SvROK (val) || SvTYPE (SvRV (val)) != SVt_PVAV)
1514 ERR ("malformed JSON string, tag value must be an array");
1515
1516 {
1517 AV *av = (AV *)SvRV (val);
1518 int i, len = av_len (av) + 1;
1519 HV *stash = gv_stashsv (tag, 0);
1520 SV *sv;
1521
1522 if (!stash)
1523 ERR ("cannot decode perl-object (package does not exist)");
1524
1525 GV *method = gv_fetchmethod_autoload (stash, "THAW", 0);
1526
1527 if (!method)
1528 ERR ("cannot decode perl-object (package does not have a THAW method)");
1529
1530 dSP;
1531
1532 ENTER; SAVETMPS; PUSHMARK (SP);
1533 EXTEND (SP, len + 2);
1534 // we re-bless the reference to get overload and other niceties right
1535 PUSHs (tag);
1536 PUSHs (sv_json);
1537
1538 for (i = 0; i < len; ++i)
1539 PUSHs (*av_fetch (av, i, 1));
1540
1541 PUTBACK;
1542 call_sv ((SV *)GvCV (method), G_SCALAR);
1543 SPAGAIN;
1544
1545 SvREFCNT_dec (tag);
1546 SvREFCNT_dec (val);
1547 sv = SvREFCNT_inc (POPs);
1548
1549 PUTBACK;
1550
1551 FREETMPS; LEAVE;
1552
1553 return sv;
1554 }
1555
1556fail:
1557 SvREFCNT_dec (tag);
1558 SvREFCNT_dec (val);
1559 return 0;
1560}
1561
1562static SV *
1456decode_sv (dec_t *dec) 1563decode_sv (dec_t *dec)
1457{ 1564{
1458 // the beauty of JSON: you need exactly one character lookahead 1565 // the beauty of JSON: you need exactly one character lookahead
1459 // to parse everything. 1566 // to parse everything.
1460 switch (*dec->cur) 1567 switch (*dec->cur)
1461 { 1568 {
1462 case '"': ++dec->cur; return decode_str (dec); 1569 case '"': ++dec->cur; return decode_str (dec);
1463 case '[': ++dec->cur; return decode_av (dec); 1570 case '[': ++dec->cur; return decode_av (dec);
1464 case '{': ++dec->cur; return decode_hv (dec); 1571 case '{': ++dec->cur; return decode_hv (dec);
1572 case '(': return decode_tag (dec);
1465 1573
1466 case '-': 1574 case '-':
1467 case '0': case '1': case '2': case '3': case '4': 1575 case '0': case '1': case '2': case '3': case '4':
1468 case '5': case '6': case '7': case '8': case '9': 1576 case '5': case '6': case '7': case '8': case '9':
1469 return decode_num (dec); 1577 return decode_num (dec);
1471 case 't': 1579 case 't':
1472 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) 1580 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4))
1473 { 1581 {
1474 dec->cur += 4; 1582 dec->cur += 4;
1475#if JSON_SLOW 1583#if JSON_SLOW
1476 json_true = get_bool ("JSON::XS::true"); 1584 types_true = get_bool ("Types::Serialiser::true");
1477#endif 1585#endif
1478 return newSVsv (json_true); 1586 return newSVsv (types_true);
1479 } 1587 }
1480 else 1588 else
1481 ERR ("'true' expected"); 1589 ERR ("'true' expected");
1482 1590
1483 break; 1591 break;
1485 case 'f': 1593 case 'f':
1486 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) 1594 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5))
1487 { 1595 {
1488 dec->cur += 5; 1596 dec->cur += 5;
1489#if JSON_SLOW 1597#if JSON_SLOW
1490 json_false = get_bool ("JSON::XS::false"); 1598 types_false = get_bool ("Types::Serialiser::false");
1491#endif 1599#endif
1492 return newSVsv (json_false); 1600 return newSVsv (types_false);
1493 } 1601 }
1494 else 1602 else
1495 ERR ("'false' expected"); 1603 ERR ("'false' expected");
1496 1604
1497 break; 1605 break;
1506 ERR ("'null' expected"); 1614 ERR ("'null' expected");
1507 1615
1508 break; 1616 break;
1509 1617
1510 default: 1618 default:
1511 ERR ("malformed JSON string, neither array, object, number, string or atom"); 1619 ERR ("malformed JSON string, neither tag, array, object, number, string or atom");
1512 break; 1620 break;
1513 } 1621 }
1514 1622
1515fail: 1623fail:
1516 return 0; 1624 return 0;
1521{ 1629{
1522 dec_t dec; 1630 dec_t dec;
1523 SV *sv; 1631 SV *sv;
1524 1632
1525 /* work around bugs in 5.10 where manipulating magic values 1633 /* work around bugs in 5.10 where manipulating magic values
1526 * will perl ignore the magic in subsequent accesses. 1634 * makes perl ignore the magic in subsequent accesses.
1527 * also make a copy of non-PV values, to get them into a clean 1635 * 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). 1636 * state (SvPV should do that, but it's buggy, see below).
1529 */ 1637 */
1530 /*SvGETMAGIC (string);*/ 1638 /*SvGETMAGIC (string);*/
1531 if (SvMAGICAL (string) || !SvPOK (string)) 1639 if (SvMAGICAL (string) || !SvPOK (string))
1743 self->incr_mode = INCR_M_STR; 1851 self->incr_mode = INCR_M_STR;
1744 goto incr_m_str; 1852 goto incr_m_str;
1745 1853
1746 case '[': 1854 case '[':
1747 case '{': 1855 case '{':
1856 case '(':
1748 if (++self->incr_nest > self->max_depth) 1857 if (++self->incr_nest > self->max_depth)
1749 croak (ERR_NESTING_EXCEEDED); 1858 croak (ERR_NESTING_EXCEEDED);
1750 break; 1859 break;
1751 1860
1752 case ']': 1861 case ']':
1753 case '}': 1862 case '}':
1754 if (--self->incr_nest <= 0) 1863 if (--self->incr_nest <= 0)
1755 goto interrupt; 1864 goto interrupt;
1865 break;
1866
1867 case ')':
1868 --self->incr_nest;
1756 break; 1869 break;
1757 1870
1758 case '#': 1871 case '#':
1759 self->incr_mode = INCR_M_C1; 1872 self->incr_mode = INCR_M_C1;
1760 goto incr_m_c; 1873 goto incr_m_c;
1786 i >= '0' && i <= '9' ? i - '0' 1899 i >= '0' && i <= '9' ? i - '0'
1787 : i >= 'a' && i <= 'f' ? i - 'a' + 10 1900 : i >= 'a' && i <= 'f' ? i - 'a' + 10
1788 : i >= 'A' && i <= 'F' ? i - 'A' + 10 1901 : i >= 'A' && i <= 'F' ? i - 'A' + 10
1789 : -1; 1902 : -1;
1790 1903
1791 json_stash = gv_stashpv ("JSON::XS" , 1); 1904 json_stash = gv_stashpv ("JSON::XS" , 1);
1792 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1); 1905 types_boolean_stash = gv_stashpv ("Types::Serialiser::Boolean", 1);
1793 1906
1794 json_true = get_bool ("JSON::XS::true"); 1907 types_true = get_bool ("Types::Serialiser::true");
1795 json_false = get_bool ("JSON::XS::false"); 1908 types_false = get_bool ("Types::Serialiser::false");
1909
1910 sv_json = newSVpv ("JSON", 0);
1911 SvREADONLY_on (sv_json);
1796 1912
1797 CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */ 1913 CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */
1798} 1914}
1799 1915
1800PROTOTYPES: DISABLE 1916PROTOTYPES: DISABLE
1801 1917
1802void CLONE (...) 1918void CLONE (...)
1803 CODE: 1919 CODE:
1804 json_stash = 0; 1920 json_stash = 0;
1805 json_boolean_stash = 0; 1921 types_boolean_stash = 0;
1806 1922
1807void new (char *klass) 1923void new (char *klass)
1808 PPCODE: 1924 PPCODE:
1809{ 1925{
1810 SV *pv = NEWSV (0, sizeof (JSON)); 1926 SV *pv = NEWSV (0, sizeof (JSON));
1811 SvPOK_only (pv); 1927 SvPOK_only (pv);
1812 json_init ((JSON *)SvPVX (pv)); 1928 json_init ((JSON *)SvPVX (pv));
1813 XPUSHs (sv_2mortal (sv_bless ( 1929 XPUSHs (sv_2mortal (sv_bless (
1814 newRV_noinc (pv), 1930 newRV_noinc (pv),
1815 strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) 1931 strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1)
1830 shrink = F_SHRINK 1946 shrink = F_SHRINK
1831 allow_blessed = F_ALLOW_BLESSED 1947 allow_blessed = F_ALLOW_BLESSED
1832 convert_blessed = F_CONV_BLESSED 1948 convert_blessed = F_CONV_BLESSED
1833 relaxed = F_RELAXED 1949 relaxed = F_RELAXED
1834 allow_unknown = F_ALLOW_UNKNOWN 1950 allow_unknown = F_ALLOW_UNKNOWN
1951 allow_tags = F_ALLOW_TAGS
1835 PPCODE: 1952 PPCODE:
1836{ 1953{
1837 if (enable) 1954 if (enable)
1838 self->flags |= ix; 1955 self->flags |= ix;
1839 else 1956 else
1855 get_shrink = F_SHRINK 1972 get_shrink = F_SHRINK
1856 get_allow_blessed = F_ALLOW_BLESSED 1973 get_allow_blessed = F_ALLOW_BLESSED
1857 get_convert_blessed = F_CONV_BLESSED 1974 get_convert_blessed = F_CONV_BLESSED
1858 get_relaxed = F_RELAXED 1975 get_relaxed = F_RELAXED
1859 get_allow_unknown = F_ALLOW_UNKNOWN 1976 get_allow_unknown = F_ALLOW_UNKNOWN
1977 get_allow_tags = F_ALLOW_TAGS
1860 PPCODE: 1978 PPCODE:
1861 XPUSHs (boolSV (self->flags & ix)); 1979 XPUSHs (boolSV (self->flags & ix));
1862 1980
1863void max_depth (JSON *self, U32 max_depth = 0x80000000UL) 1981void max_depth (JSON *self, U32 max_depth = 0x80000000UL)
1864 PPCODE: 1982 PPCODE:
2064 SvREFCNT_dec (self->incr_text); 2182 SvREFCNT_dec (self->incr_text);
2065 2183
2066PROTOTYPES: ENABLE 2184PROTOTYPES: ENABLE
2067 2185
2068void encode_json (SV *scalar) 2186void encode_json (SV *scalar)
2069 ALIAS:
2070 to_json_ = 0
2071 encode_json = F_UTF8
2072 PPCODE: 2187 PPCODE:
2073{ 2188{
2074 JSON json; 2189 JSON json;
2075 json_init (&json); 2190 json_init (&json);
2076 json.flags |= ix; 2191 json.flags |= F_UTF8;
2077 PUTBACK; scalar = encode_json (scalar, &json); SPAGAIN; 2192 PUTBACK; scalar = encode_json (scalar, &json); SPAGAIN;
2078 XPUSHs (scalar); 2193 XPUSHs (scalar);
2079} 2194}
2080 2195
2081void decode_json (SV *jsonstr) 2196void decode_json (SV *jsonstr)
2082 ALIAS:
2083 from_json_ = 0
2084 decode_json = F_UTF8
2085 PPCODE: 2197 PPCODE:
2086{ 2198{
2087 JSON json; 2199 JSON json;
2088 json_init (&json); 2200 json_init (&json);
2089 json.flags |= ix; 2201 json.flags |= F_UTF8;
2090 PUTBACK; jsonstr = decode_json (jsonstr, &json, 0); SPAGAIN; 2202 PUTBACK; jsonstr = decode_json (jsonstr, &json, 0); SPAGAIN;
2091 XPUSHs (jsonstr); 2203 XPUSHs (jsonstr);
2092} 2204}
2093 2205

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines