]> 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:30:43 +0000 (20:30 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 4 Jun 2016 17:30:43 +0000 (20:30 +0300)
Patch by Xavier de Gaye.

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

index 1eea7862daf20e2b2b15ff12a0170c1a13c21567..cc9a5815e4380c960b3982c69a5768736e554169 100644 (file)
@@ -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):
index 71a9209a0a3316a2e9f92082369ef0fb4b2c7112..80c6400845012061b221bdaa1951acccc606248e 100644 (file)
--- 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
index 4ba3e84b0f20c9c6cd1bc1af38194becbe865b81..2c8fb017492e778760f6f74d5e25f3b8ad8a5611 100644 (file)
@@ -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;
 }