summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-06-04 17:33:33 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-06-04 17:33:33 (GMT)
commit64c26e5f6004523090c52970d1ed31a351617f38 (patch)
tree1fb3d95f1e3a6b1164a2458b2e95b2a56eef4bca
parenta5071c2b4cff9c51fc0fd106a3d42b9a2563eb91 (diff)
parent64a263a1ceed726494767d833a2ea33033a6ae28 (diff)
downloadcpython-64c26e5f6004523090c52970d1ed31a351617f38.zip
cpython-64c26e5f6004523090c52970d1ed31a351617f38.tar.gz
cpython-64c26e5f6004523090c52970d1ed31a351617f38.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.c2
3 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index bb83623..25c5835 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -388,6 +388,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 setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index 21638b5..b92b312 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -120,6 +120,9 @@ Release date: 2016-05-16
Core and Builtins
-----------------
+- Issue #20041: Fixed TypeError when frame.f_trace is set to None.
+ Patch by Xavier de Gaye.
+
- Issue #26168: Fixed possible refleaks in failing Py_BuildValue() with the "N"
format unit.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 492886f..b115614 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -344,6 +344,8 @@ frame_settrace(PyFrameObject *f, PyObject* v, void *closure)
/* We rely on f_lineno being accurate when f_trace is set. */
f->f_lineno = PyFrame_GetLineNumber(f);
+ if (v == Py_None)
+ v = NULL;
Py_XINCREF(v);
Py_XSETREF(f->f_trace, v);