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.51 by root, Sun Apr 24 13:15:19 2016 UTC

100#define F_SHRINK 0x00000001UL 100#define F_SHRINK 0x00000001UL
101#define F_ALLOW_UNKNOWN 0x00000002UL 101#define F_ALLOW_UNKNOWN 0x00000002UL
102#define F_ALLOW_SHARING 0x00000004UL 102#define F_ALLOW_SHARING 0x00000004UL
103#define F_ALLOW_CYCLES 0x00000008UL 103#define F_ALLOW_CYCLES 0x00000008UL
104#define F_PACK_STRINGS 0x00000010UL 104#define F_PACK_STRINGS 0x00000010UL
105#define F_UTF8_STRINGS 0x00000020UL
105#define F_VALIDATE_UTF8 0x00000020UL 106#define F_VALIDATE_UTF8 0x00000040UL
106 107
107#define INIT_SIZE 32 // initial scalar size to be allocated 108#define INIT_SIZE 32 // initial scalar size to be allocated
108 109
109#define SB do { 110#define SB do {
110#define SE } while (0) 111#define SE } while (0)
279} 280}
280 281
281ecb_inline void 282ecb_inline void
282encode_str (enc_t *enc, int utf8, char *str, STRLEN len) 283encode_str (enc_t *enc, int utf8, char *str, STRLEN len)
283{ 284{
285 if (ecb_expect_false (enc->cbor.flags & F_UTF8_STRINGS))
286 if (!utf8)
287 {
288 SV *sv = sv_newmortal ();
289 char *s; STRLEN l;
290
291 sv_setpvn (sv, str, len);
292
293 s = SvPVutf8 (sv, l);
294 encode_str (enc, 1, s, l);
295 return;
296 }
297
284 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len); 298 encode_uint (enc, utf8 ? MAJOR_TEXT : MAJOR_BYTES, len);
285 need (enc, len); 299 need (enc, len);
286 memcpy (enc->cur, str, len); 300 memcpy (enc->cur, str, len);
287 enc->cur += len; 301 enc->cur += len;
288} 302}
449 463
450 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0))) 464 if ((method = gv_fetchmethod_autoload (stash, "TO_CBOR", 0)))
451 { 465 {
452 dSP; 466 dSP;
453 467
454 ENTER; SAVETMPS; PUSHMARK (SP); 468 ENTER; SAVETMPS;
469 PUSHMARK (SP);
455 // we re-bless the reference to get overload and other niceties right 470 // we re-bless the reference to get overload and other niceties right
456 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 471 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
457 472
458 PUTBACK; 473 PUTBACK;
459 // G_SCALAR ensures that return value is 1 474 // G_SCALAR ensures that return value is 1
472 } 487 }
473 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0) 488 else if ((method = gv_fetchmethod_autoload (stash, "FREEZE", 0)) != 0)
474 { 489 {
475 dSP; 490 dSP;
476 491
477 ENTER; SAVETMPS; PUSHMARK (SP); 492 ENTER; SAVETMPS;
493 SAVESTACK_POS ();
494 PUSHMARK (SP);
478 EXTEND (SP, 2); 495 EXTEND (SP, 2);
479 // we re-bless the reference to get overload and other niceties right 496 // we re-bless the reference to get overload and other niceties right
480 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash)); 497 PUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), stash));
481 PUSHs (sv_cbor); 498 PUSHs (sv_cbor);
482 499
994 if (!method) 1011 if (!method)
995 ERR ("cannot decode perl-object (package does not have a THAW method)"); 1012 ERR ("cannot decode perl-object (package does not have a THAW method)");
996 1013
997 dSP; 1014 dSP;
998 1015
999 ENTER; SAVETMPS; PUSHMARK (SP); 1016 ENTER; SAVETMPS;
1017 PUSHMARK (SP);
1000 EXTEND (SP, len + 1); 1018 EXTEND (SP, len + 1);
1001 // we re-bless the reference to get overload and other niceties right 1019 // we re-bless the reference to get overload and other niceties right
1002 PUSHs (*av_fetch (av, 0, 1)); 1020 PUSHs (*av_fetch (av, 0, 1));
1003 PUSHs (sv_cbor); 1021 PUSHs (sv_cbor);
1004 1022
1029 default: 1047 default:
1030 { 1048 {
1031 sv = decode_sv (dec); 1049 sv = decode_sv (dec);
1032 1050
1033 dSP; 1051 dSP;
1034 ENTER; SAVETMPS; PUSHMARK (SP); 1052 ENTER; SAVETMPS;
1053 SAVESTACK_POS ();
1054 PUSHMARK (SP);
1035 EXTEND (SP, 2); 1055 EXTEND (SP, 2);
1036 PUSHs (newSVuv (tag)); 1056 PUSHs (newSVuv (tag));
1037 PUSHs (sv); 1057 PUSHs (sv);
1038 1058
1039 PUTBACK; 1059 PUTBACK;
1384 shrink = F_SHRINK 1404 shrink = F_SHRINK
1385 allow_unknown = F_ALLOW_UNKNOWN 1405 allow_unknown = F_ALLOW_UNKNOWN
1386 allow_sharing = F_ALLOW_SHARING 1406 allow_sharing = F_ALLOW_SHARING
1387 allow_cycles = F_ALLOW_CYCLES 1407 allow_cycles = F_ALLOW_CYCLES
1388 pack_strings = F_PACK_STRINGS 1408 pack_strings = F_PACK_STRINGS
1409 utf8_strings = F_UTF8_STRINGS
1389 validate_utf8 = F_VALIDATE_UTF8 1410 validate_utf8 = F_VALIDATE_UTF8
1390 PPCODE: 1411 PPCODE:
1391{ 1412{
1392 if (enable) 1413 if (enable)
1393 self->flags |= ix; 1414 self->flags |= ix;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines