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.77 by root, Tue Mar 25 06:37:38 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);
438 449
439static void 450static void
440encode_hv (enc_t *enc, HV *hv) 451encode_hv (enc_t *enc, HV *hv)
441{ 452{
442 HE *he; 453 HE *he;
443 int count;
444 454
445 if (enc->indent >= enc->maxdepth) 455 if (enc->indent >= enc->maxdepth)
446 croak ("data structure too deep (hit recursion limit)"); 456 croak ("data structure too deep (hit recursion limit)");
447 457
448 encode_ch (enc, '{'); 458 encode_ch (enc, '{');
1344 case 't': 1354 case 't':
1345 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) 1355 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4))
1346 { 1356 {
1347 dec->cur += 4; 1357 dec->cur += 4;
1348#if JSON_SLOW 1358#if JSON_SLOW
1349 json_true = get_sv ("JSON::XS::true", 1); SvREADONLY_on (json_true); 1359 json_true = get_bool ("JSON::XS::true");
1350#endif 1360#endif
1351 return SvREFCNT_inc (json_true); 1361 return newSVsv (json_true);
1352 } 1362 }
1353 else 1363 else
1354 ERR ("'true' expected"); 1364 ERR ("'true' expected");
1355 1365
1356 break; 1366 break;
1358 case 'f': 1368 case 'f':
1359 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) 1369 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5))
1360 { 1370 {
1361 dec->cur += 5; 1371 dec->cur += 5;
1362#if JSON_SLOW 1372#if JSON_SLOW
1363 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); 1373 json_false = get_bool ("JSON::XS::false");
1364#endif 1374#endif
1365 return SvREFCNT_inc (json_false); 1375 return newSVsv (json_false);
1366 } 1376 }
1367 else 1377 else
1368 ERR ("'false' expected"); 1378 ERR ("'false' expected");
1369 1379
1370 break; 1380 break;
1608 : -1; 1618 : -1;
1609 1619
1610 json_stash = gv_stashpv ("JSON::XS" , 1); 1620 json_stash = gv_stashpv ("JSON::XS" , 1);
1611 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1); 1621 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1);
1612 1622
1613 json_true = get_sv ("JSON::XS::true" , 1); SvREADONLY_on (json_true ); 1623 json_true = get_bool ("JSON::XS::true");
1614 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); 1624 json_false = get_bool ("JSON::XS::false");
1615} 1625}
1616 1626
1617PROTOTYPES: DISABLE 1627PROTOTYPES: DISABLE
1618 1628
1619void CLONE (...) 1629void CLONE (...)
1799 if (GIMME_V != G_VOID) 1809 if (GIMME_V != G_VOID)
1800 do 1810 do
1801 { 1811 {
1802 STRLEN offset; 1812 STRLEN offset;
1803 1813
1804 incr_parse (self);
1805
1806 if (!INCR_DONE (self)) 1814 if (!INCR_DONE (self))
1815 {
1816 incr_parse (self);
1817 if (!INCR_DONE (self))
1807 break; 1818 break;
1819 }
1808 1820
1809 XPUSHs (decode_json (self->incr_text, self, &offset)); 1821 XPUSHs (decode_json (self->incr_text, self, &offset));
1810 1822
1811 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + offset); 1823 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + offset);
1812 self->incr_pos -= offset; 1824 self->incr_pos -= offset;
1819SV *incr_text (JSON *self) 1831SV *incr_text (JSON *self)
1820 ATTRS: lvalue 1832 ATTRS: lvalue
1821 CODE: 1833 CODE:
1822{ 1834{
1823 if (self->incr_pos) 1835 if (self->incr_pos)
1824 croak ("incr_text can only be called after a successful incr_parse call in scalar context %d", self->incr_pos);//D 1836 croak ("incr_text can not be called when the incremental parser already started parsing");
1825 1837
1826 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;
1827} 1839}
1828 OUTPUT: 1840 OUTPUT:
1829 RETVAL 1841 RETVAL
1842
1843void incr_skip (JSON *self)
1844 CODE:
1845{
1846 if (self->incr_pos)
1847 {
1848 sv_chop (self->incr_text, SvPV_nolen (self->incr_text) + self->incr_pos);
1849 self->incr_pos = 0;
1850 self->incr_nest = 0;
1851 self->incr_mode = 0;
1852 }
1853}
1830 1854
1831void DESTROY (JSON *self) 1855void DESTROY (JSON *self)
1832 CODE: 1856 CODE:
1833 SvREFCNT_dec (self->cb_sk_object); 1857 SvREFCNT_dec (self->cb_sk_object);
1834 SvREFCNT_dec (self->cb_object); 1858 SvREFCNT_dec (self->cb_object);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines