cython/cython — pull request #111 by scoder (2012-04-10 08:50:41+00:00)
Title: warn when taking char* from a global Python variable

I fixed up a test for PyPy that deals with the bytes<->char* conversion:

https://github.com/scoder/cython/commit/72ef3640409b4963586a2a7e92fe9f7162e8e157

In doing so, I noticed that the actual problem, when occurring in real user code, might actually hint at a bug, or at least at fragile code. In the test, a char* is taken from a global variable, which Cython only looks up temporarily. I think it would be good to do something about this in general and I consider a visible warning an appropriate measure. Here's an example of such broken code:

```
s = b"abc"

def change_s():
global s
s = b"bcd" # deallocates previous object

def broken():
cdef char* c = s
change_s()
print(c)
```

The same applies to threading, where the GIL might get released unexpectedly when calling back into the interpreter, and other threads can change the global variable.