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.24 by root, Wed Nov 20 16:29:02 2013 UTC vs.
Revision 1.34 by root, Sat Nov 30 16:19:59 2013 UTC

19# define HvNAMELEN(hv) HvNAMELEN_get (hv) 19# define HvNAMELEN(hv) HvNAMELEN_get (hv)
20#endif 20#endif
21#ifndef HvNAMEUTF8 21#ifndef HvNAMEUTF8
22# define HvNAMEUTF8(hv) 0 22# define HvNAMEUTF8(hv) 0
23#endif 23#endif
24#ifndef SvREFCNT_dec_NN
25# define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv)
26#endif
24 27
25// known tags 28// known tags
26enum cbor_tag 29enum cbor_tag
27{ 30{
28 // inofficial extensions (pending iana registration) 31 // extensions
32 CBOR_TAG_STRINGREF = 25, // http://cbor.schmorp.de/stringref
29 CBOR_TAG_PERL_OBJECT = 24, // http://cbor.schmorp.de/perl-object 33 CBOR_TAG_PERL_OBJECT = 26, // http://cbor.schmorp.de/perl-object
30 CBOR_TAG_GENERIC_OBJECT = 25, // http://cbor.schmorp.de/generic-object 34 CBOR_TAG_GENERIC_OBJECT = 27, // http://cbor.schmorp.de/generic-object
31 CBOR_TAG_VALUE_SHAREABLE = 26, // http://cbor.schmorp.de/value-sharing 35 CBOR_TAG_VALUE_SHAREABLE = 28, // http://cbor.schmorp.de/value-sharing
32 CBOR_TAG_VALUE_SHAREDREF = 27, // http://cbor.schmorp.de/value-sharing 36 CBOR_TAG_VALUE_SHAREDREF = 29, // http://cbor.schmorp.de/value-sharing
33 CBOR_TAG_STRINGREF_NAMESPACE = 65537, // http://cbor.schmorp.de/stringref 37 CBOR_TAG_STRINGREF_NAMESPACE = 256, // http://cbor.schmorp.de/stringref
34 CBOR_TAG_STRINGREF = 28, // http://cbor.schmorp.de/stringref
35 CBOR_TAG_INDIRECTION = 22098, // http://cbor.schmorp.de/indirection 38 CBOR_TAG_INDIRECTION = 22098, // http://cbor.schmorp.de/indirection
36 39
37 // rfc7049 40 // rfc7049
38 CBOR_TAG_DATETIME = 0, // rfc4287, utf-8 41 CBOR_TAG_DATETIME = 0, // rfc4287, utf-8
39 CBOR_TAG_TIMESTAMP = 1, // unix timestamp, any 42 CBOR_TAG_TIMESTAMP = 1, // unix timestamp, any
56 CBOR_TAG_MAGIC = 55799 // self-describe cbor 59 CBOR_TAG_MAGIC = 55799 // self-describe cbor
57}; 60};
58 61
59#define F_SHRINK 0x00000001UL 62#define F_SHRINK 0x00000001UL
60#define F_ALLOW_UNKNOWN 0x00000002UL 63#define F_ALLOW_UNKNOWN 0x00000002UL
61#define F_ALLOW_SHARING 0x00000004UL //TODO 64#define F_ALLOW_SHARING 0x00000004UL
62#define F_ALLOW_STRINGREF 0x00000008UL //TODO 65#define F_PACK_STRINGS 0x00000008UL
63 66
64#define INIT_SIZE 32 // initial scalar size to be allocated 67#define INIT_SIZE 32 // initial scalar size to be allocated
65 68
66#define SB do { 69#define SB do {
67#define SE } while (0) 70#define SE } while (0)
79# define CBOR_SLOW 0 82# define CBOR_SLOW 0
80# define CBOR_STASH cbor_stash 83# define CBOR_STASH cbor_stash
81#endif 84#endif
82 85
83static HV *cbor_stash, *types_boolean_stash, *types_error_stash, *cbor_tagged_stash; // CBOR::XS:: 86static HV *cbor_stash, *types_boolean_stash, *types_error_stash, *cbor_tagged_stash; // CBOR::XS::
84static SV *types_true, *types_false, *types_error, *sv_cbor; 87static SV *types_true, *types_false, *types_error, *sv_cbor, *default_filter;
85 88
86typedef struct { 89typedef struct {
87 U32 flags; 90 U32 flags;
88 U32 max_depth; 91 U32 max_depth;
89 STRLEN max_size; 92 STRLEN max_size;
93 SV *filter;
90} CBOR; 94} CBOR;
91 95
92ecb_inline void 96ecb_inline void
93cbor_init (CBOR *cbor) 97cbor_init (CBOR *cbor)
94{ 98{
95 Zero (cbor, 1, CBOR); 99 Zero (cbor, 1, CBOR);
96 cbor->max_depth = 512; 100 cbor->max_depth = 512;
101}
102
103ecb_inline void
104cbor_free (CBOR *cbor)
105{
106 SvREFCNT_dec (cbor->filter);
97} 107}
98 108
99///////////////////////////////////////////////////////////////////////////// 109/////////////////////////////////////////////////////////////////////////////
100// utility functions 110// utility functions
101 111
131{ 141{
132 return idx > 23 142 return idx > 23
133 ? idx > 0xffU 143 ? idx > 0xffU
134 ? idx > 0xffffU 144 ? idx > 0xffffU
135 ? idx > 0xffffffffU 145 ? idx > 0xffffffffU
146 ? 11
136 ? 7 147 : 7
137 : 6
138 : 5 148 : 5
139 : 4 149 : 4
140 : 3; 150 : 3;
141} 151}
142 152
179static void 189static void
180encode_uint (enc_t *enc, int major, UV len) 190encode_uint (enc_t *enc, int major, UV len)
181{ 191{
182 need (enc, 9); 192 need (enc, 9);
183 193
184 if (len < 24) 194 if (ecb_expect_true (len < 24))
185 *enc->cur++ = major | len; 195 *enc->cur++ = major | len;
186 else if (len <= 0xff) 196 else if (ecb_expect_true (len <= 0xff))
187 { 197 {
188 *enc->cur++ = major | 24; 198 *enc->cur++ = major | 24;
189 *enc->cur++ = len; 199 *enc->cur++ = len;
190 } 200 }
191 else if (len <= 0xffff) 201 else if (len <= 0xffff)
220encode_tag (enc_t *enc, UV tag) 230encode_tag (enc_t *enc, UV tag)
221{ 231{
222 encode_uint (enc, 0xc0, tag); 232 encode_uint (enc, 0xc0, tag);
223} 233}
224 234
235ecb_inline void
236encode_str (enc_t *enc, int utf8, char *str, STRLEN len)
237{
238 encode_uint (enc, utf8 ? 0x60 : 0x40, len);
239 need (enc, len);
240 memcpy (enc->cur, str, len);
241 enc->cur += len;
242}
243
225static void 244static void
226encode_str (enc_t *enc, int utf8, char *str, STRLEN len) 245encode_strref (enc_t *enc, int utf8, char *str, STRLEN len)
227{ 246{
228 if (ecb_expect_false (enc->cbor.flags & F_ALLOW_STRINGREF)) 247 if (ecb_expect_false (enc->cbor.flags & F_PACK_STRINGS))
229 { 248 {
230 SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1); 249 SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1);
231 250
232 if (SvOK (*svp)) 251 if (SvOK (*svp))
233 { 252 {
242 sv_setuv (*svp, enc->stringref_idx); 261 sv_setuv (*svp, enc->stringref_idx);
243 ++enc->stringref_idx; 262 ++enc->stringref_idx;
244 } 263 }
245 } 264 }
246 265
247 encode_uint (enc, utf8 ? 0x60 : 0x40, len); 266 encode_str (enc, utf8, str, len);
248 need (enc, len);
249 memcpy (enc->cur, str, len);
250 enc->cur += len;
251} 267}
252 268
253static void encode_sv (enc_t *enc, SV *sv); 269static void encode_sv (enc_t *enc, SV *sv);
254 270
255static void 271static void
269 SV **svp = av_fetch (av, i, 0); 285 SV **svp = av_fetch (av, i, 0);
270 encode_sv (enc, svp ? *svp : &PL_sv_undef); 286 encode_sv (enc, svp ? *svp : &PL_sv_undef);
271 } 287 }
272 288
273 --enc->depth; 289 --enc->depth;
274}
275
276ecb_inline void
277encode_he (enc_t *enc, HE *he)
278{
279} 290}
280 291
281static void 292static void
282encode_hv (enc_t *enc, HV *hv) 293encode_hv (enc_t *enc, HV *hv)
283{ 294{
299 while ((he = hv_iternext (hv))) 310 while ((he = hv_iternext (hv)))
300 { 311 {
301 if (HeKLEN (he) == HEf_SVKEY) 312 if (HeKLEN (he) == HEf_SVKEY)
302 encode_sv (enc, HeSVKEY (he)); 313 encode_sv (enc, HeSVKEY (he));
303 else 314 else
304 encode_str (enc, HeKUTF8 (he), HeKEY (he), HeKLEN (he)); 315 encode_strref (enc, HeKUTF8 (he), HeKEY (he), HeKLEN (he));
305 316
306 encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he)); 317 encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he));
307 } 318 }
308 319
309 if (mg) 320 if (mg)
315// encode objects, arrays and special \0=false and \1=true values. 326// encode objects, arrays and special \0=false and \1=true values.
316static void 327static void
317encode_rv (enc_t *enc, SV *sv) 328encode_rv (enc_t *enc, SV *sv)
318{ 329{
319 SvGETMAGIC (sv); 330 SvGETMAGIC (sv);
320
321 if (ecb_expect_false (enc->cbor.flags & F_ALLOW_SHARING)
322 && ecb_expect_false (SvREFCNT (sv) > 1))
323 {
324 if (!enc->shareable)
325 enc->shareable = (HV *)sv_2mortal ((SV *)newHV ());
326
327 SV **svp = hv_fetch (enc->shareable, (char *)&sv, sizeof (sv), 1);
328
329 if (SvOK (*svp))
330 {
331 encode_tag (enc, CBOR_TAG_VALUE_SHAREDREF);
332 encode_uint (enc, 0x00, SvUV (*svp));
333 return;
334 }
335 else
336 {
337 sv_setuv (*svp, enc->shareable_idx);
338 ++enc->shareable_idx;
339 encode_tag (enc, CBOR_TAG_VALUE_SHAREABLE);
340 }
341 }
342 331
343 svtype svt = SvTYPE (sv); 332 svtype svt = SvTYPE (sv);
344 333
345 if (ecb_expect_false (SvOBJECT (sv))) 334 if (ecb_expect_false (SvOBJECT (sv)))
346 { 335 {
353 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash 342 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash
354 ? cbor_tagged_stash 343 ? cbor_tagged_stash
355 : gv_stashpv ("CBOR::XS::Tagged" , 1); 344 : gv_stashpv ("CBOR::XS::Tagged" , 1);
356 345
357 HV *stash = SvSTASH (sv); 346 HV *stash = SvSTASH (sv);
358 GV *method;
359 347
360 if (stash == boolean_stash) 348 if (stash == boolean_stash)
349 {
361 encode_ch (enc, SvIV (sv) ? 0xe0 | 21 : 0xe0 | 20); 350 encode_ch (enc, SvIV (sv) ? 0xe0 | 21 : 0xe0 | 20);
351 return;
352 }
362 else if (stash == error_stash) 353 else if (stash == error_stash)
354 {
363 encode_ch (enc, 0xe0 | 23); 355 encode_ch (enc, 0xe0 | 23);
356 return;
357 }
364 else if (stash == tagged_stash) 358 else if (stash == tagged_stash)
365 { 359 {
366 if (svt != SVt_PVAV) 360 if (svt != SVt_PVAV)
367 croak ("encountered CBOR::XS::Tagged object that isn't an array"); 361 croak ("encountered CBOR::XS::Tagged object that isn't an array");
368 362
369 encode_uint (enc, 0xc0, SvUV (*av_fetch ((AV *)sv, 0, 1))); 363 encode_uint (enc, 0xc0, SvUV (*av_fetch ((AV *)sv, 0, 1)));
370 encode_sv (enc, *av_fetch ((AV *)sv, 1, 1)); 364 encode_sv (enc, *av_fetch ((AV *)sv, 1, 1));
365
366 return;
367 }
368 }
369
370 if (ecb_expect_false (SvREFCNT (sv) > 1)
371 && ecb_expect_false (enc->cbor.flags & F_ALLOW_SHARING))
372 {
373 if (!enc->shareable)
374 enc->shareable = (HV *)sv_2mortal ((SV *)newHV ());
375
376 SV **svp = hv_fetch (enc->shareable, (char *)&sv, sizeof (sv), 1);
377
378 if (SvOK (*svp))
371 } 379 {
380 encode_tag (enc, CBOR_TAG_VALUE_SHAREDREF);
381 encode_uint (enc, 0x00, SvUV (*svp));
382 return;
383 }
384 else
385 {
386 sv_setuv (*svp, enc->shareable_idx);
387 ++enc->shareable_idx;
388 encode_tag (enc, CBOR_TAG_VALUE_SHAREABLE);
389 }
390 }
391
392 if (ecb_expect_false (SvOBJECT (sv)))
393 {
394 HV *stash = SvSTASH (sv);
395 GV *method;
396
372 else if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0))) 397 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0)))
373 { 398 {
374 dSP; 399 dSP;
375 400
376 ENTER; SAVETMPS; PUSHMARK (SP); 401 ENTER; SAVETMPS; PUSHMARK (SP);
377 // we re-bless the reference to get overload and other niceties right 402 // we re-bless the reference to get overload and other niceties right
410 if (count == 1 && SvROK (TOPs) && SvRV (TOPs) == sv) 435 if (count == 1 && SvROK (TOPs) && SvRV (TOPs) == sv)
411 croak ("%s::FREEZE(CBOR) method returned same object as was passed instead of a new one", HvNAME (stash)); 436 croak ("%s::FREEZE(CBOR) method returned same object as was passed instead of a new one", HvNAME (stash));
412 437
413 encode_tag (enc, CBOR_TAG_PERL_OBJECT); 438 encode_tag (enc, CBOR_TAG_PERL_OBJECT);
414 encode_uint (enc, 0x80, count + 1); 439 encode_uint (enc, 0x80, count + 1);
415 encode_str (enc, HvNAMEUTF8 (stash), HvNAME (stash), HvNAMELEN (stash)); 440 encode_strref (enc, HvNAMEUTF8 (stash), HvNAME (stash), HvNAMELEN (stash));
416 441
417 while (count) 442 while (count)
418 encode_sv (enc, SP[1 - count--]); 443 encode_sv (enc, SP[1 - count--]);
419 444
420 PUTBACK; 445 PUTBACK;
479 504
480 if (SvPOKp (sv)) 505 if (SvPOKp (sv))
481 { 506 {
482 STRLEN len; 507 STRLEN len;
483 char *str = SvPV (sv, len); 508 char *str = SvPV (sv, len);
484 encode_str (enc, SvUTF8 (sv), str, len); 509 encode_strref (enc, SvUTF8 (sv), str, len);
485 } 510 }
486 else if (SvNOKp (sv)) 511 else if (SvNOKp (sv))
487 encode_nv (enc, sv); 512 encode_nv (enc, sv);
488 else if (SvIOKp (sv)) 513 else if (SvIOKp (sv))
489 { 514 {
515 enc.cur = SvPVX (enc.sv); 540 enc.cur = SvPVX (enc.sv);
516 enc.end = SvEND (enc.sv); 541 enc.end = SvEND (enc.sv);
517 542
518 SvPOK_only (enc.sv); 543 SvPOK_only (enc.sv);
519 544
520 if (cbor->flags & F_ALLOW_STRINGREF) 545 if (cbor->flags & F_PACK_STRINGS)
521 { 546 {
522 encode_tag (&enc, CBOR_TAG_STRINGREF_NAMESPACE); 547 encode_tag (&enc, CBOR_TAG_STRINGREF_NAMESPACE);
523 enc.stringref[0]= (HV *)sv_2mortal ((SV *)newHV ()); 548 enc.stringref[0]= (HV *)sv_2mortal ((SV *)newHV ());
524 enc.stringref[1]= (HV *)sv_2mortal ((SV *)newHV ()); 549 enc.stringref[1]= (HV *)sv_2mortal ((SV *)newHV ());
525 } 550 }
547 CBOR cbor; 572 CBOR cbor;
548 U32 depth; // recursion depth 573 U32 depth; // recursion depth
549 U32 maxdepth; // recursion depth limit 574 U32 maxdepth; // recursion depth limit
550 AV *shareable; 575 AV *shareable;
551 AV *stringref; 576 AV *stringref;
577 SV *decode_tagged;
552} dec_t; 578} dec_t;
553 579
554#define ERR(reason) SB if (!dec->err) dec->err = reason; goto fail; SE 580#define ERR(reason) SB if (!dec->err) dec->err = reason; goto fail; SE
555 581
556#define WANT(len) if (ecb_expect_false (dec->cur + len > dec->end)) ERR ("unexpected end of CBOR data") 582#define WANT(len) if (ecb_expect_false (dec->cur + len > dec->end)) ERR ("unexpected end of CBOR data")
588 | ((UV)dec->cur[-1]); 614 | ((UV)dec->cur[-1]);
589 615
590 case 27: 616 case 27:
591 WANT (9); 617 WANT (9);
592 dec->cur += 9; 618 dec->cur += 9;
619
620 return
621#if UVSIZE < 8
622 0
623#else
593 return (((UV)dec->cur[-8]) << 56) 624 (((UV)dec->cur[-8]) << 56)
594 | (((UV)dec->cur[-7]) << 48) 625 | (((UV)dec->cur[-7]) << 48)
595 | (((UV)dec->cur[-6]) << 40) 626 | (((UV)dec->cur[-6]) << 40)
596 | (((UV)dec->cur[-5]) << 32) 627 | (((UV)dec->cur[-5]) << 32)
628#endif
597 | (((UV)dec->cur[-4]) << 24) 629 | (((UV)dec->cur[-4]) << 24)
598 | (((UV)dec->cur[-3]) << 16) 630 | (((UV)dec->cur[-3]) << 16)
599 | (((UV)dec->cur[-2]) << 8) 631 | (((UV)dec->cur[-2]) << 8)
600 | ((UV)dec->cur[-1]); 632 | ((UV)dec->cur[-1]);
601 633
741{ 773{
742 SV *sv = 0; 774 SV *sv = 0;
743 775
744 if ((*dec->cur & 31) == 31) 776 if ((*dec->cur & 31) == 31)
745 { 777 {
778 // indefinite length strings
746 ++dec->cur; 779 ++dec->cur;
747 780
781 unsigned char major = *dec->cur & 0xe0;
782
748 sv = newSVpvn ("", 0); 783 sv = newSVpvn ("", 0);
749 784
750 // not very fast, and certainly not robust against illegal input
751 for (;;) 785 for (;;)
752 { 786 {
753 WANT (1); 787 WANT (1);
754 788
789 if ((*dec->cur ^ major) >= 31)
755 if (*dec->cur == (0xe0 | 31)) 790 if (*dec->cur == (0xe0 | 31))
756 { 791 {
757 ++dec->cur; 792 ++dec->cur;
758 break; 793 break;
759 } 794 }
795 else
796 ERR ("corrupted CBOR data (invalid chunks in indefinite length string)");
760 797
761 sv_catsv (sv, decode_sv (dec)); 798 STRLEN len = decode_uint (dec);
799
800 WANT (len);
801 sv_catpvn (sv, dec->cur, len);
802 dec->cur += len;
762 } 803 }
763 } 804 }
764 else 805 else
765 { 806 {
766 STRLEN len = decode_uint (dec); 807 STRLEN len = decode_uint (dec);
767 808
768 WANT (len); 809 WANT (len);
769 sv = newSVpvn (dec->cur, len); 810 sv = newSVpvn (dec->cur, len);
770 dec->cur += len; 811 dec->cur += len;
812
813 if (ecb_expect_false (dec->stringref)
814 && SvCUR (sv) >= minimum_string_length (AvFILLp (dec->stringref) + 1))
815 av_push (dec->stringref, SvREFCNT_inc_NN (sv));
771 } 816 }
772 817
773 if (utf8) 818 if (utf8)
774 SvUTF8_on (sv); 819 SvUTF8_on (sv);
775
776 if (ecb_expect_false (dec->stringref)
777 && SvCUR (sv) >= minimum_string_length (AvFILLp (dec->stringref) + 1))
778 av_push (dec->stringref, SvREFCNT_inc_NN (sv));
779 820
780 return sv; 821 return sv;
781 822
782fail: 823fail:
783 SvREFCNT_dec (sv); 824 SvREFCNT_dec (sv);
910 951
911 default: 952 default:
912 { 953 {
913 sv = decode_sv (dec); 954 sv = decode_sv (dec);
914 955
956 dSP;
957 ENTER; SAVETMPS; PUSHMARK (SP);
958 EXTEND (SP, 2);
959 PUSHs (newSVuv (tag));
960 PUSHs (sv);
961
962 PUTBACK;
963 int count = call_sv (dec->cbor.filter ? dec->cbor.filter : default_filter, G_ARRAY | G_EVAL);
964 SPAGAIN;
965
966 if (SvTRUE (ERRSV))
967 {
968 FREETMPS; LEAVE;
969 ERR (SvPVutf8_nolen (sv_2mortal (SvREFCNT_inc (ERRSV))));
970 }
971
972 if (count)
973 {
974 SvREFCNT_dec (sv);
975 sv = SvREFCNT_inc (POPs);
976 }
977 else
978 {
915 AV *av = newAV (); 979 AV *av = newAV ();
916 av_push (av, newSVuv (tag)); 980 av_push (av, newSVuv (tag));
917 av_push (av, sv); 981 av_push (av, sv);
918 982
919 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash 983 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash
920 ? cbor_tagged_stash 984 ? cbor_tagged_stash
921 : gv_stashpv ("CBOR::XS::Tagged" , 1); 985 : gv_stashpv ("CBOR::XS::Tagged" , 1);
922
923 sv = sv_bless (newRV_noinc ((SV *)av), tagged_stash); 986 sv = sv_bless (newRV_noinc ((SV *)av), tagged_stash);
987 }
988
989 PUTBACK;
990
991 FREETMPS; LEAVE;
924 } 992 }
925 break; 993 break;
926 } 994 }
927 995
928 return sv; 996 return sv;
1074 1142
1075 types_true = get_bool ("Types::Serialiser::true" ); 1143 types_true = get_bool ("Types::Serialiser::true" );
1076 types_false = get_bool ("Types::Serialiser::false"); 1144 types_false = get_bool ("Types::Serialiser::false");
1077 types_error = get_bool ("Types::Serialiser::error"); 1145 types_error = get_bool ("Types::Serialiser::error");
1078 1146
1147 default_filter = newSVpv ("CBOR::XS::default_filter", 0);
1148
1079 sv_cbor = newSVpv ("CBOR", 0); 1149 sv_cbor = newSVpv ("CBOR", 0);
1080 SvREADONLY_on (sv_cbor); 1150 SvREADONLY_on (sv_cbor);
1081} 1151}
1082 1152
1083PROTOTYPES: DISABLE 1153PROTOTYPES: DISABLE
1104void shrink (CBOR *self, int enable = 1) 1174void shrink (CBOR *self, int enable = 1)
1105 ALIAS: 1175 ALIAS:
1106 shrink = F_SHRINK 1176 shrink = F_SHRINK
1107 allow_unknown = F_ALLOW_UNKNOWN 1177 allow_unknown = F_ALLOW_UNKNOWN
1108 allow_sharing = F_ALLOW_SHARING 1178 allow_sharing = F_ALLOW_SHARING
1109 allow_stringref = F_ALLOW_STRINGREF 1179 pack_strings = F_PACK_STRINGS
1110 PPCODE: 1180 PPCODE:
1111{ 1181{
1112 if (enable) 1182 if (enable)
1113 self->flags |= ix; 1183 self->flags |= ix;
1114 else 1184 else
1120void get_shrink (CBOR *self) 1190void get_shrink (CBOR *self)
1121 ALIAS: 1191 ALIAS:
1122 get_shrink = F_SHRINK 1192 get_shrink = F_SHRINK
1123 get_allow_unknown = F_ALLOW_UNKNOWN 1193 get_allow_unknown = F_ALLOW_UNKNOWN
1124 get_allow_sharing = F_ALLOW_SHARING 1194 get_allow_sharing = F_ALLOW_SHARING
1125 get_allow_stringref = F_ALLOW_STRINGREF 1195 get_pack_strings = F_PACK_STRINGS
1126 PPCODE: 1196 PPCODE:
1127 XPUSHs (boolSV (self->flags & ix)); 1197 XPUSHs (boolSV (self->flags & ix));
1128 1198
1129void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) 1199void max_depth (CBOR *self, U32 max_depth = 0x80000000UL)
1130 PPCODE: 1200 PPCODE:
1143 XPUSHs (ST (0)); 1213 XPUSHs (ST (0));
1144 1214
1145int get_max_size (CBOR *self) 1215int get_max_size (CBOR *self)
1146 CODE: 1216 CODE:
1147 RETVAL = self->max_size; 1217 RETVAL = self->max_size;
1218 OUTPUT:
1219 RETVAL
1220
1221void filter (CBOR *self, SV *filter = 0)
1222 PPCODE:
1223 SvREFCNT_dec (self->filter);
1224 self->filter = filter ? newSVsv (filter) : filter;
1225 XPUSHs (ST (0));
1226
1227SV *get_filter (CBOR *self)
1228 CODE:
1229 RETVAL = self->filter ? self->filter : NEWSV (0, 0);
1148 OUTPUT: 1230 OUTPUT:
1149 RETVAL 1231 RETVAL
1150 1232
1151void encode (CBOR *self, SV *scalar) 1233void encode (CBOR *self, SV *scalar)
1152 PPCODE: 1234 PPCODE:
1167 EXTEND (SP, 2); 1249 EXTEND (SP, 2);
1168 PUSHs (sv); 1250 PUSHs (sv);
1169 PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr)))); 1251 PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr))));
1170} 1252}
1171 1253
1254void DESTROY (CBOR *self)
1255 PPCODE:
1256 cbor_free (self);
1257
1172PROTOTYPES: ENABLE 1258PROTOTYPES: ENABLE
1173 1259
1174void encode_cbor (SV *scalar) 1260void encode_cbor (SV *scalar)
1175 PPCODE: 1261 PPCODE:
1176{ 1262{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines