[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#68546: 29.1.90; end-of-file has incorrect data when signaled within
From: |
Spencer Baugh |
Subject: |
bug#68546: 29.1.90; end-of-file has incorrect data when signaled within a load |
Date: |
Tue, 08 Apr 2025 17:18:23 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> xsignal0 (Qend_of_file);
>> }
>> @@ -2434,6 +2434,8 @@ readevalloop (Lisp_Object readcharfun,
>> while (continue_reading_p)
>> {
>> specpdl_ref count1 = SPECPDL_INDEX ();
>> + if (NILP (Vread_end_of_file_data))
>> + specbind (Qread_end_of_file_name, Vload_true_file_name);
>
> Why the `if` condition here? Sounds like it could lead to problems for
> nested loads and such.
Good point.
Actually, a good enough point that I completely reworked the patch in
response to it. We don't need to add a new dynamically scoped variable
at all: we can just pass readcharfun to end_of_file_error and check
that. Much simpler.
This should solve the original bug; while I'm here, I also added a
BUFFERP check, so that read on a buffer will signal end-of-file with the
buffer as data instead of just nil.
I tried including the line number and column number as data in the
BUFFERP case, but it seemed a bit noisy, since it's only useful in the
case where the buffer is narrowed (otherwise the error is just obviously
at the end of the buffer).
>From 03e06a591896ed85f3c38908a0b3105b8bafc945 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Tue, 8 Apr 2025 17:13:08 -0400
Subject: [PATCH] Signal end-of-file with more correct data
end_of_file_error previously always signaled end-of-file with
load-true-file-name if that was non-nil (and a string).
However, this might be the wrong thing to do; for example, if a
file being loaded calls read on a buffer.
We can determine what's correct by also checking if readcharfun
is reading from a file. Also, by checking that we can signal a
better error for read on a buffer.
* src/lread.c (end_of_file_error): Check readcharfun to
determine what data to signal with. (bug#68546)
(read_char_escape, read_char_literal, read_string_literal)
(skip_space_and_comments, read0): Pass readcharfun to
end_of_file_error.
---
src/lread.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/lread.c b/src/lread.c
index d39330bd0eb..2f18d763b9c 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2342,12 +2342,14 @@ readevalloop_1 (int old)
information. */
static AVOID
-end_of_file_error (void)
+end_of_file_error (Lisp_Object readcharfun)
{
- if (STRINGP (Vload_true_file_name))
+ if (FROM_FILE_P (readcharfun) && STRINGP (Vload_true_file_name))
xsignal1 (Qend_of_file, Vload_true_file_name);
-
- xsignal0 (Qend_of_file);
+ else if (BUFFERP (readcharfun))
+ xsignal1 (Qend_of_file, readcharfun);
+ else
+ xsignal0 (Qend_of_file);
}
static Lisp_Object
@@ -2858,7 +2860,7 @@ read_char_escape (Lisp_Object readcharfun, int next_char)
switch (c)
{
case -1:
- end_of_file_error ();
+ end_of_file_error (readcharfun);
case 'a': chr = '\a'; break;
case 'b': chr = '\b'; break;
@@ -3031,7 +3033,7 @@ read_char_escape (Lisp_Object readcharfun, int next_char)
{
int c = READCHAR;
if (c < 0)
- end_of_file_error ();
+ end_of_file_error (readcharfun);
if (c == '}')
break;
if (c >= 0x80)
@@ -3201,7 +3203,7 @@ read_char_literal (Lisp_Object readcharfun)
{
int ch = READCHAR;
if (ch < 0)
- end_of_file_error ();
+ end_of_file_error (readcharfun);
/* Accept `single space' syntax like (list ? x) where the
whitespace character is SPC or TAB.
@@ -3347,7 +3349,7 @@ read_string_literal (Lisp_Object readcharfun)
}
if (ch < 0)
- end_of_file_error ();
+ end_of_file_error (readcharfun);
if (!force_multibyte && force_singlebyte)
{
@@ -3777,7 +3779,7 @@ skip_space_and_comments (Lisp_Object readcharfun)
c = READCHAR;
while (c >= 0 && c != '\n');
if (c < 0)
- end_of_file_error ();
+ end_of_file_error (readcharfun);
}
while (c <= 32 || c == NO_BREAK_SPACE);
UNREAD (c);
@@ -3972,7 +3974,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
bool multibyte;
int c = READCHAR_REPORT_MULTIBYTE (&multibyte);
if (c < 0)
- end_of_file_error ();
+ end_of_file_error (readcharfun);
switch (c)
{
@@ -4403,7 +4405,7 @@ read0 (Lisp_Object readcharfun, bool locate_syms)
{
c = READCHAR;
if (c < 0)
- end_of_file_error ();
+ end_of_file_error (readcharfun);
quoted = true;
}
--
2.39.3
- bug#68546: 29.1.90; end-of-file has incorrect data when signaled within a load,
Spencer Baugh <=