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.49 by root, Mon Feb 8 04:11:11 2016 UTC vs.
Revision 1.62 by root, Sat Nov 26 02:11:52 2016 UTC

6#include <string.h> 6#include <string.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <limits.h> 9#include <limits.h>
10#include <float.h> 10#include <float.h>
11#include <inttypes.h>
11 12
12#define ECB_NO_THREADS 1 13#define ECB_NO_THREADS 1
13#include "ecb.h" 14#include "ecb.h"
14 15
15// compatibility with perl <5.18 16// compatibility with perl <5.18
99 100
100#define F_SHRINK 0x00000001UL 101#define F_SHRINK 0x00000001UL
101#define F_ALLOW_UNKNOWN 0x00000002UL 102#define F_ALLOW_UNKNOWN 0x00000002UL
102#define F_ALLOW_SHARING 0x00000004UL 103#define F_ALLOW_SHARING 0x00000004UL
103#define F_ALLOW_CYCLES 0x00000008UL 104#define F_ALLOW_CYCLES 0x00000008UL
105#define F_FORBID_OBJECTS 0x00000010UL
104#define F_PACK_STRINGS 0x00000010UL 106#define F_PACK_STRINGS 0x00000020UL
107#define F_TEXT_KEYS 0x00000040UL
108#define F_TEXT_STRINGS 0x00000080UL
105#define F_VALIDATE_UTF8 0x00000020UL 109#define F_VALIDATE_UTF8 0x00000100UL
106 110
107#define INIT_SIZE 32 // initial scalar size to be allocated 111#define INIT_SIZE 32 // initial scalar size to be allocated
108 112
109#define SB do { 113#define SB do {
110#define SE } while (0) 114#define SE } while (0)
183 187
184// minimum length of a string to be registered for stringref 188// minimum length of a string to be registered for stringref
185ecb_inline int 189ecb_inline int
186minimum_string_length (UV idx) 190minimum_string_length (UV idx)
187{ 191{
188 return idx > 23 192 return idx <= 23 ? 3
189 ? idx > 0xffU 193 : idx <= 0xffU ? 4
190 ? idx > 0xffffU 194 : idx <= 0xffffU ? 5
191 ? idx > 0xffffffffU 195 : idx <= 0xffffffffU ? 7
192 ? 11 196 : 11;
193 : 7
194 : 5
195 : 4
196 : 3;
197} 197}
198 198
199///////////////////////////////////////////////////////////////////////////// 199/////////////////////////////////////////////////////////////////////////////
200// encoder 200// encoder
201 201
214} enc_t; 214} enc_t;
215 215
216ecb_inline void 216ecb_inline void
217need (enc_t *enc, STRLEN len) 217need (enc_t *enc, STRLEN len)
218{ 218{
219 if (ecb_expect_false (enc->cur + len >= enc->end)) 219 if (ecb_expect_false ((uintptr_t)(enc->end - enc->cur) < len))
220 { 220 {
221 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv); 221 STRLEN cur = enc->cur - (char *)SvPVX (enc->sv);
222 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1); 222 SvGROW (enc->sv, cur + (len < (cur >> 2) ? cur >> 2 : len) + 1);
223 enc->cur = SvPVX (enc->sv) + cur; 223 enc->cur = SvPVX (enc->sv) + cur;
224 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; 224 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
276encode_tag (enc_t *enc, UV tag) 276encode_tag (enc_t *enc, UV tag)
277{ 277{
278 encode_uint (enc, MAJOR_TAG, tag); 278 encode_uint (enc, MAJOR_TAG, tag);
279} 279}
280 280
281// exceptional (hopefully) slow path for byte strings that need to be utf8-encoded
282ecb_noinline static void
283encode_str_utf8 (enc_t *enc, int utf8, char *str, STRLEN len)
284{
285 STRLEN ulen = len;
286 U8 *p, *pend = (U8 *)str + len;
287
288 for (p = (U8 *)str; p < pend; ++p)
289 ulen += *p >> 7; // count set high bits
290
291 encode_uint (enc, MAJOR_TEXT, ulen);
292
293 need (enc, ulen);
294 for (p = (U8 *)str; p < pend; ++p)
295 if (*p < 0x80)
296 *enc->cur++ = *p;
297 else
298 {
299 *enc->cur++ = 0xc0 + (*p >> 6);
300 *enc->cur++ = 0x80 + (*p & 63);
301 }
302}
303
281ecb_inline void 304ecb_inline void
282encode_str (enc_t *enc, int utf8, char *str, STRLEN len) 305encode_str (enc_t *enc, int upgrade_utf8, int utf8, char *str, STRLEN len)
283{ 306{
307 if (ecb_expect_false (upgrade_utf8))
308 if (!utf8)
309 {
310 encode_str_utf8 (enc, utf8, str, len);
311 return;
312 }
313
284 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len); 314 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len);
285 need (enc, len); 315 need (enc, len);
286 memcpy (enc->cur, str, len); 316 memcpy (enc->cur, str, len);
287 enc->cur += len; 317 enc->cur += len;
288} 318}
289 319
290static void 320ecb_inline void
291encode_strref (enc_t *enc, int utf8, char *str, STRLEN len) 321encode_strref (enc_t *enc, int upgrade_utf8, int utf8, char *str, STRLEN len)
292{ 322{
293 if (ecb_expect_false (enc->cbor.flags & F_PACK_STRINGS)) 323 if (ecb_expect_false (enc->cbor.flags & F_PACK_STRINGS))
294 { 324 {
295 SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1); 325 SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1);
296 326
307 sv_setuv (*svp, enc->stringref_idx); 337 sv_setuv (*svp, enc->stringref_idx);
308 ++enc->stringref_idx; 338 ++enc->stringref_idx;
309 } 339 }
310 } 340 }
311 341
312 encode_str (enc, utf8, str, len); 342 encode_str (enc, upgrade_utf8, utf8, str, len);
313} 343}
314 344
315static void encode_sv (enc_t *enc, SV *sv); 345static void encode_sv (enc_t *enc, SV *sv);
316 346
317static void 347static void
363 while ((he = hv_iternext (hv))) 393 while ((he = hv_iternext (hv)))
364 { 394 {
365 if (HeKLEN (he) == HEf_SVKEY) 395 if (HeKLEN (he) == HEf_SVKEY)
366 encode_sv (enc, HeSVKEY (he)); 396 encode_sv (enc, HeSVKEY (he));
367 else 397 else
368 encode_strref (enc, HeKUTF8 (he), HeKEY (he), HeKLEN (he)); 398 encode_strref (enc, enc->cbor.flags & (F_TEXT_KEYS | F_TEXT_STRINGS), HeKUTF8 (he), HeKEY (he), HeKLEN (he));
369 399
370 encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he)); 400 encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he));
371 } 401 }
372 402
373 if (mg) 403 if (mg)
445 if (ecb_expect_false (SvOBJECT (sv))) 475 if (ecb_expect_false (SvOBJECT (sv)))
446 { 476 {
447 HV *stash = SvSTASH (sv); 477 HV *stash = SvSTASH (sv);
448 GV *method; 478 GV *method;
449 479
480 if (enc->cbor.flags & F_FORBID_OBJECTS)
481 croak ("encountered object '%s', but forbid_objects is enabled",
482 SvPV_nolen (sv_2mortal (newRV_inc (sv))));
450 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0))) 483 else if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0)))
451 { 484 {
452 dSP; 485 dSP;
453 486
454 ENTER; SAVETMPS; PUSHMARK (SP); 487 ENTER; SAVETMPS;
488 PUSHMARK (SP);
455 // we re-bless the reference to get overload and other niceties right 489 // we re-bless the reference to get overload and other niceties right
456 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 490 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
457 491
458 PUTBACK; 492 PUTBACK;
459 // G_SCALAR ensures that return value is 1 493 // G_SCALAR ensures that return value is 1
472 } 506 }
473 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0) 507 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0)
474 { 508 {
475 dSP; 509 dSP;
476 510
477 ENTER; SAVETMPS; PUSHMARK (SP); 511 ENTER; SAVETMPS;
512 SAVESTACK_POS ();
513 PUSHMARK (SP);
478 EXTEND (SP, 2); 514 EXTEND (SP, 2);
479 // we re-bless the reference to get overload and other niceties right 515 // we re-bless the reference to get overload and other niceties right
480 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 516 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
481 PUSHs (sv_cbor); 517 PUSHs (sv_cbor);
482 518
488 if (count == 1 && SvROK (TOPs) && SvRV (TOPs) == sv) 524 if (count == 1 && SvROK (TOPs) && SvRV (TOPs) == sv)
489 croak ("%s::FREEZE(CBOR) method returned same object as was passed instead of a new one", HvNAME (stash)); 525 croak ("%s::FREEZE(CBOR) method returned same object as was passed instead of a new one", HvNAME (stash));
490 526
491 encode_tag (enc, CBOR_TAG_PERL_OBJECT); 527 encode_tag (enc, CBOR_TAG_PERL_OBJECT);
492 encode_uint (enc, MAJOR_ARRAY, count + 1); 528 encode_uint (enc, MAJOR_ARRAY, count + 1);
493 encode_strref (enc, HvNAMEUTF8 (stash), HvNAME (stash), HvNAMELEN (stash)); 529 encode_strref (enc, 0, HvNAMEUTF8 (stash), HvNAME (stash), HvNAMELEN (stash));
494 530
495 while (count) 531 while (count)
496 encode_sv (enc, SP[1 - count--]); 532 encode_sv (enc, SP[1 - count--]);
497 533
498 PUTBACK; 534 PUTBACK;
557 593
558 if (SvPOKp (sv)) 594 if (SvPOKp (sv))
559 { 595 {
560 STRLEN len; 596 STRLEN len;
561 char *str = SvPV (sv, len); 597 char *str = SvPV (sv, len);
562 encode_strref (enc, SvUTF8 (sv), str, len); 598 encode_strref (enc, enc->cbor.flags & F_TEXT_STRINGS, SvUTF8 (sv), str, len);
563 } 599 }
564 else if (SvNOKp (sv)) 600 else if (SvNOKp (sv))
565 encode_nv (enc, sv); 601 encode_nv (enc, sv);
566 else if (SvIOKp (sv)) 602 else if (SvIOKp (sv))
567 { 603 {
626 U32 depth; // recursion depth 662 U32 depth; // recursion depth
627 U32 maxdepth; // recursion depth limit 663 U32 maxdepth; // recursion depth limit
628 AV *shareable; 664 AV *shareable;
629 AV *stringref; 665 AV *stringref;
630 SV *decode_tagged; 666 SV *decode_tagged;
667 SV *err_sv; // optional sv for error, needs to be freed
631} dec_t; 668} dec_t;
632 669
633#define ERR(reason) SB if (!dec->err) dec->err = reason; goto fail; SE 670// set dec->err to ERRSV
671ecb_cold static void
672err_errsv (dec_t *dec)
673{
674 if (!dec->err)
675 {
676 dec->err_sv = newSVsv (ERRSV);
634 677
635#define WANT(len) if (ecb_expect_false (dec->cur + len > dec->end)) ERR ("unexpected end of CBOR data") 678 // chop off the trailing \n
679 SvCUR_set (dec->err_sv, SvCUR (dec->err_sv) - 1);
680 *SvEND (dec->err_sv) = 0;
636 681
682 dec->err = SvPVutf8_nolen (dec->err_sv);
683 }
684}
685
686// the following functions are used to reduce code size and help the compiler to optimise
687ecb_cold static void
688err_set (dec_t *dec, const char *reason)
689{
690 if (!dec->err)
691 dec->err = reason;
692}
693
694ecb_cold static void
695err_unexpected_end (dec_t *dec)
696{
697 err_set (dec, "unexpected end of CBOR data");
698}
699
700ecb_cold static void
701err_nesting_exceeded (dec_t *dec)
702{
703 err_set (dec, ERR_NESTING_EXCEEDED);
704}
705
706#define ERR_DO(do) SB do; goto fail; SE
707#define ERR(reason) ERR_DO (err_set (dec, reason))
708#define ERR_ERRSV ERR_DO (err_errsv (dec))
709
710#define WANT(len) if (ecb_expect_false ((uintptr_t)(dec->end - dec->cur) < (STRLEN)len)) ERR_DO (err_unexpected_end (dec))
711
637#define DEC_INC_DEPTH if (++dec->depth > dec->cbor.max_depth) ERR (ERR_NESTING_EXCEEDED) 712#define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED)
638#define DEC_DEC_DEPTH --dec->depth 713#define DEC_DEC_DEPTH --dec->depth
639 714
640static UV 715static UV
641decode_uint (dec_t *dec) 716decode_uint (dec_t *dec)
642{ 717{
719 av_push (av, decode_sv (dec)); 794 av_push (av, decode_sv (dec));
720 } 795 }
721 } 796 }
722 else 797 else
723 { 798 {
724 int i, len = decode_uint (dec); 799 UV i, len = decode_uint (dec);
725 800
726 WANT (len); // complexity check for av_fill - need at least one byte per value, do not allow supersize arrays 801 WANT (len); // complexity check for av_fill - need at least one byte per value, do not allow supersize arrays
727 av_fill (av, len - 1); 802 av_fill (av, len - 1);
728 803
729 for (i = 0; i < len; ++i) 804 for (i = 0; i < len; ++i)
746 // byte or utf-8 strings as keys, but only when !stringref 821 // byte or utf-8 strings as keys, but only when !stringref
747 822
748 if (ecb_expect_true (!dec->stringref)) 823 if (ecb_expect_true (!dec->stringref))
749 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) 824 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8))
750 { 825 {
751 I32 len = decode_uint (dec); 826 STRLEN len = decode_uint (dec);
752 char *key = (char *)dec->cur; 827 char *key = (char *)dec->cur;
753 828
754 WANT (len); 829 WANT (len);
755 dec->cur += len; 830 dec->cur += len;
756 831
758 833
759 return; 834 return;
760 } 835 }
761 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) 836 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8))
762 { 837 {
763 I32 len = decode_uint (dec); 838 STRLEN len = decode_uint (dec);
764 char *key = (char *)dec->cur; 839 char *key = (char *)dec->cur;
765 840
766 WANT (len); 841 WANT (len);
767 dec->cur += len; 842 dec->cur += len;
768 843
775 return; 850 return;
776 } 851 }
777 852
778 SV *k = decode_sv (dec); 853 SV *k = decode_sv (dec);
779 SV *v = decode_sv (dec); 854 SV *v = decode_sv (dec);
855
856 // we leak memory if uncaught exceptions are thrown by random magical
857 // methods, and this is hopefully the only place where it can happen,
858 // so if there is a chance of an exception, take the very slow path.
859 // since catching exceptions is "undocumented/internal/forbidden" by
860 // the new p5p powers, we need to call out to a perl function :/
861 if (ecb_expect_false (SvAMAGIC (k)))
862 {
863 dSP;
864
865 ENTER; SAVETMPS;
866 PUSHMARK (SP);
867 EXTEND (SP, 3);
868 PUSHs (sv_2mortal (newRV_inc ((SV *)hv)));
869 PUSHs (sv_2mortal (k));
870 PUSHs (sv_2mortal (v));
871
872 PUTBACK;
873 call_pv ("CBOR::XS::_hv_store", G_VOID | G_DISCARD | G_EVAL);
874 SPAGAIN;
875
876 FREETMPS; LEAVE;
877
878 if (SvTRUE (ERRSV))
879 ERR_ERRSV;
880
881 return;
882 }
780 883
781 hv_store_ent (hv, k, v, 0); 884 hv_store_ent (hv, k, v, 0);
782 SvREFCNT_dec (k); 885 SvREFCNT_dec (k);
783 886
784fail: 887fail:
809 decode_he (dec, hv); 912 decode_he (dec, hv);
810 } 913 }
811 } 914 }
812 else 915 else
813 { 916 {
814 int pairs = decode_uint (dec); 917 UV pairs = decode_uint (dec);
918
919 WANT (pairs); // complexity check - need at least one byte per value, do not allow supersize hashes
815 920
816 while (pairs--) 921 while (pairs--)
817 decode_he (dec, hv); 922 decode_he (dec, hv);
818 } 923 }
819 924
907 sv = newRV_noinc (decode_sv (dec)); 1012 sv = newRV_noinc (decode_sv (dec));
908 break; 1013 break;
909 1014
910 case CBOR_TAG_STRINGREF_NAMESPACE: 1015 case CBOR_TAG_STRINGREF_NAMESPACE:
911 { 1016 {
1017 // do nmot use SAVETMPS/FREETMPS, as these will
1018 // erase mortalised caches, e.g. "shareable"
912 ENTER; SAVETMPS; 1019 ENTER;
913 1020
914 SAVESPTR (dec->stringref); 1021 SAVESPTR (dec->stringref);
915 dec->stringref = (AV *)sv_2mortal ((SV *)newAV ()); 1022 dec->stringref = (AV *)sv_2mortal ((SV *)newAV ());
916 1023
917 sv = decode_sv (dec); 1024 sv = decode_sv (dec);
918 1025
919 FREETMPS; LEAVE; 1026 LEAVE;
920 } 1027 }
921 break; 1028 break;
922 1029
923 case CBOR_TAG_STRINGREF: 1030 case CBOR_TAG_STRINGREF:
924 { 1031 {
975 } 1082 }
976 break; 1083 break;
977 1084
978 case CBOR_TAG_PERL_OBJECT: 1085 case CBOR_TAG_PERL_OBJECT:
979 { 1086 {
1087 if (dec->cbor.flags & F_FORBID_OBJECTS)
1088 goto filter;
1089
980 sv = decode_sv (dec); 1090 sv = decode_sv (dec);
981 1091
982 if (!SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV) 1092 if (!SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
983 ERR ("corrupted CBOR data (non-array perl object)"); 1093 ERR ("corrupted CBOR data (non-array perl object)");
984 1094
994 if (!method) 1104 if (!method)
995 ERR ("cannot decode perl-object (package does not have a THAW method)"); 1105 ERR ("cannot decode perl-object (package does not have a THAW method)");
996 1106
997 dSP; 1107 dSP;
998 1108
999 ENTER; SAVETMPS; PUSHMARK (SP); 1109 ENTER; SAVETMPS;
1110 PUSHMARK (SP);
1000 EXTEND (SP, len + 1); 1111 EXTEND (SP, len + 1);
1001 // we re-bless the reference to get overload and other niceties right 1112 // we re-bless the reference to get overload and other niceties right
1002 PUSHs (*av_fetch (av, 0, 1)); 1113 PUSHs (*av_fetch (av, 0, 1));
1003 PUSHs (sv_cbor); 1114 PUSHs (sv_cbor);
1004 1115
1012 SPAGAIN; 1123 SPAGAIN;
1013 1124
1014 if (SvTRUE (ERRSV)) 1125 if (SvTRUE (ERRSV))
1015 { 1126 {
1016 FREETMPS; LEAVE; 1127 FREETMPS; LEAVE;
1017 ERR (SvPVutf8_nolen (sv_2mortal (SvREFCNT_inc (ERRSV)))); 1128 ERR_ERRSV;
1018 } 1129 }
1019 1130
1020 SvREFCNT_dec (sv); 1131 SvREFCNT_dec (sv);
1021 sv = SvREFCNT_inc (POPs); 1132 sv = SvREFCNT_inc (POPs);
1022 1133
1025 FREETMPS; LEAVE; 1136 FREETMPS; LEAVE;
1026 } 1137 }
1027 break; 1138 break;
1028 1139
1029 default: 1140 default:
1141 filter:
1030 { 1142 {
1143 SV *tag_sv = newSVuv (tag);
1144
1031 sv = decode_sv (dec); 1145 sv = decode_sv (dec);
1032 1146
1033 dSP; 1147 dSP;
1034 ENTER; SAVETMPS; PUSHMARK (SP); 1148 ENTER; SAVETMPS;
1149 SAVESTACK_POS ();
1150 PUSHMARK (SP);
1035 EXTEND (SP, 2); 1151 EXTEND (SP, 2);
1036 PUSHs (newSVuv (tag)); 1152 PUSHs (tag_sv);
1037 PUSHs (sv); 1153 PUSHs (sv);
1038 1154
1039 PUTBACK; 1155 PUTBACK;
1040 int count = call_sv (dec->cbor.filter ? dec->cbor.filter : default_filter, G_ARRAY | G_EVAL); 1156 int count = call_sv (dec->cbor.filter ? dec->cbor.filter : default_filter, G_ARRAY | G_EVAL);
1041 SPAGAIN; 1157 SPAGAIN;
1042 1158
1043 if (SvTRUE (ERRSV)) 1159 if (SvTRUE (ERRSV))
1044 { 1160 {
1161 SvREFCNT_dec (tag_sv);
1045 FREETMPS; LEAVE; 1162 FREETMPS; LEAVE;
1046 ERR (SvPVutf8_nolen (sv_2mortal (SvREFCNT_inc (ERRSV)))); 1163 ERR_ERRSV;
1047 } 1164 }
1048 1165
1049 if (count) 1166 if (count)
1050 { 1167 {
1168 SvREFCNT_dec (tag_sv);
1051 SvREFCNT_dec (sv); 1169 SvREFCNT_dec (sv);
1052 sv = SvREFCNT_inc (POPs); 1170 sv = SvREFCNT_inc (POPs);
1053 } 1171 }
1054 else 1172 else
1055 { 1173 {
1056 AV *av = newAV (); 1174 AV *av = newAV ();
1057 av_push (av, newSVuv (tag)); 1175 av_push (av, tag_sv);
1058 av_push (av, sv); 1176 av_push (av, sv);
1059 1177
1060 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash 1178 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash
1061 ? cbor_tagged_stash 1179 ? cbor_tagged_stash
1062 : gv_stashpv ("CBOR::XS::Tagged" , 1); 1180 : gv_stashpv ("CBOR::XS::Tagged" , 1);
1191 1309
1192 if (dec.err) 1310 if (dec.err)
1193 { 1311 {
1194 if (dec.shareable) 1312 if (dec.shareable)
1195 { 1313 {
1196 // need to break cyclic links, which whould all be in shareable 1314 // need to break cyclic links, which would all be in shareable
1197 int i; 1315 int i;
1198 SV **svp; 1316 SV **svp;
1199 1317
1200 for (i = av_len (dec.shareable) + 1; i--; ) 1318 for (i = av_len (dec.shareable) + 1; i--; )
1201 if ((svp = av_fetch (dec.shareable, i, 0))) 1319 if ((svp = av_fetch (dec.shareable, i, 0)))
1202 sv_setsv (*svp, &PL_sv_undef); 1320 sv_setsv (*svp, &PL_sv_undef);
1203 } 1321 }
1204 1322
1205 SvREFCNT_dec (sv); 1323 SvREFCNT_dec (sv);
1324
1325 if (dec.err_sv)
1326 sv_2mortal (dec.err_sv);
1327
1206 croak ("%s, at offset %d (octet 0x%02x)", dec.err, dec.cur - (U8 *)data, (int)(uint8_t)*dec.cur); 1328 croak ("%s, at offset %d (octet 0x%02x)", dec.err, dec.cur - (U8 *)data, (int)(uint8_t)*dec.cur);
1207 } 1329 }
1208 1330
1209 sv = sv_2mortal (sv); 1331 sv = sv_2mortal (sv);
1210 1332
1354 1476
1355 default_filter = newSVpv ("CBOR::XS::default_filter", 0); 1477 default_filter = newSVpv ("CBOR::XS::default_filter", 0);
1356 1478
1357 sv_cbor = newSVpv ("CBOR", 0); 1479 sv_cbor = newSVpv ("CBOR", 0);
1358 SvREADONLY_on (sv_cbor); 1480 SvREADONLY_on (sv_cbor);
1481
1482 assert (("STRLEN must be an unsigned type", 0 <= (STRLEN)-1));
1359} 1483}
1360 1484
1361PROTOTYPES: DISABLE 1485PROTOTYPES: DISABLE
1362 1486
1363void CLONE (...) 1487void CLONE (...)
1383 ALIAS: 1507 ALIAS:
1384 shrink = F_SHRINK 1508 shrink = F_SHRINK
1385 allow_unknown = F_ALLOW_UNKNOWN 1509 allow_unknown = F_ALLOW_UNKNOWN
1386 allow_sharing = F_ALLOW_SHARING 1510 allow_sharing = F_ALLOW_SHARING
1387 allow_cycles = F_ALLOW_CYCLES 1511 allow_cycles = F_ALLOW_CYCLES
1512 forbid_objects = F_FORBID_OBJECTS
1388 pack_strings = F_PACK_STRINGS 1513 pack_strings = F_PACK_STRINGS
1514 text_keys = F_TEXT_KEYS
1515 text_strings = F_TEXT_STRINGS
1389 validate_utf8 = F_VALIDATE_UTF8 1516 validate_utf8 = F_VALIDATE_UTF8
1390 PPCODE: 1517 PPCODE:
1391{ 1518{
1392 if (enable) 1519 if (enable)
1393 self->flags |= ix; 1520 self->flags |= ix;
1401 ALIAS: 1528 ALIAS:
1402 get_shrink = F_SHRINK 1529 get_shrink = F_SHRINK
1403 get_allow_unknown = F_ALLOW_UNKNOWN 1530 get_allow_unknown = F_ALLOW_UNKNOWN
1404 get_allow_sharing = F_ALLOW_SHARING 1531 get_allow_sharing = F_ALLOW_SHARING
1405 get_allow_cycles = F_ALLOW_CYCLES 1532 get_allow_cycles = F_ALLOW_CYCLES
1533 get_forbid_objects = F_FORBID_OBJECTS
1406 get_pack_strings = F_PACK_STRINGS 1534 get_pack_strings = F_PACK_STRINGS
1535 get_text_keys = F_TEXT_KEYS
1536 get_text_strings = F_TEXT_STRINGS
1407 get_validate_utf8 = F_VALIDATE_UTF8 1537 get_validate_utf8 = F_VALIDATE_UTF8
1408 PPCODE: 1538 PPCODE:
1409 XPUSHs (boolSV (self->flags & ix)); 1539 XPUSHs (boolSV (self->flags & ix));
1410 1540
1411void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) 1541void max_depth (CBOR *self, U32 max_depth = 0x80000000UL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines