summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2023-04-25 01:31:21 (GMT)
committerGitHub <noreply@github.com>2023-04-25 01:31:21 (GMT)
commit57f8f9a66d4d0b5e590f7746a58136b3b45b1336 (patch)
treef00a9a19fa8c4896b56548a307f15b3ad21b66af /Parser
parent3df3b91e6a0d84bcb954ec894d17f4603bdf428f (diff)
downloadcpython-57f8f9a66d4d0b5e590f7746a58136b3b45b1336.zip
cpython-57f8f9a66d4d0b5e590f7746a58136b3b45b1336.tar.gz
cpython-57f8f9a66d4d0b5e590f7746a58136b3b45b1336.tar.bz2
gh-103718: Correctly set f-string buffers in all cases (GH-103815)
Turns out we always need to remember/restore fstring buffers in all of the stack of tokenizer modes, cause they might change to `TOK_REGULAR_MODE` and have newlines inside the braces (which is when we need to reallocate the buffer and restore the fstring ones).
Diffstat (limited to 'Parser')
-rw-r--r--Parser/tokenizer.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 5244ab7..a8649b8 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -371,10 +371,8 @@ remember_fstring_buffers(struct tok_state *tok)
for (index = tok->tok_mode_stack_index; index >= 0; --index) {
mode = &(tok->tok_mode_stack[index]);
- if (mode->kind == TOK_FSTRING_MODE) {
- mode->f_string_start_offset = mode->f_string_start - tok->buf;
- mode->f_string_multi_line_start_offset = mode->f_string_multi_line_start - tok->buf;
- }
+ mode->f_string_start_offset = mode->f_string_start - tok->buf;
+ mode->f_string_multi_line_start_offset = mode->f_string_multi_line_start - tok->buf;
}
}
@@ -387,10 +385,8 @@ restore_fstring_buffers(struct tok_state *tok)
for (index = tok->tok_mode_stack_index; index >= 0; --index) {
mode = &(tok->tok_mode_stack[index]);
- if (mode->kind == TOK_FSTRING_MODE) {
- mode->f_string_start = tok->buf + mode->f_string_start_offset;
- mode->f_string_multi_line_start = tok->buf + mode->f_string_multi_line_start_offset;
- }
+ mode->f_string_start = tok->buf + mode->f_string_start_offset;
+ mode->f_string_multi_line_start = tok->buf + mode->f_string_multi_line_start_offset;
}
}
@@ -1081,6 +1077,7 @@ tok_underflow_interactive(struct tok_state *tok) {
restore_fstring_buffers(tok);
}
else {
+ remember_fstring_buffers(tok);
ADVANCE_LINENO();
PyMem_Free(tok->buf);
tok->buf = newtok;
@@ -1088,6 +1085,7 @@ tok_underflow_interactive(struct tok_state *tok) {
tok->line_start = tok->buf;
tok->inp = strchr(tok->buf, '\0');
tok->end = tok->inp + 1;
+ restore_fstring_buffers(tok);
}
if (tok->done != E_OK) {
if (tok->prompt != NULL) {