Skip to content

Commit

Permalink
Fixed bug 3165 - define numbers don't match types in Swift
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Oct 1, 2016
1 parent ecea3c4 commit 614cb35
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions include/SDL.h
Expand Up @@ -72,14 +72,14 @@ extern "C" {
* specify the subsystems which you will be using in your application.
*/
/* @{ */
#define SDL_INIT_TIMER 0x00000001
#define SDL_INIT_AUDIO 0x00000010
#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
#define SDL_INIT_JOYSTICK 0x00000200 /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
#define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_GAMECONTROLLER 0x00002000 /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
#define SDL_INIT_EVENTS 0x00004000
#define SDL_INIT_NOPARACHUTE 0x00100000 /**< compatibility; this flag is ignored. */
#define SDL_INIT_TIMER 0x00000001u
#define SDL_INIT_AUDIO 0x00000010u
#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
#define SDL_INIT_JOYSTICK 0x00000200u /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
#define SDL_INIT_HAPTIC 0x00001000u
#define SDL_INIT_GAMECONTROLLER 0x00002000u /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
#define SDL_INIT_EVENTS 0x00004000u
#define SDL_INIT_NOPARACHUTE 0x00100000u /**< compatibility; this flag is ignored. */
#define SDL_INIT_EVERYTHING ( \
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
Expand Down
32 changes: 16 additions & 16 deletions include/SDL_haptic.h
Expand Up @@ -149,7 +149,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticCondition
*/
#define SDL_HAPTIC_CONSTANT (1<<0)
#define SDL_HAPTIC_CONSTANT (1u<<0)

/**
* \brief Sine wave effect supported.
Expand All @@ -158,7 +158,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticPeriodic
*/
#define SDL_HAPTIC_SINE (1<<1)
#define SDL_HAPTIC_SINE (1u<<1)

/**
* \brief Left/Right effect supported.
Expand All @@ -169,7 +169,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
* \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
* we ran out of bits, and this is important for XInput devices.
*/
#define SDL_HAPTIC_LEFTRIGHT (1<<2)
#define SDL_HAPTIC_LEFTRIGHT (1u<<2)

/* !!! FIXME: put this back when we have more bits in 2.1 */
/* #define SDL_HAPTIC_SQUARE (1<<2) */
Expand All @@ -181,7 +181,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticPeriodic
*/
#define SDL_HAPTIC_TRIANGLE (1<<3)
#define SDL_HAPTIC_TRIANGLE (1u<<3)

/**
* \brief Sawtoothup wave effect supported.
Expand All @@ -190,7 +190,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticPeriodic
*/
#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
#define SDL_HAPTIC_SAWTOOTHUP (1u<<4)

/**
* \brief Sawtoothdown wave effect supported.
Expand All @@ -199,7 +199,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticPeriodic
*/
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)

/**
* \brief Ramp effect supported.
Expand All @@ -208,7 +208,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticRamp
*/
#define SDL_HAPTIC_RAMP (1<<6)
#define SDL_HAPTIC_RAMP (1u<<6)

/**
* \brief Spring effect supported - uses axes position.
Expand All @@ -218,7 +218,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticCondition
*/
#define SDL_HAPTIC_SPRING (1<<7)
#define SDL_HAPTIC_SPRING (1u<<7)

/**
* \brief Damper effect supported - uses axes velocity.
Expand All @@ -228,7 +228,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticCondition
*/
#define SDL_HAPTIC_DAMPER (1<<8)
#define SDL_HAPTIC_DAMPER (1u<<8)

/**
* \brief Inertia effect supported - uses axes acceleration.
Expand All @@ -238,7 +238,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticCondition
*/
#define SDL_HAPTIC_INERTIA (1<<9)
#define SDL_HAPTIC_INERTIA (1u<<9)

/**
* \brief Friction effect supported - uses axes movement.
Expand All @@ -248,14 +248,14 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticCondition
*/
#define SDL_HAPTIC_FRICTION (1<<10)
#define SDL_HAPTIC_FRICTION (1u<<10)

/**
* \brief Custom effect is supported.
*
* User defined custom haptic effect.
*/
#define SDL_HAPTIC_CUSTOM (1<<11)
#define SDL_HAPTIC_CUSTOM (1u<<11)

/* @} *//* Haptic effects */

Expand All @@ -268,7 +268,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticSetGain
*/
#define SDL_HAPTIC_GAIN (1<<12)
#define SDL_HAPTIC_GAIN (1u<<12)

/**
* \brief Device can set autocenter.
Expand All @@ -277,7 +277,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticSetAutocenter
*/
#define SDL_HAPTIC_AUTOCENTER (1<<13)
#define SDL_HAPTIC_AUTOCENTER (1u<<13)

/**
* \brief Device can be queried for effect status.
Expand All @@ -286,15 +286,15 @@ typedef struct _SDL_Haptic SDL_Haptic;
*
* \sa SDL_HapticGetEffectStatus
*/
#define SDL_HAPTIC_STATUS (1<<14)
#define SDL_HAPTIC_STATUS (1u<<14)

/**
* \brief Device can be paused.
*
* \sa SDL_HapticPause
* \sa SDL_HapticUnpause
*/
#define SDL_HAPTIC_PAUSE (1<<15)
#define SDL_HAPTIC_PAUSE (1u<<15)


/**
Expand Down
12 changes: 6 additions & 6 deletions include/SDL_rwops.h
Expand Up @@ -39,12 +39,12 @@ extern "C" {
#endif

/* RWops Types */
#define SDL_RWOPS_UNKNOWN 0 /* Unknown stream type */
#define SDL_RWOPS_WINFILE 1 /* Win32 file */
#define SDL_RWOPS_STDFILE 2 /* Stdio file */
#define SDL_RWOPS_JNIFILE 3 /* Android asset */
#define SDL_RWOPS_MEMORY 4 /* Memory stream */
#define SDL_RWOPS_MEMORY_RO 5 /* Read-Only memory stream */
#define SDL_RWOPS_UNKNOWN 0U /* Unknown stream type */
#define SDL_RWOPS_WINFILE 1U /* Win32 file */
#define SDL_RWOPS_STDFILE 2U /* Stdio file */
#define SDL_RWOPS_JNIFILE 3U /* Android asset */
#define SDL_RWOPS_MEMORY 4U /* Memory stream */
#define SDL_RWOPS_MEMORY_RO 5U /* Read-Only memory stream */

/**
* This is the read/write operation structure -- very basic.
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_video.h
Expand Up @@ -122,7 +122,7 @@ typedef enum
/**
* \brief Used to indicate that you don't care what the window position is.
*/
#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000
#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
#define SDL_WINDOWPOS_ISUNDEFINED(X) \
Expand All @@ -131,7 +131,7 @@ typedef enum
/**
* \brief Used to indicate that the window position should be centered.
*/
#define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000
#define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000u
#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X))
#define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0)
#define SDL_WINDOWPOS_ISCENTERED(X) \
Expand Down

0 comments on commit 614cb35

Please sign in to comment.