… | |
… | |
60 | #else |
60 | #else |
61 | # define CBOR_SLOW 0 |
61 | # define CBOR_SLOW 0 |
62 | # define CBOR_STASH cbor_stash |
62 | # define CBOR_STASH cbor_stash |
63 | #endif |
63 | #endif |
64 | |
64 | |
65 | static HV *cbor_stash, *cbor_boolean_stash, *cbor_tagged_stash; // CBOR::XS:: |
65 | static HV *cbor_stash, *types_boolean_stash, *types_error_stash, *cbor_tagged_stash; // CBOR::XS:: |
66 | static SV *cbor_true, *cbor_false; |
66 | static SV *types_true, *types_false, *types_error; |
67 | |
67 | |
68 | typedef struct { |
68 | typedef struct { |
69 | U32 flags; |
69 | U32 flags; |
70 | U32 max_depth; |
70 | U32 max_depth; |
71 | STRLEN max_size; |
71 | STRLEN max_size; |
… | |
… | |
259 | SvGETMAGIC (sv); |
259 | SvGETMAGIC (sv); |
260 | svt = SvTYPE (sv); |
260 | svt = SvTYPE (sv); |
261 | |
261 | |
262 | if (ecb_expect_false (SvOBJECT (sv))) |
262 | if (ecb_expect_false (SvOBJECT (sv))) |
263 | { |
263 | { |
264 | HV *boolean_stash = !CBOR_SLOW || cbor_boolean_stash |
264 | HV *boolean_stash = !CBOR_SLOW || types_boolean_stash |
265 | ? cbor_boolean_stash |
265 | ? types_boolean_stash |
266 | : gv_stashpv ("CBOR::XS::Boolean", 1); |
266 | : gv_stashpv ("Types::Serialiser::Boolean", 1); |
|
|
267 | HV *error_stash = !CBOR_SLOW || types_error_stash |
|
|
268 | ? types_error_stash |
|
|
269 | : gv_stashpv ("Types::Serialiser::Error", 1); |
267 | HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash |
270 | HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash |
268 | ? cbor_tagged_stash |
271 | ? cbor_tagged_stash |
269 | : gv_stashpv ("CBOR::XS::Tagged" , 1); |
272 | : gv_stashpv ("CBOR::XS::Tagged" , 1); |
270 | |
273 | |
271 | if (SvSTASH (sv) == boolean_stash) |
274 | if (SvSTASH (sv) == boolean_stash) |
272 | encode_ch (enc, SvIV (sv) ? 0xe0 | 21 : 0xe0 | 20); |
275 | encode_ch (enc, SvIV (sv) ? 0xe0 | 21 : 0xe0 | 20); |
|
|
276 | else if (SvSTASH (sv) == error_stash) |
|
|
277 | encode_ch (enc, 0xe0 | 23); |
273 | else if (SvSTASH (sv) == tagged_stash) |
278 | else if (SvSTASH (sv) == tagged_stash) |
274 | { |
279 | { |
275 | if (svt != SVt_PVAV) |
280 | if (svt != SVt_PVAV) |
276 | croak ("encountered CBOR::XS::Tagged object that isn't an array"); |
281 | croak ("encountered CBOR::XS::Tagged object that isn't an array"); |
277 | |
282 | |
… | |
… | |
693 | case 7: // misc |
698 | case 7: // misc |
694 | switch (*dec->cur++ & 31) |
699 | switch (*dec->cur++ & 31) |
695 | { |
700 | { |
696 | case 20: |
701 | case 20: |
697 | #if CBOR_SLOW |
702 | #if CBOR_SLOW |
698 | cbor_false = get_bool ("CBOR::XS::false"); |
703 | types_false = get_bool ("Types::Serialiser::false"); |
699 | #endif |
704 | #endif |
700 | return newSVsv (cbor_false); |
705 | return newSVsv (types_false); |
701 | case 21: |
706 | case 21: |
702 | #if CBOR_SLOW |
707 | #if CBOR_SLOW |
703 | cbor_true = get_bool ("CBOR::XS::true"); |
708 | types_true = get_bool ("Types::Serialiser::true"); |
704 | #endif |
709 | #endif |
705 | return newSVsv (cbor_true); |
710 | return newSVsv (types_true); |
706 | case 22: |
711 | case 22: |
707 | return newSVsv (&PL_sv_undef); |
712 | return newSVsv (&PL_sv_undef); |
|
|
713 | case 23: |
|
|
714 | #if CBOR_SLOW |
|
|
715 | types_error = get_bool ("Types::Serialiser::error"); |
|
|
716 | #endif |
|
|
717 | return newSVsv (types_error); |
708 | |
718 | |
709 | case 25: |
719 | case 25: |
710 | { |
720 | { |
711 | WANT (2); |
721 | WANT (2); |
712 | |
722 | |
… | |
… | |
828 | MODULE = CBOR::XS PACKAGE = CBOR::XS |
838 | MODULE = CBOR::XS PACKAGE = CBOR::XS |
829 | |
839 | |
830 | BOOT: |
840 | BOOT: |
831 | { |
841 | { |
832 | cbor_stash = gv_stashpv ("CBOR::XS" , 1); |
842 | cbor_stash = gv_stashpv ("CBOR::XS" , 1); |
833 | cbor_boolean_stash = gv_stashpv ("CBOR::XS::Boolean", 1); |
|
|
834 | cbor_tagged_stash = gv_stashpv ("CBOR::XS::Tagged" , 1); |
843 | cbor_tagged_stash = gv_stashpv ("CBOR::XS::Tagged" , 1); |
835 | |
844 | |
836 | cbor_true = get_bool ("CBOR::XS::true"); |
845 | types_boolean_stash = gv_stashpv ("Types::Serialiser::Boolean", 1); |
837 | cbor_false = get_bool ("CBOR::XS::false"); |
846 | types_error_stash = gv_stashpv ("Types::Serialiser::Error" , 1); |
|
|
847 | |
|
|
848 | types_true = get_bool ("Types::Serialiser::true" ); |
|
|
849 | types_false = get_bool ("Types::Serialiser::false"); |
|
|
850 | types_error = get_bool ("Types::Serialiser::error"); |
838 | } |
851 | } |
839 | |
852 | |
840 | PROTOTYPES: DISABLE |
853 | PROTOTYPES: DISABLE |
841 | |
854 | |
842 | void CLONE (...) |
855 | void CLONE (...) |
843 | CODE: |
856 | CODE: |
844 | cbor_stash = 0; |
857 | cbor_stash = 0; |
845 | cbor_boolean_stash = 0; |
|
|
846 | cbor_tagged_stash = 0; |
858 | cbor_tagged_stash = 0; |
|
|
859 | types_error_stash = 0; |
|
|
860 | types_boolean_stash = 0; |
847 | |
861 | |
848 | void new (char *klass) |
862 | void new (char *klass) |
849 | PPCODE: |
863 | PPCODE: |
850 | { |
864 | { |
851 | SV *pv = NEWSV (0, sizeof (CBOR)); |
865 | SV *pv = NEWSV (0, sizeof (CBOR)); |