On Feb 7, 2009, at 3:17 PM, Lisandro Dalcin wrote:
> On Sat, Feb 7, 2009 at 8:02 PM, Robert Bradshaw
> <[email protected]> wrote:
>> On Feb 7, 2009, at 1:13 PM, Stefan Behnel wrote:
>>> Lisandro Dalcin wrote:
>>>>
>>>> cdef f():
>>>> cdef Py_ssize_t a = 5
>>>> cdef size_t b = 7
>>>> return a + b
>>>>
>>>> I believe the value of 'a+b' should be promoted to 'signed long
>>>> long',
>>>
>>> Wouldn't Py_ssize_t be a suitable target type? Admittedly, it's <<
>>> size_t
>>> for non-negative types, but the missing bit shouldn't matter in
>>> almost all
>>> cases. And if users really need to make use of it, I'm fine with
>>> requiring
>>> them to write
>>>
>>> return <PY_LONG_LONG>a + <PY_LONG_LONG>b
>>
>> Actually, the target should be size_t, following the C standard that
>> operations between signed and unsigned have an unsigned result. But
>> we certainly shouldn't be promoting it to a new type.
>>
>
> Yes, you are right, but then this testcase is expected to fail...
> Should we do better?
>
> __doc__ = """
>>>> f()
> -1
> """
> def f():
> cdef Py_ssize_t a = -2
> cdef size_t b = 1
> return a + b
That is because the doctest is wrong. Signed + unsigned = unsigned.
Consider
def f():
cdef Py_ssize_t a = -2
cdef size_t b = 1
print a + b, a + b < 0
Now the whole "a + b < 0" statement will be evaluated in C land, and
will always be False, which would make
-1, False
a really inconsistent thing to print out.
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev