classification
Title: setting f_exc_traceback aborts in debug builds
Type: crash Stage: needs patch
Components: Interpreter Core Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, belopolsky, benjamin.peterson, michael.foord
Priority: normal Keywords:

Created on 2008-12-22 17:20 by benjamin.peterson, last changed 2019-12-01 12:16 by BTaskaya.

Messages (7)
msg78199 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-12-22 17:20
$ ./python.exe 
Python 2.7a0 (trunk:67899, Dec 22 2008, 11:17:09) 
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
[36275 refs]
>>> sys._getframe(0).f_exc_traceback = 23
Python/ceval.c:2720: failed assertion `tstate->frame->f_exc_traceback ==
NULL'
Abort trap
msg109476 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-07 14:08
Anybody willing and able to run with this?
msg111997 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-29 20:37
As no response to msg109476 I'll close unless anyone objects.
msg112023 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-07-29 23:39
Lack of response is not an appropriate reason to close.
msg112024 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-07-29 23:43
Yup, still active:

$ ./python.exe 
Python 2.7.0+ (release27-maint:83247, Jul 30 2010, 00:41:50) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
[35067 refs]
>>> sys._getframe(0).f_exc_traceback = 23
Assertion failed: (tstate->frame->f_exc_traceback == NULL), function PyEval_EvalFrameEx, file Python/ceval.c, line 2998.
Abort trap
msg127754 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-02-02 19:46
Not applicable to 3.x because the frame object does not have f_exc_traceback attribute anymore:

>>> import sys;sys._getframe(0).f_exc_traceback = 23
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'frame' object has no attribute 'f_exc_traceback'

The issue is present in 2.7 but appears to be rather benign.   It looks like the worst that can happen in non-debug build is a reference leak in set_exc_info().

I am not sure if this is worth fixing.  If this was affecting development version, I would argue that the simplest fix is to disallow setting f_exc_traceback or f_exc_value before f_exc_type is set.  In a bug-fix reliase, however this is probably not acceptable.

Given that sys._getframe() screams "beware, expert use only", I am not sure anything should be done other than possibly documenting that assigning to f_exc_* attributes of a transient frame object is not a good idea.

Note that the following works:

>>> f = sys._getframe(0)
>>> f.f_exc_traceback = 23

If there is a legitimate use for setting f_exc_traceback, the user should know to set f.f_exc_type and f.f_exc_value as well.
msg357677 - (view) Author: Batuhan (BTaskaya) * Date: 2019-12-01 12:16
This issue looks like specific to 2.7, which is almost dead. Is there any interest about adding this to 2.7 branch?
History
Date User Action Args
2019-12-01 12:16:25BTaskayasetnosy: + BTaskaya
messages: + msg357677
2011-02-02 19:46:01belopolskysetnosy: + belopolsky, - BreamoreBoy
messages: + msg127754
versions: - Python 3.1, Python 3.2
2010-07-29 23:43:59michael.foordsetnosy: + michael.foord
messages: + msg112024
2010-07-29 23:39:23benjamin.petersonsetstatus: pending -> open

messages: + msg112023
2010-07-29 20:37:00BreamoreBoysetstatus: open -> pending
priority: high -> normal
messages: + msg111997
2010-07-07 14:08:22BreamoreBoysetversions: + Python 3.1, Python 3.2, - Python 2.6
nosy: + BreamoreBoy

messages: + msg109476

type: crash
stage: needs patch
2008-12-22 17:20:18benjamin.petersoncreate