diff options
| -rw-r--r-- | src/json.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/json.c b/src/json.c index 82df60b8507..b5d5c1f1fe7 100644 --- a/src/json.c +++ b/src/json.c | |||
| @@ -772,9 +772,9 @@ static AVOID | |||
| 772 | json_signal_error (struct json_parser *parser, Lisp_Object error) | 772 | json_signal_error (struct json_parser *parser, Lisp_Object error) |
| 773 | { | 773 | { |
| 774 | xsignal3 (error, INT_TO_INTEGER (parser->current_line), | 774 | xsignal3 (error, INT_TO_INTEGER (parser->current_line), |
| 775 | INT_TO_INTEGER (parser->current_column), | 775 | INT_TO_INTEGER (parser->current_column), |
| 776 | INT_TO_INTEGER (parser->point_of_current_line | 776 | INT_TO_INTEGER (parser->point_of_current_line |
| 777 | + parser->current_column)); | 777 | + parser->current_column)); |
| 778 | } | 778 | } |
| 779 | 779 | ||
| 780 | static void | 780 | static void |
| @@ -825,8 +825,8 @@ json_parser_init (struct json_parser *parser, | |||
| 825 | 825 | ||
| 826 | parser->byte_workspace = parser->internal_byte_workspace; | 826 | parser->byte_workspace = parser->internal_byte_workspace; |
| 827 | parser->byte_workspace_end | 827 | parser->byte_workspace_end |
| 828 | = (parser->byte_workspace | 828 | = (parser->byte_workspace |
| 829 | + JSON_PARSER_INTERNAL_BYTE_WORKSPACE_SIZE); | 829 | + JSON_PARSER_INTERNAL_BYTE_WORKSPACE_SIZE); |
| 830 | } | 830 | } |
| 831 | 831 | ||
| 832 | static void | 832 | static void |
| @@ -1579,7 +1579,7 @@ json_parse_object (struct json_parser *parser) | |||
| 1579 | json_parse_string (parser); | 1579 | json_parse_string (parser); |
| 1580 | Lisp_Object key | 1580 | Lisp_Object key |
| 1581 | = make_string_from_utf8 ((char *) | 1581 | = make_string_from_utf8 ((char *) |
| 1582 | parser->byte_workspace, | 1582 | parser->byte_workspace, |
| 1583 | (parser->byte_workspace_current | 1583 | (parser->byte_workspace_current |
| 1584 | - parser->byte_workspace)); | 1584 | - parser->byte_workspace)); |
| 1585 | Lisp_Object value | 1585 | Lisp_Object value |
| @@ -1595,12 +1595,16 @@ json_parse_object (struct json_parser *parser) | |||
| 1595 | } | 1595 | } |
| 1596 | case json_object_alist: | 1596 | case json_object_alist: |
| 1597 | { | 1597 | { |
| 1598 | ptrdiff_t nbytes; | ||
| 1599 | char *workspace; | ||
| 1600 | |||
| 1598 | json_parse_string (parser); | 1601 | json_parse_string (parser); |
| 1602 | workspace = (char *) parser->byte_workspace; | ||
| 1603 | nbytes = (parser->byte_workspace_current | ||
| 1604 | - parser->byte_workspace); | ||
| 1605 | |||
| 1599 | Lisp_Object key | 1606 | Lisp_Object key |
| 1600 | = Fintern (make_string_from_utf8 ( | 1607 | = Fintern (make_string_from_utf8 (workspace, nbytes), |
| 1601 | (char *) parser->byte_workspace, | ||
| 1602 | (parser->byte_workspace_current | ||
| 1603 | - parser->byte_workspace)), | ||
| 1604 | Qnil); | 1608 | Qnil); |
| 1605 | Lisp_Object value | 1609 | Lisp_Object value |
| 1606 | = json_parse_object_member_value (parser); | 1610 | = json_parse_object_member_value (parser); |
| @@ -1651,10 +1655,13 @@ json_parse_object (struct json_parser *parser) | |||
| 1651 | { | 1655 | { |
| 1652 | case json_object_hashtable: | 1656 | case json_object_hashtable: |
| 1653 | { | 1657 | { |
| 1658 | EMACS_INT value; | ||
| 1659 | |||
| 1660 | value | ||
| 1661 | = (parser->object_workspace_current - first) / 2; | ||
| 1654 | result | 1662 | result |
| 1655 | = CALLN (Fmake_hash_table, QCtest, Qequal, QCsize, | 1663 | = CALLN (Fmake_hash_table, QCtest, Qequal, QCsize, |
| 1656 | make_fixed_natnum ( | 1664 | make_fixed_natnum (value)); |
| 1657 | (parser->object_workspace_current - first) / 2)); | ||
| 1658 | struct Lisp_Hash_Table *h = XHASH_TABLE (result); | 1665 | struct Lisp_Hash_Table *h = XHASH_TABLE (result); |
| 1659 | for (size_t i = first; i < parser->object_workspace_current; | 1666 | for (size_t i = first; i < parser->object_workspace_current; |
| 1660 | i += 2) | 1667 | i += 2) |
| @@ -1711,7 +1718,7 @@ json_parse_value (struct json_parser *parser, int c) | |||
| 1711 | json_parse_string (parser); | 1718 | json_parse_string (parser); |
| 1712 | Lisp_Object result | 1719 | Lisp_Object result |
| 1713 | = make_string_from_utf8 ((const char *) | 1720 | = make_string_from_utf8 ((const char *) |
| 1714 | parser->byte_workspace, | 1721 | parser->byte_workspace, |
| 1715 | (parser->byte_workspace_current | 1722 | (parser->byte_workspace_current |
| 1716 | - parser->byte_workspace)); | 1723 | - parser->byte_workspace)); |
| 1717 | return result; | 1724 | return result; |
| @@ -1925,28 +1932,28 @@ syms_of_json (void) | |||
| 1925 | DEFSYM (Qjson_end_of_file, "json-end-of-file"); | 1932 | DEFSYM (Qjson_end_of_file, "json-end-of-file"); |
| 1926 | DEFSYM (Qjson_trailing_content, "json-trailing-content"); | 1933 | DEFSYM (Qjson_trailing_content, "json-trailing-content"); |
| 1927 | DEFSYM (Qjson_object_too_deep, "json-object-too-deep"); | 1934 | DEFSYM (Qjson_object_too_deep, "json-object-too-deep"); |
| 1928 | DEFSYM (Qjson_utf8_decode_error, "json-utf8-decode-error") | 1935 | DEFSYM (Qjson_utf8_decode_error, "json-utf8-decode-error"); |
| 1929 | DEFSYM (Qjson_invalid_surrogate_error, "json-invalid-surrogate-error") | 1936 | DEFSYM (Qjson_invalid_surrogate_error, "json-invalid-surrogate-error"); |
| 1930 | DEFSYM (Qjson_number_out_of_range, "json-number-out-of-range-error") | 1937 | DEFSYM (Qjson_number_out_of_range, "json-number-out-of-range-error"); |
| 1931 | DEFSYM (Qjson_escape_sequence_error, "json-escape-sequence-error") | 1938 | DEFSYM (Qjson_escape_sequence_error, "json-escape-sequence-error"); |
| 1932 | define_error (Qjson_error, "generic JSON error", Qerror); | 1939 | define_error (Qjson_error, "generic JSON error", Qerror); |
| 1933 | define_error (Qjson_out_of_memory, | 1940 | define_error (Qjson_out_of_memory, |
| 1934 | "not enough memory for creating JSON object", Qjson_error); | 1941 | "not enough memory for creating JSON object", Qjson_error); |
| 1935 | define_error (Qjson_parse_error, "could not parse JSON stream", | 1942 | define_error (Qjson_parse_error, "could not parse JSON stream", |
| 1936 | Qjson_error); | 1943 | Qjson_error); |
| 1937 | define_error (Qjson_end_of_file, "end of JSON stream", Qjson_parse_error); | 1944 | define_error (Qjson_end_of_file, "end of JSON stream", Qjson_parse_error); |
| 1938 | define_error (Qjson_trailing_content, "trailing content after JSON stream", | 1945 | define_error (Qjson_trailing_content, "trailing content after JSON stream", |
| 1939 | Qjson_parse_error); | 1946 | Qjson_parse_error); |
| 1940 | define_error (Qjson_object_too_deep, | 1947 | define_error (Qjson_object_too_deep, |
| 1941 | "object cyclic or Lisp evaluation too deep", Qjson_error); | 1948 | "object cyclic or Lisp evaluation too deep", Qjson_error); |
| 1942 | define_error (Qjson_utf8_decode_error, | 1949 | define_error (Qjson_utf8_decode_error, |
| 1943 | "invalid utf-8 encoding", Qjson_error); | 1950 | "invalid utf-8 encoding", Qjson_error); |
| 1944 | define_error (Qjson_invalid_surrogate_error, | 1951 | define_error (Qjson_invalid_surrogate_error, |
| 1945 | "invalid surrogate pair", Qjson_error); | 1952 | "invalid surrogate pair", Qjson_error); |
| 1946 | define_error (Qjson_number_out_of_range, | 1953 | define_error (Qjson_number_out_of_range, |
| 1947 | "number out of range", Qjson_error); | 1954 | "number out of range", Qjson_error); |
| 1948 | define_error (Qjson_escape_sequence_error, | 1955 | define_error (Qjson_escape_sequence_error, |
| 1949 | "invalid escape sequence", Qjson_parse_error); | 1956 | "invalid escape sequence", Qjson_parse_error); |
| 1950 | 1957 | ||
| 1951 | DEFSYM (Qpure, "pure"); | 1958 | DEFSYM (Qpure, "pure"); |
| 1952 | DEFSYM (Qside_effect_free, "side-effect-free"); | 1959 | DEFSYM (Qside_effect_free, "side-effect-free"); |