diff --git a/src/mzscheme/src/read.c b/src/mzscheme/src/read.c index 8c8e13399a..15333189ca 100644 --- a/src/mzscheme/src/read.c +++ b/src/mzscheme/src/read.c @@ -6089,21 +6089,26 @@ static Scheme_Object *read_lang(Scheme_Object *port, buf = MALLOC_N_ATOMIC(char, size); len = 0; + if (init_ch) { + ch = init_ch; + } else { + ch = scheme_getc_special_ok(port); + } + scheme_tell_all(port, &name_line, &name_col, &name_pos); + while (1) { - if (!len && init_ch) { - ch = init_ch; - } else - ch = scheme_getc_special_ok(port); - if (!len) - scheme_tell_all(port, &name_line, &name_col, &name_pos); + /* ch was only peeked at this point (except for the first iteration), so we + can leave the input immediately after the language spec */ if (ch == EOF) { break; } else if (ch == SCHEME_SPECIAL) { - scheme_read_err(port, stxsrc, line, col, pos, SPAN(port, pos), ch, indentation, + ch = scheme_getc_special_ok(port); + scheme_read_err(port, stxsrc, line, col, pos, SPAN(port, pos), ch, indentation, "read: found non-character while reading `#lang'"); } else if (scheme_isspace(ch)) { break; } else { + if (len) ch = scheme_getc_special_ok(port); if ((ch < 128) && (is_lang_nonsep_char(ch) || (ch == '/'))) { @@ -6123,6 +6128,7 @@ static Scheme_Object *read_lang(Scheme_Object *port, return NULL; } } + ch = scheme_peekc_special_ok(port); } if (!len) {