[Python-checkins] cpython (merge 3.5 -> default): Issue #20041: Fixed TypeError when frame.f_trace is set to None.

serhiy.storchaka python-checkins at python.org
Sat Jun 4 13:42:45 EDT 2016


https://hg.python.org/cpython/rev/f993dbeb2ad2
changeset:   101704:f993dbeb2ad2
parent:      101701:416441e4afab
parent:      101703:74ad78d2dd8d
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Jun 04 20:33:33 2016 +0300
summary:
  Issue #20041: Fixed TypeError when frame.f_trace is set to None.
Patch by Xavier de Gaye.

files:
  Lib/test/test_sys_settrace.py |  9 +++++++++
  Misc/NEWS                     |  3 +++
  Objects/frameobject.c         |  2 ++
  3 files changed, 14 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -388,6 +388,15 @@
              (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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -120,6 +120,9 @@
 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
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -344,6 +344,8 @@
     /* 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);
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list