]> granicus.if.org Git - python/commitdiff
Merged revisions 73064-73065 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 30 May 2009 21:43:48 +0000 (21:43 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 30 May 2009 21:43:48 +0000 (21:43 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r73064 | antoine.pitrou | 2009-05-30 23:27:00 +0200 (sam., 30 mai 2009) | 4 lines

  Issue #5330: C functions called with keyword arguments were not reported by
  the various profiling modules (profile, cProfile). Patch by Hagen Fürstenau.
........
  r73065 | antoine.pitrou | 2009-05-30 23:39:25 +0200 (sam., 30 mai 2009) | 3 lines

  The test for #5330 wasn't correct.
........

Lib/test/test_cprofile.py
Lib/test/test_profile.py
Misc/NEWS
Python/ceval.c

index 13c1060118e5708cc716e1581dacd87cc397d880..831895c389fd04fffdf3b9e416a8eaca03375b2a 100755 (executable)
@@ -9,6 +9,7 @@ from test.test_profile import ProfileTest, regenerate_expected_output
 
 class CProfileTest(ProfileTest):
     profilerclass = cProfile.Profile
+    expected_list_sort_output = "{method 'sort' of 'list' objects}"
 
     # Issue 3895.
     def test_bad_counter_during_dealloc(self):
index 0bd2530cf2abf5dd847716960e370ff3364f091f..0016d517f7dd596af2bbe156a2fc8fbde111b69d 100755 (executable)
@@ -16,6 +16,7 @@ class ProfileTest(unittest.TestCase):
     profilerclass = profile.Profile
     methodnames = ['print_stats', 'print_callers', 'print_callees']
     expected_output = {}
+    expected_list_sort_output = ':0(sort)'
 
     @classmethod
     def do_profiling(cls):
@@ -40,6 +41,25 @@ class ProfileTest(unittest.TestCase):
                              "Stats.%s output for %s doesn't fit expectation!" %
                              (method, self.profilerclass.__name__))
 
+    def test_calling_conventions(self):
+        # Issue #5330: profile and cProfile wouldn't report C functions called
+        # with keyword arguments. We test all calling conventions.
+        stmts = [
+            "[].sort()",
+            "[].sort(reverse=True)",
+            "[].sort(*(None, None, True))",
+            "[].sort(**dict(reverse=True))",
+        ]
+        for stmt in stmts:
+            s = StringIO()
+            prof = self.profilerclass(timer, 0.001)
+            prof.runctx(stmt, globals(), locals())
+            stats = pstats.Stats(prof, stream=s)
+            stats.print_stats()
+            res = s.getvalue()
+            self.assertTrue(self.expected_list_sort_output in res,
+                "Profiling {0!r} didn't report list.sort:\n{1}".format(stmt, res))
+
 
 def regenerate_expected_output(filename, cls):
     filename = filename.rstrip('co')
index 79d7f0e0b4f20b76dcbe59d1b9a106f3a6fc7ab9..6dcf1d8caa6834ab40150553a336af54c53562db 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6.3
 Core and Builtins
 -----------------
 
+- Issue #5330: C functions called with keyword arguments were not reported by
+  the various profiling modules (profile, cProfile). Patch by Hagen F�rstenau.
+
 - Issue #6089: str.format can raise SystemError with certain invalid
   field specifiers.
 
index bd35185c8464ccf1149c3ce4e464817a57ef0a70..db454d52d0d69a04e037c4438d347b7d5203c38d 100644 (file)
@@ -3911,10 +3911,17 @@ do_call(PyObject *func, PyObject ***pp_stack, int na, int nk)
                PCALL(PCALL_METHOD);
        else if (PyType_Check(func))
                PCALL(PCALL_TYPE);
+       else if (PyCFunction_Check(func))
+               PCALL(PCALL_CFUNCTION);
        else
                PCALL(PCALL_OTHER);
 #endif
-       result = PyObject_Call(func, callargs, kwdict);
+       if (PyCFunction_Check(func)) {
+               PyThreadState *tstate = PyThreadState_GET();
+               C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
+       }
+       else
+               result = PyObject_Call(func, callargs, kwdict);
  call_fail:
        Py_XDECREF(callargs);
        Py_XDECREF(kwdict);
@@ -3999,10 +4006,17 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
                PCALL(PCALL_METHOD);
        else if (PyType_Check(func))
                PCALL(PCALL_TYPE);
+       else if (PyCFunction_Check(func))
+               PCALL(PCALL_CFUNCTION);
        else
                PCALL(PCALL_OTHER);
 #endif
-       result = PyObject_Call(func, callargs, kwdict);
+       if (PyCFunction_Check(func)) {
+               PyThreadState *tstate = PyThreadState_GET();
+               C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
+       }
+       else
+               result = PyObject_Call(func, callargs, kwdict);
 ext_call_fail:
        Py_XDECREF(callargs);
        Py_XDECREF(kwdict);