[Pyrex] Callbacks from threads and PyGILState_Ensure/PyGILState_Release

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Sep 12 01:04:52 CEST 2007


Stefan Behnel wrote:
> Greg Ewing wrote:
> > Then two
> > function types would only be considered compatible
> > if they had the same value for this option.
> 
> The patch I submitted for Cython has not adopted this behaviour. The reasoning
> is that two functions can have an identical signature, while one of them
> requires the GIL in its implementation and the other one does not (maybe it's
> implemented in C-ish code or something). Still, both can be completely
> interchangeable, so their signature should not differ.

The point is, though, that they're *not* interchangeable.
One of them requires that the GIL be held when it is
called, and the other doesn't. If you tried to call the
GIL-requiring function when the GIL wasn't held, it
would crash.

The idea of making it part of the function signature is
so that Pyrex can check this.

The ultimate goal I have in mind is for Pyrex to keep
track of whether the GIL is held or not at each point
in the code, and generate code to acquire/release it
as appropriate. Making the GIL state part of the function
signature is a first step towards that goal.

> One of the implications of having different signatures is that a "with GIL"
> function would not be assignable to a C function slot

You would have to declare the function slot with the
appropriate GIL signature if it were to be capable of
pointing to a function that can work without the GIL.

--
Greg



More information about the Pyrex mailing list