Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ad474b

Browse files
committed
Update assertion in compiler_addop_i()
In practice, bytecode instruction arguments are unsigned. Update the assertion to make it more explicit that argument must be greater or equal than 0. Rewrite also the comment.
1 parent f219285 commit 2ad474b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Python/compile.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,14 @@ compiler_addop_i(struct compiler *c, int opcode, Py_ssize_t oparg)
11631163
struct instr *i;
11641164
int off;
11651165

1166-
/* Integer arguments are limit to 16-bit. There is an extension for 32-bit
1167-
integer arguments. */
1168-
assert((-2147483647-1) <= oparg);
1169-
assert(oparg <= 2147483647);
1166+
/* oparg value is unsigned, but a signed C int is usually used to store
1167+
it in the C code (like Python/ceval.c).
1168+
1169+
Limit to 32-bit signed C int (rather than INT_MAX) for portability.
1170+
1171+
The argument of a concrete bytecode instruction is limited to 16-bit.
1172+
EXTENDED_ARG is used for 32-bit arguments. */
1173+
assert(0 <= oparg && oparg <= 2147483647);
11701174

11711175
off = compiler_next_instr(c, c->u->u_curblock);
11721176
if (off < 0)

0 commit comments

Comments
 (0)