[Python-checkins] r73064 - in python/trunk: Lib/test/test_cprofile.py Lib/test/test_profile.py Misc/NEWS Python/ceval.c

antoine.pitrou python-checkins at python.org
Sat May 30 23:27:01 CEST 2009


Author: antoine.pitrou
Date: Sat May 30 23:27:00 2009
New Revision: 73064
Log:
Issue #5330: C functions called with keyword arguments were not reported by
the various profiling modules (profile, cProfile). Patch by Hagen Fürstenau.
Modified:
 python/trunk/Lib/test/test_cprofile.py
 python/trunk/Lib/test/test_profile.py
 python/trunk/Misc/NEWS
 python/trunk/Python/ceval.c
Modified: python/trunk/Lib/test/test_cprofile.py
==============================================================================
--- python/trunk/Lib/test/test_cprofile.py	(original)
+++ python/trunk/Lib/test/test_cprofile.py	Sat May 30 23:27:00 2009
@@ -9,6 +9,7 @@
 
 class CProfileTest(ProfileTest):
 profilerclass = cProfile.Profile
+ expected_list_sort_output = "{method 'sort' of 'list' objects}"
 
 # Issue 3895.
 def test_bad_counter_during_dealloc(self):
Modified: python/trunk/Lib/test/test_profile.py
==============================================================================
--- python/trunk/Lib/test/test_profile.py	(original)
+++ python/trunk/Lib/test/test_profile.py	Sat May 30 23:27:00 2009
@@ -16,6 +16,7 @@
 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 @@
 "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.
+ prof = self.profilerclass(timer, 0.001)
+ stmts = [
+ "[].sort()",
+ "[].sort(reverse=True)",
+ "[].sort(*(None, None, True))",
+ "[].sort(**dict(reverse=True))",
+ ]
+ for stmt in stmts:
+ s = StringIO()
+ 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')
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat May 30 23:27:00 2009
@@ -12,6 +12,9 @@
 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 #5982: staticmethod and classmethod now expose the wrapped
 function with __func__.
 
Modified: python/trunk/Python/ceval.c
==============================================================================
--- python/trunk/Python/ceval.c	(original)
+++ python/trunk/Python/ceval.c	Sat May 30 23:27:00 2009
@@ -4160,10 +4160,17 @@
 		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);
@@ -4248,10 +4255,17 @@
 		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);


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /