[Cython] Fix integer width constant names in stdint.pxd

2012-01-02 Thread Mansour Moufid
Hello,

Attached is a quick fix for some typos in stdint.pxd.

Tested with Cython version 0.15.1.

Mansour
From a9b3caf05b98c07b779d0ecd7d0e3498de4f4f84 Mon Sep 17 00:00:00 2001
From: Mansour Moufid 
Date: Mon, 2 Jan 2012 19:01:42 -0500
Subject: [PATCH] Fix integer width constant names in stdint.pxd

---
 Cython/Includes/libc/stdint.pxd |   78 +++---
 1 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/Cython/Includes/libc/stdint.pxd b/Cython/Includes/libc/stdint.pxd
index 21e6c33..206d468 100644
--- a/Cython/Includes/libc/stdint.pxd
+++ b/Cython/Includes/libc/stdint.pxd
@@ -41,52 +41,52 @@ cdef extern from "stdint.h" nogil:
 
 # 7.18.2 Limits of specified-width integer types
 # 7.18.2.1 Limits of exact-width integer types
-enum:   INT8_T_MIN
-enum:  INT16_T_MIN
-enum:  INT32_T_MIN
-enum:  INT64_T_MIN
-enum:   INT8_T_MAX
-enum:  INT16_T_MAX
-enum:  INT32_T_MAX
-enum:  INT64_T_MAX
-enum:  UINT8_T_MAX
-enum: UINT16_T_MAX
-enum: UINT32_T_MAX
-enum: UINT64_T_MAX
+enum:   INT8_MIN
+enum:  INT16_MIN
+enum:  INT32_MIN
+enum:  INT64_MIN
+enum:   INT8_MAX
+enum:  INT16_MAX
+enum:  INT32_MAX
+enum:  INT64_MAX
+enum:  UINT8_MAX
+enum: UINT16_MAX
+enum: UINT32_MAX
+enum: UINT64_MAX
 #7.18.2.2 Limits of minimum-width integer types
-enum:   INT_LEAST8_T_MIN
-enum:  INT_LEAST16_T_MIN
-enum:  INT_LEAST32_T_MIN
-enum:  INT_LEAST64_T_MIN
-enum:   INT_LEAST8_T_MAX
-enum:  INT_LEAST16_T_MAX
-enum:  INT_LEAST32_T_MAX
-enum:  INT_LEAST64_T_MAX
-enum:  UINT_LEAST8_T_MAX
-enum: UINT_LEAST16_T_MAX
-enum: UINT_LEAST32_T_MAX
-enum: UINT_LEAST64_T_MAX
+enum:   INT_LEAST8_MIN
+enum:  INT_LEAST16_MIN
+enum:  INT_LEAST32_MIN
+enum:  INT_LEAST64_MIN
+enum:   INT_LEAST8_MAX
+enum:  INT_LEAST16_MAX
+enum:  INT_LEAST32_MAX
+enum:  INT_LEAST64_MAX
+enum:  UINT_LEAST8_MAX
+enum: UINT_LEAST16_MAX
+enum: UINT_LEAST32_MAX
+enum: UINT_LEAST64_MAX
 #7.18.2.3 Limits of fastest minimum-width integer types
-enum:   INT_FAST8_T_MIN
-enum:  INT_FAST16_T_MIN
-enum:  INT_FAST32_T_MIN
-enum:  INT_FAST64_T_MIN
-enum:   INT_FAST8_T_MAX
-enum:  INT_FAST16_T_MAX
-enum:  INT_FAST32_T_MAX
-enum:  INT_FAST64_T_MAX
-enum:  UINT_FAST8_T_MAX
-enum: UINT_FAST16_T_MAX
-enum: UINT_FAST32_T_MAX
-enum: UINT_FAST64_T_MAX
+enum:   INT_FAST8_MIN
+enum:  INT_FAST16_MIN
+enum:  INT_FAST32_MIN
+enum:  INT_FAST64_MIN
+enum:   INT_FAST8_MAX
+enum:  INT_FAST16_MAX
+enum:  INT_FAST32_MAX
+enum:  INT_FAST64_MAX
+enum:  UINT_FAST8_MAX
+enum: UINT_FAST16_MAX
+enum: UINT_FAST32_MAX
+enum: UINT_FAST64_MAX
 #7.18.2.4 Limits of integer types capable of holding object pointers
 enum:  INTPTR_MIN
 enum:  INTPTR_MAX
 enum: UINTPTR_MAX
 # 7.18.2.5 Limits of greatest-width integer types
