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.62 by root, Sun Aug 26 22:27:32 2007 UTC vs.
Revision 1.63 by root, Mon Aug 27 01:49:01 2007 UTC

27#define F_SPACE_AFTER 0x00000040UL 27#define F_SPACE_AFTER 0x00000040UL
28#define F_ALLOW_NONREF 0x00000100UL 28#define F_ALLOW_NONREF 0x00000100UL
29#define F_SHRINK 0x00000200UL 29#define F_SHRINK 0x00000200UL
30#define F_ALLOW_BLESSED 0x00000400UL 30#define F_ALLOW_BLESSED 0x00000400UL
31#define F_CONV_BLESSED 0x00000800UL 31#define F_CONV_BLESSED 0x00000800UL
32#define F_RELAXED 0x00001000UL
33
32#define F_MAXDEPTH 0xf8000000UL 34#define F_MAXDEPTH 0xf8000000UL
33#define S_MAXDEPTH 27 35#define S_MAXDEPTH 27
34#define F_MAXSIZE 0x01f00000UL 36#define F_MAXSIZE 0x01f00000UL
35#define S_MAXSIZE 20 37#define S_MAXSIZE 20
36#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing 38#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing
708 710
709 if (ch > 0x20 711 if (ch > 0x20
710 || (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)) 712 || (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09))
711 break; 713 break;
712 714
715 if (ch == '#' && dec->json.flags & F_RELAXED)
716 ++dec->cur;
717
713 ++dec->cur; 718 ++dec->cur;
714 } 719 }
715} 720}
716 721
717#define ERR(reason) SB dec->err = reason; goto fail; SE 722#define ERR(reason) SB dec->err = reason; goto fail; SE
1053 1058
1054 if (*dec->cur != ',') 1059 if (*dec->cur != ',')
1055 ERR (", or ] expected while parsing array"); 1060 ERR (", or ] expected while parsing array");
1056 1061
1057 ++dec->cur; 1062 ++dec->cur;
1063
1064 decode_ws (dec);
1065
1066 if (*dec->cur == ']' && dec->json.flags & F_RELAXED)
1067 {
1068 ++dec->cur;
1069 break;
1070 }
1058 } 1071 }
1059 1072
1060 DEC_DEC_DEPTH; 1073 DEC_DEC_DEPTH;
1061 return newRV_noinc ((SV *)av); 1074 return newRV_noinc ((SV *)av);
1062 1075
1078 if (*dec->cur == '}') 1091 if (*dec->cur == '}')
1079 ++dec->cur; 1092 ++dec->cur;
1080 else 1093 else
1081 for (;;) 1094 for (;;)
1082 { 1095 {
1083 decode_ws (dec); EXPECT_CH ('"'); 1096 EXPECT_CH ('"');
1084 1097
1085 // heuristic: assume that 1098 // heuristic: assume that
1086 // a) decode_str + hv_store_ent are abysmally slow. 1099 // a) decode_str + hv_store_ent are abysmally slow.
1087 // b) most hash keys are short, simple ascii text. 1100 // b) most hash keys are short, simple ascii text.
1088 // => try to "fast-match" such strings to avoid 1101 // => try to "fast-match" such strings to avoid
1102 if (!key) 1115 if (!key)
1103 goto fail; 1116 goto fail;
1104 1117
1105 decode_ws (dec); EXPECT_CH (':'); 1118 decode_ws (dec); EXPECT_CH (':');
1106 1119
1120 decode_ws (dec);
1107 value = decode_sv (dec); 1121 value = decode_sv (dec);
1108 if (!value) 1122 if (!value)
1109 { 1123 {
1110 SvREFCNT_dec (key); 1124 SvREFCNT_dec (key);
1111 goto fail; 1125 goto fail;
1123 int len = p - key; 1137 int len = p - key;
1124 dec->cur = p + 1; 1138 dec->cur = p + 1;
1125 1139
1126 decode_ws (dec); EXPECT_CH (':'); 1140 decode_ws (dec); EXPECT_CH (':');
1127 1141
1142 decode_ws (dec);
1128 value = decode_sv (dec); 1143 value = decode_sv (dec);
1129 if (!value) 1144 if (!value)
1130 goto fail; 1145 goto fail;
1131 1146
1132 hv_store (hv, key, len, value, 0); 1147 hv_store (hv, key, len, value, 0);
1148 1163
1149 if (*dec->cur != ',') 1164 if (*dec->cur != ',')
1150 ERR (", or } expected while parsing object/hash"); 1165 ERR (", or } expected while parsing object/hash");
1151 1166
1152 ++dec->cur; 1167 ++dec->cur;
1168
1169 decode_ws (dec);
1170
1171 if (*dec->cur == '}' && dec->json.flags & F_RELAXED)
1172 {
1173 ++dec->cur;
1174 break;
1175 }
1153 } 1176 }
1154 1177
1155 DEC_DEC_DEPTH; 1178 DEC_DEC_DEPTH;
1156 sv = newRV_noinc ((SV *)hv); 1179 sv = newRV_noinc ((SV *)hv);
1157 1180
1222} 1245}
1223 1246
1224static SV * 1247static SV *
1225decode_sv (dec_t *dec) 1248decode_sv (dec_t *dec)
1226{ 1249{
1227 decode_ws (dec);
1228
1229 // the beauty of JSON: you need exactly one character lookahead 1250 // the beauty of JSON: you need exactly one character lookahead
1230 // to parse anything. 1251 // to parse anything.
1231 switch (*dec->cur) 1252 switch (*dec->cur)
1232 { 1253 {
1233 case '"': ++dec->cur; return decode_str (dec); 1254 case '"': ++dec->cur; return decode_str (dec);
1317 1338
1318 if (dec.json.cb_object || dec.json.cb_sk_object) 1339 if (dec.json.cb_object || dec.json.cb_sk_object)
1319 dec.json.flags |= F_HOOK; 1340 dec.json.flags |= F_HOOK;
1320 1341
1321 *dec.end = 0; // this should basically be a nop, too, but make sure it's there 1342 *dec.end = 0; // this should basically be a nop, too, but make sure it's there
1343
1344 decode_ws (&dec);
1322 sv = decode_sv (&dec); 1345 sv = decode_sv (&dec);
1323 1346
1324 if (!(offset_return || !sv)) 1347 if (!(offset_return || !sv))
1325 { 1348 {
1326 // check for trailing garbage 1349 // check for trailing garbage
1423 pretty = F_PRETTY 1446 pretty = F_PRETTY
1424 allow_nonref = F_ALLOW_NONREF 1447 allow_nonref = F_ALLOW_NONREF
1425 shrink = F_SHRINK 1448 shrink = F_SHRINK
1426 allow_blessed = F_ALLOW_BLESSED 1449 allow_blessed = F_ALLOW_BLESSED
1427 convert_blessed = F_CONV_BLESSED 1450 convert_blessed = F_CONV_BLESSED
1451 relaxed = F_RELAXED
1428 PPCODE: 1452 PPCODE:
1429{ 1453{
1430 if (enable) 1454 if (enable)
1431 self->flags |= ix; 1455 self->flags |= ix;
1432 else 1456 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines