changeset 1471:9fb0eee04dd9

Enabled libc support on Win32, so we don't break binary compatibility in 1.2
author Sam Lantinga <slouken@libsdl.org>
date Mon, 06 Mar 2006 07:42:36 +0000
parents d47d96962fcc
children 4aac8563c296
files VisualC.zip VisualCE.zip include/SDL_config_win32.h include/SDL_thread.h src/thread/SDL_systhread.h src/thread/SDL_thread.c src/thread/win32/SDL_systhread.c
diffstat 7 files changed, 88 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
Binary file VisualC.zip has changed
Binary file VisualCE.zip has changed
--- a/include/SDL_config_win32.h	Mon Mar 06 06:00:45 2006 +0000
+++ b/include/SDL_config_win32.h	Mon Mar 06 07:42:36 2006 +0000
@@ -51,14 +51,64 @@
 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
--- a/include/SDL_thread.h	Mon Mar 06 06:00:45 2006 +0000
+++ b/include/SDL_thread.h	Mon Mar 06 07:42:36 2006 +0000
@@ -45,7 +45,7 @@
 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()
@@ -59,11 +59,9 @@
    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__
--- a/src/thread/SDL_systhread.h	Mon Mar 06 06:00:45 2006 +0000
+++ b/src/thread/SDL_systhread.h	Mon Mar 06 07:42:36 2006 +0000
@@ -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);
--- a/src/thread/SDL_thread.c	Mon Mar 06 06:00:45 2006 +0000
+++ b/src/thread/SDL_thread.c	Mon Mar 06 07:42:36 2006 +0000
@@ -209,7 +209,7 @@
 	*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
@@ -250,7 +250,7 @@
 	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);
--- a/src/thread/win32/SDL_systhread.c	Mon Mar 06 06:00:45 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c	Mon Mar 06 07:42:36 2006 +0000
@@ -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;
@@ -56,8 +76,20 @@
   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) {