[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2018-07-11 Thread STINNER Victor


STINNER Victor  added the comment:

Yeah, let's close this issue.

--
resolution:  -> fixed
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2018-07-11 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Can this issue be closed now?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2018-03-22 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

I can reproduce a crash in 3.5, but not in 3.6. Seems it was fixed in 
issue30416.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2017-04-11 Thread Louie Lu

Changes by Louie Lu :


--
pull_requests: +1221

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2017-04-11 Thread Louie Lu

Changes by Louie Lu :


--
versions: +Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2015-12-09 Thread STINNER Victor

New submission from STINNER Victor:

The peephole optimizer computes 2**(2**100), but if I press CTRL+c (the result 
will probably kills my memory anyway), I get an assertion error (with a Python 
compiled in debug mode).

$ ./python
>>> 2**(2**100)
^C
python: Python/ceval.c:1218: PyEval_EvalFrameEx: Assertion `!PyErr_Occurred()' 
failed.
Abandon (core dumped)

fold_binops_on_constants() returns 0 with an exception (KeyboardInterrupt) 
raised. The problem is in the caller which doesn't handle the exception 
properly:

if (h >= 0 &&
ISBASICBLOCK(blocks, h, i-h+1)  &&
fold_binops_on_constants([i], consts, 
CONST_STACK_LASTN(2))) {
i -= 2;
memset([h], NOP, i - h);
assert(codestr[i] == LOAD_CONST);
CONST_STACK_POP(2);
CONST_STACK_PUSH_OP(i);
}

There is probably the same error on fold_unaryops_on_constants().


Python 2.7 looks to behave correctly:

$ python2.7
>>> 2**(2**100)
^C
Traceback (most recent call last):
  File "", line 1, in 
KeyboardInterrupt


But in fact Python 2.7 is much worse :-D Peephole optimizer of Python 2.7 
clears *all* exceptions (!) and it only optimizes 2**100, but not 2**(2**100). 
That's why the bug is not easily reproduced on Python 2.7. 
fold_binops_on_constants():

if (newconst == NULL) {
if(!PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
PyErr_Clear();
return 0;
}

--
messages: 256143
nosy: haypo
priority: normal
severity: normal
status: open
title: PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt 
correctly
type: crash
versions: Python 2.7, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2015-12-09 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
components: +Interpreter Core
nosy: +serhiy.storchaka
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2015-12-09 Thread STINNER Victor

STINNER Victor added the comment:

FYI.

> Peephole optimizer of Python 2.7 (...) only optimizes 2**100, but not 
> 2**(2**100).

This optimizer is dummy, it's only able to replace "LOAD_CONST x; LOAD_CONST y; 
OPERATION" with the result, whereas the optimizer replaces the bytecode with 
"NOP; NOP; NOP; NOP; LOAD_CONST z".

So "LOAD_CONST x; LOAD_CONST y; LOAD_CONST z; OPERATION1; OPERATION2" cannot be 
optimized. But it's enough to optimize 1+2+3 or 1*2*3 for example.

Python 3 peephole optimize does better thanks to a better design:
---
changeset:   68375:14205d0fee45
user:Antoine Pitrou 
date:Fri Mar 11 17:27:02 2011 +0100
files:   Lib/test/test_peepholer.py Misc/NEWS Python/peephole.c
description:
Issue #11244: The peephole optimizer is now able to constant-fold
arbitrarily complex expressions.  This also fixes a 3.2 regression where
operations involving negative numbers were not constant-folded.
---

It uses a stack for constants, so it's able to optimize more cases.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25828] PyCode_Optimize() (peephole optimizer) doesn't handle KeyboardInterrupt correctly

2015-12-09 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
nosy: +pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com