… | |
… | |
1201 | // if cycles are allowed, then we store an AV as value |
1201 | // if cycles are allowed, then we store an AV as value |
1202 | // while it is being decoded, and gather unresolved |
1202 | // while it is being decoded, and gather unresolved |
1203 | // references in it, to be re4solved after decoding. |
1203 | // references in it, to be re4solved after decoding. |
1204 | int idx, i; |
1204 | int idx, i; |
1205 | AV *av = newAV (); |
1205 | AV *av = newAV (); |
1206 | av_push (dec->shareable, SvREFCNT_inc_NN ((SV *)av)); |
1206 | av_push (dec->shareable, (SV *)av); |
1207 | idx = AvFILLp (dec->shareable); |
1207 | idx = AvFILLp (dec->shareable); |
1208 | |
1208 | |
1209 | sv = decode_sv (dec); |
1209 | sv = decode_sv (dec); |
1210 | |
1210 | |
1211 | // the AV now contains \undef for all unresolved references, |
1211 | // the AV now contains \undef for all unresolved references, |
1212 | // so we fix them up here. |
1212 | // so we fix them up here. |
1213 | for (i = 0; i <= AvFILLp (av); ++i) |
1213 | for (i = 0; i <= AvFILLp (av); ++i) |
1214 | SvRV_set (AvARRAY (av)[i], SvREFCNT_inc_NN (SvRV (sv))); |
1214 | SvRV_set (AvARRAY (av)[i], SvREFCNT_inc_NN (SvRV (sv))); |
1215 | |
1215 | |
1216 | // now replace the AV by a reference to the completed value |
1216 | // now replace the AV by a reference to the completed value |
1217 | SvREFCNT_dec_NN (av); |
1217 | SvREFCNT_dec_NN ((SV *)av); |
1218 | AvARRAY (dec->shareable)[idx] = SvREFCNT_inc_NN (sv); |
1218 | AvARRAY (dec->shareable)[idx] = SvREFCNT_inc_NN (sv); |
1219 | } |
1219 | } |
1220 | else |
1220 | else |
1221 | { |
1221 | { |
1222 | av_push (dec->shareable, &PL_sv_undef); |
1222 | av_push (dec->shareable, &PL_sv_undef); |
1223 | int idx = AvFILLp (dec->shareable); |
1223 | int idx = AvFILLp (dec->shareable); |
1224 | sv = decode_sv (dec); |
1224 | sv = decode_sv (dec); |
1225 | av_store (dec->shareable, idx, SvREFCNT_inc_NN (sv)); |
1225 | AvARRAY (dec->shareable)[idx] = SvREFCNT_inc_NN (sv); |
1226 | } |
1226 | } |
1227 | } |
1227 | } |
1228 | break; |
1228 | break; |
1229 | |
1229 | |
1230 | case CBOR_TAG_VALUE_SHAREDREF: |
1230 | case CBOR_TAG_VALUE_SHAREDREF: |