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 | 95d3ada3cd3164bb086ce1b7cc14ea6a2985d637 (patch) | |
tree | 6e6c9ced475a728cc7eb2e64135c428daec13d7b /coverage/ctracer | |
parent | 397e7c1ffb17a7ad11eb078bdf990272831eb8b9 (diff) | |
download | python-coveragepy-95d3ada3cd3164bb086ce1b7cc14ea6a2985d637.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')
-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 dba8a11..25036f9 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) { |