summaryrefslogtreecommitdiff
path: root/coverage/tracer.c
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-06-14 17:56:57 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-06-14 17:56:57 -0400
commit0b03c4f49a186f620ec05f585ad76aca6ebbdb69 (patch)
treee505fb23b3856498eebacd617933147c3d0b556e /coverage/tracer.c
parent63d542ed89d6742bebfe06477a8d8fa6a3e7702a (diff)
downloadpython-coveragepy-git-0b03c4f49a186f620ec05f585ad76aca6ebbdb69.tar.gz
Be more disciplined about the values in should_trace_cache. #374.
Diffstat (limited to 'coverage/tracer.c')
-rw-r--r--coverage/tracer.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/coverage/tracer.c b/coverage/tracer.c
index 875bfea6..fdd89d8c 100644
--- a/coverage/tracer.c
+++ b/coverage/tracer.c
@@ -498,9 +498,16 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
Py_INCREF(disposition);
}
- disp_trace = PyObject_GetAttrString(disposition, "trace");
- if (disp_trace == NULL) {
- goto error;
+ if (disposition == Py_None) {
+ /* A later check_include returned false, so don't trace it. */
+ disp_trace = Py_False;
+ Py_INCREF(Py_False);
+ }
+ else {
+ disp_trace = PyObject_GetAttrString(disposition, "trace");
+ if (disp_trace == NULL) {
+ goto error;
+ }
}
if (disp_trace == Py_True) {
@@ -547,21 +554,28 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
if (tracename != Py_None) {
/* Check the dynamic source filename against the include rules. */
PyObject * included = NULL;
+ int should_include;
included = PyDict_GetItem(self->should_trace_cache, tracename);
if (included == NULL) {
+ PyObject * should_include_bool;
if (PyErr_Occurred()) {
goto error;
}
STATS( self->stats.new_files++; )
- included = PyObject_CallFunctionObjArgs(self->check_include, tracename, frame, NULL);
- if (included == NULL) {
+ should_include_bool = PyObject_CallFunctionObjArgs(self->check_include, tracename, frame, NULL);
+ if (should_include_bool == NULL) {
goto error;
}
- if (PyDict_SetItem(self->should_trace_cache, tracename, included) < 0) {
+ should_include = (should_include_bool == Py_True);
+ Py_DECREF(should_include_bool);
+ if (PyDict_SetItem(self->should_trace_cache, tracename, should_include ? disposition : Py_None) < 0) {
goto error;
}
}
- if (included != Py_True) {
+ else {
+ should_include = (included != Py_None);
+ }
+ if (!should_include) {
Py_DECREF(tracename);
tracename = Py_None;
Py_INCREF(tracename);