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

332 SV **svp = av_fetch (av, i, 0); 332 SV **svp = av_fetch (av, i, 0);
333 encode_sv (enc, svp ? *svp : &PL_sv_undef); 333 encode_sv (enc, svp ? *svp : &PL_sv_undef);
334 } 334 }
335 else 335 else
336 for (i = 0; i <= len; ++i) 336 for (i = 0; i <= len; ++i)
337 encode_sv (enc, AvARRAY (av)[i]); 337 {
338 SV *sv = AvARRAY (av)[i];
339 encode_sv (enc, sv ? sv : &PL_sv_undef);
340 }
338 341
339 --enc->depth; 342 --enc->depth;
340} 343}
341 344
342static void 345static void
446 449
447 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0))) 450 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0)))
448 { 451 {
449 dSP; 452 dSP;
450 453
451 ENTER; SAVETMPS; PUSHMARK (SP); 454 ENTER; SAVETMPS;
455 PUSHMARK (SP);
452 // 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
453 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 457 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
454 458
455 PUTBACK; 459 PUTBACK;
456 // G_SCALAR ensures that return value is 1 460 // G_SCALAR ensures that return value is 1
469 } 473 }
470 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0) 474 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0)
471 { 475 {
472 dSP; 476 dSP;
473 477
474 ENTER; SAVETMPS; PUSHMARK (SP); 478 ENTER; SAVETMPS;
479 SAVESTACK_POS ();
480 PUSHMARK (SP);
475 EXTEND (SP, 2); 481 EXTEND (SP, 2);
476 // 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
477 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 483 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
478 PUSHs (sv_cbor); 484 PUSHs (sv_cbor);
479 485
581} 587}
582 588
583static SV * 589static SV *
584encode_cbor (SV *scalar, CBOR *cbor) 590encode_cbor (SV *scalar, CBOR *cbor)
585{ 591{
586 enc_t enc = { }; 592 enc_t enc = { 0 };
587 593
588 enc.cbor = *cbor; 594 enc.cbor = *cbor;
589 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 595 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
590 enc.cur = SvPVX (enc.sv); 596 enc.cur = SvPVX (enc.sv);
591 enc.end = SvEND (enc.sv); 597 enc.end = SvEND (enc.sv);
746 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) 752 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8))
747 { 753 {
748 I32 len = decode_uint (dec); 754 I32 len = decode_uint (dec);
749 char *key = (char *)dec->cur; 755 char *key = (char *)dec->cur;
750 756
757 WANT (len);
751 dec->cur += len; 758 dec->cur += len;
752 759
753 hv_store (hv, key, len, decode_sv (dec), 0); 760 hv_store (hv, key, len, decode_sv (dec), 0);
754 761
755 return; 762 return;
756 } 763 }
757 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))
758 { 765 {
759 I32 len = decode_uint (dec); 766 I32 len = decode_uint (dec);
760 char *key = (char *)dec->cur; 767 char *key = (char *)dec->cur;
761 768
769 WANT (len);
762 dec->cur += len; 770 dec->cur += len;
763 771
764 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) 772 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
765 if (!is_utf8_string (key, len)) 773 if (!is_utf8_string (key, len))
766 ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); 774 ERR ("corrupted CBOR data (invalid UTF-8 in map key)");
989 if (!method) 997 if (!method)
990 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)");
991 999
992 dSP; 1000 dSP;
993 1001
994 ENTER; SAVETMPS; PUSHMARK (SP); 1002 ENTER; SAVETMPS;
1003 PUSHMARK (SP);
995 EXTEND (SP, len + 1); 1004 EXTEND (SP, len + 1);
996 // 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
997 PUSHs (*av_fetch (av, 0, 1)); 1006 PUSHs (*av_fetch (av, 0, 1));
998 PUSHs (sv_cbor); 1007 PUSHs (sv_cbor);
999 1008
1024 default: 1033 default:
1025 { 1034 {
1026 sv = decode_sv (dec); 1035 sv = decode_sv (dec);
1027 1036
1028 dSP; 1037 dSP;
1029 ENTER; SAVETMPS; PUSHMARK (SP); 1038 ENTER; SAVETMPS;
1039 SAVESTACK_POS ();
1040 PUSHMARK (SP);
1030 EXTEND (SP, 2); 1041 EXTEND (SP, 2);
1031 PUSHs (newSVuv (tag)); 1042 PUSHs (newSVuv (tag));
1032 PUSHs (sv); 1043 PUSHs (sv);
1033 1044
1034 PUTBACK; 1045 PUTBACK;
1160} 1171}
1161 1172
1162static SV * 1173static SV *
1163decode_cbor (SV *string, CBOR *cbor, char **offset_return) 1174decode_cbor (SV *string, CBOR *cbor, char **offset_return)
1164{ 1175{
1165 dec_t dec = { }; 1176 dec_t dec = { 0 };
1166 SV *sv; 1177 SV *sv;
1167 STRLEN len; 1178 STRLEN len;
1168 char *data = SvPVbyte (string, len); 1179 char *data = SvPVbyte (string, len);
1169 1180
1170 if (len > cbor->max_size && cbor->max_size) 1181 if (len > cbor->max_size && cbor->max_size)
1261 1272
1262 int major = *p >> MAJOR_SHIFT; 1273 int major = *p >> MAJOR_SHIFT;
1263 1274
1264 switch (major) 1275 switch (major)
1265 { 1276 {
1277 case MAJOR_TAG >> MAJOR_SHIFT:
1278 ++count; // tags merely prefix another value
1279 break;
1280
1266 case MAJOR_BYTES >> MAJOR_SHIFT: 1281 case MAJOR_BYTES >> MAJOR_SHIFT:
1267 case MAJOR_TEXT >> MAJOR_SHIFT: 1282 case MAJOR_TEXT >> MAJOR_SHIFT:
1268 case MAJOR_ARRAY >> MAJOR_SHIFT: 1283 case MAJOR_ARRAY >> MAJOR_SHIFT:
1269 case MAJOR_MAP >> MAJOR_SHIFT: 1284 case MAJOR_MAP >> MAJOR_SHIFT:
1270 { 1285 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines