This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2015-12-09.08:03:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449648204.19.0.769728792688.issue25828@psf.upfronthosting.co.za>
In-reply-to
Content
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(&codestr[i], consts, CONST_STACK_LASTN(2))) {
                    i -= 2;
                    memset(&codestr[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 "<stdin>", line 1, in <module>
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;
    }
History
Date User Action Args
2015-12-09 08:03:24vstinnersetrecipients: + vstinner
2015-12-09 08:03:24vstinnersetmessageid: <1449648204.19.0.769728792688.issue25828@psf.upfronthosting.co.za>
2015-12-09 08:03:24vstinnerlinkissue25828 messages
2015-12-09 08:03:23vstinnercreate