From cf9a2b4c8b5bb87c73d496cad2444981e4a38551 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 16 Feb 2015 21:13:24 +0200 Subject: Issue #23450: Silenced compiler warnings and added asserts in peephole optimizer. --- Python/peephole.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Python/peephole.c') diff --git a/Python/peephole.c b/Python/peephole.c index c56c8fcc23..2f8f0e5b67 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -18,7 +18,11 @@ || op==JUMP_IF_FALSE_OR_POP || op==JUMP_IF_TRUE_OR_POP) #define JUMPS_ON_TRUE(op) (op==POP_JUMP_IF_TRUE || op==JUMP_IF_TRUE_OR_POP) #define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3)) -#define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255 +#define SETARG(arr, i, val) do { \ + assert(0 <= val && val <= 0xffff); \ + arr[i+2] = (unsigned char)(((unsigned int)val)>>8); \ + arr[i+1] = (unsigned char)(((unsigned int)val) & 255); \ +} while(0) #define CODESIZE(op) (HAS_ARG(op) ? 3 : 1) #define ISBASICBLOCK(blocks, start, bytes) \ (blocks[start]==blocks[start+bytes-1]) @@ -355,7 +359,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, unsigned char *codestr = NULL; unsigned char *lineno; int *addrmap = NULL; - int new_line, cum_orig_line, last_line, tabsiz; + int new_line, cum_orig_line, last_line; + Py_ssize_t tabsiz; PyObject **const_stack = NULL; Py_ssize_t *load_const_stack = NULL; Py_ssize_t const_stack_top = -1; @@ -660,7 +665,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, /* Fixup linenotab */ for (i=0, nops=0 ; i Date: Mon, 11 May 2015 22:57:16 -0400 Subject: PEP 0492 -- Coroutines with async and await syntax. Issue #24017. --- Python/peephole.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Python/peephole.c') diff --git a/Python/peephole.c b/Python/peephole.c index 2f8f0e5b67..59ad3b762f 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -319,6 +319,7 @@ markblocks(unsigned char *code, Py_ssize_t len) case SETUP_EXCEPT: case SETUP_FINALLY: case SETUP_WITH: + case SETUP_ASYNC_WITH: j = GETJUMPTGT(code, i); blocks[j] = 1; break; @@ -620,6 +621,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, case SETUP_EXCEPT: case SETUP_FINALLY: case SETUP_WITH: + case SETUP_ASYNC_WITH: tgt = GETJUMPTGT(codestr, i); /* Replace JUMP_* to a RETURN into just a RETURN */ if (UNCONDITIONAL_JUMP(opcode) && @@ -704,6 +706,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, case SETUP_EXCEPT: case SETUP_FINALLY: case SETUP_WITH: + case SETUP_ASYNC_WITH: j = addrmap[GETARG(codestr, i) + i + 3] - addrmap[i] - 3; SETARG(codestr, i, j); break; -- cgit v1.2.1 From ecaaa548245ae3431815a70162b0d6ef12700551 Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Thu, 26 May 2016 05:35:26 +0000 Subject: Issue #27076: Doc, comment and tests spelling fixes Most fixes to Doc/ and Lib/ directories by Ville Skytt?. --- Python/peephole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/peephole.c') diff --git a/Python/peephole.c b/Python/peephole.c index 59ad3b762f..4e657fa176 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -344,7 +344,7 @@ markblocks(unsigned char *code, Py_ssize_t len) appear before MAKE_FUNCTION; in this case both opcodes are skipped. EXTENDED_ARG preceding any other opcode causes the optimizer to bail. - Optimizations are restricted to simple transformations occuring within a + Optimizations are restricted to simple transformations occurring within a single basic block. All transformations keep the code size the same or smaller. For those that reduce size, the gaps are initially filled with NOPs. Later those NOPs are removed and the jump addresses retargeted in -- cgit v1.2.1