Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

View File

@@ -40,7 +40,7 @@ SDL_CreateCond(void)
{
SDL_cond *cond;
cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
cond = (SDL_cond *)SDL_malloc(sizeof(SDL_cond));
if (cond) {
if (pthread_cond_init(&cond->cond, NULL) != 0) {
SDL_SetError("pthread_cond_init() failed");
@@ -52,8 +52,7 @@ SDL_CreateCond(void)
}
/* Destroy a condition variable */
void
SDL_DestroyCond(SDL_cond * cond)
void SDL_DestroyCond(SDL_cond *cond)
{
if (cond) {
pthread_cond_destroy(&cond->cond);
@@ -62,8 +61,7 @@ SDL_DestroyCond(SDL_cond * cond)
}
/* Restart one of the threads that are waiting on the condition variable */
int
SDL_CondSignal(SDL_cond * cond)
int SDL_CondSignal(SDL_cond *cond)
{
int retval;
@@ -79,8 +77,7 @@ SDL_CondSignal(SDL_cond * cond)
}
/* Restart all threads that are waiting on the condition variable */
int
SDL_CondBroadcast(SDL_cond * cond)
int SDL_CondBroadcast(SDL_cond *cond)
{
int retval;
@@ -95,8 +92,7 @@ SDL_CondBroadcast(SDL_cond * cond)
return retval;
}
int
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
{
int retval;
#ifndef HAVE_CLOCK_GETTIME
@@ -124,7 +120,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
abstime.tv_nsec -= 1000000000;
}
tryagain:
tryagain:
retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime);
switch (retval) {
case EINTR:
@@ -144,8 +140,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
/* Wait on the condition variable, unlocking the provided mutex.
The mutex must be locked before entering this function!
*/
int
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
{
if (cond == NULL) {
return SDL_InvalidParamError("cond");

View File

@@ -46,7 +46,7 @@ SDL_CreateMutex(void)
pthread_mutexattr_t attr;
/* Allocate the structure */
mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex));
if (mutex) {
pthread_mutexattr_init(&attr);
#if SDL_THREAD_PTHREAD_RECURSIVE_MUTEX
@@ -67,8 +67,7 @@ SDL_CreateMutex(void)
return mutex;
}
void
SDL_DestroyMutex(SDL_mutex * mutex)
void SDL_DestroyMutex(SDL_mutex *mutex)
{
if (mutex) {
pthread_mutex_destroy(&mutex->id);
@@ -77,8 +76,7 @@ SDL_DestroyMutex(SDL_mutex * mutex)
}
/* Lock the mutex */
int
SDL_LockMutex(SDL_mutex * mutex)
int SDL_LockMutex(SDL_mutex *mutex)
{
#if FAKE_RECURSIVE_MUTEX
pthread_t this_thread;
@@ -112,8 +110,7 @@ SDL_LockMutex(SDL_mutex * mutex)
return 0;
}
int
SDL_TryLockMutex(SDL_mutex * mutex)
int SDL_TryLockMutex(SDL_mutex *mutex)
{
int retval;
int result;
@@ -158,8 +155,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
return retval;
}
int
SDL_UnlockMutex(SDL_mutex * mutex)
int SDL_UnlockMutex(SDL_mutex *mutex)
{
if (mutex == NULL) {
return SDL_InvalidParamError("mutex");

View File

@@ -45,7 +45,7 @@ struct SDL_semaphore
SDL_sem *
SDL_CreateSemaphore(Uint32 initial_value)
{
SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
SDL_sem *sem = (SDL_sem *)SDL_malloc(sizeof(SDL_sem));
if (sem != NULL) {
if (sem_init(&sem->sem, 0, initial_value) < 0) {
SDL_SetError("sem_init() failed");
@@ -58,8 +58,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
return sem;
}
void
SDL_DestroySemaphore(SDL_sem * sem)
void SDL_DestroySemaphore(SDL_sem *sem)
{
if (sem != NULL) {
sem_destroy(&sem->sem);
@@ -67,8 +66,7 @@ SDL_DestroySemaphore(SDL_sem * sem)
}
}
int
SDL_SemTryWait(SDL_sem * sem)
int SDL_SemTryWait(SDL_sem *sem)
{
int retval;
@@ -82,8 +80,7 @@ SDL_SemTryWait(SDL_sem * sem)
return retval;
}
int
SDL_SemWait(SDL_sem * sem)
int SDL_SemWait(SDL_sem *sem)
{
int retval;
@@ -101,8 +98,7 @@ SDL_SemWait(SDL_sem * sem)
return retval;
}
int
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
int retval;
#ifdef HAVE_SEM_TIMEDWAIT
@@ -128,9 +124,9 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
#ifdef HAVE_SEM_TIMEDWAIT
/* Setup the timeout. sem_timedwait doesn't wait for
* a lapse of time, but until we reach a certain time.
* This time is now plus the timeout.
*/
* a lapse of time, but until we reach a certain time.
* This time is now plus the timeout.
*/
#ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &ts_timeout);
@@ -177,7 +173,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
}
Uint32
SDL_SemValue(SDL_sem * sem)
SDL_SemValue(SDL_sem *sem)
{
int ret = 0;
@@ -190,11 +186,10 @@ SDL_SemValue(SDL_sem * sem)
if (ret < 0) {
ret = 0;
}
return (Uint32) ret;
return (Uint32)ret;
}
int
SDL_SemPost(SDL_sem * sem)
int SDL_SemPost(SDL_sem *sem)
{
int retval;

View File

@@ -68,25 +68,23 @@ static const int sig_list[] = {
};
#endif
static void *
RunThread(void *data)
static void *RunThread(void *data)
{
#ifdef __ANDROID__
Android_JNI_SetupThread();
#endif
SDL_RunThread((SDL_Thread *) data);
SDL_RunThread((SDL_Thread *)data);
return NULL;
}
#if (defined(__MACOSX__) || defined(__IPHONEOS__)) && defined(HAVE_DLOPEN)
static SDL_bool checked_setname = SDL_FALSE;
static int (*ppthread_setname_np)(const char*) = NULL;
static int (*ppthread_setname_np)(const char *) = NULL;
#elif defined(__LINUX__) && defined(HAVE_DLOPEN)
static SDL_bool checked_setname = SDL_FALSE;
static int (*ppthread_setname_np)(pthread_t, const char*) = NULL;
static int (*ppthread_setname_np)(pthread_t, const char *) = NULL;
#endif
int
SDL_SYS_CreateThread(SDL_Thread * thread)
int SDL_SYS_CreateThread(SDL_Thread *thread)
{
pthread_attr_t type;
@@ -101,14 +99,14 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
#endif
checked_setname = SDL_TRUE;
}
#endif
#endif
/* Set the thread attributes */
if (pthread_attr_init(&type) != 0) {
return SDL_SetError("Couldn't initialize pthread attributes");
}
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
/* Set caller-requested stack size. Otherwise: use the system default. */
if (thread->stacksize) {
pthread_attr_setstacksize(&type, thread->stacksize);
@@ -122,8 +120,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
return 0;
}
void
SDL_SYS_SetupThread(const char *name)
void SDL_SYS_SetupThread(const char *name)
{
#if !defined(__NACL__)
int i;
@@ -136,32 +133,32 @@ SDL_SYS_SetupThread(const char *name)
if (ppthread_setname_np != NULL) {
#if defined(__MACOSX__) || defined(__IPHONEOS__)
ppthread_setname_np(name);
#elif defined(__LINUX__)
#elif defined(__LINUX__)
if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
char namebuf[16]; /* Limited to 16 char */
SDL_strlcpy(namebuf, name, sizeof (namebuf));
SDL_strlcpy(namebuf, name, sizeof(namebuf));
ppthread_setname_np(pthread_self(), namebuf);
}
#endif
#endif
}
#elif HAVE_PTHREAD_SETNAME_NP
#if defined(__NETBSD__)
pthread_setname_np(pthread_self(), "%s", name);
#else
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
char namebuf[16]; /* Limited to 16 char */
SDL_strlcpy(namebuf, name, sizeof (namebuf));
pthread_setname_np(pthread_self(), namebuf);
}
#endif
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#elif defined(__HAIKU__)
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
char namebuf[B_OS_NAME_LENGTH];
SDL_strlcpy(namebuf, name, sizeof (namebuf));
rename_thread(find_thread(NULL), namebuf);
#endif
#elif HAVE_PTHREAD_SETNAME_NP
#if defined(__NETBSD__)
pthread_setname_np(pthread_self(), "%s", name);
#else
if (pthread_setname_np(pthread_self(), name) == ERANGE) {
char namebuf[16]; /* Limited to 16 char */
SDL_strlcpy(namebuf, name, sizeof(namebuf));
pthread_setname_np(pthread_self(), namebuf);
}
#endif
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#elif defined(__HAIKU__)
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
char namebuf[B_OS_NAME_LENGTH];
SDL_strlcpy(namebuf, name, sizeof(namebuf));
rename_thread(find_thread(NULL), namebuf);
#endif
}
/* NativeClient does not yet support signals.*/
@@ -190,8 +187,7 @@ SDL_ThreadID(void)
return (SDL_threadID)pthread_self();
}
int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
#if __NACL__ || __RISCOS__ || __OS2__
/* FIXME: Setting thread priority does not seem to be supported in NACL */
@@ -290,14 +286,12 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
#endif /* #if __NACL__ || __RISCOS__ */
}
void
SDL_SYS_WaitThread(SDL_Thread * thread)
void SDL_SYS_WaitThread(SDL_Thread *thread)
{
pthread_join(thread->handle, 0);
}
void
SDL_SYS_DetachThread(SDL_Thread * thread)
void SDL_SYS_DetachThread(SDL_Thread *thread)
{
pthread_detach(thread->handle);
}

View File

@@ -25,7 +25,6 @@
#include <pthread.h>
#define INVALID_PTHREAD_KEY ((pthread_key_t)-1)
static pthread_key_t thread_local_storage = INVALID_PTHREAD_KEY;
@@ -55,8 +54,7 @@ SDL_SYS_GetTLSData(void)
return (SDL_TLSData *)pthread_getspecific(thread_local_storage);
}
int
SDL_SYS_SetTLSData(SDL_TLSData *data)
int SDL_SYS_SetTLSData(SDL_TLSData *data)
{
if (generic_local_storage) {
return SDL_Generic_SetTLSData(data);