[Python-checkins] gh-106267: Add type cast to generated code (#106289)

gvanrossum webhook-mailer at python.org
Fri Jun 30 15:11:13 EDT 2023


https://github.com/python/cpython/commit/2062e115017d8c33e74ba14adef2a255c344f747
commit: 2062e115017d8c33e74ba14adef2a255c344f747
branch: main
author: Kirill Podoprigora <kirill.bast9 at mail.ru>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2023-06-30T12:11:10-07:00
summary:

gh-106267: Add type cast to generated code (#106289)

files:
M Python/executor_cases.c.h
M Tools/cases_generator/generate_cases.py

diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index ccef2736b7120..546b3d9f50ac7 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -187,7 +187,7 @@
         case TO_BOOL_ALWAYS_TRUE: {
             PyObject *value = stack_pointer[-1];
             PyObject *res;
-            uint32_t version = operand;
+            uint32_t version = (uint32_t)operand;
             #line 359 "Python/bytecodes.c"
             // This one is a bit weird, because we expect *some* failures:
             assert(version);
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py
index ff88b63d3bdd8..2332d12c6c0c6 100644
--- a/Tools/cases_generator/generate_cases.py
+++ b/Tools/cases_generator/generate_cases.py
@@ -520,7 +520,7 @@ def write_body(
                     f"{typ}{ceffect.name} = {func}(&next_instr[{active.offset}].cache);"
                 )
             else:
-                out.emit(f"{typ}{ceffect.name} = operand;")
+                out.emit(f"{typ}{ceffect.name} = ({typ.strip()})operand;")
 
         # Write the body, substituting a goto for ERROR_IF() and other stuff
         assert dedent <= 0



More information about the Python-checkins mailing list