diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-11-21 14:14:03 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-11-21 14:14:03 -0500 |
commit | c4937c33f95903cdf6ceb31985c399e56517ae4d (patch) | |
tree | 25961d74394efc79832c21d8263f28b49e1e9e56 /coverage/ctracer/tracer.c | |
parent | 4215f343c5906825719fcf275180158f80d8ee60 (diff) | |
download | python-coveragepy-git-c4937c33f95903cdf6ceb31985c399e56517ae4d.tar.gz |
Possible fix for #445 and #420
The line that seems to break #445 is the import of weakref, even if we never
use it. Delaying the import until we need it seems to fix #445.
Diffstat (limited to 'coverage/ctracer/tracer.c')
-rw-r--r-- | coverage/ctracer/tracer.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/coverage/ctracer/tracer.c b/coverage/ctracer/tracer.c index dba8a11c..25036f99 100644 --- a/coverage/ctracer/tracer.c +++ b/coverage/ctracer/tracer.c @@ -64,24 +64,11 @@ static int CTracer_init(CTracer *self, PyObject *args_unused, PyObject *kwds_unused) { int ret = RET_ERROR; - PyObject * weakref = NULL; if (DataStack_init(&self->stats, &self->data_stack) < 0) { goto error; } - weakref = PyImport_ImportModule("weakref"); - if (weakref == NULL) { - goto error; - } - STATS( self->stats.pycalls++; ) - self->data_stack_index = PyObject_CallMethod(weakref, "WeakKeyDictionary", NULL); - Py_XDECREF(weakref); - - if (self->data_stack_index == NULL) { - goto error; - } - self->pdata_stack = &self->data_stack; self->cur_entry.last_line = -1; @@ -212,6 +199,22 @@ CTracer_set_pdata_stack(CTracer *self) if (self->concur_id_func != Py_None) { int the_index = 0; + if (self->data_stack_index == NULL) { + PyObject * weakref = NULL; + + weakref = PyImport_ImportModule("weakref"); + if (weakref == NULL) { + goto error; + } + STATS( self->stats.pycalls++; ) + self->data_stack_index = PyObject_CallMethod(weakref, "WeakKeyDictionary", NULL); + Py_XDECREF(weakref); + + if (self->data_stack_index == NULL) { + goto error; + } + } + STATS( self->stats.pycalls++; ) co_obj = PyObject_CallObject(self->concur_id_func, NULL); if (co_obj == NULL) { |