Skip to content

Commit 8f4219a

Browse files
committed
Give condition for X an official name (X_exists)
Use this in the user code, trying to avoid the warning about an uninitialized variable. No longer initialize the variable to NULL. I'm torn about this, using `X_exists` is kind of magic. But if it gets rid of the complaint, I'm okay with it.
1 parent f109666 commit 8f4219a

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ dummy_func(
14521452
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
14531453
#endif /* ENABLE_SPECIALIZATION */
14541454
PyObject *name = GETITEM(names, oparg >> 1);
1455-
if (oparg & 1) {
1455+
if (res2_exists) {
14561456
/* Designed to work in tandem with CALL, pushes two values. */
14571457
PyObject* meth = NULL;
14581458
if (_PyObject_GetMethod(owner, name, &meth)) {

Python/generated_cases.c.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/generate_cases.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,10 @@ def declare(self, dst: StackEffect, src: StackEffect | None):
160160
if dst.name == UNUSED:
161161
return
162162
typ = f"{dst.type}" if dst.type else "PyObject *"
163+
init = ""
163164
if src:
164165
cast = self.cast(dst, src)
165166
init = f" = {cast}{src.name}"
166-
elif dst.cond:
167-
init = " = NULL"
168-
else:
169-
init = ""
170167
sepa = "" if typ.endswith("*") else " "
171168
self.emit(f"{typ}{sepa}{dst.name}{init};")
172169

@@ -241,7 +238,7 @@ def __init__(self, inst: parser.InstDef):
241238
]
242239
self.output_effects = inst.outputs # For consistency/completeness
243240
for effect in self.input_effects + self.output_effects:
244-
effect.cond_flag = f"_cond_{effect.name}" if effect.cond else ""
241+
effect.cond_flag = f"{effect.name}_exists" if effect.cond else ""
245242
unmoved_names: set[str] = set()
246243
for ieffect, oeffect in zip(self.input_effects, self.output_effects):
247244
if ieffect.name == oeffect.name:

Tools/cases_generator/test_generator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,19 @@ def test_cond_effect():
491491
output = """
492492
TARGET(OP) {
493493
PyObject *cc = PEEK(1);
494-
int _cond_input = maybe_parenthesize(oparg & 1) != 0;
495-
PyObject *input = (_cond_input) ? PEEK(1 + _cond_input) : NULL;
496-
PyObject *aa = PEEK(2 + _cond_input);
494+
int input_exists = maybe_parenthesize(oparg & 1) != 0;
495+
PyObject *input = (input_exists) ? PEEK(1 + input_exists) : NULL;
496+
PyObject *aa = PEEK(2 + input_exists);
497497
PyObject *xx;
498-
int _cond_output = (oparg & 2) != 0;
499-
PyObject *output = NULL;
498+
int output_exists = (oparg & 2) != 0;
499+
PyObject *output;
500500
PyObject *zz;
501501
output = spam(oparg, input);
502-
STACK_SHRINK(_cond_input);
503-
STACK_GROW(_cond_output);
502+
STACK_SHRINK(input_exists);
503+
STACK_GROW(output_exists);
504504
POKE(1, zz);
505-
if (_cond_output) { POKE(1 + _cond_output, output); }
506-
POKE(2 + _cond_output, xx);
505+
if (output_exists) { POKE(1 + output_exists, output); }
506+
POKE(2 + output_exists, xx);
507507
DISPATCH();
508508
}
509509
"""

0 commit comments

Comments
 (0)