… | |
… | |
97 | }; |
97 | }; |
98 | |
98 | |
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_PACK_STRINGS 0x00000008UL |
103 | #define F_PACK_STRINGS 0x00000010UL |
103 | |
104 | |
104 | #define INIT_SIZE 32 // initial scalar size to be allocated |
105 | #define INIT_SIZE 32 // initial scalar size to be allocated |
105 | |
106 | |
106 | #define SB do { |
107 | #define SB do { |
107 | #define SE } while (0) |
108 | #define SE } while (0) |
… | |
… | |
912 | case CBOR_TAG_VALUE_SHAREABLE: |
913 | case CBOR_TAG_VALUE_SHAREABLE: |
913 | { |
914 | { |
914 | if (ecb_expect_false (!dec->shareable)) |
915 | if (ecb_expect_false (!dec->shareable)) |
915 | dec->shareable = (AV *)sv_2mortal ((SV *)newAV ()); |
916 | dec->shareable = (AV *)sv_2mortal ((SV *)newAV ()); |
916 | |
917 | |
|
|
918 | if (dec->cbor.flags & F_ALLOW_CYCLES) |
|
|
919 | { |
917 | sv = newSV (0); |
920 | sv = newSV (0); |
918 | av_push (dec->shareable, SvREFCNT_inc_NN (sv)); |
921 | av_push (dec->shareable, SvREFCNT_inc_NN (sv)); |
919 | |
922 | |
920 | SV *osv = decode_sv (dec); |
923 | SV *osv = decode_sv (dec); |
921 | sv_setsv (sv, osv); |
924 | sv_setsv (sv, osv); |
922 | SvREFCNT_dec_NN (osv); |
925 | SvREFCNT_dec_NN (osv); |
|
|
926 | } |
|
|
927 | else |
|
|
928 | { |
|
|
929 | av_push (dec->shareable, &PL_sv_undef); |
|
|
930 | int idx = AvFILLp (dec->shareable); |
|
|
931 | sv = decode_sv (dec); |
|
|
932 | av_store (dec->shareable, idx, SvREFCNT_inc_NN (sv)); |
|
|
933 | } |
923 | } |
934 | } |
924 | break; |
935 | break; |
925 | |
936 | |
926 | case CBOR_TAG_VALUE_SHAREDREF: |
937 | case CBOR_TAG_VALUE_SHAREDREF: |
927 | { |
938 | { |
… | |
… | |
932 | |
943 | |
933 | if (!dec->shareable || (int)idx > AvFILLp (dec->shareable)) |
944 | if (!dec->shareable || (int)idx > AvFILLp (dec->shareable)) |
934 | ERR ("corrupted CBOR data (sharedref index out of bounds)"); |
945 | ERR ("corrupted CBOR data (sharedref index out of bounds)"); |
935 | |
946 | |
936 | sv = SvREFCNT_inc_NN (AvARRAY (dec->shareable)[idx]); |
947 | sv = SvREFCNT_inc_NN (AvARRAY (dec->shareable)[idx]); |
|
|
948 | |
|
|
949 | if (sv == &PL_sv_undef) |
|
|
950 | ERR ("cyclic CBOR data structure found, but allow_cycles is not enabled"); |
937 | } |
951 | } |
938 | break; |
952 | break; |
939 | |
953 | |
940 | case CBOR_TAG_PERL_OBJECT: |
954 | case CBOR_TAG_PERL_OBJECT: |
941 | { |
955 | { |
… | |
… | |
1207 | void shrink (CBOR *self, int enable = 1) |
1221 | void shrink (CBOR *self, int enable = 1) |
1208 | ALIAS: |
1222 | ALIAS: |
1209 | shrink = F_SHRINK |
1223 | shrink = F_SHRINK |
1210 | allow_unknown = F_ALLOW_UNKNOWN |
1224 | allow_unknown = F_ALLOW_UNKNOWN |
1211 | allow_sharing = F_ALLOW_SHARING |
1225 | allow_sharing = F_ALLOW_SHARING |
|
|
1226 | allow_cycles = F_ALLOW_CYCLES |
1212 | pack_strings = F_PACK_STRINGS |
1227 | pack_strings = F_PACK_STRINGS |
1213 | PPCODE: |
1228 | PPCODE: |
1214 | { |
1229 | { |
1215 | if (enable) |
1230 | if (enable) |
1216 | self->flags |= ix; |
1231 | self->flags |= ix; |
… | |
… | |
1223 | void get_shrink (CBOR *self) |
1238 | void get_shrink (CBOR *self) |
1224 | ALIAS: |
1239 | ALIAS: |
1225 | get_shrink = F_SHRINK |
1240 | get_shrink = F_SHRINK |
1226 | get_allow_unknown = F_ALLOW_UNKNOWN |
1241 | get_allow_unknown = F_ALLOW_UNKNOWN |
1227 | get_allow_sharing = F_ALLOW_SHARING |
1242 | get_allow_sharing = F_ALLOW_SHARING |
|
|
1243 | get_allow_cycles = F_ALLOW_CYCLES |
1228 | get_pack_strings = F_PACK_STRINGS |
1244 | get_pack_strings = F_PACK_STRINGS |
1229 | PPCODE: |
1245 | PPCODE: |
1230 | XPUSHs (boolSV (self->flags & ix)); |
1246 | XPUSHs (boolSV (self->flags & ix)); |
1231 | |
1247 | |
1232 | void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) |
1248 | void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) |