Commits

Ned Batchelder  committed 9a8e964

Use constants for return values to make it easier to see the various uses of 0 and -1.

  • Participants
  • Parent commits 91f0a00

Comments (0)

Files changed (1)

File coverage/tracer.c

 
 #endif /* Py3k */
 
+/* The values returned to indicate ok or error. */
+#define RET_OK      0
+#define RET_ERROR   -1
+
 /* An entry on the data stack.  For each call frame, we need to record the
     dictionary to capture data, and the last line number executed in that
     frame.
     if (self->data_stack == NULL) {
         STATS( self->stats.errors++; )
         PyErr_NoMemory();
-        return -1;
+        return RET_ERROR;
     }
     self->data_stack_alloc = STACK_DELTA;
 
 
     self->last_exc_back = NULL;
 
-    return 0;
+    return RET_OK;
 }
 
 static void
 static int
 Tracer_record_pair(Tracer *self, int l1, int l2)
 {
-    int ret = 0;
+    int ret = RET_OK;
 
     PyObject * t = PyTuple_New(2);
     if (t != NULL) {
         PyTuple_SET_ITEM(t, 1, MyInt_FromLong(l2));
         if (PyDict_SetItem(self->cur_file_data, t, Py_None) < 0) {
             STATS( self->stats.errors++; )
-            ret = -1;
+            ret = RET_ERROR;
         }
         Py_DECREF(t);
     }
     else {
         STATS( self->stats.errors++; )
-        ret = -1;
+        ret = RET_ERROR;
     }
     return ret;
 }
 static int
 Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg)
 {
-    int ret = 0;
+    int ret = RET_OK;
     PyObject * filename = NULL;
     PyObject * tracename = NULL;
 
             if (self->depth >= 0) {
                 if (self->tracing_arcs && self->cur_file_data) {
                     if (Tracer_record_pair(self, self->last_line, -1) < 0) {
-                        return -1;
+                        return RET_ERROR;
                     }
                 }
                 SHOWLOG(self->depth, frame->f_lineno, frame->f_code->co_filename, "missedreturn");
                 STATS( self->stats.errors++; )
                 PyErr_NoMemory();
                 self->depth--;
-                return -1;
+                return RET_ERROR;
             }
             self->data_stack = bigger_data_stack;
             self->data_stack_alloc = bigger;
             if (tracename == NULL) {
                 /* An error occurred inside should_trace. */
                 STATS( self->stats.errors++; )
-                return -1;
+                return RET_ERROR;
             }
             if (PyDict_SetItem(self->should_trace_cache, filename, tracename) < 0) {
                 STATS( self->stats.errors++; )
-                return -1;
+                return RET_ERROR;
             }
         }
         else {
                 file_data = PyDict_New();
                 if (file_data == NULL) {
                     STATS( self->stats.errors++; )
-                    return -1;
+                    return RET_ERROR;
                 }
                 ret = PyDict_SetItem(self->data, tracename, file_data);
                 Py_DECREF(file_data);
                 if (ret < 0) {
                     STATS( self->stats.errors++; )
-                    return -1;
+                    return RET_ERROR;
                 }
             }
             self->cur_file_data = file_data;
         if (self->depth >= 0) {
             if (self->tracing_arcs && self->cur_file_data) {
                 if (Tracer_record_pair(self, self->last_line, -1) < 0) {
-                    return -1;
+                    return RET_ERROR;
                 }
             }
 
                 if (self->tracing_arcs) {
                     /* Tracing arcs: key is (last_line,this_line). */
                     if (Tracer_record_pair(self, self->last_line, frame->f_lineno) < 0) {
-                        return -1;
+                        return RET_ERROR;
                     }
                 }
                 else {
                     PyObject * this_line = MyInt_FromLong(frame->f_lineno);
                     if (this_line == NULL) {
                         STATS( self->stats.errors++; )
-                        return -1;
+                        return RET_ERROR;
                     }
                     ret = PyDict_SetItem(self->cur_file_data, this_line, Py_None);
                     Py_DECREF(this_line);
                     if (ret < 0) {
                         STATS( self->stats.errors++; )
-                        return -1;
+                        return RET_ERROR;
                     }
                 }
             }
         break;
     }
 
-    return 0;
+    return RET_OK;
 }
 
 static PyObject *