summaryrefslogtreecommitdiff
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
parent63d542ed89d6742bebfe06477a8d8fa6a3e7702a (diff)
downloadpython-coveragepy-git-0b03c4f49a186f620ec05f585ad76aca6ebbdb69.tar.gz
Be more disciplined about the values in should_trace_cache. #374.
-rw-r--r--AUTHORS.txt1
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/collector.py3
-rw-r--r--coverage/tracer.c28
4 files changed, 27 insertions, 9 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt
index e23ae2a1..aaa9fa23 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -56,6 +56,7 @@ Ross Lawley
Sandra Martocchia
Sigve Tjora
Stan Hu
+Stefan Behnel
Steve Leonard
Titus Brown
Zooko Wilcox-O'Hearn
diff --git a/CHANGES.txt b/CHANGES.txt
index b23ab343..8892ab65 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -45,6 +45,9 @@ Latest
- The ``coverage annotate`` command now handles non-ASCII characters properly,
closing `issue 363`_. Thanks, Leonardo Pistone.
+- Plugin support had some bugs fixed, closing `issue 374`_. Thanks, Stefan
+ Behnel.
+
.. _issue 299: https://bitbucket.org/ned/coveragepy/issue/299/inserted-created-on-yyyy-mm-dd-hh-mm-in
.. _issue 308: https://bitbucket.org/ned/coveragepy/issue/308/yield-lambda-branch-coverage
.. _issue 324: https://bitbucket.org/ned/coveragepy/issue/324/yield-in-loop-confuses-branch-coverage
@@ -54,6 +57,7 @@ Latest
.. _issue 360: https://bitbucket.org/ned/coveragepy/issue/360/html-reports-get-confused-by-l-in-the-code
.. _issue 361: https://bitbucket.org/ned/coveragepy/issue/361/use-double-quotes-in-html-output-to
.. _issue 363: https://bitbucket.org/ned/coveragepy/issue/363/annotate-command-hits-unicode-happy-fun
+.. _issue 374: https://bitbucket.org/ned/coveragepy/issue/374/c-tracer-lookups-fail-in
Version 4.0a5 --- 16 February 2015
diff --git a/coverage/collector.py b/coverage/collector.py
index 948cbbb0..1925007b 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -52,8 +52,7 @@ class Collector(object):
"""Create a collector.
`should_trace` is a function, taking a filename, and returning a
- canonicalized filename, or None depending on whether the file should
- be traced or not.
+ `coverage.FileDisposition object`.
TODO: `check_include`
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);