From 64a263a1ceed726494767d833a2ea33033a6ae28 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 4 Jun 2016 20:32:36 +0300 Subject: Issue #20041: Fixed TypeError when frame.f_trace is set to None. Patch by Xavier de Gaye. --- Lib/test/test_sys_settrace.py | 9 +++++++++ Misc/NEWS | 3 +++ Objects/frameobject.c | 8 +++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index ae8f845..509bc3e 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 2ccf912..f51918b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: tba 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 bdf06db..9aadd61 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -349,15 +349,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; } -- cgit v0.12