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.95 by root, Sun Feb 22 06:55:28 2009 UTC vs.
Revision 1.104 by root, Tue Jan 19 00:31:13 2010 UTC

12#if defined(__BORLANDC__) || defined(_MSC_VER) 12#if defined(__BORLANDC__) || defined(_MSC_VER)
13# define snprintf _snprintf // C compilers have this in stdio.h 13# define snprintf _snprintf // C compilers have this in stdio.h
14#endif 14#endif
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// guarentees, 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 20#endif
21 21
22// three extra for rounding, sign, and end of string
22#define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 2) 23#define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3)
23 24
24#define F_ASCII 0x00000001UL 25#define F_ASCII 0x00000001UL
25#define F_LATIN1 0x00000002UL 26#define F_LATIN1 0x00000002UL
26#define F_UTF8 0x00000004UL 27#define F_UTF8 0x00000004UL
27#define F_INDENT 0x00000008UL 28#define F_INDENT 0x00000008UL
76 77
77enum { 78enum {
78 INCR_M_WS = 0, // initial whitespace skipping, must be 0 79 INCR_M_WS = 0, // initial whitespace skipping, must be 0
79 INCR_M_STR, // inside string 80 INCR_M_STR, // inside string
80 INCR_M_BS, // inside backslash 81 INCR_M_BS, // inside backslash
82 INCR_M_C0, // inside comment in initial whitespace sequence
83 INCR_M_C1, // inside comment in other places
81 INCR_M_JSON // outside anything, count nesting 84 INCR_M_JSON // outside anything, count nesting
82}; 85};
83 86
84#define INCR_DONE(json) ((json)->incr_nest <= 0 && (json)->incr_mode == INCR_M_JSON) 87#define INCR_DONE(json) ((json)->incr_nest <= 0 && (json)->incr_mode == INCR_M_JSON)
85 88
175 *s++ = 0x80 | ( ch & 0x3f); 178 *s++ = 0x80 | ( ch & 0x3f);
176 179
177 return s; 180 return s;
178} 181}
179 182
183// convert offset pointer to character index, sv must be string
184static STRLEN
185ptr_to_index (SV *sv, char *offset)
186{
187 return SvUTF8 (sv)
188 ? utf8_distance (offset, SvPVX (sv))
189 : offset - SvPVX (sv);
190}
191
192/////////////////////////////////////////////////////////////////////////////
193// fp hell
194
195// scan a group of digits, and a trailing exponent
196static void
197json_atof_scan1 (const char *s, NV *accum, int *expo, int postdp)
198{
199 UV uaccum = 0;
200 int eaccum = 0;
201
202 for (;;)
203 {
204 U8 dig = (U8)*s - '0';
205
206 if (expect_false (dig >= 10))
207 {
208 if (dig == (U8)((U8)'.' - (U8)'0'))
209 {
210 ++s;
211 json_atof_scan1 (s, accum, expo, 1);
212 }
213 else if ((dig | ' ') == 'e' - '0')
214 {
215 int exp2 = 0;
216 int neg = 0;
217
218 ++s;
219
220 if (*s == '-')
221 {
222 ++s;
223 neg = 1;
224 }
225 else if (*s == '+')
226 ++s;
227
228 while ((dig = (U8)*s - '0') < 10)
229 exp2 = exp2 * 10 + *s++ - '0';
230
231 *expo += neg ? -exp2 : exp2;
232 }
233
234 break;
235 }
236
237 ++s;
238
239 uaccum = uaccum * 10 + dig;
240 ++eaccum;
241
242 // if we have too many digits, then recurse for more
243 // we actually do this for rather few digits
244 if (uaccum >= (UV_MAX - 9) / 10)
245 {
246 if (postdp) *expo -= eaccum;
247 json_atof_scan1 (s, accum, expo, postdp);
248 if (postdp) *expo += eaccum;
249
250 break;
251 }
252 }
253
254 if (postdp) *expo -= eaccum;
255 *accum += uaccum * pow (10., *expo);
256 *expo += eaccum;
257}
258
259static NV
260json_atof (const char *s)
261{
262 NV accum = 0.;
263 int expo = 0;
264 int neg = 0;
265
266 if (*s == '-')
267 {
268 ++s;
269 neg = 1;
270 }
271
272 json_atof_scan1 (s, &accum, &expo, 0);
273
274 return neg ? -accum : accum;
275}
180///////////////////////////////////////////////////////////////////////////// 276/////////////////////////////////////////////////////////////////////////////
181// encoder 277// encoder
182 278
183// structure used for encoding JSON 279// structure used for encoding JSON
184typedef struct 280typedef struct
462 558
463 // for canonical output we have to sort by keys first 559 // for canonical output we have to sort by keys first
464 // actually, this is mostly due to the stupid so-called 560 // actually, this is mostly due to the stupid so-called
465 // security workaround added somewhere in 5.8.x 561 // security workaround added somewhere in 5.8.x
466 // that randomises hash orderings 562 // that randomises hash orderings
467 if (enc->json.flags & F_CANONICAL) 563 if (enc->json.flags & F_CANONICAL && !SvRMAGICAL (hv))
468 { 564 {
469 int count = hv_iterinit (hv); 565 int count = hv_iterinit (hv);
470 566
471 if (SvMAGICAL (hv)) 567 if (SvMAGICAL (hv))
472 { 568 {
750 : enc.json.flags & F_LATIN1 ? 0x000100UL 846 : enc.json.flags & F_LATIN1 ? 0x000100UL
751 : 0x110000UL; 847 : 0x110000UL;
752 848
753 SvPOK_only (enc.sv); 849 SvPOK_only (enc.sv);
754 encode_sv (&enc, scalar); 850 encode_sv (&enc, scalar);
851 encode_nl (&enc);
755 852
756 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); 853 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv));
757 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings 854 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings
758 855
759 if (!(enc.json.flags & (F_ASCII | F_LATIN1 | F_UTF8))) 856 if (!(enc.json.flags & (F_ASCII | F_LATIN1 | F_UTF8)))
939 else if (expect_true (ch >= 0x20 && ch < 0x80)) 1036 else if (expect_true (ch >= 0x20 && ch < 0x80))
940 *cur++ = ch; 1037 *cur++ = ch;
941 else if (ch >= 0x80) 1038 else if (ch >= 0x80)
942 { 1039 {
943 STRLEN clen; 1040 STRLEN clen;
944 UV uch;
945 1041
946 --dec_cur; 1042 --dec_cur;
947 1043
948 uch = decode_utf8 (dec_cur, dec->end - dec_cur, &clen); 1044 decode_utf8 (dec_cur, dec->end - dec_cur, &clen);
949 if (clen == (STRLEN)-1) 1045 if (clen == (STRLEN)-1)
950 ERR ("malformed UTF-8 character in JSON string"); 1046 ERR ("malformed UTF-8 character in JSON string");
951 1047
952 do 1048 do
953 *cur++ = *dec_cur++; 1049 *cur++ = *dec_cur++;
1075 1171
1076 // special case the rather common 1..5-digit-int case 1172 // special case the rather common 1..5-digit-int case
1077 if (*start == '-') 1173 if (*start == '-')
1078 switch (len) 1174 switch (len)
1079 { 1175 {
1080 case 2: return newSViv (-( start [1] - '0' * 1)); 1176 case 2: return newSViv (-(IV)( start [1] - '0' * 1));
1081 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1177 case 3: return newSViv (-(IV)( start [1] * 10 + start [2] - '0' * 11));
1082 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); 1178 case 4: return newSViv (-(IV)( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111));
1083 case 5: return newSViv (-( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); 1179 case 5: return newSViv (-(IV)( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111));
1084 case 6: return newSViv (-(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111)); 1180 case 6: return newSViv (-(IV)(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111));
1085 } 1181 }
1086 else 1182 else
1087 switch (len) 1183 switch (len)
1088 { 1184 {
1089 case 1: return newSViv ( start [0] - '0' * 1); 1185 case 1: return newSViv ( start [0] - '0' * 1);
1090 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1186 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
1091 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 1187 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
1092 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 1188 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
1093 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111); 1189 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111);
1094 } 1190 }
1095 1191
1096 { 1192 {
1097 UV uv; 1193 UV uv;
1098 int numtype = grok_number (start, len, &uv); 1194 int numtype = grok_number (start, len, &uv);
1107 } 1203 }
1108 1204
1109 len -= *start == '-' ? 1 : 0; 1205 len -= *start == '-' ? 1 : 0;
1110 1206
1111 // does not fit into IV or UV, try NV 1207 // does not fit into IV or UV, try NV
1112 if ((sizeof (NV) == sizeof (double) && DBL_DIG >= len) 1208 if (len <= NV_DIG)
1113 #if defined (LDBL_DIG)
1114 || (sizeof (NV) == sizeof (long double) && LDBL_DIG >= len)
1115 #endif
1116 )
1117 // fits into NV without loss of precision 1209 // fits into NV without loss of precision
1118 return newSVnv (Atof (start)); 1210 return newSVnv (json_atof (start));
1119 1211
1120 // everything else fails, convert it to a string 1212 // everything else fails, convert it to a string
1121 return newSVpvn (start, dec->cur - start); 1213 return newSVpvn (start, dec->cur - start);
1122 } 1214 }
1123 1215
1124 // loss of precision here 1216 // loss of precision here
1125 return newSVnv (Atof (start)); 1217 return newSVnv (json_atof (start));
1126 1218
1127fail: 1219fail:
1128 return 0; 1220 return 0;
1129} 1221}
1130 1222
1408fail: 1500fail:
1409 return 0; 1501 return 0;
1410} 1502}
1411 1503
1412static SV * 1504static SV *
1413decode_json (SV *string, JSON *json, STRLEN *offset_return) 1505decode_json (SV *string, JSON *json, char **offset_return)
1414{ 1506{
1415 dec_t dec; 1507 dec_t dec;
1416 STRLEN offset;
1417 SV *sv; 1508 SV *sv;
1418 1509
1419 /* work around bugs in 5.10 where manipulating magic values 1510 /* work around bugs in 5.10 where manipulating magic values
1420 * will perl ignore the magic in subsequent accesses 1511 * will perl ignore the magic in subsequent accesses
1421 */ 1512 */
1433 * and hope for the best. 1524 * and hope for the best.
1434 * Damnit, SvPV_nolen still trips over yet another assertion. This 1525 * Damnit, SvPV_nolen still trips over yet another assertion. This
1435 * assertion business is seriously broken, try yet another workaround 1526 * assertion business is seriously broken, try yet another workaround
1436 * for the broken -DDEBUGGING. 1527 * for the broken -DDEBUGGING.
1437 */ 1528 */
1529 {
1438#ifdef DEBUGGING 1530#ifdef DEBUGGING
1439 offset = SvOK (string) ? sv_len (string) : 0; 1531 STRLEN offset = SvOK (string) ? sv_len (string) : 0;
1440#else 1532#else
1441 offset = SvCUR (string); 1533 STRLEN offset = SvCUR (string);
1442#endif 1534#endif
1443 1535
1444 if (offset > json->max_size && json->max_size) 1536 if (offset > json->max_size && json->max_size)
1445 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", 1537 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu",
1446 (unsigned long)SvCUR (string), (unsigned long)json->max_size); 1538 (unsigned long)SvCUR (string), (unsigned long)json->max_size);
1539 }
1447 1540
1448 if (json->flags & F_UTF8) 1541 if (json->flags & F_UTF8)
1449 sv_utf8_downgrade (string, 0); 1542 sv_utf8_downgrade (string, 0);
1450 else 1543 else
1451 sv_utf8_upgrade (string); 1544 sv_utf8_upgrade (string);
1463 1556
1464 *dec.end = 0; // this should basically be a nop, too, but make sure it's there 1557 *dec.end = 0; // this should basically be a nop, too, but make sure it's there
1465 1558
1466 decode_ws (&dec); 1559 decode_ws (&dec);
1467 sv = decode_sv (&dec); 1560 sv = decode_sv (&dec);
1561
1562 if (offset_return)
1563 *offset_return = dec.cur;
1468 1564
1469 if (!(offset_return || !sv)) 1565 if (!(offset_return || !sv))
1470 { 1566 {
1471 // check for trailing garbage 1567 // check for trailing garbage
1472 decode_ws (&dec); 1568 decode_ws (&dec);
1475 { 1571 {
1476 dec.err = "garbage after JSON object"; 1572 dec.err = "garbage after JSON object";
1477 SvREFCNT_dec (sv); 1573 SvREFCNT_dec (sv);
1478 sv = 0; 1574 sv = 0;
1479 } 1575 }
1480 }
1481
1482 if (offset_return || !sv)
1483 {
1484 offset = dec.json.flags & F_UTF8
1485 ? dec.cur - SvPVX (string)
1486 : utf8_distance (dec.cur, SvPVX (string));
1487
1488 if (offset_return)
1489 *offset_return = offset;
1490 } 1576 }
1491 1577
1492 if (!sv) 1578 if (!sv)
1493 { 1579 {
1494 SV *uni = sv_newmortal (); 1580 SV *uni = sv_newmortal ();
1500 SAVEVPTR (PL_curcop); 1586 SAVEVPTR (PL_curcop);
1501 PL_curcop = &cop; 1587 PL_curcop = &cop;
1502 pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); 1588 pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ);
1503 LEAVE; 1589 LEAVE;
1504 1590
1505 croak ("%s, at character offset %d [\"%s\"]", 1591 croak ("%s, at character offset %d (before \"%s\")",
1506 dec.err, 1592 dec.err,
1507 (int)offset, 1593 ptr_to_index (string, dec.cur),
1508 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); 1594 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)");
1509 } 1595 }
1510 1596
1511 sv = sv_2mortal (sv); 1597 sv = sv_2mortal (sv);
1512 1598
1521 1607
1522static void 1608static void
1523incr_parse (JSON *self) 1609incr_parse (JSON *self)
1524{ 1610{
1525 const char *p = SvPVX (self->incr_text) + self->incr_pos; 1611 const char *p = SvPVX (self->incr_text) + self->incr_pos;
1612
1613 // the state machine here is a bit convoluted and could be simplified a lot
1614 // but this would make it slower, so...
1526 1615
1527 for (;;) 1616 for (;;)
1528 { 1617 {
1529 //printf ("loop pod %d *p<%c><%s>, mode %d nest %d\n", p - SvPVX (self->incr_text), *p, p, self->incr_mode, self->incr_nest);//D 1618 //printf ("loop pod %d *p<%c><%s>, mode %d nest %d\n", p - SvPVX (self->incr_text), *p, p, self->incr_mode, self->incr_nest);//D
1530 switch (self->incr_mode) 1619 switch (self->incr_mode)
1531 { 1620 {
1532 // only used for intiial whitespace skipping 1621 // only used for initial whitespace skipping
1533 case INCR_M_WS: 1622 case INCR_M_WS:
1534 for (;;) 1623 for (;;)
1535 { 1624 {
1536 if (*p > 0x20) 1625 if (*p > 0x20)
1537 { 1626 {
1627 if (*p == '#')
1628 {
1629 self->incr_mode = INCR_M_C0;
1630 goto incr_m_c;
1631 }
1632 else
1633 {
1538 self->incr_mode = INCR_M_JSON; 1634 self->incr_mode = INCR_M_JSON;
1539 goto incr_m_json; 1635 goto incr_m_json;
1636 }
1540 } 1637 }
1541 else if (!*p) 1638 else if (!*p)
1542 goto interrupt; 1639 goto interrupt;
1543 1640
1544 ++p; 1641 ++p;
1550 goto interrupt; 1647 goto interrupt;
1551 1648
1552 ++p; 1649 ++p;
1553 self->incr_mode = INCR_M_STR; 1650 self->incr_mode = INCR_M_STR;
1554 goto incr_m_str; 1651 goto incr_m_str;
1652
1653 // inside #-style comments
1654 case INCR_M_C0:
1655 case INCR_M_C1:
1656 incr_m_c:
1657 for (;;)
1658 {
1659 if (*p == '\n')
1660 {
1661 self->incr_mode = self->incr_mode == INCR_M_C0 ? INCR_M_WS : INCR_M_JSON;
1662 break;
1663 }
1664 else if (!*p)
1665 goto interrupt;
1666
1667 ++p;
1668 }
1669
1670 break;
1555 1671
1556 // inside a string 1672 // inside a string
1557 case INCR_M_STR: 1673 case INCR_M_STR:
1558 incr_m_str: 1674 incr_m_str:
1559 for (;;) 1675 for (;;)
1618 1734
1619 case ']': 1735 case ']':
1620 case '}': 1736 case '}':
1621 if (--self->incr_nest <= 0) 1737 if (--self->incr_nest <= 0)
1622 goto interrupt; 1738 goto interrupt;
1739 break;
1740
1741 case '#':
1742 self->incr_mode = INCR_M_C1;
1743 goto incr_m_c;
1623 } 1744 }
1624 } 1745 }
1625 } 1746 }
1626 1747
1627 modechange: 1748 modechange:
1628 ; 1749 ;
1629 } 1750 }
1630 1751
1631interrupt: 1752interrupt:
1632 self->incr_pos = p - SvPVX (self->incr_text); 1753 self->incr_pos = p - SvPVX (self->incr_text);
1754 //printf ("interrupt<%.*s>\n", self->incr_pos, SvPVX(self->incr_text));//D
1633 //printf ("return pos %d mode %d nest %d\n", self->incr_pos, self->incr_mode, self->incr_nest);//D 1755 //printf ("return pos %d mode %d nest %d\n", self->incr_pos, self->incr_mode, self->incr_nest);//D
1634} 1756}
1635 1757
1636///////////////////////////////////////////////////////////////////////////// 1758/////////////////////////////////////////////////////////////////////////////
1637// XS interface functions 1759// XS interface functions
1652 json_stash = gv_stashpv ("JSON::XS" , 1); 1774 json_stash = gv_stashpv ("JSON::XS" , 1);
1653 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1); 1775 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1);
1654 1776
1655 json_true = get_bool ("JSON::XS::true"); 1777 json_true = get_bool ("JSON::XS::true");
1656 json_false = get_bool ("JSON::XS::false"); 1778 json_false = get_bool ("JSON::XS::false");
1779
1780 CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */
1657} 1781}
1658 1782
1659PROTOTYPES: DISABLE 1783PROTOTYPES: DISABLE
1660 1784
1661void CLONE (...) 1785void CLONE (...)
1781 XPUSHs (decode_json (jsonstr, self, 0)); 1905 XPUSHs (decode_json (jsonstr, self, 0));
1782 1906
1783void decode_prefix (JSON *self, SV *jsonstr) 1907void decode_prefix (JSON *self, SV *jsonstr)
1784 PPCODE: 1908 PPCODE:
1785{ 1909{
1786 STRLEN offset; 1910 char *offset;
1787 EXTEND (SP, 2); 1911 EXTEND (SP, 2);
1788 PUSHs (decode_json (jsonstr, self, &offset)); 1912 PUSHs (decode_json (jsonstr, self, &offset));
1789 PUSHs (sv_2mortal (newSVuv (offset))); 1913 PUSHs (sv_2mortal (newSVuv (ptr_to_index (jsonstr, offset))));
1790} 1914}
1791 1915
1792void incr_parse (JSON *self, SV *jsonstr = 0) 1916void incr_parse (JSON *self, SV *jsonstr = 0)
1793 PPCODE: 1917 PPCODE:
1794{ 1918{
1796 self->incr_text = newSVpvn ("", 0); 1920 self->incr_text = newSVpvn ("", 0);
1797 1921
1798 // append data, if any 1922 // append data, if any
1799 if (jsonstr) 1923 if (jsonstr)
1800 { 1924 {
1801 if (SvUTF8 (jsonstr) && !SvUTF8 (self->incr_text)) 1925 if (SvUTF8 (jsonstr))
1802 { 1926 {
1927 if (!SvUTF8 (self->incr_text))
1928 {
1803 /* utf-8-ness differs, need to upgrade */ 1929 /* utf-8-ness differs, need to upgrade */
1804 sv_utf8_upgrade (self->incr_text); 1930 sv_utf8_upgrade (self->incr_text);
1805 1931
1806 if (self->incr_pos) 1932 if (self->incr_pos)
1807 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos) 1933 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos)
1808 - (U8 *)SvPVX (self->incr_text); 1934 - (U8 *)SvPVX (self->incr_text);
1935 }
1809 } 1936 }
1937 else if (SvUTF8 (self->incr_text))
1938 sv_utf8_upgrade (jsonstr);
1810 1939
1811 { 1940 {
1812 STRLEN len; 1941 STRLEN len;
1813 const char *str = SvPV (jsonstr, len); 1942 const char *str = SvPV (jsonstr, len);
1814 STRLEN cur = SvCUR (self->incr_text); 1943 STRLEN cur = SvCUR (self->incr_text);
1823 } 1952 }
1824 1953
1825 if (GIMME_V != G_VOID) 1954 if (GIMME_V != G_VOID)
1826 do 1955 do
1827 { 1956 {
1828 STRLEN offset; 1957 char *offset;
1829 1958
1830 if (!INCR_DONE (self)) 1959 if (!INCR_DONE (self))
1831 { 1960 {
1832 incr_parse (self); 1961 incr_parse (self);
1833 1962
1839 break; 1968 break;
1840 } 1969 }
1841 1970
1842 XPUSHs (decode_json (self->incr_text, self, &offset)); 1971 XPUSHs (decode_json (self->incr_text, self, &offset));
1843 1972
1844 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + offset);
1845 self->incr_pos -= offset; 1973 self->incr_pos -= offset - SvPVX (self->incr_text);
1846 self->incr_nest = 0; 1974 self->incr_nest = 0;
1847 self->incr_mode = 0; 1975 self->incr_mode = 0;
1976
1977 sv_chop (self->incr_text, offset);
1848 } 1978 }
1849 while (GIMME_V == G_ARRAY); 1979 while (GIMME_V == G_ARRAY);
1850} 1980}
1851 1981
1852SV *incr_text (JSON *self) 1982SV *incr_text (JSON *self)
1913 json_init (&json); 2043 json_init (&json);
1914 json.flags |= ix; 2044 json.flags |= ix;
1915 XPUSHs (decode_json (jsonstr, &json, 0)); 2045 XPUSHs (decode_json (jsonstr, &json, 0));
1916} 2046}
1917 2047
1918

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines