summaryrefslogtreecommitdiff
path: root/Python/errors.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-06-15 17:46:44 -0700
committerGitHub <noreply@github.com>2020-06-15 17:46:44 -0700
commit097b8b6d52e3d4991c68dce74f182718dc0eab9c (patch)
tree33fddfdbcb5e850058ba7ccfb64087d2aa411342 /Python/errors.c
parentbc996c67b7ba73886bb6edfd637ef3f874ddc9d4 (diff)
downloadcpython-git-097b8b6d52e3d4991c68dce74f182718dc0eab9c.tar.gz
bpo-40985: Show correct SyntaxError text when last line has a LINECONT (GH-20888)
When a file ends with a line that contains a line continuation character the text of the emitted SyntaxError is empty, contrary to the old parser, where the error text contained the text of the last line. (cherry picked from commit 113e2b0a07c72c0d5e3489076afb14f6b3ad1049) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 5d1725679c..87af39d527 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -1648,16 +1648,18 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
{
int i;
char linebuf[1000];
-
- if (fp == NULL)
+ if (fp == NULL) {
return NULL;
+ }
+
for (i = 0; i < lineno; i++) {
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
do {
*pLastChar = '\0';
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
- fp, NULL) == NULL)
- break;
+ fp, NULL) == NULL) {
+ goto after_loop;
+ }
/* fgets read *something*; if it didn't get as
far as pLastChar, it must have found a newline
or hit the end of the file; if pLastChar is \n,
@@ -1665,6 +1667,8 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
yet seen a newline, so must continue */
} while (*pLastChar != '\0' && *pLastChar != '\n');
}
+
+after_loop:
fclose(fp);
if (i == lineno) {
PyObject *res;