--- JSON-XS/XS.xs 2007/04/03 23:59:04 1.24 +++ JSON-XS/XS.xs 2007/04/06 20:37:22 1.25 @@ -410,7 +410,6 @@ } else { - SV *sv; HE *he = hv_iternext (hv); for (;;) @@ -435,9 +434,10 @@ static void encode_rv (enc_t *enc, SV *sv) { - SvGETMAGIC (sv); + svtype svt; - svtype svt = SvTYPE (sv); + SvGETMAGIC (sv); + svt = SvTYPE (sv); if (svt == SVt_PVHV) encode_hv (enc, (HV *)sv); @@ -497,10 +497,11 @@ static SV * encode_json (SV *scalar, U32 flags) { + enc_t enc; + if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); - enc_t enc; enc.flags = flags; enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); enc.cur = SvPVX (enc.sv); @@ -672,10 +673,12 @@ *cur++ = ch; else if (ch >= 0x80) { + STRLEN clen; + UV uch; + --dec->cur; - STRLEN clen; - UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); + uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); if (clen == (STRLEN)-1) ERR ("malformed UTF-8 character in JSON string"); @@ -697,16 +700,18 @@ } while (cur < buf + SHORT_STRING_LEN); - STRLEN len = cur - buf; + { + STRLEN len = cur - buf; - if (sv) - { - SvGROW (sv, SvCUR (sv) + len + 1); - memcpy (SvPVX (sv) + SvCUR (sv), buf, len); - SvCUR_set (sv, SvCUR (sv) + len); - } - else - sv = newSVpvn (buf, len); + if (sv) + { + SvGROW (sv, SvCUR (sv) + len + 1); + memcpy (SvPVX (sv) + SvCUR (sv), buf, len); + SvCUR_set (sv, SvCUR (sv) + len); + } + else + sv = newSVpvn (buf, len); + } } while (*dec->cur != '"'); @@ -971,6 +976,7 @@ static SV * decode_json (SV *string, U32 flags) { + dec_t dec; SV *sv; SvUPGRADE (string, SVt_PV); @@ -982,7 +988,6 @@ SvGROW (string, SvCUR (string) + 1); // should basically be a NOP - dec_t dec; dec.flags = flags; dec.cur = SvPVX (string); dec.end = SvEND (string); @@ -1076,7 +1081,7 @@ OUTPUT: RETVAL -SV *max_depth (SV *self, int max_depth = 0x80000000UL) +SV *max_depth (SV *self, UV max_depth = 0x80000000UL) CODE: { UV *uv = SvJSON (self);