-enum:  INTMAX_T_MAX
-enum:  INTMAX_T_MIN
-enum: UINTMAX_T_MAX
+enum:  INTMAX_MAX
+enum:  INTMAX_MIN
+enum: UINTMAX_MAX
 
 # 7.18.3 Limits of other integer types
 # ptrdiff_t
-- 
1.7.5.4

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Fix integer width constant names in stdint.pxd

2012-01-02 Thread Robert Bradshaw
Thanks.

On Mon, Jan 2, 2012 at 4:31 PM, Mansour Moufid  wrote:
> Hello,
>
> Attached is a quick fix for some typos in stdint.pxd.
>
> Tested with Cython version 0.15.1.
>
> Mansour
>
> ___
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Fix integer width constant names in stdint.pxd

2012-01-02 Thread Mansour Moufid
Now my issue is as follows.

(I CCed the cython-users list if this question is more appropriate there.)

I have a simple file, int.pyx:

from libc.stdint cimport *
print long(UINT8_MAX)
print long(UINT16_MAX)
print long(UINT32_MAX)
print long(UINT64_MAX)

with the usual setup.py stuff. Compiling and running:

$ python setup.py build_ext --inplace
...
int.c:566:3: warning: overflow in implicit constant conversion [-Woverflow]
...
$ python -c 'import int'
255
65535
-1
-1

So obviously there are overflows here. Checking int.c, I see:

  /* "int.pyx":2
 * from libc.stdint cimport *
 * print long(UINT8_MAX) # <<
 * print long(UINT16_MAX)
 * print long(UINT32_MAX)
 */
  __pyx_t_1 = PyInt_FromLong(UINT8_MAX);

and so on...

PyInt_FromLong is used for all these constants, regardless of
signedness or width, so any argument larger than LONG_MAX overflows,
*before* being converted to the arbitrary-size Python integer type.

I don't know if this is a bug, or if I'm overlooking something. Is
there a way for me to use these constants with Python's arbitrary-size
integers?

Thanks,
Mansour
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Fix integer width constant names in stdint.pxd

2012-01-02 Thread Lisandro Dalcin
On 2 January 2012 22:37, Mansour Moufid  wrote:
> Now my issue is as follows.
>
> (I CCed the cython-users list if this question is more appropriate there.)
>
> I have a simple file, int.pyx:
>
> from libc.stdint cimport *
> print long(UINT8_MAX)
> print long(UINT16_MAX)
> print long(UINT32_MAX)
> print long(UINT64_MAX)
>
> with the usual setup.py stuff. Compiling and running:
>
> $ python setup.py build_ext --inplace
> ...
> int.c:566:3: warning: overflow in implicit constant conversion [-Woverflow]
> ...
> $ python -c 'import int'
> 255
> 65535
> -1
> -1
>
> So obviously there are overflows here. Checking int.c, I see:
>
>  /* "int.pyx":2
>  * from libc.stdint cimport *
>  * print long(UINT8_MAX)             # <<
>  * print long(UINT16_MAX)
>  * print long(UINT32_MAX)
>  */
>  __pyx_t_1 = PyInt_FromLong(UINT8_MAX);
>
> and so on...
>
> PyInt_FromLong is used for all these constants, regardless of
> signedness or width, so any argument larger than LONG_MAX overflows,
> *before* being converted to the arbitrary-size Python integer type.
>
> I don't know if this is a bug, or if I'm overlooking something. Is
> there a way for me to use these constants with Python's arbitrary-size
> integers?
>

All these constants are declared as "enum", so Cython promotes them to
"int". Once again, Cython should have something like a "const" type
qualifier to poperly declare these compile-time constants.

As workaround, you could explicitly cast the constants like this
"print long(UINT8_MAX)"


-- 
Lisandro Dalcin
---
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Fix integer width constant names in stdint.pxd

