ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.xs
(Generate patch)

Comparing JSON-XS/XS.xs (file contents):
Revision 1.138 by root, Wed Mar 6 07:21:17 2019 UTC vs.
Revision 1.144 by root, Wed Nov 9 11:47:12 2022 UTC

162#endif 162#endif
163 } 163 }
164} 164}
165 165
166/* adds two STRLENs together, slow, and with paranoia */ 166/* adds two STRLENs together, slow, and with paranoia */
167STRLEN 167static STRLEN
168strlen_sum (STRLEN l1, STRLEN l2) 168strlen_sum (STRLEN l1, STRLEN l2)
169{ 169{
170 size_t sum = l1 + l2; 170 size_t sum = l1 + l2;
171 171
172 if (sum < (size_t)l2 || sum != (size_t)(STRLEN)sum) 172 if (sum < (size_t)l2 || sum != (size_t)(STRLEN)sum)
826 826
827 encode_sv (enc, TOPs); 827 encode_sv (enc, TOPs);
828 SP -= count; 828 SP -= count;
829 } 829 }
830 830
831 PUTBACK;
832
831 encode_ch (enc, ']'); 833 encode_ch (enc, ']');
832 834
833 FREETMPS; LEAVE; 835 FREETMPS; LEAVE;
834 } 836 }
835 else if ((enc->json.flags & F_CONV_BLESSED) && (method = gv_fetchmethod_autoload (stash, "TO_JSON", 0))) 837 else if ((enc->json.flags & F_CONV_BLESSED) && (method = gv_fetchmethod_autoload (stash, "TO_JSON", 0)))
916 if (SvIsUV (sv) ? SvUVX (sv) <= 59000 918 if (SvIsUV (sv) ? SvUVX (sv) <= 59000
917 : SvIVX (sv) <= 59000 && SvIVX (sv) >= -59000) 919 : SvIVX (sv) <= 59000 && SvIVX (sv) >= -59000)
918 { 920 {
919 // optimise the "small number case" 921 // optimise the "small number case"
920 // code will likely be branchless and use only a single multiplication 922 // code will likely be branchless and use only a single multiplication
921 // works for numbers up to 59074 923 // 4.28 works for numbers up to 59074
922 I32 i = SvIVX (sv); 924 I32 i = SvIVX (sv);
923 U32 u; 925 U32 u;
924 char digit, nz = 0; 926 char digit, nz = 0;
925 927
926 need (enc, 6); 928 need (enc, 6);
927 929
928 *enc->cur = '-'; enc->cur += i < 0 ? 1 : 0; 930 *enc->cur = '-'; enc->cur += i < 0 ? 1 : 0;
929 u = i < 0 ? -i : i; 931 u = i < 0 ? -i : i; // not undefined due to range check above
930 932
931 // convert to 4.28 fixed-point representation 933 // convert to 4.28 fixed-point representation
932 u = u * ((0xfffffff + 10000) / 10000); // 10**5, 5 fractional digits 934 u = u * ((0xfffffff + 10000) / 10000); // 10**5, 5 fractional digits
933 935
934 // now output digit by digit, each time masking out the integer part 936 // now output digit by digit, each time masking out the integer part
1036 else 1038 else
1037 break; 1039 break;
1038 } 1040 }
1039 else if (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09) 1041 else if (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)
1040 break; // parse error, but let higher level handle it, gives better error messages 1042 break; // parse error, but let higher level handle it, gives better error messages
1041 1043 else
1042 ++dec->cur; 1044 ++dec->cur;
1043 } 1045 }
1044} 1046}
1045 1047
1046#define ERR(reason) SB dec->err = reason; goto fail; SE 1048#define ERR(reason) SB dec->err = reason; goto fail; SE
1047 1049
1533 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; 1535 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN;
1534 1536
1535 if (count == 1) 1537 if (count == 1)
1536 { 1538 {
1537 sv = newSVsv (POPs); 1539 sv = newSVsv (POPs);
1540 PUTBACK;
1538 FREETMPS; LEAVE; 1541 FREETMPS; LEAVE;
1539 return sv; 1542 return sv;
1540 } 1543 }
1541 else if (count) 1544 else if (count)
1542 croak ("filter_json_single_key_object callbacks must not return more than one scalar"); 1545 croak ("filter_json_single_key_object callbacks must not return more than one scalar");
1543 1546
1547 PUTBACK;
1548
1544 SvREFCNT_inc (sv); 1549 SvREFCNT_inc (sv);
1550
1545 FREETMPS; LEAVE; 1551 FREETMPS; LEAVE;
1546 } 1552 }
1547 } 1553 }
1548 1554
1549 if (dec->json.cb_object) 1555 if (dec->json.cb_object)
1561 sv = newSVsv (POPs); 1567 sv = newSVsv (POPs);
1562 else if (count == 0) 1568 else if (count == 0)
1563 SvREFCNT_inc (sv); 1569 SvREFCNT_inc (sv);
1564 else 1570 else
1565 croak ("filter_json_object callbacks must not return more than one scalar"); 1571 croak ("filter_json_object callbacks must not return more than one scalar");
1572
1573 PUTBACK;
1566 1574
1567 FREETMPS; LEAVE; 1575 FREETMPS; LEAVE;
1568 } 1576 }
1569 } 1577 }
1570 1578

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines