--- JSON-XS/XS.xs 2008/05/27 05:31:39 1.86 +++ JSON-XS/XS.xs 2008/07/19 04:21:32 1.89 @@ -81,7 +81,7 @@ INCR_M_JSON // outside anything, count nesting }; -#define INCR_DONE(json) (!(json)->incr_nest && (json)->incr_mode == INCR_M_JSON) +#define INCR_DONE(json) ((json)->incr_nest <= 0 && (json)->incr_mode == INCR_M_JSON) typedef struct { U32 flags; @@ -94,7 +94,7 @@ // for the incremental parser SV *incr_text; // the source text so far STRLEN incr_pos; // the current offset into the text - unsigned char incr_nest; // {[]}-nesting level + int incr_nest; // {[]}-nesting level unsigned char incr_mode; } JSON; @@ -123,6 +123,7 @@ shrink (SV *sv) { sv_utf8_downgrade (sv, 1); + if (SvLEN (sv) > SvCUR (sv) + 1) { #ifdef SvPV_shrink_to_cur @@ -1415,6 +1416,17 @@ SvGETMAGIC (string); SvUPGRADE (string, SVt_PV); + /* work around a bug in perl 5.10, which causes SvCUR to fail an + * assertion with -DDEBUGGING, although SvCUR is documented to + * return the xpv_cur field which certainly exists after upgrading. + * according to nicholas clark, calling SvPOK fixes this. + * But it doesn't fix it, so try another workaround, call SvPV_nolen + * and hope for the best. + */ +#ifdef DEBUGGING + SvPV_nolen (string); +#endif + if (SvCUR (string) > json->max_size && json->max_size) croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", (unsigned long)SvCUR (string), (unsigned long)json->max_size); @@ -1592,7 +1604,7 @@ case ']': case '}': - if (!--self->incr_nest) + if (--self->incr_nest <= 0) goto interrupt; } }