Skip to content

Commit 81e5236

Browse files
committed
Use 'X ? 1 : 0' instead of 'X != 0'
This hopefully avoids a silly compiler warning.
1 parent 37e3b40 commit 81e5236

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

Python/generated_cases.c.h

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

Python/opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
531531
case MAP_ADD:
532532
return 0;
533533
case LOAD_ATTR:
534-
return ((oparg & 1) != 0) + 1;
534+
return ((oparg & 1) ? 1 : 0) + 1;
535535
case LOAD_ATTR_INSTANCE_VALUE:
536536
return -1;
537537
case LOAD_ATTR_MODULE:

Tools/cases_generator/generate_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def effect_size(effect: StackEffect) -> tuple[int, str]:
6464
assert not effect.cond, "Array effects cannot have a condition"
6565
return 0, effect.size
6666
elif effect.cond:
67-
return 0, f"{maybe_parenthesize(effect.cond)} != 0"
67+
return 0, f"{maybe_parenthesize(effect.cond)} ? 1 : 0"
6868
else:
6969
return 1, ""
7070

Tools/cases_generator/test_generator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,17 @@ def test_cond_effect():
491491
output = """
492492
TARGET(OP) {
493493
PyObject *cc = PEEK(1);
494-
PyObject *input = (oparg & 1) ? PEEK(1 + ((oparg & 1) != 0)) : NULL;
495-
PyObject *aa = PEEK(2 + ((oparg & 1) != 0));
494+
PyObject *input = (oparg & 1) ? PEEK(1 + ((oparg & 1) ? 1 : 0)) : NULL;
495+
PyObject *aa = PEEK(2 + ((oparg & 1) ? 1 : 0));
496496
PyObject *xx;
497497
PyObject *output = NULL;
498498
PyObject *zz;
499499
output = spam(oparg, input);
500-
STACK_SHRINK(((oparg & 1) != 0));
501-
STACK_GROW(((oparg & 2) != 0));
500+
STACK_SHRINK(((oparg & 1) ? 1 : 0));
501+
STACK_GROW(((oparg & 2) ? 1 : 0));
502502
POKE(1, zz);
503-
if (oparg & 2) { POKE(1 + ((oparg & 2) != 0), output); }
504-
POKE(2 + ((oparg & 2) != 0), xx);
503+
if (oparg & 2) { POKE(1 + ((oparg & 2) ? 1 : 0), output); }
504+
POKE(2 + ((oparg & 2) ? 1 : 0), xx);
505505
DISPATCH();
506506
}
507507
"""

0 commit comments

Comments
 (0)