GNU bug report logs - #40693
28.0.50; json-encode-alist changes alist

Previous Next

Package: emacs;

Reported by: Ivan Andrus <darthandrus <at> gmail.com>

Date: Sat, 18 Apr 2020 03:01:02 UTC

Severity: normal

Tags: fixed, patch

Found in version 28.0.50

Fixed in version 28.1

Done: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Bug is archived. No further changes may be made.

Full log


Message #125 received at 40693 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: João Távora <joaotavora <at> gmail.com>
Cc: darthandrus <at> gmail.com, 40693 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Dmitry Gutov <dgutov <at> yandex.ru>
Subject: Re: bug#40693: 28.0.50; json-encode-alist changes alist
Date: Sat, 23 May 2020 23:41:20 +0100
João Távora <joaotavora <at> gmail.com> writes:

> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>
>> João Távora <joaotavora <at> gmail.com> writes:
>>> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>
>> 0. bar.el does not use lexical-binding.
>> 1. The second lambda in forty-two does not let-bind foo-42.
>> 2. If you byte-compile bar.el with bar-have-native-42 set to t, and then
>>    load bar.elc in an Emacs that has bar-have-native-42 set to nil, then
>>    42.0 gets printed, which is wrong.  This is due to the incorrect
>>    usage of eval-when-compile: we want the check to happen at runtime as
>>    well.
>
> I think you mean load-time.

Yes.

> Anyway, this is true if you want 27.1 elc's to be loadable in 26.x.

It is also true if you want version N .elc files to be loadable in
version N.  The problems I list are not specific to either JSON or
inter-Emacs-version compat.

> I was labouring under the impression that we don't care about that
> (and this is why I thought of the macro approach).  Do we?  The source
> file is compatible between multiple emacs version, but is the
> byte-compiled file also compatible?

This isn't (primarily) about 26/27 compat, but about supporting
--without-json configurations properly.  In the examples I've given so
far I was exclusively using Emacs master --with-json, hence the
(fset 'json-parse-buffer nil).  Native JSON functions are not guaranteed
to be available in any version of Emacs to date, just like D-Bus or X.

The only benefit of the macro approach is zero overhead - no fboundp
checks at load time, and no indirection in calling jsonrpc--json-read.
But those should be negligible costs, and macros come with their slew of
drawbacks that makes them unnecessary in this simple case.

>>> No idea how to check if byte-code is "valid" or not: I just check the
>>> warnings.  Can you tell me?
>> 
>> 0. emacs -Q -batch -f batch-byte-compile foo.el
>> 1. emacs -Q
>> 2. (fset 'json-parse-buffer nil) C-j
>> 3. M-x load-file RET foo.elc RET
>> 4. (disassemble 'foo) C-j
>
> Thanks.
>
>> I think the declarations make the intention explicit to both the reader
>> and the byte-compiler in a simple way, without wrestling the
>> eval-*-compile machinery or allowing for subtle bugs like the ones
>> above.
>
> The problem, of course, is that you're repeating yourself, a maintenance
> hazard.  Not too big in this case.

Agreed.

-- 
Basil




This bug report was last modified 5 years and 77 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.