From 7d6ceb52c040df3f66e49b0ab11ec7b9108266fe Mon Sep 17 00:00:00 2001 From: David Warde-Farley Date: Tue, 20 Sep 2011 16:59:59 -0400 Subject: ENH: release the GIL for arr_insert inner loop. Releases it only conditionally, as object arrays require refcounting to be performed within the inner loop, making GIL release impractical. --- numpy/lib/src/_compiled_base.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'numpy') diff --git a/numpy/lib/src/_compiled_base.c b/numpy/lib/src/_compiled_base.c index 715656aff..57a641b8c 100644 --- a/numpy/lib/src/_compiled_base.c +++ b/numpy/lib/src/_compiled_base.c @@ -440,9 +440,20 @@ arr_insert(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwdict) copied = 0; instrides = PyArray_STRIDES(ainput); inshape = PyArray_DIMS(ainput); - arr_insert_loop(mptr, vptr, input_data, zero, PyArray_DATA(avals), - melsize, delsize, objarray, totmask, numvals, nd, - instrides, inshape); + if (objarray) { + /* object array, need to refcount, can't release the GIL */ + arr_insert_loop(mptr, vptr, input_data, zero, PyArray_DATA(avals), + melsize, delsize, objarray, totmask, numvals, nd, + instrides, inshape); + } + else { + /* No increfs take place in arr_insert_loop, so release the GIL */ + NPY_BEGIN_ALLOW_THREADS; + arr_insert_loop(mptr, vptr, input_data, zero, PyArray_DATA(avals), + melsize, delsize, objarray, totmask, numvals, nd, + instrides, inshape); + NPY_END_ALLOW_THREADS; + } Py_DECREF(amask); Py_DECREF(avals); -- cgit v1.2.1