On Jun 28, 2010, at 9:46 PM, Jared Forsyth wrote:

> Ok, so I just spent ~an hour hunting this down...and it is really  
> weird. I've pared down the code as much as possible while preserving  
> the anomaly.
>
> cdef one():
>     print two() # should be "33"...but its actually "stdout"
>
> cdef char* two():
>     cdef char* three = four()
>     print three ## will be "33"
>     return three
>
> cdef char* four():
>     cdef char* a = '33'
>     cdef char* b = '33'
>     c = ''
>     python_vbl = b  # looks like a no-op, but if you take it out,  
> the anomaly disappears
>     c = a               # is not "33"
>     return c           # returing "33"
>
> one()
>
> and...the output is
>
> >>> import strange
> 33
> stdout

The problem is that c is a Python string, which is getting cast into a  
char*, which is no longer valid once c goes out of scope (though it's  
non-deterministic exactly when the memory in question will get  
overwritten). We try to detect and prevent abuse of automatic  
conversion of str/bytes to char*, but aren't catching it in this case.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to