bpo-25083: Python can sometimes create incorrect .pyc files (GH-8449)
Python 2 never checked for I/O error when reading .py files and
thus could mistake an I/O error for EOF and create incorrect .pyc
files.
This adds an check for this and aborts on an error.
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 61bfb4e..c6e61df 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -1681,6 +1681,11 @@
PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)
{
int result = tok_get(tok, p_start, p_end);
+ if (tok->fp && ferror(tok->fp)) {
+ clearerr(tok->fp);
+ result = ERRORTOKEN;
+ tok->done = E_IO;
+ }
if (tok->decoding_erred) {
result = ERRORTOKEN;
tok->done = E_DECODE;