Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enabled libc support on Win32, so we don't break binary compatibility…
… in 1.2
  • Loading branch information
slouken committed Mar 6, 2006
1 parent 27b824b commit a626782
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 8 deletions.
Binary file modified VisualC.zip
Binary file not shown.
Binary file modified VisualCE.zip
Binary file not shown.
50 changes: 50 additions & 0 deletions include/SDL_config_win32.h
Expand Up @@ -51,14 +51,64 @@ typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#ifndef _SIZE_T_DEFINED_
#define _SIZE_T_DEFINED_
typedef unsigned int size_t;
#endif
typedef unsigned int uintptr_t;
#endif /* _MSC_VER */
#define SDL_HAS_64BIT_TYPE 1

/* Enabled for SDL 1.2 (binary compatibility) */
#define HAVE_LIBC 0
#if HAVE_LIBC
/* Useful headers */
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
#define HAVE_STRING_H 1
#define HAVE_CTYPE_H 1
#define HAVE_MATH_H 1
#ifndef _WIN32_WCE
#define HAVE_SIGNAL_H 1
#endif

/* C library functions */
#define HAVE_MALLOC 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
#define HAVE_ALLOCA 1
#define HAVE_QSORT 1
#define HAVE_ABS 1
#define HAVE_MEMSET 1
#define HAVE_MEMCPY 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMCMP 1
#define HAVE_STRLEN 1
#define HAVE__STRREV 1
#define HAVE__STRUPR 1
#define HAVE__STRLWR 1
#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
#define HAVE_ITOA 1
#define HAVE__LTOA 1
#define HAVE__ULTOA 1
#define HAVE_STRTOL 1
#define HAVE_STRTOUL 1
#define HAVE_STRTOLL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
#define HAVE_STRICMP 1
#define HAVE_STRCASECMP 1
#define HAVE_SSCANF 1
#else
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
#endif

/* Enable various audio drivers */
#ifndef _WIN32_WCE
Expand Down
8 changes: 3 additions & 5 deletions include/SDL_thread.h
Expand Up @@ -45,7 +45,7 @@ struct SDL_Thread;
typedef struct SDL_Thread SDL_Thread;

/* Create a thread */
#if defined(__WIN32__) || defined(__OS2__)
#if (defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)
/*
We compile SDL into a DLL on OS/2. This means, that it's the DLL which
creates a new thread for the calling process with the SDL_CreateThread()
Expand All @@ -59,11 +59,9 @@ typedef struct SDL_Thread SDL_Thread;
So, in short:
Always use the _beginthread() and _endthread() of the calling runtime library!
*/
#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
#ifndef _WIN32_WCE
#include <process.h> // This has _beginthread() and _endthread() defined!
#endif
#ifdef __EMX__
#include <stdlib.h> // This has _beginthread() and _endthread() defined, if -Zmt flag is used!
#include <process.h> /* This has _beginthread() and _endthread() defined! */
#endif

#ifdef __OS2__
Expand Down
2 changes: 1 addition & 1 deletion src/thread/SDL_systhread.h
Expand Up @@ -32,7 +32,7 @@
saves a system-dependent thread id in thread->id, and returns 0
on success.
*/
#if defined(__WIN32__) || defined(__OS2__)
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
extern int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread);
#else
extern int SDL_SYS_CreateThread(SDL_Thread *thread, void *args);
Expand Down
4 changes: 2 additions & 2 deletions src/thread/SDL_thread.c
Expand Up @@ -209,7 +209,7 @@ void SDL_RunThread(void *data)
*statusloc = userfunc(userdata);
}

#if defined(__WIN32__) || defined(__OS2__)
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
#undef SDL_CreateThread
DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
#else
Expand Down Expand Up @@ -250,7 +250,7 @@ DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data)
SDL_AddThread(thread);

/* Create the thread and go! */
#if defined(__WIN32__) || defined(__OS2__)
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
#else
ret = SDL_SYS_CreateThread(thread, args);
Expand Down
32 changes: 32 additions & 0 deletions src/thread/win32/SDL_systhread.c
Expand Up @@ -30,6 +30,26 @@
#include "../SDL_thread_c.h"
#include "../SDL_systhread.h"

#ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD
#ifndef _WIN32_WCE
/* We'll use the C library from this DLL */
#include <process.h>
#endif

#if __GNUC__
typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *func)(void *), void *arg,
unsigned, unsigned *threadID);
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
#else
typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
unsigned (__stdcall *func)(void *), void *arg,
unsigned, unsigned *threadID);
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
#endif
#endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */


typedef struct ThreadStartParms
{
void *args;
Expand All @@ -56,8 +76,20 @@ static unsigned __stdcall RunThread(void *data)
return(0);
}

#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
{
#else
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
{
#ifdef _WIN32_WCE
pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
pfnSDL_CurrentEndThread pfnEndThread = NULL;
#else
pfnSDL_CurrentBeginThread pfnBeginThread = _beginthreadex;
pfnSDL_CurrentEndThread pfnEndThread = _endthreadex;
#endif
#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
unsigned threadid;
pThreadStartParms pThreadParms = (pThreadStartParms)SDL_malloc(sizeof(tThreadStartParms));
if (!pThreadParms) {
Expand Down

0 comments on commit a626782

Please sign in to comment.