… | |
… | |
15 | |
15 | |
16 | // some old perls do not have this, try to make it work, no |
16 | // some old perls do not have this, try to make it work, no |
17 | // guarantees, though. if it breaks, you get to keep the pieces. |
17 | // guarantees, though. if it breaks, you get to keep the pieces. |
18 | #ifndef UTF8_MAXBYTES |
18 | #ifndef UTF8_MAXBYTES |
19 | # define UTF8_MAXBYTES 13 |
19 | # define UTF8_MAXBYTES 13 |
|
|
20 | #endif |
|
|
21 | |
|
|
22 | // compatibility with perl <5.18 |
|
|
23 | #ifndef HvNAMELEN_get |
|
|
24 | # define HvNAMELEN_get(hv) strlen (HvNAME (hv)) |
|
|
25 | #endif |
|
|
26 | #ifndef HvNAMELEN |
|
|
27 | # define HvNAMELEN(hv) HvNAMELEN_get (hv) |
|
|
28 | #endif |
|
|
29 | #ifndef HvNAMEUTF8 |
|
|
30 | # define HvNAMEUTF8(hv) 0 |
20 | #endif |
31 | #endif |
21 | |
32 | |
22 | // three extra for rounding, sign, and end of string |
33 | // three extra for rounding, sign, and end of string |
23 | #define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3) |
34 | #define IVUV_MAXCHARS (sizeof (UV) * CHAR_BIT * 28 / 93 + 3) |
24 | |
35 | |
… | |
… | |
719 | count = call_sv ((SV *)GvCV (method), G_ARRAY); |
730 | count = call_sv ((SV *)GvCV (method), G_ARRAY); |
720 | SPAGAIN; |
731 | SPAGAIN; |
721 | |
732 | |
722 | // catch this surprisingly common error |
733 | // catch this surprisingly common error |
723 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
734 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
724 | croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
735 | croak ("%s::FREEZE method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
725 | |
736 | |
726 | encode_ch (enc, '('); |
737 | encode_ch (enc, '('); |
727 | encode_ch (enc, '"'); |
738 | encode_ch (enc, '"'); |
728 | encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash)); |
739 | encode_str (enc, HvNAME (stash), HvNAMELEN (stash), HvNAMEUTF8 (stash)); |
729 | encode_ch (enc, '"'); |
740 | encode_ch (enc, '"'); |
… | |
… | |
1093 | *cur++ = *dec_cur++; |
1104 | *cur++ = *dec_cur++; |
1094 | while (--clen); |
1105 | while (--clen); |
1095 | |
1106 | |
1096 | utf8 = 1; |
1107 | utf8 = 1; |
1097 | } |
1108 | } |
|
|
1109 | else if (ch == '\t' && dec->json.flags & F_RELAXED) |
|
|
1110 | *cur++ = ch; |
1098 | else |
1111 | else |
1099 | { |
1112 | { |
1100 | --dec_cur; |
1113 | --dec_cur; |
1101 | |
1114 | |
1102 | if (!ch) |
1115 | if (!ch) |
… | |
… | |
1492 | if (!(dec->json.flags & F_ALLOW_TAGS)) |
1505 | if (!(dec->json.flags & F_ALLOW_TAGS)) |
1493 | ERR ("malformed JSON string, neither array, object, number, string or atom"); |
1506 | ERR ("malformed JSON string, neither array, object, number, string or atom"); |
1494 | |
1507 | |
1495 | ++dec->cur; |
1508 | ++dec->cur; |
1496 | |
1509 | |
|
|
1510 | decode_ws (dec); |
|
|
1511 | |
1497 | tag = decode_sv (dec); |
1512 | tag = decode_sv (dec); |
1498 | if (!tag) |
1513 | if (!tag) |
1499 | goto fail; |
1514 | goto fail; |
1500 | |
1515 | |
1501 | if (!SvPOK (tag)) |
1516 | if (!SvPOK (tag)) |
1502 | ERR ("malformed JSON string, (tag) must be a string"); |
1517 | ERR ("malformed JSON string, (tag) must be a string"); |
1503 | |
1518 | |
|
|
1519 | decode_ws (dec); |
|
|
1520 | |
1504 | if (*dec->cur != ')') |
1521 | if (*dec->cur != ')') |
1505 | ERR (") expected after tag"); |
1522 | ERR (") expected after tag"); |
1506 | |
1523 | |
1507 | ++dec->cur; |
1524 | ++dec->cur; |
|
|
1525 | |
|
|
1526 | decode_ws (dec); |
1508 | |
1527 | |
1509 | val = decode_sv (dec); |
1528 | val = decode_sv (dec); |
1510 | if (!val) |
1529 | if (!val) |
1511 | goto fail; |
1530 | goto fail; |
1512 | |
1531 | |