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.121 by root, Tue Oct 29 00:06:40 2013 UTC vs.
Revision 1.130 by root, Sat Nov 26 06:09:29 2016 UTC

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 <limits.h> 9#include <limits.h>
10#include <float.h> 10#include <float.h>
11#include <inttypes.h>
11 12
12#if defined(__BORLANDC__) || defined(_MSC_VER) 13#if defined(__BORLANDC__) || defined(_MSC_VER)
13# define snprintf _snprintf // C compilers have this in stdio.h 14# define snprintf _snprintf // C compilers have this in stdio.h
14#endif 15#endif
15 16
16// some old perls do not have this, try to make it work, no 17// 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. 18// guarantees, though. if it breaks, you get to keep the pieces.
18#ifndef UTF8_MAXBYTES 19#ifndef UTF8_MAXBYTES
19# define UTF8_MAXBYTES 13 20# define UTF8_MAXBYTES 13
21#endif
22
23// compatibility with perl <5.18
24#ifndef HvNAMELEN_get
25# define HvNAMELEN_get(hv) strlen (HvNAME (hv))
26#endif
27#ifndef HvNAMELEN
28# define HvNAMELEN(hv) HvNAMELEN_get (hv)
29#endif
30#ifndef HvNAMEUTF8
31# define HvNAMEUTF8(hv) 0
20#endif 32#endif
21 33
22// three extra for rounding, sign, and end of string 34// three extra for rounding, sign, and end of string
23#define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3) 35#define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3)
24 36
68#define ERR_NESTING_EXCEEDED "json text or perl structure exceeds maximum nesting level (max_depth set too low?)" 80#define ERR_NESTING_EXCEEDED "json text or perl structure exceeds maximum nesting level (max_depth set too low?)"
69 81
70#ifdef USE_ITHREADS 82#ifdef USE_ITHREADS
71# define JSON_SLOW 1 83# define JSON_SLOW 1
72# define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) 84# define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1))
85# define BOOL_STASH (bool_stash ? bool_stash : gv_stashpv ("Types::Serialiser::Boolean", 1))
73#else 86#else
74# define JSON_SLOW 0 87# define JSON_SLOW 0
75# define JSON_STASH json_stash 88# define JSON_STASH json_stash
89# define BOOL_STASH bool_stash
76#endif 90#endif
77 91
78// the amount of HEs to allocate on the stack, when sorting keys 92// the amount of HEs to allocate on the stack, when sorting keys
79#define STACK_HES 64 93#define STACK_HES 64
80 94
81static HV *json_stash, *types_boolean_stash; // JSON::XS:: 95static HV *json_stash, *bool_stash; // JSON::XS::, Types::Serialiser::Boolean::
82static SV *types_true, *types_false, *sv_json; 96static SV *bool_true, *bool_false, *sv_json;
83 97
84enum { 98enum {
85 INCR_M_WS = 0, // initial whitespace skipping, must be 0 99 INCR_M_WS = 0, // initial whitespace skipping, must be 0
86 INCR_M_STR, // inside string 100 INCR_M_STR, // inside string
87 INCR_M_BS, // inside backslash 101 INCR_M_BS, // inside backslash
288 // a recursion depth of ten gives us >>500 bits 302 // a recursion depth of ten gives us >>500 bits
289 json_atof_scan1 (s, &accum, &expo, 0, 10); 303 json_atof_scan1 (s, &accum, &expo, 0, 10);
290 304
291 return neg ? -accum : accum; 305 return neg ? -accum : accum;
292} 306}
307
308// target of scalar reference is bool? -1 == nope, 0 == false, 1 == true
309static int
310ref_bool_type (SV *sv)
311{
312 svtype svt = SvTYPE (sv);
313
314 if (svt < SVt_PVAV)
315 {
316 STRLEN len = 0;
317 char *pv = svt ? SvPV (sv, len) : 0;
318
319 if (len == 1)
320 if (*pv == '1')
321 return 1;
322 else if (*pv == '0')
323 return 0;
324 }
325
326 return -1;
327}
328
329// returns whether scalar is not a reference in the sense of allow_nonref
330static int
331json_nonref (SV *scalar)
332{
333 if (!SvROK (scalar))
334 return 1;
335
336 scalar = SvRV (scalar);
337
338 if (SvTYPE (scalar) >= SVt_PVMG)
339 {
340 if (SvSTASH (scalar) == bool_stash)
341 return 1;
342
343 if (!SvOBJECT (scalar) && ref_bool_type (scalar) >= 0)
344 return 1;
345 }
346
347 return 0;
348}
349
293///////////////////////////////////////////////////////////////////////////// 350/////////////////////////////////////////////////////////////////////////////
294// encoder 351// encoder
295 352
296// structure used for encoding JSON 353// structure used for encoding JSON
297typedef struct 354typedef struct
305} enc_t; 362} enc_t;
306 363
307INLINE void 364INLINE void
308need (enc_t *enc, STRLEN len) 365need (enc_t *enc, STRLEN len)
309{ 366{
310 if (expect_false (enc->cur + len >= enc->end)) 367 if (expect_false ((uintptr_t)(enc->end - enc->cur) < len))
311 { 368 {
312 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv); 369 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv);
313 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1); 370 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1);
314 enc->cur = SvPVX (enc->sv) + cur; 371 enc->cur = SvPVX (enc->sv) + cur;
315 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; 372 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
690 SvGETMAGIC (sv); 747 SvGETMAGIC (sv);
691 svt = SvTYPE (sv); 748 svt = SvTYPE (sv);
692 749
693 if (expect_false (SvOBJECT (sv))) 750 if (expect_false (SvOBJECT (sv)))
694 { 751 {
695 HV *boolean_stash = !JSON_SLOW || types_boolean_stash
696 ? types_boolean_stash
697 : gv_stashpv ("Types::Serialiser::Boolean", 1);
698 HV *stash = SvSTASH (sv); 752 HV *stash = SvSTASH (sv);
699 753
700 if (stash == boolean_stash) 754 if (stash == bool_stash)
701 { 755 {
702 if (SvIV (sv)) 756 if (SvIV (sv))
703 encode_str (enc, "true", 4, 0); 757 encode_str (enc, "true", 4, 0);
704 else 758 else
705 encode_str (enc, "false", 5, 0); 759 encode_str (enc, "false", 5, 0);
707 else if ((enc->json.flags & F_ALLOW_TAGS) && (method = gv_fetchmethod_autoload (stash, "FREEZE", 0))) 761 else if ((enc->json.flags & F_ALLOW_TAGS) && (method = gv_fetchmethod_autoload (stash, "FREEZE", 0)))
708 { 762 {
709 int count; 763 int count;
710 dSP; 764 dSP;
711 765
712 ENTER; SAVETMPS; PUSHMARK (SP); 766 ENTER; SAVETMPS;
767 SAVESTACK_POS ();
768 PUSHMARK (SP);
713 EXTEND (SP, 2); 769 EXTEND (SP, 2);
714 // we re-bless the reference to get overload and other niceties right 770 // we re-bless the reference to get overload and other niceties right
715 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 771 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
716 PUSHs (sv_json); 772 PUSHs (sv_json);
717 773
719 count = call_sv ((SV *)GvCV (method), G_ARRAY); 775 count = call_sv ((SV *)GvCV (method), G_ARRAY);
720 SPAGAIN; 776 SPAGAIN;
721 777
722 // catch this surprisingly common error 778 // catch this surprisingly common error
723 if (SvROK (TOPs) && SvRV (TOPs) == sv) 779 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))); 780 croak ("%s::FREEZE method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv)));
725 781
726 encode_ch (enc, '('); 782 encode_ch (enc, '(');
727 encode_ch (enc, '"'); 783 encode_ch (enc, '"');
728 encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash)); 784 encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash));
729 encode_ch (enc, '"'); 785 encode_ch (enc, '"');
738 encode_ch (enc, ','); 794 encode_ch (enc, ',');
739 } 795 }
740 796
741 encode_ch (enc, ']'); 797 encode_ch (enc, ']');
742 798
743 PUTBACK;
744
745 FREETMPS; LEAVE; 799 FREETMPS; LEAVE;
746 } 800 }
747 else if ((enc->json.flags & F_CONV_BLESSED) && (method = gv_fetchmethod_autoload (stash, "TO_JSON", 0))) 801 else if ((enc->json.flags & F_CONV_BLESSED) && (method = gv_fetchmethod_autoload (stash, "TO_JSON", 0)))
748 { 802 {
749 dSP; 803 dSP;
750 804
751 ENTER; SAVETMPS; PUSHMARK (SP); 805 ENTER; SAVETMPS;
806 PUSHMARK (SP);
752 // we re-bless the reference to get overload and other niceties right 807 // we re-bless the reference to get overload and other niceties right
753 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 808 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
754 809
755 // calling with G_SCALAR ensures that we always get a 1 return value 810 // calling with G_SCALAR ensures that we always get a 1 return value
756 PUTBACK; 811 PUTBACK;
778 encode_hv (enc, (HV *)sv); 833 encode_hv (enc, (HV *)sv);
779 else if (svt == SVt_PVAV) 834 else if (svt == SVt_PVAV)
780 encode_av (enc, (AV *)sv); 835 encode_av (enc, (AV *)sv);
781 else if (svt < SVt_PVAV) 836 else if (svt < SVt_PVAV)
782 { 837 {
783 STRLEN len = 0; 838 int bool_type = ref_bool_type (sv);
784 char *pv = svt ? SvPV (sv, len) : 0;
785 839
786 if (len == 1 && *pv == '1') 840 if (bool_type == 1)
787 encode_str (enc, "true", 4, 0); 841 encode_str (enc, "true", 4, 0);
788 else if (len == 1 && *pv == '0') 842 else if (bool_type == 0)
789 encode_str (enc, "false", 5, 0); 843 encode_str (enc, "false", 5, 0);
790 else if (enc->json.flags & F_ALLOW_UNKNOWN) 844 else if (enc->json.flags & F_ALLOW_UNKNOWN)
791 encode_str (enc, "null", 4, 0); 845 encode_str (enc, "null", 4, 0);
792 else 846 else
793 croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", 847 croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1",
876static SV * 930static SV *
877encode_json (SV *scalar, JSON *json) 931encode_json (SV *scalar, JSON *json)
878{ 932{
879 enc_t enc; 933 enc_t enc;
880 934
881 if (!(json->flags & F_ALLOW_NONREF) && !SvROK (scalar)) 935 if (!(json->flags & F_ALLOW_NONREF) && json_nonref (scalar))
882 croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); 936 croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)");
883 937
884 enc.json = *json; 938 enc.json = *json;
885 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 939 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
886 enc.cur = SvPVX (enc.sv); 940 enc.cur = SvPVX (enc.sv);
1093 *cur++ = *dec_cur++; 1147 *cur++ = *dec_cur++;
1094 while (--clen); 1148 while (--clen);
1095 1149
1096 utf8 = 1; 1150 utf8 = 1;
1097 } 1151 }
1152 else if (ch == '\t' && dec->json.flags & F_RELAXED)
1153 *cur++ = ch;
1098 else 1154 else
1099 { 1155 {
1100 --dec_cur; 1156 --dec_cur;
1101 1157
1102 if (!ch) 1158 if (!ch)
1424 1480
1425 hv_iterinit (hv); 1481 hv_iterinit (hv);
1426 he = hv_iternext (hv); 1482 he = hv_iternext (hv);
1427 hv_iterinit (hv); 1483 hv_iterinit (hv);
1428 1484
1429 // the next line creates a mortal sv each time its called. 1485 // the next line creates a mortal sv each time it's called.
1430 // might want to optimise this for common cases. 1486 // might want to optimise this for common cases.
1431 cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0); 1487 cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0);
1432 1488
1433 if (cb) 1489 if (cb)
1434 { 1490 {
1435 dSP; 1491 dSP;
1436 int count; 1492 int count;
1437 1493
1438 ENTER; SAVETMPS; PUSHMARK (SP); 1494 ENTER; SAVETMPS;
1495 SAVESTACK_POS ();
1496 PUSHMARK (SP);
1439 XPUSHs (HeVAL (he)); 1497 XPUSHs (HeVAL (he));
1440 sv_2mortal (sv); 1498 sv_2mortal (sv);
1441 1499
1442 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; 1500 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN;
1443 1501
1456 if (dec->json.cb_object) 1514 if (dec->json.cb_object)
1457 { 1515 {
1458 dSP; 1516 dSP;
1459 int count; 1517 int count;
1460 1518
1461 ENTER; SAVETMPS; PUSHMARK (SP); 1519 ENTER; SAVETMPS;
1520 SAVESTACK_POS ();
1521 PUSHMARK (SP);
1462 XPUSHs (sv_2mortal (sv)); 1522 XPUSHs (sv_2mortal (sv));
1463 1523
1464 PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; 1524 PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN;
1465 1525
1466 if (count == 1) 1526 if (count == 1)
1533 if (!method) 1593 if (!method)
1534 ERR ("cannot decode perl-object (package does not have a THAW method)"); 1594 ERR ("cannot decode perl-object (package does not have a THAW method)");
1535 1595
1536 dSP; 1596 dSP;
1537 1597
1538 ENTER; SAVETMPS; PUSHMARK (SP); 1598 ENTER; SAVETMPS;
1599 PUSHMARK (SP);
1539 EXTEND (SP, len + 2); 1600 EXTEND (SP, len + 2);
1540 // we re-bless the reference to get overload and other niceties right 1601 // we re-bless the reference to get overload and other niceties right
1541 PUSHs (tag); 1602 PUSHs (tag);
1542 PUSHs (sv_json); 1603 PUSHs (sv_json);
1543 1604
1585 case 't': 1646 case 't':
1586 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) 1647 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4))
1587 { 1648 {
1588 dec->cur += 4; 1649 dec->cur += 4;
1589#if JSON_SLOW 1650#if JSON_SLOW
1590 types_true = get_bool ("Types::Serialiser::true"); 1651 bool_true = get_bool ("Types::Serialiser::true");
1591#endif 1652#endif
1592 return newSVsv (types_true); 1653 return newSVsv (bool_true);
1593 } 1654 }
1594 else 1655 else
1595 ERR ("'true' expected"); 1656 ERR ("'true' expected");
1596 1657
1597 break; 1658 break;
1599 case 'f': 1660 case 'f':
1600 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) 1661 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5))
1601 { 1662 {
1602 dec->cur += 5; 1663 dec->cur += 5;
1603#if JSON_SLOW 1664#if JSON_SLOW
1604 types_false = get_bool ("Types::Serialiser::false"); 1665 bool_false = get_bool ("Types::Serialiser::false");
1605#endif 1666#endif
1606 return newSVsv (types_false); 1667 return newSVsv (bool_false);
1607 } 1668 }
1608 else 1669 else
1609 ERR ("'false' expected"); 1670 ERR ("'false' expected");
1610 1671
1611 break; 1672 break;
1629fail: 1690fail:
1630 return 0; 1691 return 0;
1631} 1692}
1632 1693
1633static SV * 1694static SV *
1634decode_json (SV *string, JSON *json, char **offset_return) 1695decode_json (SV *string, JSON *json, STRLEN *offset_return)
1635{ 1696{
1636 dec_t dec; 1697 dec_t dec;
1637 SV *sv; 1698 SV *sv;
1638 1699
1639 /* work around bugs in 5.10 where manipulating magic values 1700 /* work around bugs in 5.10 where manipulating magic values
1640 * makes perl ignore the magic in subsequent accesses. 1701 * makes perl ignore the magic in subsequent accesses.
1641 * also make a copy of non-PV values, to get them into a clean 1702 * also make a copy of non-PV values, to get them into a clean
1642 * state (SvPV should do that, but it's buggy, see below). 1703 * state (SvPV should do that, but it's buggy, see below).
1704 *
1705 * SvIsCOW_shared_hash works around a bug in perl (possibly 5.16),
1706 * as reported by Reini Urban.
1643 */ 1707 */
1644 /*SvGETMAGIC (string);*/ 1708 /*SvGETMAGIC (string);*/
1645 if (SvMAGICAL (string) || !SvPOK (string)) 1709 if (SvMAGICAL (string) || !SvPOK (string) || SvIsCOW_shared_hash (string))
1646 string = sv_2mortal (newSVsv (string)); 1710 string = sv_2mortal (newSVsv (string));
1647 1711
1648 SvUPGRADE (string, SVt_PV); 1712 SvUPGRADE (string, SVt_PV);
1649 1713
1650 /* work around a bug in perl 5.10, which causes SvCUR to fail an 1714 /* work around a bug in perl 5.10, which causes SvCUR to fail an
1689 1753
1690 decode_ws (&dec); 1754 decode_ws (&dec);
1691 sv = decode_sv (&dec); 1755 sv = decode_sv (&dec);
1692 1756
1693 if (offset_return) 1757 if (offset_return)
1694 *offset_return = dec.cur; 1758 *offset_return = dec.cur - SvPVX (string);
1695 1759 else if (sv)
1696 if (!(offset_return || !sv))
1697 { 1760 {
1698 // check for trailing garbage 1761 // check for trailing garbage
1699 decode_ws (&dec); 1762 decode_ws (&dec);
1700 1763
1701 if (*dec.cur) 1764 if (*dec.cur)
1725 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); 1788 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)");
1726 } 1789 }
1727 1790
1728 sv = sv_2mortal (sv); 1791 sv = sv_2mortal (sv);
1729 1792
1730 if (!(dec.json.flags & F_ALLOW_NONREF) && !SvROK (sv)) 1793 if (!(dec.json.flags & F_ALLOW_NONREF) && json_nonref (sv))
1731 croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); 1794 croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)");
1732 1795
1733 return sv; 1796 return sv;
1734} 1797}
1735 1798
1905 i >= '0' && i <= '9' ? i - '0' 1968 i >= '0' && i <= '9' ? i - '0'
1906 : i >= 'a' && i <= 'f' ? i - 'a' + 10 1969 : i >= 'a' && i <= 'f' ? i - 'a' + 10
1907 : i >= 'A' && i <= 'F' ? i - 'A' + 10 1970 : i >= 'A' && i <= 'F' ? i - 'A' + 10
1908 : -1; 1971 : -1;
1909 1972
1910 json_stash = gv_stashpv ("JSON::XS" , 1); 1973 json_stash = gv_stashpv ("JSON::XS" , 1);
1911 types_boolean_stash = gv_stashpv ("Types::Serialiser::Boolean", 1); 1974 bool_stash = gv_stashpv ("Types::Serialiser::Boolean", 1);
1912
1913 types_true = get_bool ("Types::Serialiser::true"); 1975 bool_true = get_bool ("Types::Serialiser::true");
1914 types_false = get_bool ("Types::Serialiser::false"); 1976 bool_false = get_bool ("Types::Serialiser::false");
1915 1977
1916 sv_json = newSVpv ("JSON", 0); 1978 sv_json = newSVpv ("JSON", 0);
1917 SvREADONLY_on (sv_json); 1979 SvREADONLY_on (sv_json);
1918 1980
1919 CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */ 1981 CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */
1921 1983
1922PROTOTYPES: DISABLE 1984PROTOTYPES: DISABLE
1923 1985
1924void CLONE (...) 1986void CLONE (...)
1925 CODE: 1987 CODE:
1926 json_stash = 0; 1988 json_stash = 0;
1927 types_boolean_stash = 0; 1989 bool_stash = 0;
1928 1990
1929void new (char *klass) 1991void new (char *klass)
1930 PPCODE: 1992 PPCODE:
1931{ 1993{
1932 SV *pv = NEWSV (0, sizeof (JSON)); 1994 SV *pv = NEWSV (0, sizeof (JSON));
2049 2111
2050void decode_prefix (JSON *self, SV *jsonstr) 2112void decode_prefix (JSON *self, SV *jsonstr)
2051 PPCODE: 2113 PPCODE:
2052{ 2114{
2053 SV *sv; 2115 SV *sv;
2054 char *offset; 2116 STRLEN offset;
2055 PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN; 2117 PUTBACK; sv = decode_json (jsonstr, self, &offset); SPAGAIN;
2056 EXTEND (SP, 2); 2118 EXTEND (SP, 2);
2057 PUSHs (sv); 2119 PUSHs (sv);
2058 PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset)))); 2120 PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, SvPV_nolen (jsonstr) + offset))));
2059} 2121}
2060 2122
2061void incr_parse (JSON *self, SV *jsonstr = 0) 2123void incr_parse (JSON *self, SV *jsonstr = 0)
2062 PPCODE: 2124 PPCODE:
2063{ 2125{
2110 2172
2111 if (GIMME_V != G_VOID) 2173 if (GIMME_V != G_VOID)
2112 do 2174 do
2113 { 2175 {
2114 SV *sv; 2176 SV *sv;
2115 char *offset; 2177 STRLEN offset;
2116 2178
2117 if (!INCR_DONE (self)) 2179 if (!INCR_DONE (self))
2118 { 2180 {
2119 incr_parse (self); 2181 incr_parse (self);
2120 2182
2136 } 2198 }
2137 2199
2138 PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN; 2200 PUTBACK; sv = decode_json (self->incr_text, self, &offset); SPAGAIN;
2139 XPUSHs (sv); 2201 XPUSHs (sv);
2140 2202
2141 self->incr_pos -= offset - SvPVX (self->incr_text); 2203 self->incr_pos -= offset;
2142 self->incr_nest = 0; 2204 self->incr_nest = 0;
2143 self->incr_mode = 0; 2205 self->incr_mode = 0;
2144 2206
2145 sv_chop (self->incr_text, offset); 2207 sv_chop (self->incr_text, SvPVX (self->incr_text) + offset);
2146 } 2208 }
2147 while (GIMME_V == G_ARRAY); 2209 while (GIMME_V == G_ARRAY);
2148} 2210}
2149 2211
2150SV *incr_text (JSON *self) 2212SV *incr_text (JSON *self)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines