]> granicus.if.org Git - python/commitdiff
Update assertion in compiler_addop_i()
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 1 Mar 2016 22:34:47 +0000 (23:34 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 1 Mar 2016 22:34:47 +0000 (23:34 +0100)
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.

Python/compile.c

index 568bdfe37933f2a3915da7349882a9cb4c1efe0a..e86b2935432d4512ddeb439928950a43444e0674 100644 (file)
@@ -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)