Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e124f3

Browse files
committed
Merged revisions 73064 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent c06de47 commit 8e124f3

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

Lib/test/test_cprofile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class CProfileTest(ProfileTest):
1111
profilerclass = cProfile.Profile
12+
expected_max_output = "{built-in method max}"
1213

1314
def get_expected_output(self):
1415
return _ProfileOutput

Lib/test/test_profile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ProfileTest(unittest.TestCase):
1616

1717
profilerclass = profile.Profile
1818
methodnames = ['print_stats', 'print_callers', 'print_callees']
19+
expected_max_output = ':0(max)'
1920

2021
def get_expected_output(self):
2122
return _ProfileOutput
@@ -53,6 +54,27 @@ def test_cprofile(self):
5354
results[i+1].split('\n'),
5455
expected[method].split('\n'))))
5556

57+
def test_calling_conventions(self):
58+
# Issue #5330: profile and cProfile wouldn't report C functions called
59+
# with keyword arguments. We test all calling conventions.
60+
stmts = [
61+
"max([0])",
62+
"max([0], key=int)",
63+
"max([0], **dict(key=int))",
64+
"max(*([0],))",
65+
"max(*([0],), key=int)",
66+
"max(*([0],), **dict(key=int))",
67+
]
68+
for stmt in stmts:
69+
s = StringIO()
70+
prof = self.profilerclass(timer, 0.001)
71+
prof.runctx(stmt, globals(), locals())
72+
stats = pstats.Stats(prof, stream=s)
73+
stats.print_stats()
74+
res = s.getvalue()
75+
self.assertTrue(self.expected_max_output in res,
76+
"Profiling {0!r} didn't report max:\n{1}".format(stmt, res))
77+
5678

5779
def regenerate_expected_output(filename, cls):
5880
filename = filename.rstrip('co')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.1 Release Candidate 2?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #5330: C functions called with keyword arguments were not reported by
16+
the various profiling modules (profile, cProfile). Patch by Hagen F�rstenau.
17+
1518
Library
1619
-------
1720

Python/ceval.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,10 +3951,17 @@ do_call(PyObject *func, PyObject ***pp_stack, int na, int nk)
39513951
PCALL(PCALL_METHOD);
39523952
else if (PyType_Check(func))
39533953
PCALL(PCALL_TYPE);
3954+
else if (PyCFunction_Check(func))
3955+
PCALL(PCALL_CFUNCTION);
39543956
else
39553957
PCALL(PCALL_OTHER);
39563958
#endif
3957-
result = PyObject_Call(func, callargs, kwdict);
3959+
if (PyCFunction_Check(func)) {
3960+
PyThreadState *tstate = PyThreadState_GET();
3961+
C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
3962+
}
3963+
else
3964+
result = PyObject_Call(func, callargs, kwdict);
39583965
call_fail:
39593966
Py_XDECREF(callargs);
39603967
Py_XDECREF(kwdict);
@@ -4039,10 +4046,17 @@ ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
40394046
PCALL(PCALL_METHOD);
40404047
else if (PyType_Check(func))
40414048
PCALL(PCALL_TYPE);
4049+
else if (PyCFunction_Check(func))
4050+
PCALL(PCALL_CFUNCTION);
40424051
else
40434052
PCALL(PCALL_OTHER);
40444053
#endif
4045-
result = PyObject_Call(func, callargs, kwdict);
4054+
if (PyCFunction_Check(func)) {
4055+
PyThreadState *tstate = PyThreadState_GET();
4056+
C_TRACE(result, PyCFunction_Call(func, callargs, kwdict));
4057+
}
4058+
else
4059+
result = PyObject_Call(func, callargs, kwdict);
40464060
ext_call_fail:
40474061
Py_XDECREF(callargs);
40484062
Py_XDECREF(kwdict);

0 commit comments

Comments
 (0)