diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-01 22:34:47 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-01 22:34:47 (GMT) |
commit | 2ad474ba5e8ac06b7edae3cd2e15ab93212dd01b (patch) | |
tree | 2ece1014f0f7e4ec0c4309b376c6fb207da9e921 /Python/compile.c | |
parent | f2192855dd16b3f5316599c47d958b3ccc2d3758 (diff) | |
download | cpython-2ad474ba5e8ac06b7edae3cd2e15ab93212dd01b.zip cpython-2ad474ba5e8ac06b7edae3cd2e15ab93212dd01b.tar.gz cpython-2ad474ba5e8ac06b7edae3cd2e15ab93212dd01b.tar.bz2 |
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.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index 568bdfe..e86b293 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1163,10 +1163,14 @@ compiler_addop_i(struct compiler *c, int opcode, Py_ssize_t oparg) struct instr *i; int off; - /* Integer arguments are limit to 16-bit. There is an extension for 32-bit - integer arguments. */ - assert((-2147483647-1) <= oparg); - assert(oparg <= 2147483647); + /* oparg value is unsigned, but a signed C int is usually used to store + it in the C code (like Python/ceval.c). + + Limit to 32-bit signed C int (rather than INT_MAX) for portability. + + The argument of a concrete bytecode instruction is limited to 16-bit. + EXTENDED_ARG is used for 32-bit arguments. */ + assert(0 <= oparg && oparg <= 2147483647); off = compiler_next_instr(c, c->u->u_curblock); if (off < 0) |