Skip to content

Commit

Permalink
Fixed a bunch of 64-bit compatibility problems
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Mar 1, 2006
1 parent 1fd7c2a commit 11eb4c0
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 48 deletions.
Binary file modified VisualC.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion configure.in
Expand Up @@ -116,7 +116,7 @@ if test x$enable_libc = xyes; then
if test x$ac_cv_func_strtod = xyes; then
AC_DEFINE(HAVE_STRTOD)
fi
AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol _i64toa _ui64toa strtoll atoi atof strcmp strncmp stricmp strcasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep)
AC_CHECK_FUNCS(malloc calloc realloc free getenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp stricmp strcasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep)

AC_CHECK_LIB(m, pow, [BUILD_LDFLAGS="$BUILD_LDFLAGS -lm"])
fi
Expand Down
12 changes: 12 additions & 0 deletions include/SDL_stdinc.h
Expand Up @@ -446,6 +446,12 @@ extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int
extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
#endif

#if HAVE_STRTOUL
#define SDL_strtoul strtoul
#else
extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *string, char **endp, int base);
#endif

#if SDL_HAS_64BIT_TYPE

#if HAVE__I64TOA
Expand All @@ -466,6 +472,12 @@ extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
#endif

#if HAVE_STRTOULL
#define SDL_strtoull strtoull
#else
extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *string, char **endp, int base);
#endif

#endif /* SDL_HAS_64BIT_TYPE */

