GNU bug report logs -
#70988
(read FUNCTION) uses Latin-1 [PATCH]
Previous Next
Full log
Message #8 received at 70988 <at> debbugs.gnu.org (full text, mbox):
> Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
> From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
> Date: Thu, 16 May 2024 20:13:18 +0200
>
> When `read` is called with a function as stream argument, the return values of that function are often interpreted as Latin-1 characters with only the 8 low bits used. Example:
>
> (let* ((next '(?A #x12a nil))
> (f (lambda (&rest args)
> (if args
> (push (car args) next)
> (pop next)))))
> (read f))
> => A* ; expected: AĪ
>
> This is a result of `readchar` setting *multibyte to 0 on this code path.
When is this situation relevant? How many uses of
function-as-a-stream are there out there?
In general, I wouldn't touch these rare cases with a 3-mile pole. The
gain is generally very small (satisfaction from some abstract sense of
correctness aside), while the risk to break some code is usually high.
It is better to document this behavior and move on.
> The fix is straightforward (attached).
>
> diff --git a/src/lread.c b/src/lread.c
> index c92b2ede932..2626272c4e2 100644
> --- a/src/lread.c
> +++ b/src/lread.c
> @@ -422,6 +422,8 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
> goto read_multibyte;
> }
>
> + if (multibyte)
> + *multibyte = 1;
> tem = call0 (readcharfun);
Is it an accident that the code does the same only _after_ the call to
readbyte?
This bug report was last modified 10 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.