unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Géza Herman" <geza.herman@gmail.com>
Cc: mattiase@acm.org, emacs-devel@gnu.org
Subject: Re: [PATCH] Implement fast verisons of json-parse functions
Date: Sun, 31 Mar 2024 08:08:29 +0300	[thread overview]
Message-ID: <86zfufasz6.fsf@gnu.org> (raw)
In-Reply-To: <87wmpjmsie.fsf@gmail.com> (message from Herman, Géza on Sat, 30 Mar 2024 19:36:57 +0100)

> From: Herman, Géza <geza.herman@gmail.com>
> Cc: Géza Herman <geza.herman@gmail.com>, Mattias
>   Engdegård
>  <mattiase@acm.org>, emacs-devel@gnu.org
> Date: Sat, 30 Mar 2024 19:36:57 +0100
> 
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Herman, Géza <geza.herman@gmail.com>
> >> 3 test failures:
> >> 1. Handling of utf-8 decode errors: the new parser emits
> >> json-utf8-decode-error instead of json-parse-error (this is 
> >> what
> >> the test expects).  I can fix this by modifying the test
> >
> > OK, but we will need to mention this in NEWS as an incompatible
> > change.
> 
> Yes.  I'm just mentioning this as an alternative solution: 
> originally the parser emitted json-parse-error for this, it was 
> changed during the review.  So if we prefer maintaining 
> compatibility, it's easy to revert this change.

I don't think we should revert it, this error is fine.

> >> 2. Handling of a single \0 byte
> >
> > Does JSON allow null bytes in its strings?  If not, why
> > wrong-type-argument is not TRT?
> 
> That's correct, null bytes are not allowed (anywhere, not just in 
> strings).  But my point is that the old parser made a special 
> distinction here.  It is not just null bytes which is not allowed 
> in JSON, but for example, \x01 isn't allowed either.  But, for 
> null bytes, the old parser gives a different error message than 
> for \x01 bytes.  But from the JSON spec perspective, both \x00 and 
> \x01 are forbidden in the same way.  I don't know why null bytes 
> are handled specially in this regard, so I didn't follow this 
> behavior in my parser.  Maybe this special error case was added 
> because libjansson couldn't parse strings with null bytes back 
> then (because the API only accepted zero-terminated strings)?

libjansson couldn't parse such strings because it uses a C interface,
and C terminates strings at the first null byte.

> To me, wrong-type-argument means that the input argument to the 
> parser is incorrect. Like it's not a string, but an integer.  But 
> here, the parser gets a string, it's just that the string has null 
> bytes in it somewhere.

Well, it's "kind-of" wrong argument: a string with embedded null
bytes.  But I'm also interested to hear from Mattias on this (and from
anyone else who might have an opinion about the kind of error we
should signal in this case).

> > But please also compare with what the Lisp implementation does in
> > these cases, as that could give us further ideas or make us
> > reconsider.
> 
> I checked json-read, and it seems that it has the exact same 
> behavior that my parser has.  I thought that json-read can only 
> produce one format, but it turned out it has json-object-type and 
> json-array-type variables, so it can produce the same variety of 
> output that the C-based parsers can do.  I think that the doc of 
> json-read should mention this fact.  Anyways, the doc says:
> 
> (defvar json-object-type 'alist
>   "Type to convert JSON objects to.
> Must be one of `alist', `plist', or `hash-table'.  Consider 
> let-binding
> this around your call to `json-read' instead of `setq'ing it. 
> Ordering
> is maintained for `alist' and `plist', but not for `hash-table'.")

Please suggest the change for the doc string.

> I think this behavior is important, because this is used when 
> pretty-formatting JSON.  Pretty formatting shouldn't remove 
> duplicate entries, nor change the ordering of members.  Because 
> the new parser also behaves like this, it can be used to speed up 
> pretty formatting as well (yeah, I know, half of it, as there is 
> no new to-JSON serializer implemented yet).

There is now, it was installed yesterday evening.



  parent reply	other threads:[~2024-03-31  5:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 18:23 [PATCH] Implement fast verisons of json-parse functions Herman, Géza
2024-03-19 18:47 ` Eli Zaretskii
2024-03-19 18:50   ` Herman, Géza
2024-03-19 19:28     ` Eli Zaretskii
2024-03-19 19:50       ` Herman, Géza
2024-03-20  3:37         ` Eli Zaretskii
2024-03-23 10:40           ` Herman, Géza
2024-03-23 11:11             ` Eli Zaretskii
2024-03-30  7:43             ` Eli Zaretskii
2024-03-30 10:50               ` Herman, Géza
2024-03-30 13:00                 ` Eli Zaretskii
2024-03-30 18:36                   ` Herman, Géza
2024-03-30 20:18                     ` [External] : " Drew Adams
2024-03-30 20:51                       ` Herman, Géza
2024-03-30 23:28                         ` Drew Adams
2024-03-31  5:08                     ` Eli Zaretskii [this message]
2024-03-31 14:51                       ` Mattias Engdegård
2024-03-31 15:44                         ` Eli Zaretskii
2024-04-01  8:48                           ` Mattias Engdegård
2024-04-01 16:54                             ` Herman, Géza
2024-03-31 17:48                       ` Adam Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86zfufasz6.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=geza.herman@gmail.com \
    --cc=mattiase@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).