#if HAVE_STRTOD
Expand Down
8 changes: 4 additions & 4 deletions src/audio/windib/SDL_dibaudio.c
Expand Up @@ -99,7 +99,7 @@ AudioBootStrap WAVEOUT_bootstrap = {


/* The Win32 callback for filling the WAVE device */
static void CALLBACK FillSound(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance,
static void CALLBACK FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
DWORD dwParam1, DWORD dwParam2)
{
SDL_AudioDevice *this = (SDL_AudioDevice *)dwInstance;
Expand All @@ -118,7 +118,7 @@ static void CALLBACK FillSound(HWAVEOUT hwo, UINT uMsg, DWORD dwInstance,

static void SetMMerror(char *function, MMRESULT code)
{
int len;
size_t len;
char errbuf[MAXERRORLENGTH];
#ifdef _WIN32_WCE
wchar_t werrbuf[MAXERRORLENGTH];
Expand All @@ -132,7 +132,7 @@ static void SetMMerror(char *function, MMRESULT code)
waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH-len);
WideCharToMultiByte(CP_ACP,0,werrbuf,-1,errbuf+len,MAXERRORLENGTH-len,NULL,NULL);
#else
waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len);
waveOutGetErrorText(code, errbuf+len, (UINT)(MAXERRORLENGTH-len));
#endif

SDL_SetError("%s",errbuf);
Expand Down Expand Up @@ -266,7 +266,7 @@ int DIB_OpenAudio(_THIS, SDL_AudioSpec *spec)

/* Open the audio device */
result = waveOutOpen(&sound, WAVE_MAPPER, &waveformat,
(DWORD)FillSound, (DWORD)this, CALLBACK_FUNCTION);
(DWORD_PTR)FillSound, (DWORD_PTR)this, CALLBACK_FUNCTION);
if ( result != MMSYSERR_NOERROR ) {
SetMMerror("waveOutOpen()", result);
return(-1);
Expand Down
2 changes: 1 addition & 1 deletion src/cdrom/win32/SDL_syscdrom.c
Expand Up @@ -111,7 +111,7 @@ static int SDL_SYS_CDioctl(int id, UINT msg, DWORD flags, void *arg)
{
MCIERROR mci_error;

mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD)arg);
mci_error = mciSendCommand(SDL_mciID[id], msg, flags, (DWORD_PTR)arg);
if ( mci_error ) {
char error[256];

Expand Down
4 changes: 2 additions & 2 deletions src/file/SDL_rwops.c
Expand Up @@ -245,8 +245,8 @@ static int mem_seek(SDL_RWops *context, int offset, int whence)
}
static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
int total_bytes;
int mem_available;
size_t total_bytes;
size_t mem_available;

total_bytes = (maxnum * size);
if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/stdlib/SDL_getenv.c
Expand Up @@ -33,12 +33,12 @@
/* Note this isn't thread-safe! */

static char *SDL_envmem = NULL; /* Ugh, memory leak */
static DWORD SDL_envmemlen = 0;
static size_t SDL_envmemlen = 0;

/* Put a variable of the form "name=value" into the environment */
int SDL_putenv(const char *variable)
{
DWORD bufferlen;
size_t bufferlen;
char *value;
const char *sep;

Expand Down Expand Up @@ -67,7 +67,7 @@ int SDL_putenv(const char *variable)
/* Retrieve a variable named "name" from the environment */
char *SDL_getenv(const char *name)
{
DWORD bufferlen;
size_t bufferlen;

bufferlen = GetEnvironmentVariable(name, SDL_envmem, SDL_envmemlen);
if ( bufferlen == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib/SDL_malloc.c
Expand Up @@ -1647,7 +1647,7 @@ struct malloc_chunk {
typedef struct malloc_chunk mchunk;
typedef struct malloc_chunk* mchunkptr;
typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */
typedef unsigned int bindex_t; /* Described below */
typedef size_t bindex_t; /* Described below */
typedef unsigned int binmap_t; /* Described below */
typedef unsigned int flag_t; /* The type of various bit flag sets */

Expand Down
4 changes: 2 additions & 2 deletions src/stdlib/SDL_qsort.c
Expand Up @@ -263,7 +263,7 @@ typedef struct { char * first; char * last; } stack_entry;

static char * pivot_big(char *first, char *mid, char *last, size_t size,
int compare(const void *, const void *)) {
int d=(((last-first)/size)>>3)*size;
size_t d=(((last-first)/size)>>3)*size;
char *m1,*m2,*m3;
{ char *a=first, *b=first+d, *c=first+2*d;
#ifdef DEBUG_QSORT
Expand Down Expand Up @@ -414,7 +414,7 @@ void qsort(void *base, size_t nmemb, size_t size,
int (*compare)(const void *, const void *)) {

if (nmemb<=1) return;
if (((int)base|size)&(WORD_BYTES-1))
if (((uintptr_t)base|size)&(WORD_BYTES-1))
qsort_nonaligned(base,nmemb,size,compare);
else if (size!=WORD_BYTES)
qsort_aligned(base,nmemb,size,compare);
Expand Down
69 changes: 64 additions & 5 deletions src/stdlib/SDL_string.c
Expand Up @@ -69,7 +69,7 @@ static size_t SDL_ScanLong(const char *text, int radix, long *valuep)
}
#endif

#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOD)
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
{
const char *textstart = text;
Expand Down Expand Up @@ -100,6 +100,37 @@ static size_t SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *v
}
#endif

#ifndef HAVE_SSCANF
static size_t SDL_ScanUintPtrT(const char *text, int radix, uintptr_t *valuep)
{
const char *textstart = text;
uintptr_t value = 0;

if ( radix == 16 && SDL_strncmp(text, "0x", 2) == 0 ) {
text += 2;
}
for ( ; ; ) {
int v;
if ( SDL_isdigit(*text) ) {
v = *text - '0';
} else if ( radix == 16 && SDL_isupperhex(*text) ) {
v = 10 + (*text - 'A');
} else if ( radix == 16 && SDL_islowerhex(*text) ) {
v = 10 + (*text - 'a');
} else {
break;
}
value *= radix;
value += v;
++text;
}
if ( valuep ) {
*valuep = value;
}
return (text - textstart);
}
#endif

#ifdef SDL_HAS_64BIT_TYPE
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOLL)
static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
Expand Down Expand Up @@ -141,7 +172,7 @@ static size_t SDL_ScanLongLong(const char *text, int radix, Sint64 *valuep)
}
#endif

#ifndef HAVE_SSCANF
#if !defined(HAVE_SSCANF) || !defined(HAVE_STRTOULL)
static size_t SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 *valuep)
{
const char *textstart = text;
Expand Down Expand Up @@ -488,6 +519,20 @@ long SDL_strtol(const char *string, char **endp, int base)
}
#endif

#ifndef HAVE_STRTOUL
unsigned long SDL_strtoul(const char *string, char **endp, int base)
{
size_t len;
unsigned long value;

len = SDL_ScanUnsignedLong(string, base ? base : 10, &value);
if ( endp ) {
*endp = (char *)string + len;
}
return value;
}
#endif

#ifdef SDL_HAS_64BIT_TYPE

#ifndef HAVE__I64TOA
Expand Down Expand Up @@ -556,6 +601,20 @@ Sint64 SDL_strtoll(const char *string, char **endp, int base)
}
#endif

#ifndef HAVE_STRTOULL
Uint64 SDL_strtoull(const char *string, char **endp, int base)
{
size_t len;
Uint64 value;

len = SDL_ScanUnsignedLongLong(string, base ? base : 10, &value);
if ( endp ) {
*endp = (char *)string + len;
}
return value;
}
#endif

#endif /* SDL_HAS_64BIT_TYPE */

#ifndef HAVE_STRTOD
Expand Down Expand Up @@ -817,8 +876,8 @@ int SDL_sscanf(const char *text, const char *fmt, ...)
break;
case 'p':
{
unsigned long value;
text += SDL_ScanUnsignedLong(text, 16, &value);
uintptr_t value;
text += SDL_ScanUintPtrT(text, 16, &value);
if ( ! suppress ) {
void** valuep = va_arg(ap, void**);
*valuep = (void*)value;
Expand Down Expand Up @@ -1003,7 +1062,7 @@ static size_t SDL_PrintString(char *text, const char *string, size_t maxlen)
}
return (text - textstart);
}
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
{
char *textstart = text;
if ( maxlen <= 0 ) {
Expand Down
14 changes: 7 additions & 7 deletions src/video/SDL_RLEaccel.c
Expand Up @@ -587,12 +587,12 @@ do { \
unsigned n = (length); \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
if(((unsigned long)src ^ (unsigned long)dst) & 3) { \
if(((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
/* source and destination not in phase, blit one by one */ \
while(n--) \
BLEND16_50(dst, src, mask); \
} else { \
if((unsigned long)src & 3) { \
if((uintptr_t)src & 3) { \
/* first odd pixel */ \
BLEND16_50(dst, src, mask); \
n--; \
Expand Down Expand Up @@ -1055,7 +1055,7 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *dst,
} while(ofs < w); \
/* skip padding if necessary */ \
if(sizeof(Ptype) == 2) \
srcbuf += (unsigned long)srcbuf & 2; \
srcbuf += (uintptr_t)srcbuf & 2; \
/* blit translucent pixels on the same line */ \
ofs = 0; \
do { \
Expand Down Expand Up @@ -1147,7 +1147,7 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,
} while(ofs < w);

/* skip padding */
srcbuf += (unsigned long)srcbuf & 2;
srcbuf += (uintptr_t)srcbuf & 2;

/* skip translucent line */
ofs = 0;
Expand Down Expand Up @@ -1211,7 +1211,7 @@ int SDL_RLEAlphaBlit(SDL_Surface *src, SDL_Rect *srcrect,
} while(ofs < w); \
/* skip padding if necessary */ \
if(sizeof(Ptype) == 2) \
srcbuf += (unsigned long)srcbuf & 2; \
srcbuf += (uintptr_t)srcbuf & 2; \
/* blit translucent pixels on the same line */ \
ofs = 0; \
do { \
Expand Down Expand Up @@ -1547,7 +1547,7 @@ static int RLEAlphaSurface(SDL_Surface *surface)
} while(x < w);

/* Make sure the next output address is 32-bit aligned */
dst += (unsigned long)dst & 2;
dst += (uintptr_t)dst & 2;

/* Next, encode all translucent pixels of the same scan line */
x = 0;
Expand Down Expand Up @@ -1874,7 +1874,7 @@ static SDL_bool UnRLEAlpha(SDL_Surface *surface)

/* skip padding if needed */
if(bpp == 2)
srcbuf += (unsigned long)srcbuf & 2;
srcbuf += (uintptr_t)srcbuf & 2;

/* copy translucent pixels */
ofs = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/video/SDL_blit_A.c
Expand Up @@ -1442,7 +1442,7 @@ static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
int dstskip = info->d_skip >> 1;

while(height--) {
if(((unsigned long)srcp ^ (unsigned long)dstp) & 2) {
if(((uintptr_t)srcp ^ (uintptr_t)dstp) & 2) {
/*
* Source and destination not aligned, pipeline it.
* This is mostly a win for big blits but no loss for
Expand All @@ -1452,7 +1452,7 @@ static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
int w = width;

/* handle odd destination */
if((unsigned long)dstp & 2) {
if((uintptr_t)dstp & 2) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
dstp++;
Expand Down Expand Up @@ -1499,7 +1499,7 @@ static void Blit16to16SurfaceAlpha128(SDL_BlitInfo *info, Uint16 mask)
int w = width;

/* first odd pixel? */
if((unsigned long)srcp & 2) {
if((uintptr_t)srcp & 2) {
Uint16 d = *dstp, s = *srcp;
*dstp = BLEND16_50(d, s, mask);
srcp++;
Expand Down
4 changes: 2 additions & 2 deletions src/video/SDL_surface.c
Expand Up @@ -604,7 +604,7 @@ int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
dstrect->x*dst->format->BytesPerPixel;
if ( dst->format->palette || (color == 0) ) {
x = dstrect->w*dst->format->BytesPerPixel;
if ( !color && !((long)row&3) && !(x&3) && !(dst->pitch&3) ) {
if ( !color && !((uintptr_t)row&3) && !(x&3) && !(dst->pitch&3) ) {
int n = x >> 2;
for ( y=dstrect->h; y; --y ) {
SDL_memset4(row, 0, n);
Expand Down Expand Up @@ -690,7 +690,7 @@ int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
Uint16 c = (Uint16)color;
Uint32 cc = (Uint32)c << 16 | c;
int n = dstrect->w;
if((unsigned long)pixels & 3) {
if((uintptr_t)pixels & 3) {
*pixels++ = c;
n--;
}
Expand Down
4 changes: 2 additions & 2 deletions src/video/wincommon/SDL_sysevents.c
Expand Up @@ -191,7 +191,7 @@ static BOOL WINAPI WIN_TrackMouseEvent(TRACKMOUSEEVENT *ptme)
{
if ( ptme->dwFlags == TME_LEAVE ) {
return SetTimer(ptme->hwndTrack, ptme->dwFlags, 100,
(TIMERPROC)TrackMouseTimerProc);
(TIMERPROC)TrackMouseTimerProc) != 0;
}
return FALSE;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ static void WIN_GetKeyboardState(void)
/* The main Win32 event handler
DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
*/
LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
SDL_VideoDevice *this = current_video;
static int mouse_pressed = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/video/wincommon/SDL_sysmouse.c
Expand Up @@ -172,7 +172,7 @@ WMcursor *WIN_CreateWMCursor(_THIS,

/* Create the cursor */
cursor->curs = CreateCursor(
(HINSTANCE)GetWindowLong(SDL_Window, GWL_HINSTANCE),
(HINSTANCE)GetWindowLongPtr(SDL_Window, GWL_HINSTANCE),
hot_x, hot_y, allowed_x, allowed_y,
cursor->ands, cursor->xors);
if ( cursor->curs == NULL ) {
Expand Down

0 comments on commit 11eb4c0

Please sign in to comment.