Merge upstream updates
authorKees Bakker <kees@ijzerbout.nl>
Sat, 08 Oct 2011 12:45:10 +0200
changeset 60120291eb4caec4
parent 6011 83a21d3bd5c1
parent 5974 13e67468b846
child 6013 b253cc3c4276
Merge upstream updates
     1.1 --- a/configure.in	Wed Sep 28 21:42:02 2011 +0200
     1.2 +++ b/configure.in	Sat Oct 08 12:45:10 2011 +0200
     1.3 @@ -1642,6 +1642,30 @@
     1.4              ])
     1.5              AC_MSG_RESULT($has_pthread_spin_trylock)
     1.6  
     1.7 +            AC_CHECK_HEADER(pthread_np.h, have_pthread_np_h=yes)
     1.8 +            if test x$have_pthread_np_h = xyes; then
     1.9 +                AC_DEFINE(HAVE_PTHREAD_NP_H, 1, [ ])
    1.10 +            fi
    1.11 +
    1.12 +            # Check to see if pthread naming is available
    1.13 +            AC_MSG_CHECKING(for pthread_setname_np)
    1.14 +            AC_TRY_LINK_FUNC(pthread_setname_np, [
    1.15 +              has_pthread_setname_np=yes
    1.16 +              AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [ ])
    1.17 +            ],[
    1.18 +              has_pthread_setname_np=no
    1.19 +            ])
    1.20 +            AC_MSG_RESULT($has_pthread_setname_np)
    1.21 +
    1.22 +            AC_MSG_CHECKING(for pthread_set_name_np)
    1.23 +            AC_TRY_LINK_FUNC(pthread_set_name_np, [
    1.24 +              has_pthread_set_name_np=yes
    1.25 +              AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [ ])
    1.26 +            ],[
    1.27 +              has_pthread_set_name_np=no
    1.28 +            ])
    1.29 +            AC_MSG_RESULT($has_pthread_set_name_np)
    1.30 +
    1.31              # Restore the compiler flags and libraries
    1.32              CFLAGS="$ac_save_cflags"; LIBS="$ac_save_libs"
    1.33  
     2.1 --- a/include/SDL_config.h.in	Wed Sep 28 21:42:02 2011 +0200
     2.2 +++ b/include/SDL_config.h.in	Sat Oct 08 12:45:10 2011 +0200
     2.3 @@ -69,6 +69,7 @@
     2.4  #undef HAVE_ICONV_H
     2.5  #undef HAVE_SIGNAL_H
     2.6  #undef HAVE_ALTIVEC_H
     2.7 +#undef HAVE_PTHREAD_NP_H
     2.8  
     2.9  /* C library functions */
    2.10  #undef HAVE_MALLOC
    2.11 @@ -148,6 +149,8 @@
    2.12  #undef HAVE_GETPAGESIZE
    2.13  #undef HAVE_MPROTECT
    2.14  #undef HAVE_ICONV
    2.15 +#undef HAVE_PTHREAD_SETNAME_NP
    2.16 +#undef HAVE_PTHREAD_SET_NAME_NP
    2.17  
    2.18  #else
    2.19  /* We may need some replacement for stdarg.h here */
     3.1 --- a/include/SDL_thread.h	Wed Sep 28 21:42:02 2011 +0200
     3.2 +++ b/include/SDL_thread.h	Sat Oct 08 12:45:10 2011 +0200
     3.3 @@ -102,7 +102,7 @@
     3.4   *  Create a thread.
     3.5   */
     3.6  extern DECLSPEC SDL_Thread *SDLCALL
     3.7 -SDL_CreateThread(SDL_ThreadFunction fn, void *data,
     3.8 +SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
     3.9                   pfnSDL_CurrentBeginThread pfnBeginThread,
    3.10                   pfnSDL_CurrentEndThread pfnEndThread);
    3.11  
    3.12 @@ -111,27 +111,51 @@
    3.13  /**
    3.14   *  Create a thread.
    3.15   */
    3.16 -#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, NULL, NULL)
    3.17 +#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, NULL, NULL)
    3.18  
    3.19  #else
    3.20  
    3.21  /**
    3.22   *  Create a thread.
    3.23   */
    3.24 -#define SDL_CreateThread(fn, data) SDL_CreateThread(fn, data, _beginthreadex, _endthreadex)
    3.25 +#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, _beginthreadex, _endthreadex)
    3.26  
    3.27  #endif
    3.28  #else
    3.29  
    3.30  /**
    3.31   *  Create a thread.
    3.32 + *
    3.33 + *   Thread naming is a little complicated: Most systems have very small
    3.34 + *    limits for the string length (BeOS has 32 bytes, Linux currently has 16,
    3.35 + *    Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll
    3.36 + *    have to see what happens with your system's debugger. The name should be
    3.37 + *    UTF-8 (but using the naming limits of C identifiers is a better bet).
    3.38 + *   There are no requirements for thread naming conventions, so long as the
    3.39 + *    string is null-terminated UTF-8, but these guidelines are helpful in
    3.40 + *    choosing a name:
    3.41 + *
    3.42 + *    http://stackoverflow.com/questions/149932/naming-conventions-for-threads
    3.43 + *
    3.44 + *   If a system imposes requirements, SDL will try to munge the string for
    3.45 + *    it (truncate, etc), but the original string contents will be available
    3.46 + *    from SDL_GetThreadName().
    3.47   */
    3.48  extern DECLSPEC SDL_Thread *SDLCALL
    3.49 -SDL_CreateThread(SDL_ThreadFunction fn, void *data);
    3.50 +SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
    3.51  
    3.52  #endif
    3.53  
    3.54  /**
    3.55 + * Get the thread name, as it was specified in SDL_CreateThread().
    3.56 + *  This function returns a pointer to a UTF-8 string that names the
    3.57 + *  specified thread, or NULL if it doesn't have a name. This is internal
    3.58 + *  memory, not to be free()'d by the caller, and remains valid until the
    3.59 + *  specified thread is cleaned up by SDL_WaitThread().
    3.60 + */
    3.61 +extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
    3.62 +
    3.63 +/**
    3.64   *  Get the thread identifier for the current thread.
    3.65   */
    3.66  extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
     4.1 --- a/src/audio/SDL_audio.c	Wed Sep 28 21:42:02 2011 +0200
     4.2 +++ b/src/audio/SDL_audio.c	Sat Oct 08 12:45:10 2011 +0200
     4.3 @@ -1033,12 +1033,14 @@
     4.4      /* Start the audio thread if necessary */
     4.5      if (!current_audio.impl.ProvidesOwnCallbackThread) {
     4.6          /* Start the audio thread */
     4.7 +        char name[64];
     4.8 +        SDL_snprintf(name, sizeof (name), "SDLAudioDev%d", (int) (id + 1));
     4.9  /* !!! FIXME: this is nasty. */
    4.10  #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
    4.11  #undef SDL_CreateThread
    4.12 -        device->thread = SDL_CreateThread(SDL_RunAudio, device, NULL, NULL);
    4.13 +        device->thread = SDL_CreateThread(SDL_RunAudio, name, device, NULL, NULL);
    4.14  #else
    4.15 -        device->thread = SDL_CreateThread(SDL_RunAudio, device);
    4.16 +        device->thread = SDL_CreateThread(SDL_RunAudio, name, device);
    4.17  #endif
    4.18          if (device->thread == NULL) {
    4.19              SDL_CloseAudioDevice(id + 1);
     5.1 --- a/src/main/beos/SDL_BeApp.cc	Wed Sep 28 21:42:02 2011 +0200
     5.2 +++ b/src/main/beos/SDL_BeApp.cc	Sat Oct 08 12:45:10 2011 +0200
     5.3 @@ -60,7 +60,7 @@
     5.4  {
     5.5      /* Create the BApplication that handles appserver interaction */
     5.6      if (SDL_BeAppActive <= 0) {
     5.7 -        SDL_AppThread = SDL_CreateThread(StartBeApp, NULL);
     5.8 +        SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL);
     5.9          if (SDL_AppThread == NULL) {
    5.10              SDL_SetError("Couldn't create BApplication thread");
    5.11              return (-1);
     6.1 --- a/src/thread/SDL_systhread.h	Wed Sep 28 21:42:02 2011 +0200
     6.2 +++ b/src/thread/SDL_systhread.h	Sat Oct 08 12:45:10 2011 +0200
     6.3 @@ -40,7 +40,7 @@
     6.4  #endif
     6.5  
     6.6  /* This function does any necessary setup in the child thread */
     6.7 -extern void SDL_SYS_SetupThread(void);
     6.8 +extern void SDL_SYS_SetupThread(const char *name);
     6.9  
    6.10  /* This function sets the current thread priority */
    6.11  extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
     7.1 --- a/src/thread/SDL_thread.c	Wed Sep 28 21:42:02 2011 +0200
     7.2 +++ b/src/thread/SDL_thread.c	Sat Oct 08 12:45:10 2011 +0200
     7.3 @@ -188,25 +188,19 @@
     7.4  void
     7.5  SDL_RunThread(void *data)
     7.6  {
     7.7 -    thread_args *args;
     7.8 -    int (SDLCALL * userfunc) (void *);
     7.9 -    void *userdata;
    7.10 -    int *statusloc;
    7.11 +    thread_args *args = (thread_args *) data;
    7.12 +    int (SDLCALL * userfunc) (void *) = args->func;
    7.13 +    void *userdata = args->data;
    7.14 +    int *statusloc = &args->info->status;
    7.15  
    7.16      /* Perform any system-dependent setup
    7.17         - this function cannot fail, and cannot use SDL_SetError()
    7.18       */
    7.19 -    SDL_SYS_SetupThread();
    7.20 +    SDL_SYS_SetupThread(args->info->name);
    7.21  
    7.22      /* Get the thread id */
    7.23 -    args = (thread_args *) data;
    7.24      args->info->threadid = SDL_ThreadID();
    7.25  
    7.26 -    /* Figure out what function to run */
    7.27 -    userfunc = args->func;
    7.28 -    userdata = args->data;
    7.29 -    statusloc = &args->info->status;
    7.30 -
    7.31      /* Wake up the parent thread */
    7.32      SDL_SemPost(args->wait);
    7.33  
    7.34 @@ -217,12 +211,14 @@
    7.35  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
    7.36  #undef SDL_CreateThread
    7.37  DECLSPEC SDL_Thread *SDLCALL
    7.38 -SDL_CreateThread(int (SDLCALL * fn) (void *), void *data,
    7.39 +SDL_CreateThread(int (SDLCALL * fn) (void *),
    7.40 +                 const char *name, void *data,
    7.41                   pfnSDL_CurrentBeginThread pfnBeginThread,
    7.42                   pfnSDL_CurrentEndThread pfnEndThread)
    7.43  #else
    7.44  DECLSPEC SDL_Thread *SDLCALL
    7.45 -SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
    7.46 +SDL_CreateThread(int (SDLCALL * fn) (void *),
    7.47 +                 const char *name, void *data)
    7.48  #endif
    7.49  {
    7.50      SDL_Thread *thread;
    7.51 @@ -239,9 +235,20 @@
    7.52      thread->status = -1;
    7.53  
    7.54      /* Set up the arguments for the thread */
    7.55 +    if (name != NULL) {
    7.56 +        thread->name = SDL_strdup(name);
    7.57 +        if (thread->name == NULL) {
    7.58 +            SDL_OutOfMemory();
    7.59 +            SDL_free(thread);
    7.60 +            return (NULL);
    7.61 +        }
    7.62 +    }
    7.63 +
    7.64 +    /* Set up the arguments for the thread */
    7.65      args = (thread_args *) SDL_malloc(sizeof(*args));
    7.66      if (args == NULL) {
    7.67          SDL_OutOfMemory();
    7.68 +        SDL_free(thread->name);
    7.69          SDL_free(thread);
    7.70          return (NULL);
    7.71      }
    7.72 @@ -250,6 +257,7 @@
    7.73      args->info = thread;
    7.74      args->wait = SDL_CreateSemaphore(0);
    7.75      if (args->wait == NULL) {
    7.76 +        SDL_free(thread->name);
    7.77          SDL_free(thread);
    7.78          SDL_free(args);
    7.79          return (NULL);
    7.80 @@ -270,6 +278,7 @@
    7.81      } else {
    7.82          /* Oops, failed.  Gotta free everything */
    7.83          SDL_DelThread(thread);
    7.84 +        SDL_free(thread->name);
    7.85          SDL_free(thread);
    7.86          thread = NULL;
    7.87      }
    7.88 @@ -293,6 +302,12 @@
    7.89      return id;
    7.90  }
    7.91  
    7.92 +const char *
    7.93 +SDL_GetThreadName(SDL_Thread * thread)
    7.94 +{
    7.95 +    return thread->name;
    7.96 +}
    7.97 +
    7.98  int
    7.99  SDL_SetThreadPriority(SDL_ThreadPriority priority)
   7.100  {
   7.101 @@ -308,6 +323,7 @@
   7.102              *status = thread->status;
   7.103          }
   7.104          SDL_DelThread(thread);
   7.105 +        SDL_free(thread->name);
   7.106          SDL_free(thread);
   7.107      }
   7.108  }
     8.1 --- a/src/thread/SDL_thread_c.h	Wed Sep 28 21:42:02 2011 +0200
     8.2 +++ b/src/thread/SDL_thread_c.h	Sat Oct 08 12:45:10 2011 +0200
     8.3 @@ -51,6 +51,7 @@
     8.4      SYS_ThreadHandle handle;
     8.5      int status;
     8.6      SDL_error errbuf;
     8.7 +    char *name;
     8.8      void *data;
     8.9  };
    8.10  
     9.1 --- a/src/thread/beos/SDL_systhread.c	Wed Sep 28 21:42:02 2011 +0200
     9.2 +++ b/src/thread/beos/SDL_systhread.c	Sat Oct 08 12:45:10 2011 +0200
     9.3 @@ -65,8 +65,13 @@
     9.4  int
     9.5  SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
     9.6  {
     9.7 +    /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
     9.8 +    char name[B_OS_NAME_LENGTH];
     9.9 +    SDL_snprintf(name, sizeof (name), "%s", thread->name);
    9.10 +    name[sizeof (name) - 1] = '\0';
    9.11 +
    9.12      /* Create the thread and go! */
    9.13 -    thread->handle = spawn_thread(RunThread, "SDL", B_NORMAL_PRIORITY, args);
    9.14 +    thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args);
    9.15      if ((thread->handle == B_NO_MORE_THREADS) ||
    9.16          (thread->handle == B_NO_MEMORY)) {
    9.17          SDL_SetError("Not enough resources to create thread");
    9.18 @@ -77,8 +82,9 @@
    9.19  }
    9.20  
    9.21  void
    9.22 -SDL_SYS_SetupThread(void)
    9.23 +SDL_SYS_SetupThread(const char *name)
    9.24  {
    9.25 +    /* We set the thread name during SDL_SYS_CreateThread(). */
    9.26      /* Mask asynchronous signals for this thread */
    9.27      SDL_MaskSignals(NULL);
    9.28  }
    10.1 --- a/src/thread/generic/SDL_systhread.c	Wed Sep 28 21:42:02 2011 +0200
    10.2 +++ b/src/thread/generic/SDL_systhread.c	Sat Oct 08 12:45:10 2011 +0200
    10.3 @@ -33,7 +33,7 @@
    10.4  }
    10.5  
    10.6  void
    10.7 -SDL_SYS_SetupThread(void)
    10.8 +SDL_SYS_SetupThread(const char *name)
    10.9  {
   10.10      return;
   10.11  }
    11.1 --- a/src/thread/irix/SDL_systhread.c	Wed Sep 28 21:42:02 2011 +0200
    11.2 +++ b/src/thread/irix/SDL_systhread.c	Sat Oct 08 12:45:10 2011 +0200
    11.3 @@ -50,7 +50,7 @@
    11.4  }
    11.5  
    11.6  void
    11.7 -SDL_SYS_SetupThread(void)
    11.8 +SDL_SYS_SetupThread(const char *name)
    11.9  {
   11.10      int i;
   11.11      sigset_t mask;
    12.1 --- a/src/thread/nds/SDL_systhread.c	Wed Sep 28 21:42:02 2011 +0200
    12.2 +++ b/src/thread/nds/SDL_systhread.c	Sat Oct 08 12:45:10 2011 +0200
    12.3 @@ -38,7 +38,7 @@
    12.4  }
    12.5  
    12.6  void
    12.7 -SDL_SYS_SetupThread(void)
    12.8 +SDL_SYS_SetupThread(const char *name)
    12.9  {
   12.10      return;
   12.11  }
    13.1 --- a/src/thread/pthread/SDL_systhread.c	Wed Sep 28 21:42:02 2011 +0200
    13.2 +++ b/src/thread/pthread/SDL_systhread.c	Sat Oct 08 12:45:10 2011 +0200
    13.3 @@ -21,6 +21,11 @@
    13.4  #include "SDL_config.h"
    13.5  
    13.6  #include <pthread.h>
    13.7 +
    13.8 +#if HAVE_PTHREAD_NP_H
    13.9 +#include <pthread_np.h>
   13.10 +#endif
   13.11 +
   13.12  #include <signal.h>
   13.13  #ifdef __LINUX__
   13.14  #include <sys/time.h>
   13.15 @@ -28,6 +33,7 @@
   13.16  #include <sys/syscall.h>
   13.17  #endif
   13.18  
   13.19 +#include "SDL_platform.h"
   13.20  #include "SDL_thread.h"
   13.21  #include "../SDL_thread_c.h"
   13.22  #include "../SDL_systhread.h"
   13.23 @@ -68,11 +74,20 @@
   13.24  }
   13.25  
   13.26  void
   13.27 -SDL_SYS_SetupThread(void)
   13.28 +SDL_SYS_SetupThread(const char *name)
   13.29  {
   13.30      int i;
   13.31      sigset_t mask;
   13.32  
   13.33 +#if ( (__MACOSX__ && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)) || \
   13.34 +      (__IPHONEOS__ && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)) )
   13.35 +    if (pthread_setname_np != NULL) { pthread_setname_np(name); }
   13.36 +#elif HAVE_PTHREAD_SETNAME_NP
   13.37 +    pthread_setname_np(pthread_self(), name);
   13.38 +#elif HAVE_PTHREAD_SET_NAME_NP
   13.39 +    pthread_set_name_np(pthread_self(), name);
   13.40 +#endif
   13.41 +
   13.42      /* Mask asynchronous signals for this thread */
   13.43      sigemptyset(&mask);
   13.44      for (i = 0; sig_list[i]; ++i) {
    14.1 --- a/src/thread/windows/SDL_systhread.c	Wed Sep 28 21:42:02 2011 +0200
    14.2 +++ b/src/thread/windows/SDL_systhread.c	Sat Oct 08 12:45:10 2011 +0200
    14.3 @@ -146,10 +146,40 @@
    14.4      return (0);
    14.5  }
    14.6  
    14.7 +#ifdef _MSC_VER
    14.8 +#pragma pack(push,8)
    14.9 +typedef struct tagTHREADNAME_INFO
   14.10 +{
   14.11 +    DWORD dwType; /* must be 0x1000 */
   14.12 +    LPCSTR szName; /* pointer to name (in user addr space) */
   14.13 +    DWORD dwThreadID; /* thread ID (-1=caller thread) */
   14.14 +    DWORD dwFlags; /* reserved for future use, must be zero */
   14.15 +} THREADNAME_INFO;
   14.16 +#pragma pack(pop)
   14.17 +#endif
   14.18 +
   14.19  void
   14.20 -SDL_SYS_SetupThread(void)
   14.21 +SDL_SYS_SetupThread(const char *name)
   14.22  {
   14.23 -    return;
   14.24 +#if 0  /* !!! FIXME: __except needs C runtime, which we don't link against. */
   14.25 +#ifdef _MSC_VER  /* !!! FIXME: can we do SEH on other compilers yet? */
   14.26 +    /* This magic tells the debugger to name a thread if it's listening. */
   14.27 +    THREADNAME_INFO inf;
   14.28 +    inf.dwType = 0x1000;
   14.29 +    inf.szName = name;
   14.30 +    inf.dwThreadID = (DWORD) -1;
   14.31 +    inf.dwFlags = 0;
   14.32 +
   14.33 +    __try
   14.34 +    {
   14.35 +        RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
   14.36 +    }
   14.37 +    __except(EXCEPTION_CONTINUE_EXECUTION)
   14.38 +    {
   14.39 +        /* The program itself should ignore this bogus exception. */
   14.40 +    }
   14.41 +#endif
   14.42 +#endif
   14.43  }
   14.44  
   14.45  SDL_threadID
    15.1 --- a/src/timer/SDL_timer.c	Wed Sep 28 21:42:02 2011 +0200
    15.2 +++ b/src/timer/SDL_timer.c	Sat Oct 08 12:45:10 2011 +0200
    15.3 @@ -209,6 +209,7 @@
    15.4      SDL_TimerData *data = &SDL_timer_data;
    15.5  
    15.6      if (!data->active) {
    15.7 +        const char *name = "SDLTimer";
    15.8          data->timermap_lock = SDL_CreateMutex();
    15.9          if (!data->timermap_lock) {
   15.10              return -1;
   15.11 @@ -224,9 +225,9 @@
   15.12          /* !!! FIXME: this is nasty. */
   15.13  #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
   15.14  #undef SDL_CreateThread
   15.15 -        data->thread = SDL_CreateThread(SDL_TimerThread, data, NULL, NULL);
   15.16 +        data->thread = SDL_CreateThread(SDL_TimerThread, name, data, NULL, NULL);
   15.17  #else
   15.18 -        data->thread = SDL_CreateThread(SDL_TimerThread, data);
   15.19 +        data->thread = SDL_CreateThread(SDL_TimerThread, name, data);
   15.20  #endif
   15.21          if (!data->thread) {
   15.22              SDL_TimerQuit();
    16.1 --- a/src/video/x11/SDL_x11touch.c	Wed Sep 28 21:42:02 2011 +0200
    16.2 +++ b/src/video/x11/SDL_x11touch.c	Sat Oct 08 12:45:10 2011 +0200
    16.3 @@ -38,55 +38,57 @@
    16.4  #ifdef SDL_INPUT_LINUXEV
    16.5    FILE *fd;
    16.6    fd = fopen("/proc/bus/input/devices","r");
    16.7 -  
    16.8 +
    16.9    char c;
   16.10    int i = 0;
   16.11 +  int tsfd;
   16.12    char line[256];
   16.13    char tstr[256];
   16.14    int vendor = -1,product = -1,event = -1;
   16.15    while(!feof(fd)) {
   16.16      if(fgets(line,256,fd) <=0) continue;
   16.17      if(line[0] == '\n') {
   16.18 -    if(vendor == 1386 || vendor==1){
   16.19 +      if(vendor == 1386 || vendor==1) {
   16.20 +
   16.21 +        sprintf(tstr,"/dev/input/event%i",event);
   16.22  
   16.23 -	sprintf(tstr,"/dev/input/event%i",event);
   16.24 +        tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
   16.25 +        if ( tsfd == -1 )
   16.26 +            continue;   /* Maybe not enough permissions ? */
   16.27  
   16.28 -	SDL_Touch touch;
   16.29 -	touch.pressure_max = 0;
   16.30 -	touch.pressure_min = 0;
   16.31 -	touch.id = event; 
   16.32 -	
   16.33 +        SDL_Touch touch;
   16.34 +        touch.pressure_max = 0;
   16.35 +        touch.pressure_min = 0;
   16.36 +        touch.id = event; 
   16.37  
   16.38 -	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
   16.39 -	EventTouchData* data = (EventTouchData*)(touch.driverdata);
   16.40 +        touch.driverdata = SDL_malloc(sizeof(EventTouchData));
   16.41 +        EventTouchData* data = (EventTouchData*)(touch.driverdata);
   16.42  
   16.43 -	data->x = -1;
   16.44 -	data->y = -1;
   16.45 -	data->pressure = -1;
   16.46 -	data->finger = 0;
   16.47 -	data->up = SDL_FALSE;
   16.48 -    data->down = SDL_FALSE;
   16.49 -	
   16.50 +        data->x = -1;
   16.51 +        data->y = -1;
   16.52 +        data->pressure = -1;
   16.53 +        data->finger = 0;
   16.54 +        data->up = SDL_FALSE;
   16.55 +        data->down = SDL_FALSE;
   16.56  
   16.57 -	data->eventStream = open(tstr, 
   16.58 -				 O_RDONLY | O_NONBLOCK);
   16.59 -	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
   16.60 +        data->eventStream = tsfd;
   16.61 +        ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
   16.62  
   16.63 -	int abs[5];
   16.64 -	ioctl(data->eventStream,EVIOCGABS(0),abs);	
   16.65 -	touch.x_min = abs[1];
   16.66 -	touch.x_max = abs[2];
   16.67 -	touch.native_xres = touch.x_max - touch.x_min;
   16.68 -	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
   16.69 -	touch.y_min = abs[1];
   16.70 -	touch.y_max = abs[2];
   16.71 -	touch.native_yres = touch.y_max - touch.y_min;
   16.72 -	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
   16.73 -	touch.pressure_min = abs[1];
   16.74 -	touch.pressure_max = abs[2];
   16.75 -	touch.native_pressureres = touch.pressure_max - touch.pressure_min;
   16.76 +        int abs[5];
   16.77 +        ioctl(data->eventStream,EVIOCGABS(0),abs);	
   16.78 +        touch.x_min = abs[1];
   16.79 +        touch.x_max = abs[2];
   16.80 +        touch.native_xres = touch.x_max - touch.x_min;
   16.81 +        ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
   16.82 +        touch.y_min = abs[1];
   16.83 +        touch.y_max = abs[2];
   16.84 +        touch.native_yres = touch.y_max - touch.y_min;
   16.85 +        ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
   16.86 +        touch.pressure_min = abs[1];
   16.87 +        touch.pressure_max = abs[2];
   16.88 +        touch.native_pressureres = touch.pressure_max - touch.pressure_min;
   16.89  
   16.90 -	SDL_AddTouch(&touch, tstr);
   16.91 +        SDL_AddTouch(&touch, tstr);
   16.92        }
   16.93        vendor = -1;
   16.94        product = -1;
   16.95 @@ -95,20 +97,20 @@
   16.96      else if(line[0] == 'I') {
   16.97        i = 1;
   16.98        while(line[i]) {
   16.99 -	sscanf(&line[i],"Vendor=%x",&vendor);
  16.100 -	sscanf(&line[i],"Product=%x",&product);
  16.101 -	i++;
  16.102 +        sscanf(&line[i],"Vendor=%x",&vendor);
  16.103 +        sscanf(&line[i],"Product=%x",&product);
  16.104 +        i++;
  16.105        }
  16.106      }
  16.107      else if(line[0] == 'H') {
  16.108        i = 1;
  16.109        while(line[i]) {
  16.110 -	sscanf(&line[i],"event%d",&event);
  16.111 -	i++;
  16.112 +        sscanf(&line[i],"event%d",&event);
  16.113 +        i++;
  16.114        }
  16.115      }
  16.116    }
  16.117 -  
  16.118 +
  16.119    close(fd);
  16.120  #endif
  16.121  }
    17.1 --- a/test/test-automation/tests/testaudio/testaudio.c	Wed Sep 28 21:42:02 2011 +0200
    17.2 +++ b/test/test-automation/tests/testaudio/testaudio.c	Sat Oct 08 12:45:10 2011 +0200
    17.3 @@ -1,5 +1,6 @@
    17.4  /**
    17.5 - * Original code: automated SDL rect test written by Edgar Simo "bobbens"
    17.6 + * Original code: automated SDL audio test written by Edgar Simo "bobbens"
    17.7 + * New/updated tests: aschiffler at ferzkopp dot net
    17.8   */
    17.9  
   17.10  #include <stdio.h>
   17.11 @@ -10,10 +11,10 @@
   17.12  
   17.13  /* Test cases */
   17.14  static const TestCaseReference test1 =
   17.15 -		(TestCaseReference){ "audio_printOutputDevices", "Checks available output (non-capture) device names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
   17.16 +		(TestCaseReference){ "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
   17.17  
   17.18  static const TestCaseReference test2 =
   17.19 -		(TestCaseReference){ "audio_printInputDevices", "Checks available input (capture) device names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
   17.20 +		(TestCaseReference){ "audio_enumerateAndNameAudioDevicesNegativeTests", "Netative tests around enumeration and naming of audio devices.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
   17.21  
   17.22  static const TestCaseReference test3 =
   17.23  		(TestCaseReference){ "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED, TEST_REQUIRES_AUDIO, 0};
   17.24 @@ -31,7 +32,7 @@
   17.25  	return (TestCaseReference **)testSuite;
   17.26  }
   17.27  
   17.28 -// Fixture
   17.29 +/* Fixture */
   17.30  
   17.31  void
   17.32  SetUp(void *arg)
   17.33 @@ -51,49 +52,94 @@
   17.34  /* Test case functions */
   17.35  
   17.36  /**
   17.37 - * @brief Checks available output (non-capture) device names.
   17.38 + * \brief Enumerate and name available audio devices (output and capture).
   17.39 + * 
   17.40 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
   17.41 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
   17.42   */
   17.43 -int audio_printOutputDevices()
   17.44 +int audio_enumerateAndNameAudioDevices()
   17.45  {
   17.46     int ret;
   17.47 -   int i, n;
   17.48 -   const char *name;
   17.49 +   int t, tt;
   17.50 +   int i, n, nn;
   17.51 +   const char *name, *nameAgain;
   17.52  
   17.53 -   /* Get number of devices. */
   17.54 -   n = SDL_GetNumAudioDevices(0);
   17.55 -   AssertTrue(n>=0, "Number of output devices < 0, reported as %i", n);
   17.56 +   /* Iterate over types: t=0 output device, t=1 input/capture device */
   17.57 +   for (t=0; t<2; t++) {
   17.58     
   17.59 -   /* List devices. */
   17.60 -   if (n>0)
   17.61 -   {
   17.62 -      for (i=0; i<n; i++) {
   17.63 -         name = SDL_GetAudioDeviceName(i, 0);
   17.64 -         AssertTrue(name != NULL, "name != NULL");
   17.65 -         AssertTrue(strlen(name)>0, "name blank");
   17.66 +      /* Get number of devices. */
   17.67 +      n = SDL_GetNumAudioDevices(t);
   17.68 +      AssertTrue(n>=0, 
   17.69 +         "Number of %s devices < 0, reported as %i: %s", 
   17.70 +         (t) ? "output" : "capture",
   17.71 +         n, 
   17.72 +         SDL_GetError());
   17.73 +
   17.74 +      /* Variation of non-zero type */
   17.75 +      if (t==1) {
   17.76 +         tt = t + RandomIntegerInRange(1,10);
   17.77 +         nn = SDL_GetNumAudioDevices(tt);
   17.78 +         AssertTrue(n==nn, "SDL_GetNumAudioDevices(%i) : expected same number of audio devices %i, got %i", tt, n, nn);
   17.79 +         nn = SDL_GetNumAudioDevices(-tt);
   17.80 +         AssertTrue(n==nn, "SDL_GetNumAudioDevices(%i) : expected same number of audio devices %i, got %i", -tt, n, nn);
   17.81 +      } 
   17.82 +   
   17.83 +      /* List devices. */
   17.84 +      if (n>0) {
   17.85 +         for (i=0; i<n; i++) {
   17.86 +            name = SDL_GetAudioDeviceName(i, t);
   17.87 +            AssertTrue(name != NULL, "SDL_GetAudioDeviceName(%i, %i): returned NULL name", i, t);
   17.88 +            AssertTrue(strlen(name)>0, "SDL_GetAudioDeviceName(%i, %i): returned empty name string", i, t);
   17.89 +            if (t==1) {
   17.90 +               /* Also try non-zero type */
   17.91 +               nameAgain = SDL_GetAudioDeviceName(i, tt);
   17.92 +               AssertTrue(nameAgain != NULL, "SDL_GetAudioDeviceName(%i, %i): returned NULL name", i, tt);
   17.93 +               AssertTrue(strlen(nameAgain)>0, "SDL_GetAudioDeviceName(%i, %i): returned empty name string", i, tt);
   17.94 +               AssertTrue(strcmp(name, nameAgain)==0, 
   17.95 +                  "SDL_GetAudioDeviceName(%i, %i): returned unexpected name string %s, expected %s", 
   17.96 +                  i, tt, nameAgain, name);
   17.97 +            }
   17.98 +         }
   17.99        }
  17.100     }
  17.101  }
  17.102  
  17.103  /**
  17.104 - * @brief Checks available input (capture) device names.
  17.105 + * \brief Negative tests around enumeration and naming of audio devices.
  17.106 + * 
  17.107 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
  17.108 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
  17.109   */
  17.110 -int audio_printInputDevices()
  17.111 +int audio_enumerateAndNameAudioDevicesNegativeTests()
  17.112  {
  17.113     int ret;
  17.114 -   int i, n;
  17.115 +   int t;
  17.116 +   int i, j, no, nc;
  17.117     const char *name;
  17.118 -
  17.119 +      
  17.120     /* Get number of devices. */
  17.121 -   n = SDL_GetNumAudioDevices(1);
  17.122 -   AssertTrue(n>=0, "Number of input devices < 0, reported as %i", n);
  17.123 +   no = SDL_GetNumAudioDevices(0);
  17.124 +   nc = SDL_GetNumAudioDevices(1);
  17.125     
  17.126 -   /* List devices. */
  17.127 -   if (n>0)
  17.128 -   {
  17.129 -      for (i=0; i<n; i++) {
  17.130 -         name = SDL_GetAudioDeviceName(i, 1);
  17.131 -         AssertTrue(name != NULL, "name != NULL");
  17.132 -         AssertTrue(strlen(name)>0, "name empty");
  17.133 +   /* Invalid device index when getting name */
  17.134 +   for (t=0; t<2; t++) {
  17.135 +      /* Negative device index */
  17.136 +      i = -1;
  17.137 +      name = SDL_GetAudioDeviceName(i, t);
  17.138 +      AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
  17.139 +      
  17.140 +      /* Device index past range */
  17.141 +      for (j=0; j<3; j++) {
  17.142 +         i = (t) ? nc+j : no+j;
  17.143 +         name = SDL_GetAudioDeviceName(i, t);
  17.144 +         AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
  17.145 +      }
  17.146 +      
  17.147 +      /* Capture index past capture range but within output range */
  17.148 +      if ((no>0) && (no>nc) && (t==1)) {
  17.149 +         i = no-1;
  17.150 +         name = SDL_GetAudioDeviceName(i, t);
  17.151 +         AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
  17.152        }
  17.153     }
  17.154  }
    18.1 --- a/test/testatomic.c	Wed Sep 28 21:42:02 2011 +0200
    18.2 +++ b/test/testatomic.c	Sat Oct 08 12:45:10 2011 +0200
    18.3 @@ -143,7 +143,7 @@
    18.4      SDL_AtomicSet(&threadsRunning, NThreads);
    18.5  
    18.6      while (T--)
    18.7 -        SDL_CreateThread(adder, NULL);
    18.8 +        SDL_CreateThread(adder, "Adder", NULL);
    18.9   
   18.10      while (SDL_AtomicGet(&threadsRunning) > 0)
   18.11          SDL_SemWait(threadDone);
   18.12 @@ -618,7 +618,7 @@
   18.13  #ifdef TEST_SPINLOCK_FIFO
   18.14      /* Start a monitoring thread */
   18.15      if (lock_free) {
   18.16 -        SDL_CreateThread(FIFO_Watcher, &queue);
   18.17 +        SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
   18.18      }
   18.19  #endif
   18.20  
   18.21 @@ -627,9 +627,11 @@
   18.22      SDL_zero(readerData);
   18.23      SDL_AtomicSet(&readersRunning, NUM_READERS);
   18.24      for (i = 0; i < NUM_READERS; ++i) {
   18.25 +        char name[64];
   18.26 +        SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
   18.27          readerData[i].queue = &queue;
   18.28          readerData[i].lock_free = lock_free;
   18.29 -        SDL_CreateThread(FIFO_Reader, &readerData[i]);
   18.30 +        SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
   18.31      }
   18.32  
   18.33      /* Start up the writers */
   18.34 @@ -637,10 +639,12 @@
   18.35      SDL_zero(writerData);
   18.36      SDL_AtomicSet(&writersRunning, NUM_WRITERS);
   18.37      for (i = 0; i < NUM_WRITERS; ++i) {
   18.38 +        char name[64];
   18.39 +        SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
   18.40          writerData[i].queue = &queue;
   18.41          writerData[i].index = i;
   18.42          writerData[i].lock_free = lock_free;
   18.43 -        SDL_CreateThread(FIFO_Writer, &writerData[i]);
   18.44 +        SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
   18.45      }
   18.46   
   18.47      /* Wait for the writers */
    19.1 --- a/test/testerror.c	Wed Sep 28 21:42:02 2011 +0200
    19.2 +++ b/test/testerror.c	Sat Oct 08 12:45:10 2011 +0200
    19.3 @@ -58,7 +58,7 @@
    19.4      SDL_SetError("No worries");
    19.5  
    19.6      alive = 1;
    19.7 -    thread = SDL_CreateThread(ThreadFunc, "#1");
    19.8 +    thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
    19.9      if (thread == NULL) {
   19.10          fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
   19.11          quit(1);
    20.1 --- a/test/testlock.c	Wed Sep 28 21:42:02 2011 +0200
    20.2 +++ b/test/testlock.c	Sat Oct 08 12:45:10 2011 +0200
    20.3 @@ -112,7 +112,9 @@
    20.4      printf("Main thread: %lu\n", mainthread);
    20.5      atexit(printid);
    20.6      for (i = 0; i < maxproc; ++i) {
    20.7 -        if ((threads[i] = SDL_CreateThread(Run, NULL)) == NULL)
    20.8 +        char name[64];
    20.9 +        SDL_snprintf(name, sizeof (name), "Worker%d", i);
   20.10 +        if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
   20.11              fprintf(stderr, "Couldn't create thread!\n");
   20.12      }
   20.13      signal(SIGINT, terminate);
    21.1 --- a/test/testsem.c	Wed Sep 28 21:42:02 2011 +0200
    21.2 +++ b/test/testsem.c	Sat Oct 08 12:45:10 2011 +0200
    21.3 @@ -100,7 +100,9 @@
    21.4             init_sem);
    21.5      /* Create all the threads */
    21.6      for (i = 0; i < NUM_THREADS; ++i) {
    21.7 -        threads[i] = SDL_CreateThread(ThreadFunc, (void *) i);
    21.8 +        char name[64];
    21.9 +        SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
   21.10 +        threads[i] = SDL_CreateThread(ThreadFunc, name, (void *) i);
   21.11      }
   21.12  
   21.13      /* Wait 10 seconds */
    22.1 --- a/test/testthread.c	Wed Sep 28 21:42:02 2011 +0200
    22.2 +++ b/test/testthread.c	Sat Oct 08 12:45:10 2011 +0200
    22.3 @@ -63,7 +63,7 @@
    22.4      }
    22.5  
    22.6      alive = 1;
    22.7 -    thread = SDL_CreateThread(ThreadFunc, "#1");
    22.8 +    thread = SDL_CreateThread(ThreadFunc, "One", "#1");
    22.9      if (thread == NULL) {
   22.10          fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
   22.11          quit(1);
   22.12 @@ -75,7 +75,7 @@
   22.13  
   22.14      alive = 1;
   22.15      signal(SIGTERM, killed);
   22.16 -    thread = SDL_CreateThread(ThreadFunc, "#2");
   22.17 +    thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
   22.18      if (thread == NULL) {
   22.19          fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
   22.20          quit(1);
    23.1 --- a/test/threadwin.c	Wed Sep 28 21:42:02 2011 +0200
    23.2 +++ b/test/threadwin.c	Sat Oct 08 12:45:10 2011 +0200
    23.3 @@ -296,8 +296,8 @@
    23.4      SDL_SetEventFilter(FilterEvents, NULL);
    23.5  
    23.6      /* Create the event handling threads */
    23.7 -    mouse_thread = SDL_CreateThread(HandleMouse, NULL);
    23.8 -    keybd_thread = SDL_CreateThread(HandleKeyboard, NULL);
    23.9 +    mouse_thread = SDL_CreateThread(HandleMouse, "MouseHandler", NULL);
   23.10 +    keybd_thread = SDL_CreateThread(HandleKeyboard, "KeyboardHandler", NULL);
   23.11  
   23.12      /* Set the surface pixels and refresh! */
   23.13      for (i = 0; i < 256; ++i) {
    24.1 --- a/test/torturethread.c	Wed Sep 28 21:42:02 2011 +0200
    24.2 +++ b/test/torturethread.c	Sat Oct 08 12:45:10 2011 +0200
    24.3 @@ -52,8 +52,10 @@
    24.4      fprintf(stderr, "Creating Thread %d\n", tid);
    24.5  
    24.6      for (i = 0; i < NUMTHREADS; i++) {
    24.7 +        char name[64];
    24.8 +        SDL_snprintf(name, sizeof (name), "Child%d_%d", tid, i);
    24.9          flags[i] = 0;
   24.10 -        sub_threads[i] = SDL_CreateThread(SubThreadFunc, &flags[i]);
   24.11 +        sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
   24.12      }
   24.13  
   24.14      printf("Thread '%d' waiting for signal\n", tid);
   24.15 @@ -86,8 +88,10 @@
   24.16  
   24.17      signal(SIGSEGV, SIG_DFL);
   24.18      for (i = 0; i < NUMTHREADS; i++) {
   24.19 +        char name[64];
   24.20 +        SDL_snprintf(name, sizeof (name), "Parent%d", i);
   24.21          time_for_threads_to_die[i] = 0;
   24.22 -        threads[i] = SDL_CreateThread(ThreadFunc, (void *) (uintptr_t) i);
   24.23 +        threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
   24.24  
   24.25          if (threads[i] == NULL) {
   24.26              fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());