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

@@ -26,12 +26,11 @@
#include "SDL_systhread.h"
#include "../SDL_error_c.h"
SDL_TLSID
SDL_TLSCreate()
{
static SDL_atomic_t SDL_tls_id;
return SDL_AtomicIncRef(&SDL_tls_id)+1;
return SDL_AtomicIncRef(&SDL_tls_id) + 1;
}
void *
@@ -43,11 +42,10 @@ SDL_TLSGet(SDL_TLSID id)
if (storage == NULL || id == 0 || id > storage->limit) {
return NULL;
}
return storage->array[id-1].data;
return storage->array[id - 1].data;
}
int
SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *))
int SDL_TLSSet(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *))
{
SDL_TLSData *storage;
@@ -61,7 +59,7 @@ SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *))
oldlimit = storage ? storage->limit : 0;
newlimit = (id + TLS_ALLOC_CHUNKSIZE);
storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage)+(newlimit-1)*sizeof(storage->array[0]));
storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0]));
if (storage == NULL) {
return SDL_OutOfMemory();
}
@@ -75,13 +73,12 @@ SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *))
}
}
storage->array[id-1].data = SDL_const_cast(void*, value);
storage->array[id-1].destructor = destructor;
storage->array[id - 1].data = SDL_const_cast(void *, value);
storage->array[id - 1].destructor = destructor;
return 0;
}
void
SDL_TLSCleanup()
void SDL_TLSCleanup()
{
SDL_TLSData *storage;
@@ -98,7 +95,6 @@ SDL_TLSCleanup()
}
}
/* This is a generic implementation of thread-local storage which doesn't
require additional OS support.
@@ -107,7 +103,8 @@ SDL_TLSCleanup()
storage this implementation should be improved to be production quality.
*/
typedef struct SDL_TLSEntry {
typedef struct SDL_TLSEntry
{
SDL_threadID thread;
SDL_TLSData *storage;
struct SDL_TLSEntry *next;
@@ -116,7 +113,6 @@ typedef struct SDL_TLSEntry {
static SDL_mutex *SDL_generic_TLS_mutex;
static SDL_TLSEntry *SDL_generic_TLS;
SDL_TLSData *
SDL_Generic_GetTLSData(void)
{
@@ -156,8 +152,7 @@ SDL_Generic_GetTLSData(void)
return storage;
}
int
SDL_Generic_SetTLSData(SDL_TLSData *storage)
int SDL_Generic_SetTLSData(SDL_TLSData *storage)
{
SDL_threadID thread = SDL_ThreadID();
SDL_TLSEntry *prev, *entry;
@@ -199,8 +194,7 @@ SDL_Generic_SetTLSData(SDL_TLSData *storage)
}
/* Non-thread-safe global error variable */
static SDL_error *
SDL_GetStaticErrBuf()
static SDL_error *SDL_GetStaticErrBuf()
{
static SDL_error SDL_global_error;
static char SDL_global_error_str[128];
@@ -210,8 +204,7 @@ SDL_GetStaticErrBuf()
}
#if !SDL_THREADS_DISABLED
static void SDLCALL
SDL_FreeErrBuf(void *data)
static void SDLCALL SDL_FreeErrBuf(void *data)
{
SDL_error *errbuf = (SDL_error *)data;
@@ -284,12 +277,10 @@ SDL_GetErrBuf(void)
#endif /* SDL_THREADS_DISABLED */
}
void
SDL_RunThread(SDL_Thread *thread)
void SDL_RunThread(SDL_Thread *thread)
{
void *userdata = thread->userdata;
int (SDLCALL * userfunc) (void *) = thread->userfunc;
int(SDLCALL * userfunc)(void *) = thread->userfunc;
int *statusloc = &thread->status;
@@ -322,27 +313,27 @@ SDL_RunThread(SDL_Thread *thread)
#undef SDL_CreateThreadWithStackSize
#endif
#if SDL_DYNAMIC_API
#define SDL_CreateThread SDL_CreateThread_REAL
#define SDL_CreateThread SDL_CreateThread_REAL
#define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
#endif
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
SDL_Thread *
SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
const char *name, const size_t stacksize, void *data,
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread)
SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
const char *name, const size_t stacksize, void *data,
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread)
#else
SDL_Thread *
SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
const char *name, const size_t stacksize, void *data)
SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
const char *name, const size_t stacksize, void *data)
#endif
{
SDL_Thread *thread;
int ret;
/* Allocate memory for the thread info structure */
thread = (SDL_Thread *) SDL_calloc(1, sizeof(*thread));
thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread));
if (thread == NULL) {
SDL_OutOfMemory();
return NULL;
@@ -383,13 +374,13 @@ SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
DECLSPEC SDL_Thread *SDLCALL
SDL_CreateThread(int (SDLCALL * fn) (void *),
SDL_CreateThread(int(SDLCALL *fn)(void *),
const char *name, void *data,
pfnSDL_CurrentBeginThread pfnBeginThread,
pfnSDL_CurrentEndThread pfnEndThread)
#else
DECLSPEC SDL_Thread *SDLCALL
SDL_CreateThread(int (SDLCALL * fn) (void *),
SDL_CreateThread(int(SDLCALL *fn)(void *),
const char *name, void *data)
#endif
{
@@ -401,9 +392,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
if (stackhint != NULL) {
char *endp = NULL;
const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10);
if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */
if (hintval > 0) { /* reject bogus values. */
stacksize = (size_t) hintval;
if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */
if (hintval > 0) { /* reject bogus values. */
stacksize = (size_t)hintval;
}
}
}
@@ -416,8 +407,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
}
SDL_Thread *
SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
const size_t stacksize, void *data) {
SDL_CreateThreadInternal(int(SDLCALL *fn)(void *), const char *name,
const size_t stacksize, void *data)
{
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, NULL, NULL);
#else
@@ -426,7 +418,7 @@ SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
}
SDL_threadID
SDL_GetThreadID(SDL_Thread * thread)
SDL_GetThreadID(SDL_Thread *thread)
{
SDL_threadID id;
@@ -439,7 +431,7 @@ SDL_GetThreadID(SDL_Thread * thread)
}
const char *
SDL_GetThreadName(SDL_Thread * thread)
SDL_GetThreadName(SDL_Thread *thread)
{
if (thread) {
return thread->name;
@@ -448,14 +440,12 @@ SDL_GetThreadName(SDL_Thread * thread)
}
}
int
SDL_SetThreadPriority(SDL_ThreadPriority priority)
int SDL_SetThreadPriority(SDL_ThreadPriority priority)
{
return SDL_SYS_SetThreadPriority(priority);
}
void
SDL_WaitThread(SDL_Thread * thread, int *status)
void SDL_WaitThread(SDL_Thread *thread, int *status)
{
if (thread) {
SDL_SYS_WaitThread(thread);
@@ -469,8 +459,7 @@ SDL_WaitThread(SDL_Thread * thread, int *status)
}
}
void
SDL_DetachThread(SDL_Thread * thread)
void SDL_DetachThread(SDL_Thread *thread)
{
if (thread == NULL) {
return;
@@ -483,9 +472,9 @@ SDL_DetachThread(SDL_Thread * thread)
/* all other states are pretty final, see where we landed. */
const int thread_state = SDL_AtomicGet(&thread->state);
if ((thread_state == SDL_THREAD_STATE_DETACHED) || (thread_state == SDL_THREAD_STATE_CLEANED)) {
return; /* already detached (you shouldn't call this twice!) */
return; /* already detached (you shouldn't call this twice!) */
} else if (thread_state == SDL_THREAD_STATE_ZOMBIE) {
SDL_WaitThread(thread, NULL); /* already done, clean it up. */
SDL_WaitThread(thread, NULL); /* already done, clean it up. */
} else {
SDL_assert(0 && "Unexpected thread state");
}