From db25269cb8266d6672c3f5b3dbd569cdf74af6e3 Mon Sep 17 00:00:00 2001 From: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com> Date: Sun, 20 Nov 2022 09:26:58 +0800 Subject: [PATCH 1/2] implement logic + remove redundancy Note on "remove redundancy": in `compiler_joined_str()`, replace all further references of `asdl_seq_LEN(e->v.JoinedStr.values)` with `value_count`. --- Python/compile.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index 9226bc233ead74..894c15ce33c0e3 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4926,12 +4926,16 @@ compiler_joined_str(struct compiler *c, expr_ty e) { location loc = LOC(e); Py_ssize_t value_count = asdl_seq_LEN(e->v.JoinedStr.values); - if (value_count > STACK_USE_GUIDELINE) { + if (!value_count || value_count > STACK_USE_GUIDELINE) { + /* Also handle empty f-strings here */ _Py_DECLARE_STR(empty, ""); ADDOP_LOAD_CONST_NEW(c, loc, Py_NewRef(&_Py_STR(empty))); + if (!value_count) { + return 0; + } ADDOP_NAME(c, loc, LOAD_METHOD, &_Py_ID(join), names); ADDOP_I(c, loc, BUILD_LIST, 0); - for (Py_ssize_t i = 0; i < asdl_seq_LEN(e->v.JoinedStr.values); i++) { + for (Py_ssize_t i = 0; i < value_count; i++) { VISIT(c, expr, asdl_seq_GET(e->v.JoinedStr.values, i)); ADDOP_I(c, loc, LIST_APPEND, 1); } @@ -4939,8 +4943,8 @@ compiler_joined_str(struct compiler *c, expr_ty e) } else { VISIT_SEQ(c, expr, e->v.JoinedStr.values); - if (asdl_seq_LEN(e->v.JoinedStr.values) != 1) { - ADDOP_I(c, loc, BUILD_STRING, asdl_seq_LEN(e->v.JoinedStr.values)); + if (value_count != 1) { + ADDOP_I(c, loc, BUILD_STRING, value_count); } } return 1; From c226f0e4db9d40851dfe636e11c391a340dcb036 Mon Sep 17 00:00:00 2001 From: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com> Date: Sun, 20 Nov 2022 09:54:24 +0800 Subject: [PATCH 2/2] returned fail instead of success --- Python/compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/compile.c b/Python/compile.c index 894c15ce33c0e3..f9afd44c701283 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -4931,7 +4931,7 @@ compiler_joined_str(struct compiler *c, expr_ty e) _Py_DECLARE_STR(empty, ""); ADDOP_LOAD_CONST_NEW(c, loc, Py_NewRef(&_Py_STR(empty))); if (!value_count) { - return 0; + return 1; } ADDOP_NAME(c, loc, LOAD_METHOD, &_Py_ID(join), names); ADDOP_I(c, loc, BUILD_LIST, 0); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy