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 171ad2ddcd
commit 16cdc59bab
106 changed files with 616 additions and 1189 deletions

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 */