diff options
| author | Spencer Baugh <sbaugh@janestreet.com> | 2025-04-08 17:13:08 -0400 |
|---|---|---|
| committer | Sean Whitton <spwhitton@spwhitton.name> | 2025-08-19 17:00:03 +0100 |
| commit | 63662f6ceeb7644d24cbd8b50c8bd8d0c19e79ed (patch) | |
| tree | 2dc99fe58c301eddf8c64bcb278fba7eccf1f860 /src | |
| parent | ab577467e4feb681246a8d28afde729c6040dfc7 (diff) | |
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.
* src/lread.c (end_of_file_error): <source>: New argument; check
it to determine what data to signal with. (bug#68546)
(read_char_escape, read_char_literal, read_string_literal)
(skip_space_and_comments, read0): Pass source to
end_of_file_error.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/lread.c b/src/lread.c index 57d3239e283..80172dbe7c8 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2114,12 +2114,16 @@ build_load_history (Lisp_Object filename, bool entire) information. */ static AVOID -end_of_file_error (void) +end_of_file_error (source_t *source) { - if (STRINGP (Vload_true_file_name)) + if (from_file_p (source)) + /* Only Fload calls read on a file, and Fload always binds + load-true-file-name around the call. */ xsignal1 (Qend_of_file, Vload_true_file_name); - - xsignal0 (Qend_of_file); + else if (source->get == source_buffer_get) + xsignal1 (Qend_of_file, source->object); + else + xsignal0 (Qend_of_file); } static Lisp_Object @@ -2604,7 +2608,7 @@ read_char_escape (source_t *source, int next_char) switch (c) { case -1: - end_of_file_error (); + end_of_file_error (source); case 'a': chr = '\a'; break; case 'b': chr = '\b'; break; @@ -2777,7 +2781,7 @@ read_char_escape (source_t *source, int next_char) { int c = readchar (source); if (c < 0) - end_of_file_error (); + end_of_file_error (source); if (c == '}') break; if (c >= 0x80) @@ -2819,7 +2823,7 @@ read_char_escape (source_t *source, int next_char) break; } if (chr < 0) - end_of_file_error (); + end_of_file_error (source); eassert (chr >= 0 && chr < (1 << CHARACTERBITS)); /* Apply Control modifiers, using the rules: @@ -2982,7 +2986,7 @@ read_char_literal (source_t *source) { int ch = readchar (source); if (ch < 0) - end_of_file_error (); + end_of_file_error (source); /* Accept `single space' syntax like (list ? x) where the whitespace character is SPC or TAB. @@ -3118,7 +3122,7 @@ read_string_literal (source_t *source) } if (ch < 0) - end_of_file_error (); + end_of_file_error (source); if (!force_multibyte && force_singlebyte) { @@ -3548,7 +3552,7 @@ skip_space_and_comments (source_t *source) c = readchar (source); while (c >= 0 && c != '\n'); if (c < 0) - end_of_file_error (); + end_of_file_error (source); } while (c <= 32 || c == NO_BREAK_SPACE); unreadchar (source, c); @@ -3734,7 +3738,7 @@ read0 (source_t *source, bool locate_syms) Lisp_Object obj; int c = readchar (source); if (c < 0) - end_of_file_error (); + end_of_file_error (source); switch (c) { @@ -4151,7 +4155,7 @@ read0 (source_t *source, bool locate_syms) { c = readchar (source); if (c < 0) - end_of_file_error (); + end_of_file_error (source); quoted = true; } |
