Fixed bug 3165 - define numbers don't match types in Swift
authorSam Lantinga <slouken@libsdl.org>
Sat, 01 Oct 2016 13:35:36 -0700
changeset 10430dc59df175689
parent 10429 581bf4dc2783
child 10431 8f9a69bfdef0
Fixed bug 3165 - define numbers don't match types in Swift

C.W. Betts

Swift is very strict with types, so much that those of different signedness/size must be cast. Most of the defines are imported as 32-bit signed integers, while the corresponding field in a struct is a 32-bit unsigned integer. Appending a "u" would cause the defined types to be imported as 32-bit unsigned integers.
include/SDL.h
include/SDL_haptic.h
include/SDL_rwops.h
include/SDL_video.h
     1.1 --- a/include/SDL.h	Sat Oct 01 13:33:32 2016 -0700
     1.2 +++ b/include/SDL.h	Sat Oct 01 13:35:36 2016 -0700
     1.3 @@ -72,14 +72,14 @@
     1.4   *  specify the subsystems which you will be using in your application.
     1.5   */
     1.6  /* @{ */
     1.7 -#define SDL_INIT_TIMER          0x00000001
     1.8 -#define SDL_INIT_AUDIO          0x00000010
     1.9 -#define SDL_INIT_VIDEO          0x00000020  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    1.10 -#define SDL_INIT_JOYSTICK       0x00000200  /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
    1.11 -#define SDL_INIT_HAPTIC         0x00001000
    1.12 -#define SDL_INIT_GAMECONTROLLER 0x00002000  /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
    1.13 -#define SDL_INIT_EVENTS         0x00004000
    1.14 -#define SDL_INIT_NOPARACHUTE    0x00100000  /**< compatibility; this flag is ignored. */
    1.15 +#define SDL_INIT_TIMER          0x00000001u
    1.16 +#define SDL_INIT_AUDIO          0x00000010u
    1.17 +#define SDL_INIT_VIDEO          0x00000020u  /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
    1.18 +#define SDL_INIT_JOYSTICK       0x00000200u  /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
    1.19 +#define SDL_INIT_HAPTIC         0x00001000u
    1.20 +#define SDL_INIT_GAMECONTROLLER 0x00002000u  /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
    1.21 +#define SDL_INIT_EVENTS         0x00004000u
    1.22 +#define SDL_INIT_NOPARACHUTE    0x00100000u  /**< compatibility; this flag is ignored. */
    1.23  #define SDL_INIT_EVERYTHING ( \
    1.24                  SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
    1.25                  SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
     2.1 --- a/include/SDL_haptic.h	Sat Oct 01 13:33:32 2016 -0700
     2.2 +++ b/include/SDL_haptic.h	Sat Oct 01 13:35:36 2016 -0700
     2.3 @@ -149,7 +149,7 @@
     2.4   *
     2.5   *  \sa SDL_HapticCondition
     2.6   */
     2.7 -#define SDL_HAPTIC_CONSTANT   (1<<0)
     2.8 +#define SDL_HAPTIC_CONSTANT   (1u<<0)
     2.9  
    2.10  /**
    2.11   *  \brief Sine wave effect supported.
    2.12 @@ -158,7 +158,7 @@
    2.13   *
    2.14   *  \sa SDL_HapticPeriodic
    2.15   */
    2.16 -#define SDL_HAPTIC_SINE       (1<<1)
    2.17 +#define SDL_HAPTIC_SINE       (1u<<1)
    2.18  
    2.19  /**
    2.20   *  \brief Left/Right effect supported.
    2.21 @@ -169,7 +169,7 @@
    2.22   * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
    2.23   *          we ran out of bits, and this is important for XInput devices.
    2.24   */
    2.25 -#define SDL_HAPTIC_LEFTRIGHT     (1<<2)
    2.26 +#define SDL_HAPTIC_LEFTRIGHT     (1u<<2)
    2.27  
    2.28  /* !!! FIXME: put this back when we have more bits in 2.1 */
    2.29  /* #define SDL_HAPTIC_SQUARE     (1<<2) */
    2.30 @@ -181,7 +181,7 @@
    2.31   *
    2.32   *  \sa SDL_HapticPeriodic
    2.33   */
    2.34 -#define SDL_HAPTIC_TRIANGLE   (1<<3)
    2.35 +#define SDL_HAPTIC_TRIANGLE   (1u<<3)
    2.36  
    2.37  /**
    2.38   *  \brief Sawtoothup wave effect supported.
    2.39 @@ -190,7 +190,7 @@
    2.40   *
    2.41   *  \sa SDL_HapticPeriodic
    2.42   */
    2.43 -#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
    2.44 +#define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
    2.45  
    2.46  /**
    2.47   *  \brief Sawtoothdown wave effect supported.
    2.48 @@ -199,7 +199,7 @@
    2.49   *
    2.50   *  \sa SDL_HapticPeriodic
    2.51   */
    2.52 -#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
    2.53 +#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
    2.54  
    2.55  /**
    2.56   *  \brief Ramp effect supported.
    2.57 @@ -208,7 +208,7 @@
    2.58   *
    2.59   *  \sa SDL_HapticRamp
    2.60   */
    2.61 -#define SDL_HAPTIC_RAMP       (1<<6)
    2.62 +#define SDL_HAPTIC_RAMP       (1u<<6)
    2.63  
    2.64  /**
    2.65   *  \brief Spring effect supported - uses axes position.
    2.66 @@ -218,7 +218,7 @@
    2.67   *
    2.68   *  \sa SDL_HapticCondition
    2.69   */
    2.70 -#define SDL_HAPTIC_SPRING     (1<<7)
    2.71 +#define SDL_HAPTIC_SPRING     (1u<<7)
    2.72  
    2.73  /**
    2.74   *  \brief Damper effect supported - uses axes velocity.
    2.75 @@ -228,7 +228,7 @@
    2.76   *
    2.77   *  \sa SDL_HapticCondition
    2.78   */
    2.79 -#define SDL_HAPTIC_DAMPER     (1<<8)
    2.80 +#define SDL_HAPTIC_DAMPER     (1u<<8)
    2.81  
    2.82  /**
    2.83   *  \brief Inertia effect supported - uses axes acceleration.
    2.84 @@ -238,7 +238,7 @@
    2.85   *
    2.86   *  \sa SDL_HapticCondition
    2.87   */
    2.88 -#define SDL_HAPTIC_INERTIA    (1<<9)
    2.89 +#define SDL_HAPTIC_INERTIA    (1u<<9)
    2.90  
    2.91  /**
    2.92   *  \brief Friction effect supported - uses axes movement.
    2.93 @@ -248,14 +248,14 @@
    2.94   *
    2.95   *  \sa SDL_HapticCondition
    2.96   */
    2.97 -#define SDL_HAPTIC_FRICTION   (1<<10)
    2.98 +#define SDL_HAPTIC_FRICTION   (1u<<10)
    2.99  
   2.100  /**
   2.101   *  \brief Custom effect is supported.
   2.102   *
   2.103   *  User defined custom haptic effect.
   2.104   */
   2.105 -#define SDL_HAPTIC_CUSTOM     (1<<11)
   2.106 +#define SDL_HAPTIC_CUSTOM     (1u<<11)
   2.107  
   2.108  /* @} *//* Haptic effects */
   2.109  
   2.110 @@ -268,7 +268,7 @@
   2.111   *
   2.112   *  \sa SDL_HapticSetGain
   2.113   */
   2.114 -#define SDL_HAPTIC_GAIN       (1<<12)
   2.115 +#define SDL_HAPTIC_GAIN       (1u<<12)
   2.116  
   2.117  /**
   2.118   *  \brief Device can set autocenter.
   2.119 @@ -277,7 +277,7 @@
   2.120   *
   2.121   *  \sa SDL_HapticSetAutocenter
   2.122   */
   2.123 -#define SDL_HAPTIC_AUTOCENTER (1<<13)
   2.124 +#define SDL_HAPTIC_AUTOCENTER (1u<<13)
   2.125  
   2.126  /**
   2.127   *  \brief Device can be queried for effect status.
   2.128 @@ -286,7 +286,7 @@
   2.129   *
   2.130   *  \sa SDL_HapticGetEffectStatus
   2.131   */
   2.132 -#define SDL_HAPTIC_STATUS     (1<<14)
   2.133 +#define SDL_HAPTIC_STATUS     (1u<<14)
   2.134  
   2.135  /**
   2.136   *  \brief Device can be paused.
   2.137 @@ -294,7 +294,7 @@
   2.138   *  \sa SDL_HapticPause
   2.139   *  \sa SDL_HapticUnpause
   2.140   */
   2.141 -#define SDL_HAPTIC_PAUSE      (1<<15)
   2.142 +#define SDL_HAPTIC_PAUSE      (1u<<15)
   2.143  
   2.144  
   2.145  /**
     3.1 --- a/include/SDL_rwops.h	Sat Oct 01 13:33:32 2016 -0700
     3.2 +++ b/include/SDL_rwops.h	Sat Oct 01 13:35:36 2016 -0700
     3.3 @@ -39,12 +39,12 @@
     3.4  #endif
     3.5  
     3.6  /* RWops Types */
     3.7 -#define SDL_RWOPS_UNKNOWN   0   /* Unknown stream type */
     3.8 -#define SDL_RWOPS_WINFILE   1   /* Win32 file */
     3.9 -#define SDL_RWOPS_STDFILE   2   /* Stdio file */
    3.10 -#define SDL_RWOPS_JNIFILE   3   /* Android asset */
    3.11 -#define SDL_RWOPS_MEMORY    4   /* Memory stream */
    3.12 -#define SDL_RWOPS_MEMORY_RO 5   /* Read-Only memory stream */
    3.13 +#define SDL_RWOPS_UNKNOWN   0U  /* Unknown stream type */
    3.14 +#define SDL_RWOPS_WINFILE   1U  /* Win32 file */
    3.15 +#define SDL_RWOPS_STDFILE   2U  /* Stdio file */
    3.16 +#define SDL_RWOPS_JNIFILE   3U  /* Android asset */
    3.17 +#define SDL_RWOPS_MEMORY    4U  /* Memory stream */
    3.18 +#define SDL_RWOPS_MEMORY_RO 5U  /* Read-Only memory stream */
    3.19  
    3.20  /**
    3.21   * This is the read/write operation structure -- very basic.
     4.1 --- a/include/SDL_video.h	Sat Oct 01 13:33:32 2016 -0700
     4.2 +++ b/include/SDL_video.h	Sat Oct 01 13:35:36 2016 -0700
     4.3 @@ -122,7 +122,7 @@
     4.4  /**
     4.5   *  \brief Used to indicate that you don't care what the window position is.
     4.6   */
     4.7 -#define SDL_WINDOWPOS_UNDEFINED_MASK    0x1FFF0000
     4.8 +#define SDL_WINDOWPOS_UNDEFINED_MASK    0x1FFF0000u
     4.9  #define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X)  (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
    4.10  #define SDL_WINDOWPOS_UNDEFINED         SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
    4.11  #define SDL_WINDOWPOS_ISUNDEFINED(X)    \
    4.12 @@ -131,7 +131,7 @@
    4.13  /**
    4.14   *  \brief Used to indicate that the window position should be centered.
    4.15   */
    4.16 -#define SDL_WINDOWPOS_CENTERED_MASK    0x2FFF0000
    4.17 +#define SDL_WINDOWPOS_CENTERED_MASK    0x2FFF0000u
    4.18  #define SDL_WINDOWPOS_CENTERED_DISPLAY(X)  (SDL_WINDOWPOS_CENTERED_MASK|(X))
    4.19  #define SDL_WINDOWPOS_CENTERED         SDL_WINDOWPOS_CENTERED_DISPLAY(0)
    4.20  #define SDL_WINDOWPOS_ISCENTERED(X)    \