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.70 by root, Fri Dec 4 02:57:14 2020 UTC vs.
Revision 1.75 by root, Thu Sep 7 23:52:24 2023 UTC

28#endif 28#endif
29#ifndef SvREFCNT_dec_NN 29#ifndef SvREFCNT_dec_NN
30# define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) 30# define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv)
31#endif 31#endif
32 32
33// perl's is_utf8_string interprets len=0 as "calculate len", but we want it to mean 0
34#define cbor_is_utf8_string(str,len) (!(len) || is_utf8_string ((str), (len)))
35
33// known major and minor types 36// known major and minor types
34enum cbor_type 37enum cbor_type
35{ 38{
36 MAJOR_SHIFT = 5, 39 MAJOR_SHIFT = 5,
37 MINOR_MASK = 0x1f, 40 MINOR_MASK = 0x1f,
201#endif 204#endif
202 } 205 }
203} 206}
204 207
205// minimum length of a string to be registered for stringref 208// minimum length of a string to be registered for stringref
206ecb_inline int 209ecb_inline STRLEN
207minimum_string_length (UV idx) 210minimum_string_length (UV idx)
208{ 211{
209 return idx <= 23 ? 3 212 return idx <= 23 ? 3
210 : idx <= 0xffU ? 4 213 : idx <= 0xffU ? 4
211 : idx <= 0xffffU ? 5 214 : idx <= 0xffffU ? 5
987 990
988 WANT (len); 991 WANT (len);
989 dec->cur += len; 992 dec->cur += len;
990 993
991 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) 994 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
992 if (!is_utf8_string (key, len)) 995 if (!cbor_is_utf8_string ((U8 *)key, len))
993 ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); 996 ERR ("corrupted CBOR data (invalid UTF-8 in map key)");
994 997
995 hv_store (hv, key, -len, decode_sv (dec), 0); 998 hv_store (hv, key, -len, decode_sv (dec), 0);
996 999
997 return; 1000 return;
1126 } 1129 }
1127 1130
1128 if (utf8) 1131 if (utf8)
1129 { 1132 {
1130 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) 1133 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
1131 if (!is_utf8_string (SvPVX (sv), SvCUR (sv))) 1134 if (!cbor_is_utf8_string (SvPVX (sv), SvCUR (sv)))
1132 ERR ("corrupted CBOR data (invalid UTF-8 in text string)"); 1135 ERR ("corrupted CBOR data (invalid UTF-8 in text string)");
1133 1136
1134 SvUTF8_on (sv); 1137 SvUTF8_on (sv);
1135 } 1138 }
1136 1139
1220 UV idx = decode_uint (dec); 1223 UV idx = decode_uint (dec);
1221 1224
1222 if (!dec->shareable || idx >= (UV)(1 + AvFILLp (dec->shareable))) 1225 if (!dec->shareable || idx >= (UV)(1 + AvFILLp (dec->shareable)))
1223 ERR ("corrupted CBOR data (sharedref index out of bounds)"); 1226 ERR ("corrupted CBOR data (sharedref index out of bounds)");
1224 1227
1225 sv = SvREFCNT_inc_NN (AvARRAY (dec->shareable)[idx]); 1228 sv = newRV_inc (AvARRAY (dec->shareable)[idx]);
1226 1229
1227 if (sv == &PL_sv_undef) 1230 if (sv == &PL_sv_undef)
1228 ERR ("cyclic CBOR data structure found, but allow_cycles is not enabled"); 1231 ERR ("cyclic CBOR data structure found, but allow_cycles is not enabled");
1229 } 1232 }
1230 break; 1233 break;
1470 SvREFCNT_dec_NN (sv); 1473 SvREFCNT_dec_NN (sv);
1471 1474
1472 if (dec.err_sv) 1475 if (dec.err_sv)
1473 sv_2mortal (dec.err_sv); 1476 sv_2mortal (dec.err_sv);
1474 1477
1475 croak ("%s, at offset %d (octet 0x%02x)", dec.err, dec.cur - (U8 *)data, (int)(uint8_t)*dec.cur); 1478 croak ("%s, at offset %ld (octet 0x%02x)", dec.err, (long)(dec.cur - (U8 *)data), (int)(uint8_t)*dec.cur);
1476 } 1479 }
1477 1480
1478 sv = sv_2mortal (sv); 1481 sv = sv_2mortal (sv);
1479 1482
1480 return sv; 1483 return sv;
1569 1572
1570 break; 1573 break;
1571 1574
1572 case MAJOR_MAP >> MAJOR_SHIFT: 1575 case MAJOR_MAP >> MAJOR_SHIFT:
1573 len <<= 1; 1576 len <<= 1;
1577 /* FALLTHROUGH */
1574 case MAJOR_ARRAY >> MAJOR_SHIFT: 1578 case MAJOR_ARRAY >> MAJOR_SHIFT:
1575 if (len) 1579 if (len)
1576 { 1580 {
1577 av_push (self->incr_count, newSViv (len + 1)); //TODO: nest 1581 av_push (self->incr_count, newSViv (len + 1)); //TODO: nest
1578 count = len + 1; 1582 count = len + 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines