--- cvsroot/CBOR-XS/XS.xs 2016/11/26 02:11:52 1.62 +++ cvsroot/CBOR-XS/XS.xs 2016/11/26 04:50:58 1.63 @@ -23,6 +23,9 @@ #ifndef HvNAMEUTF8 # define HvNAMEUTF8(hv) 0 #endif +#ifndef SvREFCNT_inc_NN +# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) +#endif #ifndef SvREFCNT_dec_NN # define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) #endif @@ -356,7 +359,7 @@ encode_uint (enc, MAJOR_ARRAY, len + 1); - if (SvMAGICAL (av)) + if (ecb_expect_false (SvMAGICAL (av))) for (i = 0; i <= len; ++i) { SV **svp = av_fetch (av, i, 0); @@ -385,7 +388,7 @@ int pairs = hv_iterinit (hv); int mg = SvMAGICAL (hv); - if (mg) + if (ecb_expect_false (mg)) encode_ch (enc, MAJOR_MAP | MINOR_INDEF); else encode_uint (enc, MAJOR_MAP, pairs); @@ -400,7 +403,7 @@ encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he)); } - if (mg) + if (ecb_expect_false (mg)) encode_ch (enc, MAJOR_MISC | MINOR_INDEF); --enc->depth; @@ -453,7 +456,7 @@ if (ecb_expect_false (SvREFCNT (sv) > 1) && ecb_expect_false (enc->cbor.flags & F_ALLOW_SHARING)) { - if (!enc->shareable) + if (ecb_expect_false (!enc->shareable)) enc->shareable = (HV *)sv_2mortal ((SV *)newHV ()); SV **svp = hv_fetch (enc->shareable, (char *)&sv, sizeof (sv), 1); @@ -562,10 +565,10 @@ //TODO: maybe I32? else if (ecb_expect_false (nv == (float)nv)) { - uint32_t fp = ecb_float_to_binary32 (nv); - *enc->cur++ = MAJOR_MISC | MISC_FLOAT32; + uint32_t fp = ecb_float_to_binary32 (nv); + if (!ecb_big_endian ()) fp = ecb_bswap32 (fp); @@ -574,10 +577,10 @@ } else { - uint64_t fp = ecb_double_to_binary64 (nv); - *enc->cur++ = MAJOR_MISC | MISC_FLOAT64; + uint64_t fp = ecb_double_to_binary64 (nv); + if (!ecb_big_endian ()) fp = ecb_bswap64 (fp); @@ -624,10 +627,10 @@ { enc_t enc = { 0 }; - enc.cbor = *cbor; - enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); - enc.cur = SvPVX (enc.sv); - enc.end = SvEND (enc.sv); + enc.cbor = *cbor; + enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); + enc.cur = SvPVX (enc.sv); + enc.end = SvEND (enc.sv); SvPOK_only (enc.sv); @@ -697,12 +700,6 @@ err_set (dec, "unexpected end of CBOR data"); } -ecb_cold static void -err_nesting_exceeded (dec_t *dec) -{ - err_set (dec, ERR_NESTING_EXCEEDED); -} - #define ERR_DO(do) SB do; goto fail; SE #define ERR(reason) ERR_DO (err_set (dec, reason)) #define ERR_ERRSV ERR_DO (err_errsv (dec)) @@ -809,7 +806,7 @@ return newRV_noinc ((SV *)av); fail: - SvREFCNT_dec (av); + SvREFCNT_dec_NN (av); DEC_DEC_DEPTH; return &PL_sv_undef; } @@ -882,7 +879,7 @@ } hv_store_ent (hv, k, v, 0); - SvREFCNT_dec (k); + SvREFCNT_dec_NN (k); fail: ; @@ -926,7 +923,7 @@ return newRV_noinc ((SV *)hv); fail: - SvREFCNT_dec (hv); + SvREFCNT_dec_NN (hv); DEC_DEC_DEPTH; return &PL_sv_undef; } @@ -936,7 +933,7 @@ { SV *sv = 0; - if ((*dec->cur & MINOR_MASK) == MINOR_INDEF) + if (ecb_expect_false ((*dec->cur & MINOR_MASK) == MINOR_INDEF)) { // indefinite length strings ++dec->cur; @@ -1014,7 +1011,7 @@ case CBOR_TAG_STRINGREF_NAMESPACE: { - // do nmot use SAVETMPS/FREETMPS, as these will + // do not use SAVETMPS/FREETMPS, as these will // erase mortalised caches, e.g. "shareable" ENTER; @@ -1128,7 +1125,7 @@ ERR_ERRSV; } - SvREFCNT_dec (sv); + SvREFCNT_dec_NN (sv); sv = SvREFCNT_inc (POPs); PUTBACK; @@ -1158,16 +1155,16 @@ if (SvTRUE (ERRSV)) { - SvREFCNT_dec (tag_sv); + SvREFCNT_dec_NN (tag_sv); FREETMPS; LEAVE; ERR_ERRSV; } if (count) { - SvREFCNT_dec (tag_sv); - SvREFCNT_dec (sv); - sv = SvREFCNT_inc (POPs); + SvREFCNT_dec_NN (tag_sv); + SvREFCNT_dec_NN (sv); + sv = SvREFCNT_inc_NN (POPs); } else { @@ -1320,7 +1317,7 @@ sv_setsv (*svp, &PL_sv_undef); } - SvREFCNT_dec (sv); + SvREFCNT_dec_NN (sv); if (dec.err_sv) sv_2mortal (dec.err_sv);