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.11 by root, Sun Oct 27 22:35:15 2013 UTC vs.
Revision 1.15 by root, Tue Oct 29 18:37:31 2013 UTC

8#include <stdio.h> 8#include <stdio.h>
9#include <limits.h> 9#include <limits.h>
10#include <float.h> 10#include <float.h>
11 11
12#include "ecb.h" 12#include "ecb.h"
13
14// compatibility with perl <5.18
15#ifndef HvNAMELEN_get
16# define HvNAMELEN_get(hv) strlen (HvNAME (hv))
17#endif
18#ifndef HvNAMELEN
19# define HvNAMELEN(hv) HvNAMELEN_get (hv)
20#endif
21#ifndef HvNAMEUTF8
22# define HvNAMEUTF8(hv) 0
23#endif
13 24
14// known tags 25// known tags
15enum cbor_tag 26enum cbor_tag
16{ 27{
17 // inofficial extensions (pending iana registration) 28 // inofficial extensions (pending iana registration)
598 609
599 SV *k = decode_sv (dec); 610 SV *k = decode_sv (dec);
600 SV *v = decode_sv (dec); 611 SV *v = decode_sv (dec);
601 612
602 hv_store_ent (hv, k, v, 0); 613 hv_store_ent (hv, k, v, 0);
614 SvREFCNT_dec (k);
603 } 615 }
604 } 616 }
605 else 617 else
606 { 618 {
607 int len = decode_uint (dec); 619 int len = decode_uint (dec);
610 { 622 {
611 SV *k = decode_sv (dec); 623 SV *k = decode_sv (dec);
612 SV *v = decode_sv (dec); 624 SV *v = decode_sv (dec);
613 625
614 hv_store_ent (hv, k, v, 0); 626 hv_store_ent (hv, k, v, 0);
627 SvREFCNT_dec (k);
615 } 628 }
616 } 629 }
617 630
618 DEC_DEC_DEPTH; 631 DEC_DEC_DEPTH;
619 return newRV_noinc ((SV *)hv); 632 return newRV_noinc ((SV *)hv);
708 721
709 PUTBACK; 722 PUTBACK;
710 call_sv ((SV *)GvCV (method), G_SCALAR); 723 call_sv ((SV *)GvCV (method), G_SCALAR);
711 SPAGAIN; 724 SPAGAIN;
712 725
726 SvREFCNT_dec (sv);
713 sv = SvREFCNT_inc (POPs); 727 sv = SvREFCNT_inc (POPs);
714 728
715 PUTBACK; 729 PUTBACK;
716 730
717 FREETMPS; LEAVE; 731 FREETMPS; LEAVE;
977 CODE: 991 CODE:
978 RETVAL = self->max_size; 992 RETVAL = self->max_size;
979 OUTPUT: 993 OUTPUT:
980 RETVAL 994 RETVAL
981 995
982#if 0 //TODO
983
984void filter_cbor_object (CBOR *self, SV *cb = &PL_sv_undef)
985 PPCODE:
986{
987 SvREFCNT_dec (self->cb_object);
988 self->cb_object = SvOK (cb) ? newSVsv (cb) : 0;
989
990 XPUSHs (ST (0));
991}
992
993void filter_cbor_single_key_object (CBOR *self, SV *key, SV *cb = &PL_sv_undef)
994 PPCODE:
995{
996 if (!self->cb_sk_object)
997 self->cb_sk_object = newHV ();
998
999 if (SvOK (cb))
1000 hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0);
1001 else
1002 {
1003 hv_delete_ent (self->cb_sk_object, key, G_DISCARD, 0);
1004
1005 if (!HvKEYS (self->cb_sk_object))
1006 {
1007 SvREFCNT_dec (self->cb_sk_object);
1008 self->cb_sk_object = 0;
1009 }
1010 }
1011
1012 XPUSHs (ST (0));
1013}
1014
1015#endif
1016
1017void encode (CBOR *self, SV *scalar) 996void encode (CBOR *self, SV *scalar)
1018 PPCODE: 997 PPCODE:
1019 PUTBACK; scalar = encode_cbor (scalar, self); SPAGAIN; 998 PUTBACK; scalar = encode_cbor (scalar, self); SPAGAIN;
1020 XPUSHs (scalar); 999 XPUSHs (scalar);
1021 1000
1033 EXTEND (SP, 2); 1012 EXTEND (SP, 2);
1034 PUSHs (sv); 1013 PUSHs (sv);
1035 PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr)))); 1014 PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr))));
1036} 1015}
1037 1016
1038#if 0
1039
1040void DESTROY (CBOR *self)
1041 CODE:
1042 SvREFCNT_dec (self->cb_sk_object);
1043 SvREFCNT_dec (self->cb_object);
1044
1045#endif
1046
1047PROTOTYPES: ENABLE 1017PROTOTYPES: ENABLE
1048 1018
1049void encode_cbor (SV *scalar) 1019void encode_cbor (SV *scalar)
1050 PPCODE: 1020 PPCODE:
1051{ 1021{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines