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.96 by root, Sat May 30 06:26:05 2009 UTC vs.
Revision 1.102 by root, Sat Oct 10 01:48:50 2009 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
471 472
472 // for canonical output we have to sort by keys first 473 // for canonical output we have to sort by keys first
473 // actually, this is mostly due to the stupid so-called 474 // actually, this is mostly due to the stupid so-called
474 // security workaround added somewhere in 5.8.x 475 // security workaround added somewhere in 5.8.x
475 // that randomises hash orderings 476 // that randomises hash orderings
476 if (enc->json.flags & F_CANONICAL) 477 if (enc->json.flags & F_CANONICAL && !SvRMAGICAL (hv))
477 { 478 {
478 int count = hv_iterinit (hv); 479 int count = hv_iterinit (hv);
479 480
480 if (SvMAGICAL (hv)) 481 if (SvMAGICAL (hv))
481 { 482 {
759 : enc.json.flags & F_LATIN1 ? 0x000100UL 760 : enc.json.flags & F_LATIN1 ? 0x000100UL
760 : 0x110000UL; 761 : 0x110000UL;
761 762
762 SvPOK_only (enc.sv); 763 SvPOK_only (enc.sv);
763 encode_sv (&enc, scalar); 764 encode_sv (&enc, scalar);
765 encode_nl (&enc);
764 766
765 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); 767 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv));
766 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings 768 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings
767 769
768 if (!(enc.json.flags & (F_ASCII | F_LATIN1 | F_UTF8))) 770 if (!(enc.json.flags & (F_ASCII | F_LATIN1 | F_UTF8)))
948 else if (expect_true (ch >= 0x20 && ch < 0x80)) 950 else if (expect_true (ch >= 0x20 && ch < 0x80))
949 *cur++ = ch; 951 *cur++ = ch;
950 else if (ch >= 0x80) 952 else if (ch >= 0x80)
951 { 953 {
952 STRLEN clen; 954 STRLEN clen;
953 UV uch;
954 955
955 --dec_cur; 956 --dec_cur;
956 957
957 uch = decode_utf8 (dec_cur, dec->end - dec_cur, &clen); 958 decode_utf8 (dec_cur, dec->end - dec_cur, &clen);
958 if (clen == (STRLEN)-1) 959 if (clen == (STRLEN)-1)
959 ERR ("malformed UTF-8 character in JSON string"); 960 ERR ("malformed UTF-8 character in JSON string");
960 961
961 do 962 do
962 *cur++ = *dec_cur++; 963 *cur++ = *dec_cur++;
1084 1085
1085 // special case the rather common 1..5-digit-int case 1086 // special case the rather common 1..5-digit-int case
1086 if (*start == '-') 1087 if (*start == '-')
1087 switch (len) 1088 switch (len)
1088 { 1089 {
1089 case 2: return newSViv (-( start [1] - '0' * 1)); 1090 case 2: return newSViv (-(IV)( start [1] - '0' * 1));
1090 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1091 case 3: return newSViv (-(IV)( start [1] * 10 + start [2] - '0' * 11));
1091 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); 1092 case 4: return newSViv (-(IV)( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111));
1092 case 5: return newSViv (-( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); 1093 case 5: return newSViv (-(IV)( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111));
1093 case 6: return newSViv (-(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111)); 1094 case 6: return newSViv (-(IV)(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111));
1094 } 1095 }
1095 else 1096 else
1096 switch (len) 1097 switch (len)
1097 { 1098 {
1098 case 1: return newSViv ( start [0] - '0' * 1); 1099 case 1: return newSViv ( start [0] - '0' * 1);
1099 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1100 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
1100 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 1101 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
1101 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 1102 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
1102 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111); 1103 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111);
1103 } 1104 }
1104 1105
1105 { 1106 {
1106 UV uv; 1107 UV uv;
1107 int numtype = grok_number (start, len, &uv); 1108 int numtype = grok_number (start, len, &uv);
1655 json_stash = gv_stashpv ("JSON::XS" , 1); 1656 json_stash = gv_stashpv ("JSON::XS" , 1);
1656 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1); 1657 json_boolean_stash = gv_stashpv ("JSON::XS::Boolean", 1);
1657 1658
1658 json_true = get_bool ("JSON::XS::true"); 1659 json_true = get_bool ("JSON::XS::true");
1659 json_false = get_bool ("JSON::XS::false"); 1660 json_false = get_bool ("JSON::XS::false");
1661
1662 CvNODEBUG_on (get_cv ("JSON::XS::incr_text", 0)); /* the debugger completely breaks lvalue subs */
1660} 1663}
1661 1664
1662PROTOTYPES: DISABLE 1665PROTOTYPES: DISABLE
1663 1666
1664void CLONE (...) 1667void CLONE (...)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines