]> granicus.if.org Git - python/commitdiff
Issue #20041: Fixed TypeError when frame.f_trace is set to None.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Jun 2016 17:32:36 +0000 (20:32 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Jun 2016 17:32:36 +0000 (20:32 +0300)
Patch by Xavier de Gaye.

Lib/test/test_sys_settrace.py
Misc/NEWS
Objects/frameobject.c

index ae8f845ee1bdab1dbc29370636e3c6186163a995..509bc3e505dea7a60bcd70b38e5a899a9932ac73 100644 (file)
@@ -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):
index 2ccf912eca5e5727e65daa110ac67de31c2abe66..f51918bf89f1c07a7f0729930cfe4b8fac1457e2 100644 (file)
--- 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.
 
index bdf06db33540101576111ebe1f956ba70078d61f..9aadd61019e0abb7f290fff26a801e81de4f739c 100644 (file)
@@ -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;
 }