consider this code:
cdef void foo() except * with gil:
raise ValueError
cdef int bar() except ? -1 with gil:
raise ValueError
with nogil:
foo()
with nogil:
bar()
Currently, Cython generates segfaulting code because in both cases it
is using PyErr_Occurred() without re-acquiring the GIL. I think the
easiest solution would be to use a utility code wrapping around
PyErr_Occurred() and implemented with the PyGILState_XXX API's, more
or less like below:
int __Pyx_PyErr_Occurred_WithGIL()
{
int err;
_save = PyGILState_Ensure();
err = !!PyErr_Occurred(); /* note: PyErr_Occurred() returns PyObject* */
PyGILState_Release(_save);
return err;
}
Of course, this function is going to be used ONLY when calling C
functions within nogil blocks.
Would such fix be fine? I would prefer to use the Py_[UN]BLOCK_THREAD
macros, but in such case the fix is not trivial for me and I do not
want to make a mess...
PS: note that in order to fix C++ exc handling, now SimpleCallNode
gets a "nogil" attribute at analyse_c_function_call() ...
--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev