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.108 by root, Tue Aug 17 23:27:36 2010 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)
1546 if (offset > json->max_size && json->max_size) 1550 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", 1551 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); 1552 (unsigned long)SvCUR (string), (unsigned long)json->max_size);
1549 } 1553 }
1550 1554
1551 if (json->flags & F_UTF8) 1555 if (DECODE_WANTS_OCTETS (json))
1552 sv_utf8_downgrade (string, 0); 1556 sv_utf8_downgrade (string, 0);
1553 else 1557 else
1554 sv_utf8_upgrade (string); 1558 sv_utf8_upgrade (string);
1555 1559
1556 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP 1560 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP
1927 PPCODE: 1931 PPCODE:
1928{ 1932{
1929 if (!self->incr_text) 1933 if (!self->incr_text)
1930 self->incr_text = newSVpvn ("", 0); 1934 self->incr_text = newSVpvn ("", 0);
1931 1935
1936 /* if utf8-ness doesn't match the decoder, need to upgrade/downgrade */
1937 if (!DECODE_WANTS_OCTETS (self) == !SvUTF8 (self->incr_text))
1938 if (DECODE_WANTS_OCTETS (self))
1939 {
1940 if (self->incr_pos)
1941 self->incr_pos = utf8_length ((U8 *)SvPVX (self->incr_text),
1942 (U8 *)SvPVX (self->incr_text) + self->incr_pos);
1943
1944 sv_utf8_downgrade (self->incr_text, 0);
1945 }
1946 else
1947 {
1948 sv_utf8_upgrade (self->incr_text);
1949
1950 if (self->incr_pos)
1951 self->incr_pos = utf8_hop ((U8 *)SvPVX (self->incr_text), self->incr_pos)
1952 - (U8 *)SvPVX (self->incr_text);
1953 }
1954
1932 // append data, if any 1955 // append data, if any
1933 if (jsonstr) 1956 if (jsonstr)
1934 { 1957 {
1958 /* make sure both strings have same encoding */
1959 if (SvUTF8 (jsonstr) != SvUTF8 (self->incr_text))
1935 if (SvUTF8 (jsonstr)) 1960 if (SvUTF8 (jsonstr))
1961 sv_utf8_downgrade (jsonstr, 0);
1936 { 1962 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); 1963 sv_utf8_upgrade (jsonstr);
1949 1964
1965 /* and then just blindly append */
1950 { 1966 {
1951 STRLEN len; 1967 STRLEN len;
1952 const char *str = SvPV (jsonstr, len); 1968 const char *str = SvPV (jsonstr, len);
1953 STRLEN cur = SvCUR (self->incr_text); 1969 STRLEN cur = SvCUR (self->incr_text);
1954 1970

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines