Subject: Re: bug#40693: 28.0.50; json-encode-alist changes alist

From: "Basil L. Contovounesios" <[email-masked]>
Date: Fri, 22 May 2020 15:54:33 +0100

tags 40693 fixed
close 40693 28.1
quit

João Távora <[email-masked]> writes:

> "Basil L. Contovounesios" <[email-masked]> writes:
>> The declarations are needed because the byte-compiler does not know that
>> loading json.el will e.g. define a dynamically bound variable
>> json-object-type and a nullary function symbol json-read.  It therefore
>> not only complains but also generates invalid byte-code.
>
> Basil, I understand the need for the declarations, but I was suggesting
> something different.  This, at the top, near all the other requires.
>
>    (eval-and-compile
>      (unless (fboundp 'json-parse-buffer)
>        (require 'json)))
>
> and then do the defalias without the declarations below.
>
>    (defalias blabla
>       (if (fboundp 'json-parse-buffer)
>           (lambda () json-c-things...)
>           (lambda () json-el-things...)))
>
> Am I missing something or doesn't this work like you want?

There's a problem with the conditional require at byte-compile time.  If
the version of Emacs doing the byte-compilation has native JSON support,
then it will generate invalid byte-code (and complain) for the case
where there is no native JSON support.  In other words, there will be a
bug when an Emacs without native JSON loads a file that was
byte-compiled in an Emacs with native JSON.

> We're checking json.c function thrice instead of twice, but doesn't
> seem very bad, only a 50% increase :-)

Indeed, that wouldn't be an issue.

>> But I find this more heavy handed and intrusive, since it
>> unconditionally loads json.el during byte-compilation, even when
>> json-parse-buffer is available.
>
> I think the snippet above doesn't have this problem.

Indeed, but I think it suffers from the worse aforementioned problem.

> Anyway, this is a minor nitpick, push whatever you think is better.

Thanks.  I've therefore gone with the original patch[1], as it exhibits
correct behaviour and is the least intrusive, but you should obviously
feel free to tweak it as you prefer.

[1]: Various json.el improvements
3f082af536 2020-05-22 15:16:13 +0100
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=3f082af536c33ba713561e7ad4b691aaad488701

Thanks also to everyone who reviewed the patch.
I'm now closing this bug.

-- 
Basil