ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.37 by root, Sat Nov 30 18:13:53 2013 UTC vs.
Revision 1.38 by root, Sun Dec 1 14:30:52 2013 UTC

99#define F_SHRINK 0x00000001UL 99#define F_SHRINK 0x00000001UL
100#define F_ALLOW_UNKNOWN 0x00000002UL 100#define F_ALLOW_UNKNOWN 0x00000002UL
101#define F_ALLOW_SHARING 0x00000004UL 101#define F_ALLOW_SHARING 0x00000004UL
102#define F_ALLOW_CYCLES 0x00000008UL 102#define F_ALLOW_CYCLES 0x00000008UL
103#define F_PACK_STRINGS 0x00000010UL 103#define F_PACK_STRINGS 0x00000010UL
104#define F_VALIDATE_UTF8 0x00000020UL
104 105
105#define INIT_SIZE 32 // initial scalar size to be allocated 106#define INIT_SIZE 32 // initial scalar size to be allocated
106 107
107#define SB do { 108#define SB do {
108#define SE } while (0) 109#define SE } while (0)
736 I32 len = decode_uint (dec); 737 I32 len = decode_uint (dec);
737 char *key = (char *)dec->cur; 738 char *key = (char *)dec->cur;
738 739
739 dec->cur += len; 740 dec->cur += len;
740 741
741 if (ecb_expect_false (dec->stringref))
742 av_push (dec->stringref, newSVpvn (key, len));
743
744 hv_store (hv, key, len, decode_sv (dec), 0); 742 hv_store (hv, key, len, decode_sv (dec), 0);
745 743
746 return; 744 return;
747 } 745 }
748 else if (ecb_expect_true ((*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) 746 else if (ecb_expect_true ((*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8))
750 I32 len = decode_uint (dec); 748 I32 len = decode_uint (dec);
751 char *key = (char *)dec->cur; 749 char *key = (char *)dec->cur;
752 750
753 dec->cur += len; 751 dec->cur += len;
754 752
755 if (ecb_expect_false (dec->stringref)) 753 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
756 av_push (dec->stringref, newSVpvn_utf8 (key, len, 1)); 754 if (!is_utf8_string (key, len))
755 ERR ("corrupted CBOR data (invalid UTF-8 in map key)");
757 756
758 hv_store (hv, key, -len, decode_sv (dec), 0); 757 hv_store (hv, key, -len, decode_sv (dec), 0);
759 758
760 return; 759 return;
761 } 760 }
763 SV *k = decode_sv (dec); 762 SV *k = decode_sv (dec);
764 SV *v = decode_sv (dec); 763 SV *v = decode_sv (dec);
765 764
766 hv_store_ent (hv, k, v, 0); 765 hv_store_ent (hv, k, v, 0);
767 SvREFCNT_dec (k); 766 SvREFCNT_dec (k);
767
768fail:
769 ;
768} 770}
769 771
770static SV * 772static SV *
771decode_hv (dec_t *dec) 773decode_hv (dec_t *dec)
772{ 774{
854 && SvCUR (sv) >= minimum_string_length (AvFILLp (dec->stringref) + 1)) 856 && SvCUR (sv) >= minimum_string_length (AvFILLp (dec->stringref) + 1))
855 av_push (dec->stringref, SvREFCNT_inc_NN (sv)); 857 av_push (dec->stringref, SvREFCNT_inc_NN (sv));
856 } 858 }
857 859
858 if (utf8) 860 if (utf8)
861 {
862 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
863 if (!is_utf8_string (SvPVX (sv), SvCUR (sv)))
864 ERR ("corrupted CBOR data (invalid UTF-8 in text string)");
865
859 SvUTF8_on (sv); 866 SvUTF8_on (sv);
867 }
860 868
861 return sv; 869 return sv;
862 870
863fail: 871fail:
864 SvREFCNT_dec (sv); 872 SvREFCNT_dec (sv);
1223 shrink = F_SHRINK 1231 shrink = F_SHRINK
1224 allow_unknown = F_ALLOW_UNKNOWN 1232 allow_unknown = F_ALLOW_UNKNOWN
1225 allow_sharing = F_ALLOW_SHARING 1233 allow_sharing = F_ALLOW_SHARING
1226 allow_cycles = F_ALLOW_CYCLES 1234 allow_cycles = F_ALLOW_CYCLES
1227 pack_strings = F_PACK_STRINGS 1235 pack_strings = F_PACK_STRINGS
1236 validate_utf8 = F_VALIDATE_UTF8
1228 PPCODE: 1237 PPCODE:
1229{ 1238{
1230 if (enable) 1239 if (enable)
1231 self->flags |= ix; 1240 self->flags |= ix;
1232 else 1241 else
1240 get_shrink = F_SHRINK 1249 get_shrink = F_SHRINK
1241 get_allow_unknown = F_ALLOW_UNKNOWN 1250 get_allow_unknown = F_ALLOW_UNKNOWN
1242 get_allow_sharing = F_ALLOW_SHARING 1251 get_allow_sharing = F_ALLOW_SHARING
1243 get_allow_cycles = F_ALLOW_CYCLES 1252 get_allow_cycles = F_ALLOW_CYCLES
1244 get_pack_strings = F_PACK_STRINGS 1253 get_pack_strings = F_PACK_STRINGS
1254 get_validate_utf8 = F_VALIDATE_UTF8
1245 PPCODE: 1255 PPCODE:
1246 XPUSHs (boolSV (self->flags & ix)); 1256 XPUSHs (boolSV (self->flags & ix));
1247 1257
1248void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) 1258void max_depth (CBOR *self, U32 max_depth = 0x80000000UL)
1249 PPCODE: 1259 PPCODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines