--- JSON-XS/XS.xs 2018/08/28 16:16:17 1.133 +++ JSON-XS/XS.xs 2018/11/15 20:13:03 1.134 @@ -52,7 +52,7 @@ #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER -#define INIT_SIZE 32 // initial scalar size to be allocated +#define INIT_SIZE 64 // initial scalar size to be allocated #define INDENT_STEP 3 // spaces per indentation level #define SHORT_STRING_LEN 16384 // special-case strings of up to this size @@ -790,7 +790,6 @@ dSP; ENTER; SAVETMPS; - SAVESTACK_POS (); PUSHMARK (SP); EXTEND (SP, 2); // we re-bless the reference to get overload and other niceties right @@ -812,12 +811,18 @@ encode_ch (enc, ')'); encode_ch (enc, '['); - while (count) + if (count) { - encode_sv (enc, SP[1 - count--]); + int i; - if (count) - encode_ch (enc, ','); + for (i = 0; i < count - 1; ++i) + { + encode_sv (enc, SP[i + 1 - count]); + encode_ch (enc, ','); + } + + encode_sv (enc, TOPs); + SP -= count; } encode_ch (enc, ']'); @@ -1518,7 +1523,6 @@ int count; ENTER; SAVETMPS; - SAVESTACK_POS (); PUSHMARK (SP); XPUSHs (HeVAL (he)); sv_2mortal (sv); @@ -1531,6 +1535,8 @@ FREETMPS; LEAVE; return sv; } + else if (count) + croak ("filter_json_single_key_object callbacks must not return more than one scalar"); SvREFCNT_inc (sv); FREETMPS; LEAVE; @@ -1543,7 +1549,6 @@ int count; ENTER; SAVETMPS; - SAVESTACK_POS (); PUSHMARK (SP); XPUSHs (sv_2mortal (sv)); @@ -1555,6 +1560,8 @@ FREETMPS; LEAVE; return sv; } + else if (count) + croak ("filter_json_object callbacks must not return more than one scalar"); SvREFCNT_inc (sv); FREETMPS; LEAVE;