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.44 by root, Tue Feb 18 22:12:12 2014 UTC vs.
Revision 1.50 by root, Thu Feb 25 02:29:22 2016 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines