From 51618b65197639b4079ee9f8f949cec6e5df9992 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 9 Oct 2024 14:56:47 -0400 Subject: [PATCH 1/3] gh-125207: Use {0} array initializers --- Python/jit.c | 2 +- Tools/jit/_stencils.py | 5 ++++- Tools/jit/_writer.py | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Python/jit.c b/Python/jit.c index 234fc7dda83231..963bde2303dc2c 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -469,7 +469,7 @@ _PyJIT_Compile(_PyExecutorObject *executor, const _PyUOpInstruction trace[], siz // Loop once to find the total compiled size: size_t code_size = 0; size_t data_size = 0; - jit_state state = {}; + jit_state state = {0}; group = &trampoline; code_size += group->code_size; data_size += group->data_size; diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index bbb52f391f4b01..ed226dd0c0bc38 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -339,7 +339,10 @@ def _get_trampoline_mask(self) -> str: word = bitmask & ((1 << 32) - 1) trampoline_mask.append(f"{word:#04x}") bitmask >>= 32 - return "{" + ", ".join(trampoline_mask) + "}" + if len(trampoline_mask): + return "{" + ", ".join(trampoline_mask) + "}" + else: + return "{0}" def as_c(self, opname: str) -> str: """Dump this hole as a StencilGroup initializer.""" diff --git a/Tools/jit/_writer.py b/Tools/jit/_writer.py index 7b99d10310a645..06fea519ccc6d5 100644 --- a/Tools/jit/_writer.py +++ b/Tools/jit/_writer.py @@ -32,8 +32,11 @@ def _dump_footer( yield "};" yield "" yield f"static const void * const symbols_map[{max(len(symbols), 1)}] = {{" - for symbol, ordinal in symbols.items(): - yield f" [{ordinal}] = &{symbol}," + if len(symbols): + for symbol, ordinal in symbols.items(): + yield f" [{ordinal}] = &{symbol}," + else: + yield " 0" yield "};" From 8e4799004283b8d3f215e3ad7c5de3a87dbec996 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 18 Oct 2024 10:33:01 -0400 Subject: [PATCH 2/3] Simplify, as suggested in PR --- Tools/jit/_stencils.py | 5 +---- Tools/jit/_writer.py | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index ed226dd0c0bc38..e4b2bf6e4702b3 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -339,10 +339,7 @@ def _get_trampoline_mask(self) -> str: word = bitmask & ((1 << 32) - 1) trampoline_mask.append(f"{word:#04x}") bitmask >>= 32 - if len(trampoline_mask): - return "{" + ", ".join(trampoline_mask) + "}" - else: - return "{0}" + return "{" + (", ".join(trampoline_mask) or "0") + "}" def as_c(self, opname: str) -> str: """Dump this hole as a StencilGroup initializer.""" diff --git a/Tools/jit/_writer.py b/Tools/jit/_writer.py index 06fea519ccc6d5..7f0606beb3f61d 100644 --- a/Tools/jit/_writer.py +++ b/Tools/jit/_writer.py @@ -31,8 +31,8 @@ def _dump_footer( yield f" [{opname}] = {group.as_c(opname)}," yield "};" yield "" - yield f"static const void * const symbols_map[{max(len(symbols), 1)}] = {{" - if len(symbols): + yield "static const void * const symbols_map[] = {" + if symbols: for symbol, ordinal in symbols.items(): yield f" [{ordinal}] = &{symbol}," else: From 6ffc67857a262849ae86e75157dbaf4f8a0a2892 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 18 Oct 2024 10:43:36 -0400 Subject: [PATCH 3/3] Revert change to explicitly specify length --- Tools/jit/_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/jit/_writer.py b/Tools/jit/_writer.py index 7f0606beb3f61d..4e7f614b0e9d23 100644 --- a/Tools/jit/_writer.py +++ b/Tools/jit/_writer.py @@ -31,7 +31,7 @@ def _dump_footer( yield f" [{opname}] = {group.as_c(opname)}," yield "};" yield "" - yield "static const void * const symbols_map[] = {" + yield f"static const void * const symbols_map[{max(len(symbols), 1)}] = {{" if symbols: for symbol, ordinal in symbols.items(): yield f" [{ordinal}] = &{symbol},"