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.106 by root, Tue Jan 19 01:36:34 2010 UTC vs.
Revision 1.109 by root, Tue Mar 8 10:18:50 2011 UTC

41 41
42#define INIT_SIZE 32 // initial scalar size to be allocated 42#define INIT_SIZE 32 // initial scalar size to be allocated
43#define INDENT_STEP 3 // spaces per indentation level 43#define INDENT_STEP 3 // spaces per indentation level
44 44
45#define SHORT_STRING_LEN 16384 // special-case strings of up to this size 45#define SHORT_STRING_LEN 16384 // special-case strings of up to this size
46
47#define DECODE_WANTS_OCTETS(json) ((json)->flags & F_UTF8)
46 48
47#define SB do { 49#define SB do {
48#define SE } while (0) 50#define SE } while (0)
49 51
50#if __GNUC__ >= 3 52#if __GNUC__ >= 3
1401 dSP; 1403 dSP;
1402 int count; 1404 int count;
1403 1405
1404 ENTER; SAVETMPS; PUSHMARK (SP); 1406 ENTER; SAVETMPS; PUSHMARK (SP);
1405 XPUSHs (HeVAL (he)); 1407 XPUSHs (HeVAL (he));
1408 sv_2mortal (sv);
1406 1409
1407 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; 1410 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN;
1408 1411
1409 if (count == 1) 1412 if (count == 1)
1410 { 1413 {
1411 sv = newSVsv (POPs); 1414 sv = newSVsv (POPs);
1412 FREETMPS; LEAVE; 1415 FREETMPS; LEAVE;
1413 return sv; 1416 return sv;
1414 } 1417 }
1415 1418
1419 SvREFCNT_inc (sv);
1416 FREETMPS; LEAVE; 1420 FREETMPS; LEAVE;
1417 } 1421 }
1418 } 1422 }
1419 1423
1420 if (dec->json.cb_object) 1424 if (dec->json.cb_object)
1516{ 1520{
1517 dec_t dec; 1521 dec_t dec;
1518 SV *sv; 1522 SV *sv;
1519 1523
1520 /* work around bugs in 5.10 where manipulating magic values 1524 /* work around bugs in 5.10 where manipulating magic values
1521 * will perl ignore the magic in subsequent accesses 1525 * will perl ignore the magic in subsequent accesses.
1526 * also make a copy of non-PV values, to get them into a clean
1527 * state (SvPV should do that, but it's buggy, see below).
1522 */ 1528 */
1523 /*SvGETMAGIC (string);*/ 1529 /*SvGETMAGIC (string);*/
1524 if (SvMAGICAL (string)) 1530 if (SvMAGICAL (string) || !SvPOK (string))
1525 string = sv_2mortal (newSVsv (string)); 1531 string = sv_2mortal (newSVsv (string));
1526 1532
1527 SvUPGRADE (string, SVt_PV); 1533 SvUPGRADE (string, SVt_PV);
1528 1534
1529 /* work around a bug in perl 5.10, which causes SvCUR to fail an 1535 /* work around a bug in perl 5.10, which causes SvCUR to fail an
1546 if (offset > json->max_size && json->max_size) 1552 if (offset > json->max_size && json->max_size)
1547 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", 1553 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu",
1548 (unsigned long)SvCUR (string), (unsigned long)json->max_size); 1554 (unsigned long)SvCUR (string), (unsigned long)json->max_size);
1549 } 1555 }
1550 1556
1551 if (json->flags & F_UTF8) 1557 if (DECODE_WANTS_OCTETS (json))
1552 sv_utf8_downgrade (string, 0); 1558 sv_utf8_downgrade (string, 0);
1553 else 1559 else
1554 sv_utf8_upgrade (string); 1560 sv_utf8_upgrade (string);
1555 1561
1556 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP 1562 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP
1927 PPCODE: 1933 PPCODE:
1928{ 1934{
1929 if (!self->incr_text) 1935 if (!self->incr_text)
1930 self->incr_text = newSVpvn ("", 0); 1936 self->incr_text = newSVpvn ("", 0);
1931 1937
1938 /* if utf8-ness doesn't match the decoder, need to upgrade/downgrade */
1939 if (!DECODE_WANTS_OCTETS (self) == !SvUTF8 (self->incr_text))
1940 if (DECODE_WANTS_OCTETS (self))
1941 {
1942 if (self->incr_pos)
1943 self->incr_pos = utf8_length ((U8 *)SvPVX (self->incr_text),
1944 (U8 *)SvPVX (self->incr_text) + self->incr_pos);
1945
1946 sv_utf8_downgrade (self->incr_text, 0);
1947 }
1948 else
1949 {
1950 sv_utf8_upgrade (self->incr_text);
1951
1952 if (self->incr_pos)
1953 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos)
1954 - (U8 *)SvPVX (self->incr_text);
1955 }
1956
1932 // append data, if any 1957 // append data, if any
1933 if (jsonstr) 1958 if (jsonstr)
1934 { 1959 {
1960 /* make sure both strings have same encoding */
1961 if (SvUTF8 (jsonstr) != SvUTF8 (self->incr_text))
1935 if (SvUTF8 (jsonstr)) 1962 if (SvUTF8 (jsonstr))
1963 sv_utf8_downgrade (jsonstr, 0);
1936 { 1964 else
1937 if (!SvUTF8 (self->incr_text))
1938 {
1939 /* utf-8-ness differs, need to upgrade */
1940 sv_utf8_upgrade (self->incr_text);
1941
1942 if (self->incr_pos)
1943 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos)
1944 - (U8 *)SvPVX (self->incr_text);
1945 }
1946 }
1947 else if (SvUTF8 (self->incr_text))
1948 sv_utf8_upgrade (jsonstr); 1965 sv_utf8_upgrade (jsonstr);
1949 1966
1967 /* and then just blindly append */
1950 { 1968 {
1951 STRLEN len; 1969 STRLEN len;
1952 const char *str = SvPV (jsonstr, len); 1970 const char *str = SvPV (jsonstr, len);
1953 STRLEN cur = SvCUR (self->incr_text); 1971 STRLEN cur = SvCUR (self->incr_text);
1954 1972

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines