On 28 September 2010 13:33, Lisandro Dalcin <[email protected]> wrote: > On 28 September 2010 13:02, Robert Bradshaw > <[email protected]> wrote: >> On Mon, Sep 27, 2010 at 1:55 PM, Lisandro Dalcin <[email protected]> wrote: >>> 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... >>> >> >> Yes, I would be fine with that for a fix. >> > > Still not sure about it... We also have to handle this: > http://bugs.python.org/issue9972 > > And I would like to change GILStatNode&GILExitNode: > > {PyThreadState *_save; > Py_UNBLOCK_THREADS > .... > Py_BLOCK_THREADS} > > with these macros: > > Py_BEGIN_ALLOW_THREADS > ... > Py_BEGIN_ALLOW_THREADS > >
Fixed: http://hg.cython.org/cython-devel/rev/812f81b23dc8 @Stephane: Sorry, I forgot to give you credits in the commit message. -- 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
