Make SDL_SetError and friends unconditionally return -1.

This lets us change things like this...

    if (Failed) {
        SDL_SetError("We failed");
        return -1;
    }

...into this...

    if (Failed) {
        return SDL_SetError("We failed");
    }


 Fixes Bugzilla #1778.
This commit is contained in:
Ryan C. Gordon 2013-03-31 12:48:50 -04:00
parent 8c6b9f4743
commit 4f438b70a2
106 changed files with 616 additions and 1189 deletions

View file

@ -73,8 +73,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
int retval;
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
tryagain:
@ -97,8 +96,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
retval = SDL_MUTEX_TIMEDOUT;
break;
default:
SDL_SetError("acquire_sem() failed");
retval = -1;
retval = SDL_SetError("acquire_sem() failed");
break;
}
@ -139,13 +137,11 @@ int
SDL_SemPost(SDL_sem * sem)
{
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
if (release_sem(sem->id) != B_NO_ERROR) {
SDL_SetError("release_sem() failed");
return -1;
return SDL_SetError("release_sem() failed");
}
return 0;
}

View file

@ -77,8 +77,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args);
if ((thread->handle == B_NO_MORE_THREADS) ||
(thread->handle == B_NO_MEMORY)) {
SDL_SetError("Not enough resources to create thread");
return (-1);
return SDL_SetError("Not enough resources to create thread");
}
resume_thread(thread->handle);
return (0);

View file

