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
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -39,7 +39,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");
@@ -51,8 +51,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);
@@ -61,8 +60,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;
@@ -78,8 +76,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;
@@ -94,8 +91,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
@@ -123,7 +119,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:
@@ -143,8 +139,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

@@ -23,7 +23,6 @@
#include <errno.h>
#include <pthread.h>
#if !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX && \
!SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
#define FAKE_RECURSIVE_MUTEX 1
@@ -45,7 +44,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
@@ -66,8 +65,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);
@@ -76,8 +74,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;
@@ -111,8 +108,7 @@ SDL_LockMutex(SDL_mutex * mutex)
return 0;
}
int
SDL_TryLockMutex(SDL_mutex * mutex)
int SDL_TryLockMutex(SDL_mutex *mutex)
{
int retval;
int result;
@@ -157,8 +153,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

@@ -26,7 +26,6 @@
#include <sys/time.h>
#include <time.h>
/* Wrapper around POSIX 1003.1b semaphores */
#if defined(__MACOS__) || defined(__IOS__)
@@ -43,7 +42,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");
@@ -56,8 +55,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);
@@ -65,8 +63,7 @@ SDL_DestroySemaphore(SDL_sem * sem)
}
}
int
SDL_SemTryWait(SDL_sem * sem)
int SDL_SemTryWait(SDL_sem *sem)
{
int retval;
@@ -80,8 +77,7 @@ SDL_SemTryWait(SDL_sem * sem)
return retval;
}
int
SDL_SemWait(SDL_sem * sem)
int SDL_SemWait(SDL_sem *sem)
{
int retval;
@@ -99,8 +95,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
@@ -126,9 +121,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);
@@ -175,7 +170,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
}
Uint32
SDL_SemValue(SDL_sem * sem)
SDL_SemValue(SDL_sem *sem)
{
int ret = 0;
@@ -188,11 +183,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

@@ -20,7 +20,6 @@
*/
#include "SDL_internal.h"
#include <pthread.h>
#if HAVE_PTHREAD_NP_H
@@ -56,54 +55,51 @@
#include <kernel/OS.h>
#endif
/* List of signals to mask in the subthreads */
static const int sig_list[] = {
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
SIGVTALRM, SIGPROF, 0
};
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(__MACOS__) || defined(__IOS__)) && 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;
/* do this here before any threads exist, so there's no race condition. */
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
/* do this here before any threads exist, so there's no race condition. */
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
if (!checked_setname) {
void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
#if defined(__MACOS__) || defined(__IOS__)
ppthread_setname_np = (int(*)(const char*)) fn;
#elif defined(__LINUX__)
ppthread_setname_np = (int(*)(pthread_t, const char*)) fn;
#endif
#if defined(__MACOS__) || defined(__IOS__)
ppthread_setname_np = (int (*)(const char *))fn;
#elif defined(__LINUX__)
ppthread_setname_np = (int (*)(pthread_t, const char *))fn;
#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);
@@ -117,44 +113,43 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
return 0;
}
void
SDL_SYS_SetupThread(const char *name)
void SDL_SYS_SetupThread(const char *name)
{
int i;
sigset_t mask;
if (name != NULL) {
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
SDL_assert(checked_setname);
if (ppthread_setname_np != NULL) {
#if defined(__MACOS__) || defined(__IOS__)
#if defined(__MACOS__) || defined(__IOS__)
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
}
/* Mask asynchronous signals for this thread */
@@ -179,8 +174,7 @@ SDL_ThreadID(void)
return (SDL_threadID)pthread_self();
}
int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
#if __RISCOS__
/* FIXME: Setting thread priority does not seem to be supported */
@@ -279,14 +273,12 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
#endif /* #if __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

@@ -24,7 +24,6 @@
#include <pthread.h>
#define INVALID_PTHREAD_KEY ((pthread_key_t)-1)
static pthread_key_t thread_local_storage = INVALID_PTHREAD_KEY;
@@ -54,8 +53,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);