diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-06-23 21:19:00 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-06-23 21:19:00 -0400 |
commit | 6fe58fb557567dc4502c62f7f865a33cefbf4374 (patch) | |
tree | a3cdebc133ae8478944143842afe7f22e3f72dff /coverage/tracer.c | |
parent | 7e1205ef7710cb828289d3fb46258805b57f3b70 (diff) | |
download | python-coveragepy-git-6fe58fb557567dc4502c62f7f865a33cefbf4374.tar.gz |
Remove the fixed limit on recursion depth. Fixes issue #9.
Diffstat (limited to 'coverage/tracer.c')
-rw-r--r-- | coverage/tracer.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/coverage/tracer.c b/coverage/tracer.c index ac103726..b1b82fe4 100644 --- a/coverage/tracer.c +++ b/coverage/tracer.c @@ -16,8 +16,6 @@ /* The Tracer type. */
-#define MAX_STACK_DEPTH 500
-
typedef struct {
PyObject_HEAD
PyObject * should_trace;
@@ -27,9 +25,12 @@ typedef struct { /* The index of the last-used entry in tracenames. */
int depth;
/* Filenames to record at each level, or NULL if not recording. */
- PyObject * tracenames[MAX_STACK_DEPTH];
+ PyObject ** tracenames; /* PyMem_Malloc'ed. */
+ int tracenames_alloc; /* number of entries at tracenames. */
} Tracer;
+#define TRACENAMES_DELTA 100
+
static int
Tracer_init(Tracer *self, PyObject *args, PyObject *kwds)
{
@@ -38,6 +39,11 @@ Tracer_init(Tracer *self, PyObject *args, PyObject *kwds) self->should_trace_cache = NULL;
self->started = 0;
self->depth = -1;
+ self->tracenames = PyMem_Malloc(TRACENAMES_DELTA*sizeof(PyObject *));
+ if (self->tracenames == NULL) {
+ return -1;
+ }
+ self->tracenames_alloc = TRACENAMES_DELTA;
return 0;
}
@@ -56,6 +62,8 @@ Tracer_dealloc(Tracer *self) Py_XDECREF(self->tracenames[self->depth]);
self->depth--;
}
+
+ PyMem_Free(self->tracenames);
self->ob_type->tp_free((PyObject*)self);
}
@@ -71,9 +79,16 @@ Tracer_trace(Tracer *self, PyFrameObject *frame, int what, PyObject *arg) switch (what) {
case PyTrace_CALL: /* 0 */
self->depth++;
- if (self->depth > MAX_STACK_DEPTH) {
- PyErr_SetString(PyExc_RuntimeError, "Tracer stack overflow");
- return -1;
+ if (self->depth >= self->tracenames_alloc) {
+ /* We've outgrown our tracenames array: make it bigger. */
+ int bigger = self->tracenames_alloc + TRACENAMES_DELTA;
+ PyObject ** bigger_tracenames = PyMem_Realloc(self->tracenames, bigger * sizeof(PyObject *));
+ if (bigger_tracenames == NULL) {
+ self->depth--;
+ return -1;
+ }
+ self->tracenames = bigger_tracenames;
+ self->tracenames_alloc = bigger;
}
/* Check if we should trace this line. */
filename = frame->f_code->co_filename;
|