@ -82,8 +82,7 @@ int
SDL_CondSignal(SDL_cond * cond)
{
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
/* If there are waiting threads not already signalled, then
@ -107,8 +106,7 @@ int
SDL_CondBroadcast(SDL_cond * cond)
{
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
/* If there are waiting threads not already signalled, then
@ -164,8 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
int retval;
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
/* Obtain the protection mutex, and increment the number of waiters.

View file

@ -78,8 +78,7 @@ SDL_LockMutex(SDL_mutex * mutex)
SDL_threadID this_thread;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
this_thread = SDL_ThreadID();
@ -110,8 +109,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
SDL_threadID this_thread;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
this_thread = SDL_ThreadID();
@ -141,14 +139,12 @@ SDL_mutexV(SDL_mutex * mutex)
return 0;
#else
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
/* If we don't own the mutex, we can't unlock it */
if (SDL_ThreadID() != mutex->owner) {
SDL_SetError("mutex not owned by this thread");
return -1;
return SDL_SetError("mutex not owned by this thread");
}
if (mutex->recursive) {

View file

@ -39,28 +39,24 @@ SDL_CreateSemaphore(Uint32 initial_value)
void
SDL_DestroySemaphore(SDL_sem * sem)
{
return;
}
int
SDL_SemTryWait(SDL_sem * sem)
{
SDL_SetError("SDL not configured with thread support");
return -1;
return SDL_SetError("SDL not configured with thread support");
}
int
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
{
SDL_SetError("SDL not configured with thread support");
return -1;
return SDL_SetError("SDL not configured with thread support");
}
int
SDL_SemWait(SDL_sem * sem)
{
SDL_SetError("SDL not configured with thread support");
return -1;
return SDL_SetError("SDL not configured with thread support");
}
Uint32
@ -72,8 +68,7 @@ SDL_SemValue(SDL_sem * sem)
int
SDL_SemPost(SDL_sem * sem)
{
SDL_SetError("SDL not configured with thread support");
return -1;
return SDL_SetError("SDL not configured with thread support");
}
#else
@ -137,8 +132,7 @@ SDL_SemTryWait(SDL_sem * sem)
int retval;
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
retval = SDL_MUTEX_TIMEDOUT;
@ -158,8 +152,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
int retval;
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
/* A timeout of 0 is an easy case */
@ -207,8 +200,7 @@ int
SDL_SemPost(SDL_sem * sem)
{
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
SDL_LockMutex(sem->count_lock);

View file

@ -28,8 +28,7 @@
int
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
{
SDL_SetError("Threads are not supported on this platform");
return (-1);
return SDL_SetError("Threads are not supported on this platform");
}
void

View file

@ -82,8 +82,7 @@ int
SDL_CondSignal(SDL_cond * cond)
{
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
/* If there are waiting threads not already signalled, then
@ -107,8 +106,7 @@ int
SDL_CondBroadcast(SDL_cond * cond)
{
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
/* If there are waiting threads not already signalled, then
@ -164,8 +162,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
int retval;
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
/* Obtain the protection mutex, and increment the number of waiters.

View file

@ -78,8 +78,7 @@ SDL_mutexP(SDL_mutex * mutex)
SDL_threadID this_thread;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
this_thread = SDL_ThreadID();
@ -107,14 +106,12 @@ SDL_mutexV(SDL_mutex * mutex)
return 0;
#else
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
/* If we don't own the mutex, we can't unlock it */
if (SDL_ThreadID() != mutex->owner) {
SDL_SetError("mutex not owned by this thread");
return -1;
return SDL_SetError("mutex not owned by this thread");
}
if (mutex->recursive) {

View file

@ -105,8 +105,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
return SDL_MUTEX_TIMEDOUT;
default:
SDL_SetError("WaitForSingleObject() failed");
return -1;
return SDL_SetError("WaitForSingleObject() failed");
}
}
@ -142,14 +141,12 @@ int SDL_SemPost(SDL_sem *sem)
int res;
if (sem == NULL) {
SDL_SetError("Passed a NULL sem");
return -1;
return SDL_SetError("Passed a NULL sem");
}
res = sceKernelSignalSema(sem->semid, 1);
if (res < 0) {
SDL_SetError("sceKernelSignalSema() failed");
return -1;
return SDL_SetError("sceKernelSignalSema() failed");
}
return 0;

View file

@ -54,8 +54,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
priority, 0x8000,
PSP_THREAD_ATTR_VFPU, NULL);
if (thread->handle < 0) {
SDL_SetError("sceKernelCreateThread() failed");
return -1;
return SDL_SetError("sceKernelCreateThread() failed");
}
sceKernelStartThread(thread->handle, 4, &args);

View file

@ -67,14 +67,12 @@ SDL_CondSignal(SDL_cond * cond)
int retval;
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
retval = 0;
if (pthread_cond_signal(&cond->cond) != 0) {
SDL_SetError("pthread_cond_signal() failed");
retval = -1;
return SDL_SetError("pthread_cond_signal() failed");
}
return retval;
}
@ -86,14 +84,12 @@ SDL_CondBroadcast(SDL_cond * cond)
int retval;
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
retval = 0;
if (pthread_cond_broadcast(&cond->cond) != 0) {
SDL_SetError("pthread_cond_broadcast() failed");
retval = -1;
return SDL_SetError("pthread_cond_broadcast() failed");
}
return retval;
}
@ -106,8 +102,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
struct timespec abstime;
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
}
gettimeofday(&delta, NULL);
@ -131,9 +126,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
case 0:
break;
default:
SDL_SetError("pthread_cond_timedwait() failed");
retval = -1;
break;
retval = SDL_SetError("pthread_cond_timedwait() failed");
}
return retval;
}
@ -144,19 +137,12 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
int
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
{
int retval;
if (!cond) {
SDL_SetError("Passed a NULL condition variable");
return -1;
return SDL_SetError("Passed a NULL condition variable");
} else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
return SDL_SetError("pthread_cond_wait() failed");
}
retval = 0;
if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
SDL_SetError("pthread_cond_wait() failed");
retval = -1;
}
return retval;
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -81,17 +81,14 @@ SDL_DestroyMutex(SDL_mutex * mutex)
int
SDL_LockMutex(SDL_mutex * mutex)
{
int retval;
#if FAKE_RECURSIVE_MUTEX
pthread_t this_thread;
#endif
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
retval = 0;
#if FAKE_RECURSIVE_MUTEX
this_thread = pthread_self();
if (mutex->owner == this_thread) {
@ -105,17 +102,15 @@ SDL_LockMutex(SDL_mutex * mutex)
mutex->owner = this_thread;
mutex->recursive = 0;
} else {
SDL_SetError("pthread_mutex_lock() failed");
retval = -1;
return SDL_SetError("pthread_mutex_lock() failed");
}
}
#else
if (pthread_mutex_lock(&mutex->id) < 0) {
SDL_SetError("pthread_mutex_lock() failed");
retval = -1;
return SDL_SetError("pthread_mutex_lock() failed");
}
#endif
return retval;
return 0;
}
int
@ -127,8 +122,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
#endif
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
retval = 0;
@ -147,8 +141,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
} else if (errno == EBUSY) {
retval = SDL_MUTEX_TIMEDOUT;
} else {
SDL_SetError("pthread_mutex_trylock() failed");
retval = -1;
retval = SDL_SetError("pthread_mutex_trylock() failed");
}
}
#else
@ -156,8 +149,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
if (errno == EBUSY) {
retval = SDL_MUTEX_TIMEDOUT;
} else {
SDL_SetError("pthread_mutex_trylock() failed");
retval = -1;
retval = SDL_SetError("pthread_mutex_trylock() failed");
}
}
#endif
@ -167,14 +159,10 @@ SDL_TryLockMutex(SDL_mutex * mutex)
int
SDL_UnlockMutex(SDL_mutex * mutex)
{
int retval;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
retval = 0;
#if FAKE_RECURSIVE_MUTEX
/* We can only unlock the mutex if we own it */
if (pthread_self() == mutex->owner) {
@ -190,18 +178,16 @@ SDL_UnlockMutex(SDL_mutex * mutex)
pthread_mutex_unlock(&mutex->id);
}
} else {
SDL_SetError("mutex not owned by this thread");
retval = -1;
return SDL_SetError("mutex not owned by this thread");
}
#else
if (pthread_mutex_unlock(&mutex->id) < 0) {
SDL_SetError("pthread_mutex_unlock() failed");
retval = -1;
return SDL_SetError("pthread_mutex_unlock() failed");
}
#endif /* FAKE_RECURSIVE_MUTEX */
return retval;
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -72,8 +72,7 @@ SDL_SemTryWait(SDL_sem * sem)
int retval;
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
retval = SDL_MUTEX_TIMEDOUT;
if (sem_trywait(&sem->sem) == 0) {
@ -88,13 +87,12 @@ SDL_SemWait(SDL_sem * sem)
int retval;
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
retval = sem_wait(&sem->sem);
if (retval < 0) {
SDL_SetError("sem_wait() failed");
retval = SDL_SetError("sem_wait() failed");
}
return retval;
}
@ -111,8 +109,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
#endif
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
/* Try the easy cases first */
@ -188,8 +185,7 @@ SDL_SemPost(SDL_sem * sem)
int retval;
if (!sem) {
SDL_SetError("Passed a NULL semaphore");
return -1;
return SDL_SetError("Passed a NULL semaphore");
}
retval = sem_post(&sem->sem);

