Commits

Ned Batchelder committed d251f45

Use a finally clause to ensure that coverage measurement is stopped no matter how the main program terminates.

Comments (0)

Files changed (2)

coverage/cmdline.py

             
             # Run the script.
             self.coverage.start()
-            run_python_file(args[0], args)
-            self.coverage.stop()
+            try:
+                run_python_file(args[0], args)
+            finally:
+                self.coverage.stop()
         
         if settings.get('combine'):
             self.coverage.combine()

coverage/tracer.c

 #include "structmember.h"
 #include "frameobject.h"
 
+#define DEBUG 1
+
+#if DEBUG
+#define IFDEBUG(x)      x
+#else
+#define IFDEBUG(x)
+#endif
+
 // The Tracer type.
 
 typedef struct {
     int depth;
     // Filenames to record at each level, or NULL if not recording.
     PyObject * tracenames[300];
+    
+    IFDEBUG(int nshould;)
 } Tracer;
 
 static int
     self->should_trace_cache = NULL;
     self->started = 0;
     self->depth = -1;
+    IFDEBUG(self->nshould = 0;)
     return 0;
 }
 
         tracename = PyDict_GetItem(self->should_trace_cache, filename);
         if (tracename == NULL) {
             // We've never considered this file before.  Ask should_trace about it.
+            IFDEBUG(self->nshould++;)
             PyObject * args = Py_BuildValue("(O)", filename);
             tracename = PyObject_Call(self->should_trace, args, NULL);
             Py_DECREF(args);
         PyEval_SetTrace(NULL, NULL);
         self->started = 0;
     }
+    IFDEBUG(printf("nshould=%d\n", self->nshould);)
     return Py_BuildValue("");
 }