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.79 by root, Tue Mar 25 23:00:31 2008 UTC vs.
Revision 1.83 by root, Wed Mar 26 22:54:38 2008 UTC

101 int incr_mode; 101 int incr_mode;
102} JSON; 102} JSON;
103 103
104///////////////////////////////////////////////////////////////////////////// 104/////////////////////////////////////////////////////////////////////////////
105// utility functions 105// utility functions
106
107INLINE SV *
108get_bool (const char *name)
109{
110 SV *sv = get_sv (name, 1);
111
112 SvREADONLY_on (sv);
113 SvREADONLY_on (SvRV (sv));
114
115 return sv;
116}
106 117
107INLINE void 118INLINE void
108shrink (SV *sv) 119shrink (SV *sv)
109{ 120{
110 sv_utf8_downgrade (sv, 1); 121 sv_utf8_downgrade (sv, 1);
1343 case 't': 1354 case 't':
1344 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) 1355 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4))
1345 { 1356 {
1346 dec->cur += 4; 1357 dec->cur += 4;
1347#if JSON_SLOW 1358#if JSON_SLOW
1348 json_true = get_sv ("JSON::XS::true", 1); SvREADONLY_on (json_true); 1359 json_true = get_bool ("JSON::XS::true");
1349#endif 1360#endif
1350 return SvREFCNT_inc (json_true); 1361 return newSVsv (json_true);
1351 } 1362 }
1352 else 1363 else
1353 ERR ("'true' expected"); 1364 ERR ("'true' expected");
1354 1365
1355 break; 1366 break;
1357 case 'f': 1368 case 'f':
1358 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) 1369 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5))
1359 { 1370 {
1360 dec->cur += 5; 1371 dec->cur += 5;
1361#if JSON_SLOW 1372#if JSON_SLOW
1362 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); 1373 json_false = get_bool ("JSON::XS::false");
1363#endif 1374#endif
1364 return SvREFCNT_inc (json_false); 1375 return newSVsv (json_false);
1365 } 1376 }
1366 else 1377 else
1367 ERR ("'false' expected"); 1378 ERR ("'false' expected");
1368 1379
1369 break; 1380 break;
1607 : -1; 1618 : -1;
1608 1619
1609 json_stash = gv_stashpv ("JSON::XS" , 1); 1620 json_stash = gv_stashpv ("JSON::XS" , 1);
1610 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1); 1621 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1);
1611 1622
1612 json_true = get_sv ("JSON::XS::true" , 1); SvREADONLY_on (json_true ); 1623 json_true = get_bool ("JSON::XS::true");
1613 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); 1624 json_false = get_bool ("JSON::XS::false");
1614} 1625}
1615 1626
1616PROTOTYPES: DISABLE 1627PROTOTYPES: DISABLE
1617 1628
1618void CLONE (...) 1629void CLONE (...)
1798 if (GIMME_V != G_VOID) 1809 if (GIMME_V != G_VOID)
1799 do 1810 do
1800 { 1811 {
1801 STRLEN offset; 1812 STRLEN offset;
1802 1813
1803 incr_parse (self);
1804
1805 if (!INCR_DONE (self)) 1814 if (!INCR_DONE (self))
1815 {
1816 incr_parse (self);
1817 if (!INCR_DONE (self))
1806 break; 1818 break;
1819 }
1807 1820
1808 XPUSHs (decode_json (self->incr_text, self, &offset)); 1821 XPUSHs (decode_json (self->incr_text, self, &offset));
1809 1822
1810 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + offset); 1823 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + offset);
1811 self->incr_pos -= offset; 1824 self->incr_pos -= offset;
1818SV *incr_text (JSON *self) 1831SV *incr_text (JSON *self)
1819 ATTRS: lvalue 1832 ATTRS: lvalue
1820 CODE: 1833 CODE:
1821{ 1834{
1822 if (self->incr_pos) 1835 if (self->incr_pos)
1823 croak ("incr_text can only be called after a successful incr_parse call in scalar context"); 1836 croak ("incr_text can not be called when the incremental parser already started parsing");
1824 1837
1825 RETVAL = self->incr_text ? SvREFCNT_inc (self->incr_text) : &PL_sv_undef; 1838 RETVAL = self->incr_text ? SvREFCNT_inc (self->incr_text) : &PL_sv_undef;
1826} 1839}
1827 OUTPUT: 1840 OUTPUT:
1828 RETVAL 1841 RETVAL
1829 1842
1830void incr_skip (JSON *self) 1843void incr_skip (JSON *self)
1831 CODE: 1844 CODE:
1832{ 1845{
1833 if (!self->incr_pos || !INCR_DONE (self)) 1846 if (self->incr_pos)
1834 croak ("incr_text can only be called after an unsuccessful incr_parse call in scalar context");//D 1847 {
1835
1836 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + self->incr_pos); 1848 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + self->incr_pos);
1837 self->incr_pos = 0; 1849 self->incr_pos = 0;
1838 self->incr_nest = 0; 1850 self->incr_nest = 0;
1839 self->incr_mode = 0; 1851 self->incr_mode = 0;
1852 }
1840} 1853}
1841 1854
1842void DESTROY (JSON *self) 1855void DESTROY (JSON *self)
1843 CODE: 1856 CODE:
1844 SvREFCNT_dec (self->cb_sk_object); 1857 SvREFCNT_dec (self->cb_sk_object);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines