[Python-checkins] cpython: Cleanup callmethod()

victor.stinner python-checkins at python.org
Fri Aug 19 11:32:17 EDT 2016


https://hg.python.org/cpython/rev/adceb14cab96
changeset:   102760:adceb14cab96
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Aug 19 16:56:49 2016 +0200
summary:
  Cleanup callmethod()

Make callmethod() less weird: don't decrement func reference counter,
the caller is now responsible to do that.

Issue #27128.

files:
  Objects/abstract.c |  8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Objects/abstract.c b/Objects/abstract.c
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2343,9 +2343,10 @@
 {
     PyObject *args, *result;
 
+    assert(func != NULL);
+
     if (!PyCallable_Check(func)) {
         type_error("attribute of type '%.200s' is not callable", func);
-        Py_XDECREF(func);
         return NULL;
     }
 
@@ -2363,7 +2364,6 @@
     }
 
     result = call_function_tail(func, args);
-    Py_XDECREF(func);
     Py_DECREF(args);
     return result;
 }
@@ -2385,6 +2385,7 @@
     va_start(va, format);
     retval = callmethod(func, format, va, 0);
     va_end(va);
+    Py_DECREF(func);
     return retval;
 }
 
@@ -2406,6 +2407,7 @@
     va_start(va, format);
     retval = callmethod(func, format, va, 0);
     va_end(va);
+    Py_DECREF(func);
     return retval;
 }
 
@@ -2426,6 +2428,7 @@
     va_start(va, format);
     retval = callmethod(func, format, va, 1);
     va_end(va);
+    Py_DECREF(func);
     return retval;
 }
 
@@ -2447,6 +2450,7 @@
     va_start(va, format);
     retval = callmethod(func, format, va, 1);
     va_end(va);
+    Py_DECREF(func);
     return retval;
 }
 

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


More information about the Python-checkins mailing list