On Tue, May 21, 2013 at 9:32 AM, Josh Ayers <
josh....@gmail.com> wrote:
>
>>
>> > Looking at the generated C code, PyInt_FromLong is called on (end - f),
>> > which is the difference of two pointers. If I manually change the
>> > conversion function to PyInt_FromSsize_t, the warning goes away.
>>
>> Ssize_t isn't necessarily large enough to hold the difference of
>> two pointers.
>
>
> Right, but to convert it to a Python integer, that function is the only
> reasonable option that I can find.
I don't know of any modern systems where ptrdiff_t != ssize_t, though
it is allowed by the C standard.
>> > I believe the root problem is that Cython assumes a difference of two
>> > pointers can be stored in an int. Here's another short example that
>> > gives
>> > the same warning.
>>
>> > def ptr_diff():
>> > cdef int *a, *b
>> > diff = a - b # compiler warning on this line
>> > return diff
>>
>> FWIW, the correct type for storing a pointer difference is
>> ptrdiff_t.
>
>
> Is ptrdiff_t always available? If so, then that seems like the right
> choice. Either way, my main point was that Cython should infer something
> other than an int, which is incorrect on any 64 bit system.
It's part of ANSI C (89), so it should be.
https://github.com/cython/cython/commit/3087d7fd4f78514f3e962a321b5c865dafe859d9
https://github.com/cython/cython/commit/1fcaf85398e4a3ee9d4d77fc0647fdf9984b1d5b