include: explicitly indicate values are unsigned when it could matter

In C, mixing up between int and unsigned int doesn't matter too much for constants
because in memory they end up the same.
However, in Python, they appear differently.

Swig assumes (wrongly?) by default that the constants are signed, intead of being unsigned.
For every value equal or greater that 2**31, it matters.
For instance CR_INVERT should be 2147483648, but it is -2147483648 in python.
By marking the values explicitly unsigned, swig generates the right values.

That's excepted for enum, which swig just consider int. So for the only constant in that
case, we manually override it in swig.
This commit is contained in:
Éric Piel 2015-06-06 23:34:27 +02:00 committed by Ian Abbott
parent cda898efc6
commit da0fe745fc
2 changed files with 6 additions and 3 deletions

View file

@ -67,13 +67,13 @@ typedef unsigned short sampl_t;
#define CR_RANGE(a) (((a)>>16)&0xff)
#define CR_AREF(a) (((a)>>24)&0x03)
#define CR_FLAGS_MASK 0xfc000000
#define CR_FLAGS_MASK 0xfc000000U
#define CR_ALT_FILTER (1<<26)
#define CR_DITHER CR_ALT_FILTER
#define CR_DEGLITCH CR_ALT_FILTER
#define CR_ALT_SOURCE (1<<27)
#define CR_EDGE (1<<30)
#define CR_INVERT (1<<31)
#define CR_INVERT (1U<<31)
#define AREF_GROUND 0x00 /* analog ref = analog ground */
#define AREF_COMMON 0x01 /* analog ref = analog common */
@ -153,7 +153,7 @@ typedef unsigned short sampl_t;
/* trigger sources */
#define TRIG_ANY 0xffffffff
#define TRIG_ANY 0xffffffffU
#define TRIG_INVALID 0x00000000
#define TRIG_NONE 0x00000001 /* never trigger */

View file

@ -59,6 +59,9 @@ static unsigned int cr_range(unsigned int a){
static unsigned int cr_aref(unsigned int a){
return CR_AREF(a);
}
/*Trick to force this enum value from being unsigned instead of signed (and wrong value) */
#define NI_GPCT_INVERT_CLOCK_SRC_BIT 0x80000000U
%}
#ifdef SWIGRUBY