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.46 by root, Sun Dec 14 05:57:22 2014 UTC vs.
Revision 1.50 by root, Thu Feb 25 02:29:22 2016 UTC

449 449
450 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0))) 450 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0)))
451 { 451 {
452 dSP; 452 dSP;
453 453
454 ENTER; SAVETMPS; PUSHMARK (SP); 454 ENTER; SAVETMPS;
455 PUSHMARK (SP);
455 // we re-bless the reference to get overload and other niceties right 456 // we re-bless the reference to get overload and other niceties right
456 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 457 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
457 458
458 PUTBACK; 459 PUTBACK;
459 // G_SCALAR ensures that return value is 1 460 // G_SCALAR ensures that return value is 1
472 } 473 }
473 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0) 474 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0)
474 { 475 {
475 dSP; 476 dSP;
476 477
477 ENTER; SAVETMPS; PUSHMARK (SP); 478 ENTER; SAVETMPS;
479 SAVESTACK_POS ();
480 PUSHMARK (SP);
478 EXTEND (SP, 2); 481 EXTEND (SP, 2);
479 // we re-bless the reference to get overload and other niceties right 482 // we re-bless the reference to get overload and other niceties right
480 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 483 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
481 PUSHs (sv_cbor); 484 PUSHs (sv_cbor);
482 485
584} 587}
585 588
586static SV * 589static SV *
587encode_cbor (SV *scalar, CBOR *cbor) 590encode_cbor (SV *scalar, CBOR *cbor)
588{ 591{
589 enc_t enc = { }; 592 enc_t enc = { 0 };
590 593
591 enc.cbor = *cbor; 594 enc.cbor = *cbor;
592 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 595 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
593 enc.cur = SvPVX (enc.sv); 596 enc.cur = SvPVX (enc.sv);
594 enc.end = SvEND (enc.sv); 597 enc.end = SvEND (enc.sv);
749 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) 752 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8))
750 { 753 {
751 I32 len = decode_uint (dec); 754 I32 len = decode_uint (dec);
752 char *key = (char *)dec->cur; 755 char *key = (char *)dec->cur;
753 756
757 WANT (len);
754 dec->cur += len; 758 dec->cur += len;
755 759
756 hv_store (hv, key, len, decode_sv (dec), 0); 760 hv_store (hv, key, len, decode_sv (dec), 0);
757 761
758 return; 762 return;
759 } 763 }
760 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) 764 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8))
761 { 765 {
762 I32 len = decode_uint (dec); 766 I32 len = decode_uint (dec);
763 char *key = (char *)dec->cur; 767 char *key = (char *)dec->cur;
764 768
769 WANT (len);
765 dec->cur += len; 770 dec->cur += len;
766 771
767 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) 772 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
768 if (!is_utf8_string (key, len)) 773 if (!is_utf8_string (key, len))
769 ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); 774 ERR ("corrupted CBOR data (invalid UTF-8 in map key)");
992 if (!method) 997 if (!method)
993 ERR ("cannot decode perl-object (package does not have a THAW method)"); 998 ERR ("cannot decode perl-object (package does not have a THAW method)");
994 999
995 dSP; 1000 dSP;
996 1001
997 ENTER; SAVETMPS; PUSHMARK (SP); 1002 ENTER; SAVETMPS;
1003 PUSHMARK (SP);
998 EXTEND (SP, len + 1); 1004 EXTEND (SP, len + 1);
999 // we re-bless the reference to get overload and other niceties right 1005 // we re-bless the reference to get overload and other niceties right
1000 PUSHs (*av_fetch (av, 0, 1)); 1006 PUSHs (*av_fetch (av, 0, 1));
1001 PUSHs (sv_cbor); 1007 PUSHs (sv_cbor);
1002 1008
1027 default: 1033 default:
1028 { 1034 {
1029 sv = decode_sv (dec); 1035 sv = decode_sv (dec);
1030 1036
1031 dSP; 1037 dSP;
1032 ENTER; SAVETMPS; PUSHMARK (SP); 1038 ENTER; SAVETMPS;
1039 SAVESTACK_POS ();
1040 PUSHMARK (SP);
1033 EXTEND (SP, 2); 1041 EXTEND (SP, 2);
1034 PUSHs (newSVuv (tag)); 1042 PUSHs (newSVuv (tag));
1035 PUSHs (sv); 1043 PUSHs (sv);
1036 1044
1037 PUTBACK; 1045 PUTBACK;
1163} 1171}
1164 1172
1165static SV * 1173static SV *
1166decode_cbor (SV *string, CBOR *cbor, char **offset_return) 1174decode_cbor (SV *string, CBOR *cbor, char **offset_return)
1167{ 1175{
1168 dec_t dec = { }; 1176 dec_t dec = { 0 };
1169 SV *sv; 1177 SV *sv;
1170 STRLEN len; 1178 STRLEN len;
1171 char *data = SvPVbyte (string, len); 1179 char *data = SvPVbyte (string, len);
1172 1180
1173 if (len > cbor->max_size && cbor->max_size) 1181 if (len > cbor->max_size && cbor->max_size)
1264 1272
1265 int major = *p >> MAJOR_SHIFT; 1273 int major = *p >> MAJOR_SHIFT;
1266 1274
1267 switch (major) 1275 switch (major)
1268 { 1276 {
1277 case MAJOR_TAG >> MAJOR_SHIFT:
1278 ++count; // tags merely prefix another value
1279 break;
1280
1269 case MAJOR_BYTES >> MAJOR_SHIFT: 1281 case MAJOR_BYTES >> MAJOR_SHIFT:
1270 case MAJOR_TEXT >> MAJOR_SHIFT: 1282 case MAJOR_TEXT >> MAJOR_SHIFT:
1271 case MAJOR_ARRAY >> MAJOR_SHIFT: 1283 case MAJOR_ARRAY >> MAJOR_SHIFT:
1272 case MAJOR_MAP >> MAJOR_SHIFT: 1284 case MAJOR_MAP >> MAJOR_SHIFT:
1273 { 1285 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines