diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2024-09-08 20:02:34 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2024-09-08 20:02:34 +0200 |
commit | e55e2e1c6baebbd105f930fa553ec65c74a3000d (patch) | |
tree | c171c29f7bcfb8a4a52e74e641506aaf9a2b960d /src/json.c | |
parent | 89c99891b2b3ab087cd7e824cef391ef26800ab4 (diff) | |
download | emacs-e55e2e1c6baebbd105f930fa553ec65c74a3000d.tar.gz emacs-e55e2e1c6baebbd105f930fa553ec65c74a3000d.tar.bz2 emacs-e55e2e1c6baebbd105f930fa553ec65c74a3000d.zip |
Make json-serialize always return a unibyte string (bug#70007)
The JSON format is defined as a byte sequence and will always be used as
such, so returning a multibyte string makes little sense.
* src/json.c (json_out_to_string): Remove.
(Fjson_serialize): Return unibyte string.
* test/src/json-tests.el (json-serialize/roundtrip)
(json-serialize/roundtrip-scalars, json-serialize/string):
Update tests.
* doc/lispref/text.texi (Parsing JSON): Document.
* etc/NEWS: Announce.
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/src/json.c b/src/json.c index 21066d21328..41566f8369b 100644 --- a/src/json.c +++ b/src/json.c @@ -559,16 +559,6 @@ json_out_something (json_out_t *jo, Lisp_Object obj) wrong_type_argument (Qjson_value_p, obj); } -static Lisp_Object -json_out_to_string (json_out_t *jo) -{ - /* FIXME: should this be a unibyte or multibyte string? - Right now we make a multibyte string for test compatibility, - but we are really encoding so unibyte would make more sense. */ - ptrdiff_t nchars = jo->size - jo->chars_delta; - return make_multibyte_string (jo->buf, nchars, jo->size); -} - static void json_serialize (json_out_t *jo, Lisp_Object object, ptrdiff_t nargs, Lisp_Object *args) @@ -596,7 +586,7 @@ json_serialize (json_out_t *jo, Lisp_Object object, DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY, NULL, - doc: /* Return the JSON representation of OBJECT as a string. + doc: /* Return the JSON representation of OBJECT as a unibyte string. OBJECT is translated as follows: @@ -629,7 +619,7 @@ usage: (json-serialize OBJECT &rest ARGS) */) specpdl_ref count = SPECPDL_INDEX (); json_out_t jo; json_serialize (&jo, args[0], nargs - 1, args + 1); - return unbind_to (count, json_out_to_string (&jo)); + return unbind_to (count, make_unibyte_string (jo.buf, jo.size)); } DEFUN ("json-insert", Fjson_insert, Sjson_insert, 1, MANY, |