From 0a923897152af561c59282a7a0fecd3bc9d82dad Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 26 Apr 2010 06:51:18 -0400 Subject: Use constants for return values to make it easier to see the various uses of 0 and -1. --- coverage/tracer.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/coverage/tracer.c b/coverage/tracer.c index 8193c34..448f945 100644 --- a/coverage/tracer.c +++ b/coverage/tracer.c @@ -41,6 +41,10 @@ #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. @@ -139,7 +143,7 @@ Tracer_init(Tracer *self, PyObject *args, PyObject *kwds) if (self->data_stack == NULL) { STATS( self->stats.errors++; ) PyErr_NoMemory(); - return -1; + return RET_ERROR; } self->data_stack_alloc = STACK_DELTA; @@ -148,7 +152,7 @@ Tracer_init(Tracer *self, PyObject *args, PyObject *kwds) self->last_exc_back = NULL; - return 0; + return RET_OK; } static void @@ -219,7 +223,7 @@ static const char * what_sym[] = {"CALL", "EXC ", "LINE", "RET "}; 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) { @@ -227,13 +231,13 @@ Tracer_record_pair(Tracer *self, int l1, int l2) 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; } @@ -244,7 +248,7 @@ Tracer_record_pair(Tracer *self, int l1, int l2) 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; @@ -277,7 +281,7 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) 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"); @@ -304,7 +308,7 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) STATS( self->stats.errors++; ) PyErr_NoMemory(); self->depth--; - return -1; + return RET_ERROR; } self->data_stack = bigger_data_stack; self->data_stack_alloc = bigger; @@ -327,11 +331,11 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) 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 { @@ -345,13 +349,13 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) 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; @@ -373,7 +377,7 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) 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; } } @@ -393,7 +397,7 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) 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 { @@ -401,13 +405,13 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) 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; } } } @@ -439,7 +443,7 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) break; } - return 0; + return RET_OK; } static PyObject * -- cgit v1.2.1