View file

@ -97,18 +97,16 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
/* Set the thread attributes */
if (pthread_attr_init(&type) != 0) {
SDL_SetError("Couldn't initialize pthread attributes");
return (-1);
return SDL_SetError("Couldn't initialize pthread attributes");
}
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
/* Create the thread and go! */
if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
SDL_SetError("Not enough resources to create thread");
return (-1);
return SDL_SetError("Not enough resources to create thread");
}
return (0);
return 0;
}
void
@ -173,8 +171,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
/* Note that this fails if you're trying to set high priority
and you don't have root permission. BUT DON'T RUN AS ROOT!
*/
SDL_SetError("setpriority() failed");
return -1;
return SDL_SetError("setpriority() failed");
}
return 0;
#else
@ -183,8 +180,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
pthread_t thread = pthread_self();
if (pthread_getschedparam(thread, &policy, &sched) < 0) {
SDL_SetError("pthread_getschedparam() failed");
return -1;
return SDL_SetError("pthread_getschedparam() failed");
}
if (priority == SDL_THREAD_PRIORITY_LOW) {
sched.sched_priority = sched_get_priority_min(policy);
@ -196,8 +192,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
}
if (pthread_setschedparam(thread, policy, &sched) < 0) {
SDL_SetError("pthread_setschedparam() failed");
return -1;
return SDL_SetError("pthread_setschedparam() failed");
}
return 0;
#endif /* linux */

View file

@ -67,8 +67,7 @@ int
SDL_LockMutex(SDL_mutex * mutex)
{
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
EnterCriticalSection(&mutex->cs);
@ -81,8 +80,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
{
int retval = 0;
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
if (TryEnterCriticalSection(&mutex->cs) == 0) {
@ -96,8 +94,7 @@ int
SDL_UnlockMutex(SDL_mutex * mutex)
{
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
return -1;
return SDL_SetError("Passed a NULL mutex");
}
LeaveCriticalSection(&mutex->cs);

View file

@ -78,8 +78,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
DWORD dwMilliseconds;
if (!sem) {
SDL_SetError("Passed a NULL sem");
return -1;
return SDL_SetError("Passed a NULL sem");
}
if (timeout == SDL_MUTEX_MAXWAIT) {
@ -96,8 +95,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
retval = SDL_MUTEX_TIMEDOUT;
break;
default:
SDL_SetError("WaitForSingleObject() failed");
retval = -1;
retval = SDL_SetError("WaitForSingleObject() failed");
break;
}
return retval;
@ -130,8 +128,7 @@ int
SDL_SemPost(SDL_sem * sem)
{
if (!sem) {
SDL_SetError("Passed a NULL sem");
return -1;
return SDL_SetError("Passed a NULL sem");
}
/* Increase the counter in the first place, because
* after a successful release the semaphore may
@ -141,8 +138,7 @@ SDL_SemPost(SDL_sem * sem)
InterlockedIncrement(&sem->count);
if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) {
InterlockedDecrement(&sem->count); /* restore */
SDL_SetError("ReleaseSemaphore() failed");
return -1;
return SDL_SetError("ReleaseSemaphore() failed");
}
return 0;
}

View file

@ -116,8 +116,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
pThreadStartParms pThreadParms =
(pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
if (!pThreadParms) {
SDL_OutOfMemory();
return (-1);
return SDL_OutOfMemory();
}
// Save the function which we will have to call to clear the RTL of calling app!
pThreadParms->pfnCurrentEndThread = pfnEndThread;
@ -135,10 +134,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
pThreadParms, 0, &threadid);
}
if (thread->handle == NULL) {
SDL_SetError("Not enough resources to create thread");
return (-1);
return SDL_SetError("Not enough resources to create thread");
}
return (0);
return 0;
}
#ifdef _MSC_VER
@ -198,8 +196,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
value = THREAD_PRIORITY_NORMAL;
}
if (!SetThreadPriority(GetCurrentThread(), value)) {
WIN_SetError("SetThreadPriority()");
return -1;
return WIN_SetError("SetThreadPriority()");
}
return 0;
}