summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-04 17:30:43 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-04 17:30:43 (GMT)
commitd37781eb2ea9263c846286117170c7b195c31076 (patch)
treec5b50f6081a89a00bb9ad5e065f6b89c20cb6a67
parent06cd1c3d36ff7c38ba2e4836a8b83ea64df3ab29 (diff)
downloadcpython-d37781eb2ea9263c846286117170c7b195c31076.zip
cpython-d37781eb2ea9263c846286117170c7b195c31076.tar.gz
cpython-d37781eb2ea9263c846286117170c7b195c31076.tar.bz2
Issue #20041: Fixed TypeError when frame.f_trace is set to None.
Patch by Xavier de Gaye.
-rw-r--r--Lib/test/test_sys_settrace.py9
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/frameobject.c8
3 files changed, 15 insertions, 5 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 1eea786..cc9a581 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -386,6 +386,15 @@ class TraceTestCase(unittest.TestCase):
(257, 'line'),
(257, 'return')])
+ def test_17_none_f_trace(self):
+ # Issue 20041: fix TypeError when f_trace is set to None.
+ def func():
+ sys._getframe().f_trace = None
+ lineno = 2
+ self.run_and_compare(func,
+ [(0, 'call'),
+ (1, 'line')])
+
class RaisingTraceFuncTestCase(unittest.TestCase):
def trace(self, frame, event, arg):
diff --git a/Misc/NEWS b/Misc/NEWS
index 71a9209..80c6400 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
Core and Builtins
-----------------
+- Issue #20041: Fixed TypeError when frame.f_trace is set to None.
+ Patch by Xavier de Gaye.
+
- Issue #25702: A --with-lto configure option has been added that will
enable link time optimizations at build time during a make profile-opt.
Some compilers and toolchains are known to not produce stable code when
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 4ba3e84..2c8fb01 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -364,15 +364,13 @@ frame_gettrace(PyFrameObject *f, void *closure)
static int
frame_settrace(PyFrameObject *f, PyObject* v, void *closure)
{
- PyObject* old_value;
-
/* We rely on f_lineno being accurate when f_trace is set. */
f->f_lineno = PyFrame_GetLineNumber(f);
- old_value = f->f_trace;
+ if (v == Py_None)
+ v = NULL;
Py_XINCREF(v);
- f->f_trace = v;
- Py_XDECREF(old_value);
+ Py_XSETREF(f->f_trace, v);
return 0;
}