2012-01-02 Thread Mansour Moufid
On Mon, Jan 2, 2012 at 8:48 PM, Lisandro Dalcin  wrote:
> On 2 January 2012 22:37, Mansour Moufid  wrote:
>> Now my issue is as follows.
>>
>> (I CCed the cython-users list if this question is more appropriate there.)
>>
>> I have a simple file, int.pyx:
>>
>> from libc.stdint cimport *
>> print long(UINT8_MAX)
>> print long(UINT16_MAX)
>> print long(UINT32_MAX)
>> print long(UINT64_MAX)
>>
>> with the usual setup.py stuff. Compiling and running:
>>
>> $ python setup.py build_ext --inplace
>> ...
>> int.c:566:3: warning: overflow in implicit constant conversion [-Woverflow]
>> ...
>> $ python -c 'import int'
>> 255
>> 65535
>> -1
>> -1
>>
>> So obviously there are overflows here. Checking int.c, I see:
>>
>>  /* "int.pyx":2
>>  * from libc.stdint cimport *
>>  * print long(UINT8_MAX)             # <<
>>  * print long(UINT16_MAX)
>>  * print long(UINT32_MAX)
>>  */
>>  __pyx_t_1 = PyInt_FromLong(UINT8_MAX);
>>
>> and so on...
>>
>> PyInt_FromLong is used for all these constants, regardless of
>> signedness or width, so any argument larger than LONG_MAX overflows,
>> *before* being converted to the arbitrary-size Python integer type.
>>
>> I don't know if this is a bug, or if I'm overlooking something. Is
>> there a way for me to use these constants with Python's arbitrary-size
>> integers?
>>
>
> All these constants are declared as "enum", so Cython promotes them to
> "int". Once again, Cython should have something like a "const" type
> qualifier to poperly declare these compile-time constants.
>
> As workaround, you could explicitly cast the constants like this
> "print long(UINT8_MAX)"

This works great. Exactly what I was looking for, thanks.

Mansour
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Fix integer width constant names in stdint.pxd

2012-01-02 Thread Robert Bradshaw
On Mon, Jan 2, 2012 at 5:48 PM, Lisandro Dalcin  wrote:
> On 2 January 2012 22:37, Mansour Moufid  wrote:
>> Now my issue is as follows.
>>
>> (I CCed the cython-users list if this question is more appropriate there.)
>>
>> I have a simple file, int.pyx:
>>
>> from libc.stdint cimport *
>> print long(UINT8_MAX)
>> print long(UINT16_MAX)
>> print long(UINT32_MAX)
>> print long(UINT64_MAX)
>>
>> with the usual setup.py stuff. Compiling and running:
>>
>> $ python setup.py build_ext --inplace
>> ...
>> int.c:566:3: warning: overflow in implicit constant conversion [-Woverflow]
>> ...
>> $ python -c 'import int'
>> 255
>> 65535
>> -1
>> -1
>>
>> So obviously there are overflows here. Checking int.c, I see:
>>
>>  /* "int.pyx":2
>>  * from libc.stdint cimport *
>>  * print long(UINT8_MAX)             # <<
>>  * print long(UINT16_MAX)
>>  * print long(UINT32_MAX)
>>  */
>>  __pyx_t_1 = PyInt_FromLong(UINT8_MAX);
>>
>> and so on...
>>
>> PyInt_FromLong is used for all these constants, regardless of
>> signedness or width, so any argument larger than LONG_MAX overflows,
>> *before* being converted to the arbitrary-size Python integer type.
>>
>> I don't know if this is a bug, or if I'm overlooking something. Is
>> there a way for me to use these constants with Python's arbitrary-size
>> integers?
>>
>
> All these constants are declared as "enum", so Cython promotes them to
> "int". Once again, Cython should have something like a "const" type
> qualifier to poperly declare these compile-time constants.
>
> As workaround, you could explicitly cast the constants like this
> "print long(UINT8_MAX)"

I'm leaning towards declaring them as being the proper type to begin
with; what's to be gained by declaring these extern values as enums
(=const)? At least with the larger types we should do this to avoid
patently incorrect behavior, and this way they would be consistant
with the actual C for arithmetic promotion, etc.

- Robert
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel